|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
MDRepository | Interface for accessing content of a metadata repository. |
MDRObject | Interface implemented by each repository object (besides the standard JMI interfaces). |
Class Summary | |
DTDProducer | DTD generation utility. |
JMIMapper | JMI mapping utility. |
JMIStreamFactory | Class used by JMI mapper to obtain output streams for generating JMI interfaces. |
MDRManager | Entry point to the metadata repositories. |
Exception Summary | |
CreationFailedException | Exception thrown when creation of a new repository package instance fails. |
API classes and interfaces that serve as an entry point to a metadata repository. The fundamental classes in this regard are MDRManager and MDRepository.
MDRManager is used to access repositories (represented by instances of MDRepository, these can then be used to access instances of MOF metamodels (represented by javax.jmi.reflect.RefPackage instances corresponding to package proxies for outermost packages of the metamodels). MDRManager is a singleton. There can be several repositories in the system (accessible via MDRManager) and each repository may contain any number of instances of any number of metamodels.
// get default repository MDRepository repository = MDRManager.getDefault().getDefaultRepository(); // create a new instance of MOF metamodel - name it MyInstanceOfMOF RefPackage mof = null; try { mof = repository.createExtent("MyInstanceOfMOF"); } catch (CreationFailedException e) { // handle the failure - happens if extent (i.e. metamodel instance) named // MyInstanceOfMOF already exists in the repository, or if some other fatal // error occurs ... } ...
// get default repository MDRepository repository = MDRManager.getDefault().getDefaultRepository(); // get an extent named MyInstanceOfMOF RefPackage mof = repository.getExtent("MyInstanceOfMOF"); if (mof == null) { // the previous call returned null - it means that an extent with a given // name was not found System.out.println("Extent named MyInstanceOfMOF not found in the repository."); ... } ...
When working with transactions it is important to strictly enforce the following pattern:
It is essential to use transactions in multithreaded applications especially when iterating through the content of collections returned from JMI calls (since these collections are live) to avoid concurrent modifications. Here is an example code that iterates through all class proxies in a given extent and uses a read-only transaction to ensure that the collection is not modified by other thread during the iteration:
// get the default repository MDRepository repository = MDRManager.getDefault().getDefaultRepository(); // start a read-only transaction repository.beginTrans(false); try { // get an extent named MyInstanceOfMOF (assuming that this extent was already created by // other part of the application RefPackage mof = repository.getExtent("MyInstanceOfMOF"); for (Iterator it = mof.refAllClasses(); it.hasNext();) { RefClass clsProxy = (RefClass) it.next(); // print name of the class proxy meta-object System.out.println(((MofClass) clsProxy.refMetaObject()).getName()); } } finally { // release the transaction repository.endTrans(); }
Also for a more complete example of an application that uses MDR to load UML metamodel, instantiate it in the repository, load an UML model from XMI to the instance of UML metamodel, transform it to MOF (into an instance of MOF metamodel) and serialize it to XMI as an instance of MOF, please refer to the source code of the Main class of UML2MOF tool.
|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |