Author: tfmorris
Date: 2008-05-22 13:58:38-0700
New Revision: 14788
Modified:
trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Log:
Issue 4724 - Improve error reporting for XMI reader. Include file position in exception. Make XMI header available to consumers.
Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java?view=diff&rev=14788&p1=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java&p2=trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java&r1=14787&r2=14788
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java (original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java 2008-05-22 13:58:38-0700
@@ -61,8 +61,11 @@
import org.netbeans.api.xmi.XMIReaderFactory;
import org.netbeans.lib.jmi.xmi.InputConfig;
import org.netbeans.lib.jmi.xmi.UnknownElementsListener;
+import org.netbeans.lib.jmi.xmi.XMIHeaderConsumer;
+import org.openide.ErrorManager;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
import org.xml.sax.XMLFilter;
import org.xml.sax.XMLReader;
@@ -72,7 +75,8 @@
*
* @author Bob Tarling
*/
-class XmiReaderImpl implements XmiReader, UnknownElementsListener {
+class XmiReaderImpl implements XmiReader, UnknownElementsListener,
+ XMIHeaderConsumer {
/**
* Logger.
@@ -109,6 +113,11 @@
* Flag indicating that we stripped at least one diagram during the import.
*/
private int ignoredElementCount;
+
+ /**
+ * String that we pulled from the header of the XMI file
+ */
+ private String xmiHeader;
/**
* Constructor for XMIReader.
@@ -146,6 +155,7 @@
profile,
inputSource.getPublicId(), inputSource.getSystemId());
config.setReferenceResolver(resolver);
+ config.setHeaderConsumer(this);
XMIReader xmiReader =
XMIReaderFactory.getDefault().createXMIReader(config);
@@ -161,6 +171,7 @@
* This can be uses to disable logging. Default output is
* System.err
* setProperty("org.netbeans.lib.jmi.Logger.fileName", "")
+ * org.netbeans.mdr.Logger
*
* The property org.netbeans.lib.jmi.Logger controls the minimum
* severity level for logging
@@ -235,6 +246,19 @@
}
} catch (MalformedXMIException e) {
+ // If we can find a nested SAX exception, it will have information
+ // on the line number, etc.
+ ErrorManager.Annotation[] annotations =
+ ErrorManager.getDefault().findAnnotations(e);
+ for (ErrorManager.Annotation annotation : annotations) {
+ Throwable throwable = annotation.getStackTrace();
+ if (throwable instanceof SAXParseException) {
+ SAXParseException spe = (SAXParseException) throwable;
+ throw new XmiException(spe.getMessage(), spe.getPublicId(),
+ spe.getSystemId(), spe.getLineNumber(),
+ spe.getColumnNumber(), e);
+ }
+ }
throw new XmiException(e);
} catch (IOException e) {
throw new XmiException(e);
@@ -577,4 +601,21 @@
return modelImpl.getSearchPath();
}
+ public void consumeHeader(InputStream stream) {
+ try {
+ int length = stream.available();
+ byte[] bytes = new byte[length];
+ stream.read(bytes, 0, length);
+ // we presume the stream is encoded using the default char encoding
+ xmiHeader = new String(bytes);
+ } catch (IOException e) {
+ LOG.error("Exception reading XMI file header", e);
+ }
+ }
+
+
+ public String getHeader() {
+ return xmiHeader;
+ }
+
}
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.