svn commit: r13087 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-07-16 00:31:15-0700
New Revision: 13087

Modified:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/XmiReaderEUMLImpl.java

Log:
Fixed the input reader.

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=13087&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=13086&r2=13087
==============================================================================
--- 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-07-16 00:31:15-0700
@@ -26,10 +26,7 @@
 
 package org.argouml.model.euml;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -37,15 +34,8 @@
 import org.apache.log4j.Logger;
 import org.argouml.model.UmlException;
 import org.argouml.model.XmiReader;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EcorePackage;
 import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.resource.UMLResource;
+import org.eclipse.emf.edit.domain.EditingDomain;
 import org.xml.sax.InputSource;
 
 /**
@@ -54,17 +44,12 @@
 class XmiReaderEUMLImpl implements XmiReader {
 
     private static Logger LOG = Logger.getLogger(XmiReaderEUMLImpl.class);
-    
-    // TODO: This shouldn't really be hardcoded - tfm
-    private final static String ENCODING = "UTF-8";
-    
+        
     /**
      * The model implementation.
      */
     private EUMLModelImplementation modelImpl;
 
-    private ResourceSet resourceSet;
-
     /**
      * Constructor.
      * 
@@ -73,40 +58,6 @@
      */
     public XmiReaderEUMLImpl(EUMLModelImplementation implementation) {
         modelImpl = implementation;
-
-        resourceSet = new ResourceSetImpl();
-        
-        // TODO: We need both complete paths and version independence here
-        // We probably need sometype of run-time lookup scheme
-        // This code is from 
-        // http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2.0_Migration_Guide/guide.html
-        URI umlPluginURI = URI.createURI("jar:file:/" 
-                + "org.eclipse.uml2.uml_2.1.0.v200703011358.jar" 
-                + "!/");
-        URI umlResourcesPluginURI = URI.createURI("jar:file:/" 
-                + "org.eclipse.uml2.uml.resources_2.1.0.v200705251139.jar"
-                + "!/");
-
-        // register the necessary pathmaps
-        Map uriMap = URIConverter.URI_MAP;
-        uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
-                umlResourcesPluginURI.appendSegment("libraries").appendSegment(""));
-        uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
-                umlResourcesPluginURI.appendSegment("metamodels").appendSegment(""));
-        uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
-                umlResourcesPluginURI.appendSegment("profiles").appendSegment(""));
-
-
-        // for a stand alone application, it is necessary to map the
-        // platform plugin URI scheme to the workspace location
-        uriMap.put(URI.createURI("platform:/plugin/org.eclipse.uml2.uml/"), 
-                umlPluginURI);
-
-        // Add namespace URIs for eCore and eUML2 to package registry
-        Map packageRegistry = resourceSet.getPackageRegistry();
-        packageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
-        packageRegistry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
-
     }
 
     public int getIgnoredElementCount() {
@@ -129,20 +80,21 @@
     }
 
     public Collection parse(InputSource inputSource, boolean profile)
-    throws UmlException {
-
-        // TODO:  This is a hack.  Look for alternatives, possibly reworking API
-        File inputFile;
-        try {
-            inputFile = copySource(inputSource);
-        } catch (IOException e) {
-            throw new UmlException("Error creating temporary file", e);
-        }
-        
-        Resource resource = resourceSet.getResource(URI.createFileURI(inputFile.toString()), true);
-        EcoreUtil.resolveAll(resource);
-
-        return resource.getContents();
+	    throws UmlException {
+	EditingDomain editingDomain = modelImpl.getEditingDomain();
+	for (Resource resource : editingDomain.getResourceSet().getResources()) {
+	    resource.unload();
+	}
+	
+	// Dummy resource
+	Resource r = editingDomain.createResource("foo.xmi"); //$NON-NLS-1$
+	try {
+	    r.load(inputSource.getByteStream(), null);
+	} catch (IOException e) {
+	    throw new UmlException(e);
+	}
+	
+	return r.getContents();
     }
 
     public boolean setIgnoredElements(String[] elementNames) {
@@ -150,30 +102,10 @@
         return false;
     }
 
-    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);
-        
-        // Add our XML declaration back to the front of the file
-//        String decl = "<?xml version=\"1.0\" encoding=\"" 
-//            + ENCODING + "\"?>\n";
-//        out.write(decl.getBytes(ENCODING), 0, decl.length());
-
-        InputStream in = input.getByteStream();
-        while ((len = in.read(buf)) > 0) {
-            out.write(buf, 0, len);
-        }
-
-        LOG.debug("Wrote copied XMI file to " + tmpOutFile);
-        return tmpOutFile;
-    }
-
     public String getTagName() {
+	// This is not quite right
+	// TODO: Solve this
         return "uml: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.