Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.api.mdr/1 1.4.22
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

## Package org.netbeans.api.xmi

API classes and interfaces that are used for import/export of XMI documents into/from a JMI-compliant repository.

See:
Description

Interface Summary
XMIReferenceProvider | Implementation of this interface can be passed to XMI producers/writers (using `XMIOutputConfig.setReferenceProvider(org.netbeans.api.xmi.XMIReferenceProvider)` method) to enable custom controling of target documents the written object should go into and what XMI ID they should use.
XMIReferenceResolver | Implementation of this interface can be passed to XMI reader/consumer (using `XMIInputConfig.setReferenceResolver(org.netbeans.api.xmi.XMIReferenceResolver)` method) to enable custom resolving of hrefs.
XMIReferenceResolver.Client |

Class Summary
XMIInputConfig | Configuration class for objects taking XMI as input (e.g.
XMIOutputConfig | Configuration class for objects producing XMI as output (e.g.
XMIReader | Base class for enhanced XMI readers.
XMIReaderFactory | Factory class for creating instances of XMI reader objects.
XMIReferenceProvider.XMIReference | Simple structure for representing XMI references to elements corresponding to an object.
XMIWriter | Base class for enhanced XMI writers.
XMIWriterFactory | Factory for XMI writers.

## Package org.netbeans.api.xmi Description

API classes and interfaces that are used for import/export of XMI documents into/from a JMI-compliant repository. Below is a description of the most common use-cases.

### Reading XMI

XMIReader instances can be used for reading XMI documents. XMIReader class extends the standard javax.jmi.xmi.XmiReader interface and is a little more flexible (allows plugging of custom XMIReferenceResolver implementations via XMIInputConfig for custom handling of references (href's) in the XMI documents being read).

Here is a sample code that creates an empty instance of MOF and reads in an XMI containing some MOF metamodel:

        // get the default repository
        MDRepository repository = MDRManager.getDefault().getDefaultRepository();

        // start a write transaction
        boolean fail = true;
        repository.beginTrans(true);
        try {
            // create a new MOF extent
            RefPackage mof = repository.createExtent("MyMOFExtent");
            // create an XMIReader
            XMIReader reader = XMIReaderFactory.getDefault().createXMIReader();
            // read the document
            reader.read(new File("myxmifile.xmi").toURL().toString(), mof);
            // everything succeeded => set fail flag to false
            fail = false;
        } catch (Exception e) {
            System.out.println("Fatal error reading XMI.");
            e.printStackTrace();
        } finally {
            // commit/rollback the transaction
            repository.endTrans(fail);
        }

### Writing XMI

Writing is similar to reading. The following code writes content of "MyMOFExtent" to an XMI file:

        // get the default repository
        MDRepository repository = MDRManager.getDefault().getDefaultRepository();

        // declare an output stream
        FileOutputStream out = null;

        // start a read-only transaction
        repository.beginTrans(false);
        try {
            // get the extent
            RefPackage mof = repository.getExtent("MyMOFExtent");
            // create an XMIWriter
            XMIWriter writer = XMIWriterFactory.getDefault().createXMIWriter();
            // open a stream
            out = new FileOutputStream("myxmifile.xml");
            // export the document (default version of XMI = 1.2)
            writer.write(out, mof, null);
        } catch (Exception e) {
            System.out.println("Fatal error reading XMI.");
            e.printStackTrace();
        } finally {
            // release the transaction
            repository.endTrans();
            // close the stream if necessary
            if (out != null) {
                try {
                   out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.api.mdr/1 1.4.22
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

Built on December 7 2006. | Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.