Class JavaModelMapper

java.lang.Object
net.aifusion.metamodel.JavaModelMapper

public class JavaModelMapper extends Object
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 Details

    • getAnnotatedMethods

      public static Vector<Method> getAnnotatedMethods(Class<?> c)
      Get all annotated methods from a class (or superclasses/interfaces)
      Parameters:
      c - - class to introspect
      Returns:
      - vector containing all annotated methods
    • getPackagePath

      public static String getPackagePath(Class<?> javaClass)
      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

      public static ElementType getCimElementType(Class<?> javaClass)
      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

      public static boolean isStructure(Class<?> javaClass)
      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

      public static String getCimClassName(String javaClassName)
      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

      public static String getCimClassName(Class<?> javaClass)
      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

      public static String getCimSuperClassName(Class<?> javaClass)
      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

      public static String getFeatureName(Method javaMethod)
      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

      public static 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 method
      Parameters:
      javaMethod - - java method representing the feature
      Returns:
      - java type corresponding to the feature
    • getRefCimClass

      public static String getRefCimClass(Method m)
      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

      public static String getRefCimClass(Parameter p)
      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

      public static String getMappedJavaClassName(Method m)
      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

      public static String getMappedJavaClassName(Parameter p)
      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

      public static String getMappingString(Method m)
      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

      public static String getMappingString(Parameter p)
      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

      public static String getClassVersion(Class<?> javaClass)
      Get the version associated with with an annotated java class
      Parameters:
      javaClass - - java class to introspect
      Returns:
      - CIM version of the class
    • isPropertyMethod

      public static boolean isPropertyMethod(Method javaMethod)
      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

      public static boolean isGetter(Method javaMethod)
      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

      public static boolean isSetter(Method javaMethod)
      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

      public static ObjectPath getObjectPathFromClass(Class<?> javaClass)
      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

      public static NameSpacePath getNameSpacePathFromClass(Class<?> javaClass)
      Get a namespace path from an annotated java class
      Parameters:
      javaClass - - java class to be introspected
      Returns:
      - namespace path from the java annotation
    • createJavaObjectForCim

      public static 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)
      Parameters:
      structureValue - - structure value to use in the constructor
      javaClass - - 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 object
      javaObject - - java object to convert
      Returns:
      StructureValue based on the java object
    • validatePropertyBinding

      public static Method[] validatePropertyBinding(CimProperty cimProperty, Object implObject)
      Validate that an implementation object implements the given CIM property
      Parameters:
      cimProperty - - Cim Property to validate
      implObject - - java object to validate
      Returns:
      - a two element Java Method array containing the getter[0] and the setter[1] methods
    • validateStaticPropertyBinding

      public static Method[] validateStaticPropertyBinding(CimProperty p, Class<?> javaClass)
      Validate that a java class implements the given static CIM Property
      Parameters:
      p - - CimProperty to check
      javaClass - - 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 binding
      getter - - getter method to be bound
      setter - - setter method to be bound
      implObject - - 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 value
      getter - - getter method associated with the property
      javaObject - - 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 setter
      setter - - setter method in the java object
      javaObject - - java implementation object
      value - - Cim DataValue to write to the object
    • validateStaticMethodBinding

      public static Method validateStaticMethodBinding(CimMethod m, Class<?> javaClass)
      Validate that a java class implements the given static CIM Method
      Parameters:
      m - - CimMethod to check
      javaClass - - java class to use
      Returns:
      - corresponding class method
    • validateMethodBinding

      public static Method validateMethodBinding(CimMethod cimMethod, Object implObject)
      Validate that a java object implements the given CIM Method
      Parameters:
      cimMethod - - Cim Method to validate
      implObject - - java object to validate
      Returns:
      - Java Method mapped to the Cim Method in the implementation object
    • validateEnumBinding

      public static void validateEnumBinding(CimEnumeration cimEnum, Class<?> javaEnum)
      Validate that a java Enum can be bound to a CimEnumeration
      Parameters:
      cimEnum - - Cim Enumeration to validate
      javaEnum - - Java Enumeration to validate
    • validateMethodBinding

      public static void validateMethodBinding(CimMethod cimMethod, Method javaMethod, Object implObject)
      Validate that a java method can be bound to a CIM Method
      Parameters:
      cimMethod - - CimMethod to be used for binding
      javaMethod - - Java Method to be used for binding
      implObject - - 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 invoked
      boundObject - - bound java object
      boundMethod - - bound java method
      cimParameters - - CIM parameters to be used in this method call
      Returns:
      - Data Value returned from the method. Null if the method returns void