Package net.aifusion.metamodel
Class JavaModelMapper
java.lang.Object
net.aifusion.metamodel.JavaModelMapper
Utility methods to map data structures between java and CIM classes. This class is used internally within Fusion, and
should not be used in application code.
- Author:
- Sharad Singhal
-
Method Summary
Modifier and TypeMethodDescriptionstatic StructureValue
createCimValueFromJavaObject
(CimStructure cimStruct, Object javaObject) Create a StructureValue by introspection of a java objectstatic Object
createJavaObjectForCim
(StructureValue structureValue, Class<?> javaClass) Create an instance of a java class based on values defined in a structure value.
See Cim2Java for required constructor (use non-structurevalue constructor)getAnnotatedMethods
(Class<?> c) Get all annotated methods from a class (or superclasses/interfaces)static String
getCimClassName
(Class<?> javaClass) Obtain the CIM class name corresponding to some annotated java class.static String
getCimClassName
(String javaClassName) Get the CIM class name corresponding to an annotated java classstatic ElementType
getCimElementType
(Class<?> javaClass) Get the CIM element type (Enumeration, Interface, Structure or Class) corresponding to a java classstatic String
getCimSuperClassName
(Class<?> javaClass) Get the CIM name of the superType of a java class.static String
getClassVersion
(Class<?> javaClass) Get the version associated with with an annotated java classstatic String
getFeatureName
(Method javaMethod) Get the name of the CIM feature represented by an exported Java Methodstatic Class
<?> getFeatureType
(Method javaMethod) Get the java type for a CIM feature represented by an exported Java Method
This is the java type for the property getter or setter, or type returned by a methodstatic String
Get the name of the java class referenced by a property or returned by a methodstatic String
Get the name of the java class referenced by method parameterstatic String
Get the MappingString{} qualifier for an exported method that returns complex values or referencesstatic String
Get the MappingString{} qualifier for a method parameter that represents a complex value or referencestatic NameSpacePath
getNameSpacePathFromClass
(Class<?> javaClass) Get a namespace path from an annotated java classstatic ObjectPath
getObjectPathFromClass
(Class<?> javaClass) Get the object path corresponding to a Java class.static String
getPackagePath
(Class<?> javaClass) Get the package path annotation needed on MOF to allow binding to a java classstatic String
Get the CIM class referenced by a java method defining a complex property or methodstatic String
Get the CIM class referenced by a java parameter defining a complex property (or method)static DataValue
invokeMethod
(CimMethod cimMethod, Object boundObject, Method boundMethod, List<CimParameter> cimParameters) Invoke a Java method bound to a CIM Methodstatic boolean
Test if an exported java method represents a property getterstatic boolean
isPropertyMethod
(Method javaMethod) Test if an exported method represents a CIM propertystatic boolean
Test if an exported java method represents a property setterstatic boolean
isStructure
(Class<?> javaClass) Check if a class can map to a CIM Structurestatic DataValue
readPropertyValue
(CimProperty cimProperty, Method getter, Object javaObject) Read a property value from a Java Object.static void
validateEnumBinding
(CimEnumeration cimEnum, Class<?> javaEnum) Validate that a java Enum can be bound to a CimEnumerationstatic Method
validateMethodBinding
(CimMethod cimMethod, Object implObject) Validate that a java object implements the given CIM Methodstatic void
validateMethodBinding
(CimMethod cimMethod, Method javaMethod, Object implObject) Validate that a java method can be bound to a CIM Methodstatic Method[]
validatePropertyBinding
(CimProperty cimProperty, Object implObject) Validate that an implementation object implements the given CIM propertystatic void
validatePropertyBinding
(CimProperty cimProperty, Method getter, Method setter, Object implObject) Validate that a pair of Java methods (getter and setter pair) can be bound to a cim propertystatic Method
validateStaticMethodBinding
(CimMethod m, Class<?> javaClass) Validate that a java class implements the given static CIM Methodstatic Method[]
validateStaticPropertyBinding
(CimProperty p, Class<?> javaClass) Validate that a java class implements the given static CIM Propertystatic void
writePropertyValue
(CimProperty cimProperty, Method setter, Object javaObject, DataValue value) Write a property value to a java object.
-
Method Details
-
getAnnotatedMethods
Get all annotated methods from a class (or superclasses/interfaces)- Parameters:
c
- - class to introspect- Returns:
- - vector containing all annotated methods
-
getPackagePath
Get the package path annotation needed on MOF to allow binding to a java class- Parameters:
javaClass
- - java class (must be non-null) to introspect- Returns:
- - string containing package path
-
getCimElementType
Get the CIM element type (Enumeration, Interface, Structure or Class) corresponding to a java class- Parameters:
javaClass
- - class to introspect- Returns:
- - Element type for the class
-
isStructure
Check if a class can map to a CIM Structure- Parameters:
javaClass
- - java class to check- Returns:
- - true if the given java class can be linked to a CIM structure, false otherwise
-
getCimClassName
Get the CIM class name corresponding to an annotated java class- Parameters:
javaClassName
- - name of the java class to introspect- Returns:
- - name of the corresponding CIM element in Schema_ClassName form. Null if the class is not annotated
- See Also:
-
getCimClassName
Obtain the CIM class name corresponding to some annotated java class.- Parameters:
javaClass
- - java class to introspect- Returns:
- - name of the corresponding CIM element in schema_className form. Returns null if the class does not have an @Export annotation
-
getCimSuperClassName
Get the CIM name of the superType of a java class. The java class hierarchy is traversed to find the nearest annotated superclass, and its CIM name is returned.- Parameters:
javaClass
- - java class to introspect- Returns:
- - CIM name of the nearest CIM superType, if any. Null returned if no CIM superType exists
-
getFeatureName
Get the name of the CIM feature represented by an exported Java Method- Parameters:
javaMethod
- - exported Java method to test- Returns:
- - name of the CIM feature (property or method) represented by this java method. Null if the java method is not exported
-
getFeatureType
Get the java type for a CIM feature represented by an exported Java Method
This is the java type for the property getter or setter, or type returned by a method- Parameters:
javaMethod
- - java method representing the feature- Returns:
- - java type corresponding to the feature
-
getRefCimClass
Get the CIM class referenced by a java method defining a complex property or method- Parameters:
m
- - java method to introspect- Returns:
- - CIM class name. Empty string for non-complex properties or methods
-
getRefCimClass
Get the CIM class referenced by a java parameter defining a complex property (or method)- Parameters:
p
- - java parameter to introspect- Returns:
- - CIM class name. Empty for non-complex parameters
-
getMappedJavaClassName
Get the name of the java class referenced by a property or returned by a method- Parameters:
m
- - Method to introspect- Returns:
- - java class name for complex properties, else empty string
-
getMappedJavaClassName
Get the name of the java class referenced by method parameter- Parameters:
p
- - parameter to introspect- Returns:
- - java class name for complex properties, else empty string
-
getMappingString
Get the MappingString{} qualifier for an exported method that returns complex values or references- Parameters:
m
- - method to introspect- Returns:
- - MappingString qualifier. Empty string if the method is not a complex value or a reference
-
getMappingString
Get the MappingString{} qualifier for a method parameter that represents a complex value or reference- Parameters:
p
- - parameter to introspect- Returns:
- - mappingString qualifier. Empty string if the parameter is not complex or reference
-
getClassVersion
Get the version associated with with an annotated java class- Parameters:
javaClass
- - java class to introspect- Returns:
- - CIM version of the class
-
isPropertyMethod
Test if an exported method represents a CIM property- Parameters:
javaMethod
- - exported method to test- Returns:
- - true if this method is a CIM property, false otherwise
-
isGetter
Test if an exported java method represents a property getter- Parameters:
javaMethod
- - exported method to test- Returns:
- - true if the method is a getter, false otherwise
-
isSetter
Test if an exported java method represents a property setter- Parameters:
javaMethod
- - java method to test- Returns:
- - true if the method is a property setter, false otherwise
-
getObjectPathFromClass
Get the object path corresponding to a Java class. Note that the class must be bound to a CIM element to be accessible via the object path- Parameters:
javaClass
- - java class to introspect- Returns:
- - object path corresponding to the corresponding NamedElement. Null if the java class is not an annotated class
-
getNameSpacePathFromClass
Get a namespace path from an annotated java class- Parameters:
javaClass
- - java class to be introspected- Returns:
- - namespace path from the java annotation
-
createJavaObjectForCim
Create an instance of a java class based on values defined in a structure value.
See Cim2Java for required constructor (use non-structurevalue constructor)- Parameters:
structureValue
- - structure value to use in the constructorjavaClass
- - java class to use for creating the object- Returns:
- - constructed object
- See Also:
-
createCimValueFromJavaObject
public static StructureValue createCimValueFromJavaObject(CimStructure cimStruct, Object javaObject) Create a StructureValue by introspection of a java object- Parameters:
cimStruct
- - expected CimStructure for the objectjavaObject
- - java object to convert- Returns:
- StructureValue based on the java object
-
validatePropertyBinding
Validate that an implementation object implements the given CIM property- Parameters:
cimProperty
- - Cim Property to validateimplObject
- - java object to validate- Returns:
- - a two element Java Method array containing the getter[0] and the setter[1] methods
-
validateStaticPropertyBinding
Validate that a java class implements the given static CIM Property- Parameters:
p
- - CimProperty to checkjavaClass
- - java class to use- Returns:
- - a two element Java Method array containing the getter[0] and the setter[1] methods
-
validatePropertyBinding
public static void validatePropertyBinding(CimProperty cimProperty, Method getter, Method setter, Object implObject) Validate that a pair of Java methods (getter and setter pair) can be bound to a cim property- Parameters:
cimProperty
- - CimProperty to be used for bindinggetter
- - getter method to be boundsetter
- - setter method to be boundimplObject
- - Java implementation object to be used for invocation
-
readPropertyValue
public static DataValue readPropertyValue(CimProperty cimProperty, Method getter, Object javaObject) Read a property value from a Java Object. Note that this method assumes that the getter has been validated when the property was bound to the java object, and does not re-check the data types or method arguments- Parameters:
cimProperty
- - Cim property to use for reading valuegetter
- - getter method associated with the propertyjavaObject
- - Java Implementation object bound to the property- Returns:
- - DataValue containing the property value
-
writePropertyValue
public static void writePropertyValue(CimProperty cimProperty, Method setter, Object javaObject, DataValue value) Write a property value to a java object. Note that this method assumes that the setter has been validated when the property was bound to the java object, and does not re-check the data types or method arguments- Parameters:
cimProperty
- - Cim Property bound to this settersetter
- - setter method in the java objectjavaObject
- - java implementation objectvalue
- - Cim DataValue to write to the object
-
validateStaticMethodBinding
Validate that a java class implements the given static CIM Method- Parameters:
m
- - CimMethod to checkjavaClass
- - java class to use- Returns:
- - corresponding class method
-
validateMethodBinding
Validate that a java object implements the given CIM Method- Parameters:
cimMethod
- - Cim Method to validateimplObject
- - java object to validate- Returns:
- - Java Method mapped to the Cim Method in the implementation object
-
validateEnumBinding
Validate that a java Enum can be bound to a CimEnumeration- Parameters:
cimEnum
- - Cim Enumeration to validatejavaEnum
- - Java Enumeration to validate
-
validateMethodBinding
Validate that a java method can be bound to a CIM Method- Parameters:
cimMethod
- - CimMethod to be used for bindingjavaMethod
- - Java Method to be used for bindingimplObject
- - implementation object to be used for invocation.
-
invokeMethod
public static DataValue invokeMethod(CimMethod cimMethod, Object boundObject, Method boundMethod, List<CimParameter> cimParameters) Invoke a Java method bound to a CIM Method- Parameters:
cimMethod
- - CIM Method being invokedboundObject
- - bound java objectboundMethod
- - bound java methodcimParameters
- - CIM parameters to be used in this method call- Returns:
- - Data Value returned from the method. Null if the method returns void
-