![]() |
|||||
|
Chapter 3. JMI Mapping OverviewThe JMI accessor is an implementation of the [17] specification. The JMI accessor is layered on top of the openMDX generic accessor as shown in Figure 3-1. The JMI externalizer of the MOF repository supports the generation of JMI interfaces and implementations as defined by the JMI specification. The JMI externalizer supports two different flavors of JMI: a) JDK compliant, b) .NET compliant which uses the .NET interfaces and classes for collections and primitive types instead of the JDK classes. The JMI specification defines the purpose and scope of JMI: "The JavaT Metadata Interface (JMI) Specification defines a dynamic, platform-neutral infrastructure that enables the creation, storage, access, discovery, and exchange of metadata. JMI is based on the Meta Object Facility (MOF) specification from the Object Management Group (OMG), an industry-endorsed standard for metadata management. The MOF standard provides an open-ended information modeling capability, and consists of a base set of metamodeling constructs used to describe technologies and application domains, and a mapping of those constructs to CORBA IDL (Interface Definition Language) for automatically generating model-specific APIs. The MOF also defines a reflective programming capability that allows for applications to query a model at run time to determine the structure and semantics of the modeled system. JMI defines a Java mapping for the MOF. As the Java language mapping to MOF, JMI provides a common Java programming model for metadata access for the Java platform. JMI provides a natural and easy-to-use mapping from a MOF-compliant data abstraction (usually defined in UML) to the Java programming language. Using JMI, applications and tools which specify their metamodels using MOF-compliant Unified Modeling Language (UML) can have the Java interfaces to the models automatically generated. Further, metamodel and metadata interchange via XML is enabled by JMI's use of the XML Metadata Interchange (XMI) specification, an XML-based mechanism for interchanging metamodel information among applications. Java applications can create, update, delete, and retrieve information contained in a JMI compliant metadata service. The flexibility and extensibility of the MOF allows JMI to be used in a wide range of usage scenarios." As described the scope of JMI is metadata interfaces. However, as described in [], application-models (Level M1) modeled in UML are mapped according to the 'UML Profile for MOF' to MOF-compliant models. Having a MOF-compliant application-level model allows to apply the MOF-to-JMI mapping. The MOF-to-JMI mapping has been extended by the following features:
The JMI APIs has a three-layered approach to manage objects:
Package Objects and Package CreationA package object is little more than a 'directory' of operations that give access to the classes described by the model. The outer most package extent (a.k.a. outer most extent) represents the "root" package. All other objects (i.e., instance objects, class proxies, associations, and (nested) package objects) are contained within some outer most extent. Class Proxy ObjectsA class proxy object serves a number of purposes:
The interface of a class proxy object provides operations for accessing and updating the classifier scoped attribute state. The interface also provides factory operations that allows the client to create instance objects. Instance ObjectsAn instance object holds the state corresponding to the instance-scoped attributes, and any other "hidden" state implied by the class specification. Generally speaking, many instance objects can exist within a given package object. Instance objects are always tied to a class proxy object. The class proxy provides a factory operation for creating instance objects. When an instance object is created, it is automatically added to the class proxy container. An instance is removed from the container when it is destroyed. The interface for an instance object provides:
Association ObjectsAn association object holds a collection of links (i.e. the link set) corresponding to an association defined in the metamodel. The association object is a 'static' container object (similar to a class proxy object) that is contained by a package object. Its interface provides:
NOTE: Association objects are NOT supported by the openMDX JMI mapping. All assocations between objects must be managed through references. Figure 3-2 shows the mapping of a UML model to Java files.
JMI Mapping - PackageEach model is mapped to a package file as shown in Figure 3-3. For each class a corresponding getter is created. The returned class is associated with the package and therefore knows the accessor. A package is created an initialized as shown below: Example 3-1. Initializing the JMI package. RefPackage rootPkg = new RefRootPackage_1( manager, // manager used for object management (get, create, modify) null, // impls null // context ); lab1Package lab1Pkg = (lab1Package)rootPkg.refPackage("org:openmdx:example:lab1"); The root package has to be initialized only once. Based on the provided manager, the root package creates a basic accessor which is used for all object management (get, create, modify). The root package serves as factory for retrieving model-specific packages which are retrieved by refPackage(). All objects managed by the JMI package (class-level and instance-level objects) delegate to the basic accessor of the root package. This allows a consistent unit of work policy even if multiple accessors delegate to the same manager. As shown in the figure each instance-level JMI object wraps a RefObject which is managed by the basic accessor. Generic objects retrieved from the generic accessor are marshalled (by the root package) to JMI objects, JMI objects forwarded to the generic accessor are marshalled to generic objects.. Units of work and transactions are controlled by the manager. |
||||