Author: b00__1
Date: 2007-08-18 03:43:00-0700
New Revision: 13392
Modified:
branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java
Log:
Fixes to load a file without exceptions or errors.
Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java?view=diff&rev=13392&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java&r1=13391&r2=13392
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java (original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java 2007-08-18 03:43:00-0700
@@ -26,7 +26,12 @@
package org.argouml.model.euml;
+import java.io.BufferedInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -47,6 +52,8 @@
* The model implementation.
*/
private EUMLModelImplementation modelImpl;
+
+ private static List<String> searchDirs = new ArrayList();
/**
* Constructor.
@@ -82,6 +89,31 @@
if (inputSource == null) {
throw new NullPointerException("The input source must be non-null."); //$NON-NLS-1$
}
+ InputStream is = null;
+ boolean needsClosing = false;
+ if (inputSource.getByteStream() != null) {
+ is = inputSource.getByteStream();
+ } else if (inputSource.getSystemId() != null) {
+ try {
+ URL url = new URL(inputSource.getSystemId());
+ if (url != null) {
+ is = url.openStream();
+ if (is != null) {
+ is = new BufferedInputStream(is);
+ needsClosing = true;
+ }
+ }
+ } catch (MalformedURLException e) {
+ // do nothing
+ } catch (IOException e) {
+ // do nothing
+ }
+
+ }
+ if (is == null) {
+ throw new UnsupportedOperationException();
+ }
+
EditingDomain editingDomain = modelImpl.getEditingDomain();
for (Resource resource : editingDomain.getResourceSet().getResources()) {
resource.unload();
@@ -89,9 +121,17 @@
Resource r = editingDomain.createResource("http://argouml.tigris.org/euml/resource/default_uri.xmi"); //$NON-NLS-1$
try {
- r.load(inputSource.getByteStream(), null);
+ r.load(is, null);
} catch (IOException e) {
throw new UmlException(e);
+ } finally {
+ if (needsClosing) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
return r.getContents();
@@ -109,21 +149,15 @@
}
public void addSearchPath(String path) {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ searchDirs.add(path);
}
public List<String> getSearchPath() {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ return searchDirs;
}
public void removeSearchPath(String path) {
- // TODO: Auto-generated method stub
- throw new NotYetImplementedException();
-
+ searchDirs.remove(path);
}
}
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.