Author: bobtarling
Date: 2008-04-07 16:41:39-0700
New Revision: 14302
Modified:
trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Log:
This fixes a P1 defect but I think it needs reviewing. I'll highlight it on the dev list.
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=14302&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=14301&r2=14302
==============================================================================
--- trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java (original)
+++ trunk/src/model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java 2008-04-07 16:41:39-0700
@@ -189,11 +189,9 @@
try {
String systemId = inputSource.getSystemId();
- if (systemId == null) {
- File file = copySource(inputSource);
- systemId = file.toURI().toURL().toExternalForm();
- inputSource = new InputSource(systemId);
- }
+ File file = copySource(inputSource);
+ systemId = file.toURI().toURL().toExternalForm();
+ inputSource = new InputSource(systemId);
newElements =
xmiReader.read(inputSource.getByteStream(), systemId, extent);
@@ -373,6 +371,9 @@
for (int i = 0; i < styles.length; i++) {
// Set up source for style sheet
String xsltFileName = STYLE_PATH + styles[i];
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Transforming with " + xsltFileName);
+ }
URL xsltUrl = getClass().getResource(xsltFileName);
if (xsltUrl == null) {
throw new UmlException("Error opening XSLT style sheet : "
@@ -415,16 +416,31 @@
private File copySource(InputSource input) throws IOException {
byte[] buf = new byte[2048];
int len;
-
+
// Create & set up temporary output file
File tmpOutFile = File.createTempFile("zargo_model_", ".xmi");
tmpOutFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tmpOutFile);
+
+ // TODO: Bob says - Coding by use of side effect here.
+ // Maybe this should be done in a clearer way but it fixes
+ // http://argouml.tigris.org/issues/show_bug.cgi?id=4978
+ // It seems that when loading an XMI that is not contained in a zip
+ // file then the InputStream given as the argument to this method
+ // can't be reused as it is at the end of the stream. In that case
+ // systemId appears to be none-null at this stage.
+ // So if systemId is not null we recreate the InputSource.
+ String systemId = input.getSystemId();
+ if (systemId != null) {
+ input = new InputSource(new URL(systemId).openStream());
+ }
+
InputStream in = input.getByteStream();
- while ((len = in.read(buf)) > 0) {
+ while ((len = in.read(buf)) >= 0) {
out.write(buf, 0, len);
}
+ out.close();
LOG.debug("Wrote copied XMI file to " + tmpOutFile);
return tmpOutFile;
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.