PROPOSAL (round 2): Extensions to MDR XMI API
Martin Matula <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, based on many valuable comments, I have reworked the proposed changes to the XMI API in MDR. Attached is the source code and javadoc of the new API. Here is a short description of the proposed changes: 1) remove current XMIReader and XMIWriter abstract classes 2) add XMIReaderFactory and XMIWriterFactory abstract classes - implementations of these classes will be registered in lookup. 3) create new XMIReader interface - this interface will inherit from org.xml.sax.ContentHandler 4) create new XMIWriter interface - write method of this interface will take ContentHandler as one of its parameters 5) I have made slight changes to XMIReferenceProvider and XMIHRefResolver interfaces. These interfaces can be added to XMIReader/XMIWriter using XMIReader/Writer properties (key-value map). Implementation of the new API: Our XMLReaderFactoryImpl will besides XMLReaderFactory interface implement also javax.jmi.xmi.XmiReader interface. Read methods of this interface will be implemented by calling this.createXMIReader().read(...). Similarly it will be done for XMIWriterFactoryImpl. Usage of the new API: 1) for using the standard functionality of XMIReader/XMIWriter (defined in JMI intefaces), user can use: org.openide.util.Lookup.getDefault().lookup(javax.jmi.xmi.XmiReader.class), etc.... 2) for using extended functionality of XMIReader one will be able to do the following: // get new instance of XMIReader XMIReader xmiReader = XMIReaderFactory.getDefault().createXMIReader(); // add extent into which I want to read the XMI file xmiReader.getExtents().add(<targetExtent>); // add XMIHRefResolver xmiReader.getProperties().put(XMIHRefResolver.class, <myHRefResolver>); // read the XMI document xmiReader.read(<input source>); 3) for using extended functionality of XMIWriter one will be able to do the following: // get new instance of XMIWriter XMIWriter xmiWriter = XMIWriterFactory.getDefault().createXMIWriter(); // add objects that I want to serialize xmiWriter.getObjects().add(<myPackageExtent>); // add XMIReferenceProvider xmiWriter.getProperties().put(XMIReferenceProvider.class, <myReferenceProvider>); // write the XMI file using the default ContentHandler xmiWriter.write(<myOutputTarget>); 4) one can chain XMIReader and XMIWriter. The simplest example would be to chain them directly which enables copying from one extent to another: xmiWriter.write(<myOutputTarget>, xmiReader); Discussion: - note that for representing output I have created a class corresponding to InputSource representing input - OutputTarget. This is to enable users to pass streams as well as systemId (document URI). Document URI is important for getting XMIWriter to work well with XMIReferenceProvider. Is it a good idea or it can be solved more ellegantly? - XMIHRefResolver.resolve now receives also a pointer to XMIReader. This is to make it possible for the resolver to clone the instance of XMIReader (this will make a new copy with preserved properties and extents) and read a new XMI file if necessary. Any comments are very welcome. Martin --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
src.zip
(application/x-zip-compressed, 7.5 KB) - not displayed
javadoc.zip
(application/x-zip-compressed, 29.9 KB) - not displayed