Author: tfmorris
Date: 2007-06-08 00:50:06-0700
New Revision: 12779
Modified:
trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java
trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java
trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java
trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java
trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java
Log:
Issue 4777 - Refactor XMI writer
Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java?view=diff&rev=12779&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java (original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/MDRModelImplementation.java 2007-06-08 00:50:06-0700
@@ -25,6 +25,7 @@
package org.argouml.model.mdr;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.Writer;
import java.net.URL;
import java.util.Collections;
@@ -603,29 +604,29 @@
return theKindsObject;
}
- /*
- * @see org.argouml.model.ModelImplementation#getVisibilityKind()
- */
+
public VisibilityKind getVisibilityKind() {
return theKindsObject;
}
- /*
- * @see org.argouml.model.ModelImplementation#getXmiReader()
- */
+
public XmiReader getXmiReader() throws UmlException {
XmiReader reader = new XmiReaderImpl(this, umlPackage);
return reader;
}
-
- /*
- * @see org.argouml.model.ModelImplementation#getXmiWriter(Object, Writer, String)
- */
+
+ @SuppressWarnings("deprecation")
public XmiWriter getXmiWriter(Object model, Writer writer, String version)
throws UmlException {
return new XmiWriterMDRImpl(this, model, writer, version);
}
+
+ public XmiWriter getXmiWriter(Object model, OutputStream stream,
+ String version) throws UmlException {
+ return new XmiWriterMDRImpl(this, model, stream, version);
+ }
+
/**
* @return the collection of model elements which make up the profile.
*/
Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java?view=diff&rev=12779&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java (original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java 2007-06-08 00:50:06-0700
@@ -126,31 +126,15 @@
modelPackage = mp;
}
- /**
- * Parses a given inputsource as an XMI file conforming to our metamodel.
- *
- * @param pIs
- * The input source for parsing.
- * @return a collection of top level ModelElements
- * @throws UmlException
- * if there is a problem
+
+ /*
+ * @see org.argouml.model.XmiReader#parse(org.xml.sax.InputSource)
*/
public Collection parse(InputSource pIs) throws UmlException {
return parse(pIs, false);
}
- /**
- * Parses a given inputsource as an XMI file conforming to our metamodel.
- *
- * @param pIs
- * The input source for parsing.
- * @param profile
- * true if the model is a profile model. This will be read into a
- * separate extent.
- * @return a collection of top level ModelElements
- * @throws UmlException
- * if there is a problem
- *
+ /*
* @see org.argouml.model.XmiReader#parse(org.xml.sax.InputSource, boolean)
*/
public Collection parse(InputSource pIs, boolean profile)
@@ -375,8 +359,9 @@
return elements;
}
- /**
- * @return the map
+
+ /*
+ * @see org.argouml.model.XmiReader#getXMIUUIDToObjectMap()
*/
public Map getXMIUUIDToObjectMap() {
if (resolver != null) {
@@ -647,4 +632,9 @@
public int getIgnoredElementCount() {
return ignoredElementCount;
}
+
+
+ public String getTagName() {
+ return "XMI";
+ }
}
Modified: trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java?view=diff&rev=12779&p1=trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java&p2=trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java (original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/XmiWriterMDRImpl.java 2007-06-08 00:50:06-0700
@@ -51,8 +51,8 @@
* could easily create a Writer from an OutputStream, but the reverse is not
* true.
*
- * TODO: Change interface to use OutputStream instead of Writer and change this
- * to match
+ * TODO: The old Writer based interface can be removed when the deprecated
+ * ModelImplementation.getXmiWriter is removed.
*
* @author lmaitre
*
@@ -69,6 +69,8 @@
private Writer writer;
+ private OutputStream oStream;
+
private static final String ENCODING = "UTF-8";
private static final String XMI_VERSION = "1.2";
@@ -84,8 +86,30 @@
*/
private static final boolean WRITE_ALL = false;
+
+ /*
+ * Private constructor for common work needed by both public
+ * constructors.
+ */
+ private XmiWriterMDRImpl(MDRModelImplementation theParent, Object theModel,
+ String version) {
+ if (theModel == null) {
+ throw new IllegalArgumentException("A model must be provided");
+ }
+ if (theParent == null) {
+ throw new IllegalArgumentException("A parent must be provided");
+ }
+ this.modelImpl = theParent;
+ this.model = theModel;
+ config = new OutputConfig();
+ config.setEncoding(ENCODING);
+ config.setReferenceProvider(new XmiReferenceProviderImpl(modelImpl
+ .getObjectToId()));
+ config.setHeaderProvider(new XmiHeaderProviderImpl(version));
+ }
+
/**
- * Create an XMI writer for the given model or extent.
+ * Create an XMI writer for the given model.
*
* @param theParent
* The ModelImplementation
@@ -96,31 +120,43 @@
* The writer to write to
* @param version the ArgoUML version
* @throws IllegalArgumentException if no writer provided
+ * @deprecated for 0.25.4 by tfmorris. Use other constructor.
*/
public XmiWriterMDRImpl(MDRModelImplementation theParent, Object theModel,
Writer theWriter, String version) {
+ this(theParent, theModel, version);
if (theWriter == null) {
throw new IllegalArgumentException("A writer must be provided");
}
- if (theModel == null) {
- throw new IllegalArgumentException("A model must be provided");
- }
- if (theParent == null) {
- throw new IllegalArgumentException("A parent must be provided");
+ writer = theWriter;
+ }
+
+ /**
+ * Create an XMI writer for the given model.
+ *
+ * @param theParent
+ * The ModelImplementation
+ * @param theModel
+ * The Model to write. If null, write all top-level model
+ * elements.
+ * @param theStream
+ * The OutputStream to write to.
+ * @param version
+ * the ArgoUML version
+ * @throws IllegalArgumentException
+ * if no output stream is provided
+ * @since 0.25.4
+ */
+ public XmiWriterMDRImpl(MDRModelImplementation theParent, Object theModel,
+ OutputStream theStream, String version) {
+ this(theParent, theModel, version);
+ if (theStream == null) {
+ throw new IllegalArgumentException("A writer must be provided");
}
- this.modelImpl = theParent;
- this.model = theModel;
- this.writer = theWriter;
- config = new OutputConfig();
- config.setEncoding(ENCODING);
- config.setReferenceProvider(new XmiReferenceProviderImpl(modelImpl
- .getObjectToId()));
- config.setHeaderProvider(new XmiHeaderProviderImpl(version));
+ oStream = theStream;
}
- /*
- * @see org.argouml.model.XmiWriter#write()
- */
+
public void write() throws UmlException {
XMIWriter xmiWriter = XMIWriterFactory.getDefault().createXMIWriter(
config);
@@ -146,8 +182,14 @@
+ " top level model elements");
}
- WriterOuputStream wos = new WriterOuputStream(writer);
- xmiWriter.write(wos, elements, XMI_VERSION);
+ OutputStream stream;
+ if (oStream == null) {
+ stream = new WriterOuputStream(writer);
+ } else {
+ stream = oStream;
+ }
+
+ xmiWriter.write(stream, elements, XMI_VERSION);
} catch (IOException e) {
throw new UmlException(e);
}
@@ -156,10 +198,11 @@
/**
* Class which wraps a Writer into an OutputStream.
*
- * (this can go away when/if org.argouml.model.XmiWriter
- * interface changes - see ToDo in header)
+ * TODO: This entire class can go away when we remove
+ * the Writer based interface.
*
* @author lmaitre
+ * @deprecated for 0.25.4 by tfmorris
*/
public class WriterOuputStream extends OutputStream {
Modified: trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java?view=diff&rev=12779&p1=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java&p2=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java (original)
+++ trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementation.java 2007-06-08 00:50:06-0700
@@ -24,6 +24,9 @@
package org.argouml.model.mdr;
+import java.io.OutputStream;
+import java.io.Writer;
+
import junit.framework.TestCase;
import org.argouml.model.UmlException;
@@ -292,7 +295,8 @@
* @throws UmlException If an error occur
*/
public void testGetXmiWriter() throws UmlException {
- assertNotNull(modelImplementation.getXmiWriter(null, null, null));
+ assertNotNull(modelImplementation.getXmiWriter(
+ null, (OutputStream) null, null));
}
}
Modified: trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java?view=diff&rev=12779&p1=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java&p2=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java (original)
+++ trunk/src/model-mdr/tests/org/argouml/model/mdr/TestMDRModelImplementationCreate.java 2007-06-08 00:50:06-0700
@@ -85,7 +85,7 @@
assertTrue(fileModel.exists());
InputSource source = new InputSource(new FileInputStream(fileModel));
//Model aLittleBit = (Model) xmiReader.parse(source);
- Collection modelElements = xmiReader.parse(source);
+ Collection modelElements = xmiReader.parse(source, false);
assertNotNull(modelElements);
assertEquals(1, modelElements.size());
}
Modified: trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java?view=diff&rev=12779&p1=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java&p2=trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java&r1=12778&r2=12779
==============================================================================
--- trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java (original)
+++ trunk/src/model-mdr/tests/org/argouml/model/mdr/TestReadCompressedFilesAndHref.java 2007-06-08 00:50:06-0700
@@ -66,8 +66,8 @@
(RefPackage) modelImplementation.getMofPackage());
try {
//persister.doLoad(new File(testModel));
- reader.parse(new InputSource(new FileInputStream(
- testModel)));
+ reader.parse(
+ new InputSource(new FileInputStream(testModel)), false);
} catch (Exception e) {
e.printStackTrace();
fail("Exception while loading model");
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.