Re: Impossible to load UML model via Java code [message #626903] |
Mon, 08 September 2008 12:08 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------040509020302060109050906
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Laurent,
It's best to ask about UML things on the UML2 newsgroup (I've added it
to the "to" list of the reply) and ask about compare on the EMFT
newsgroup. Be sure to read the UML2 FAQ:
http://wiki.eclipse.org/MDT-UML2-FAQ#What.27s_required_to_lo ad_a_UML_.28.uml.29_resource_from_a_standalone_application.3 F
And use google to find related similar questions:
http://www.google.com/cse?cx=017941334893793413703%3Asqfrdtd 112s&q=UML+load+stand+alone&sa=Search
< http://www.google.com/cse?cx=017941334893793413703%3Asqfrdtd 112s&q=UML+load+stand+alone&sa=Search>
Laurent Roubele wrote:
> Hello,
>
> I'm trying to load a model via java (emf) in order to merge it with
> another one... My UML model (.uml) was exported from Magic Draw into
> "EMF UML (v2.x) XMI". Here is my code :
>
>
> import java.io.File;
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Calendar;
> import java.util.Collections;
> import java.util.List;
>
> import org.eclipse.emf.compare.diff.merge.service.MergeService;
> import org.eclipse.emf.compare.diff.metamodel.DiffElement;
> import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
> import org.eclipse.emf.compare.diff.metamodel.DiffModel;
> import org.eclipse.emf.compare.diff.metamodel.ModelInputSnapshot;
> import org.eclipse.emf.compare.diff.service.DiffService;
> import org.eclipse.emf.compare.match.metamodel.MatchModel;
> import org.eclipse.emf.compare.match.service.MatchService;
> import org.eclipse.emf.compare.util.ModelUtils;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
>
> public final class ExampleLauncher {
> /**
> * This class doesn't need to be instantiated.
> */
> private ExampleLauncher() {
> // prevents instantiation
> }
>
> public static void main(String[] args) {
> // Creates the resourceSet where we'll load the models
> final ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register additional packages here. For UML2:
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> try {
> System.out.println("Loading resources.\n"); //$NON-NLS-1$
> // Loads the model to modify
> final EObject model1 = ModelUtils.load(new
> File("D:/eclipse/workspace/EMFTEST/model/model.uml"),resourceSet);
>
> System.out.println("Loaded.");
> } catch (Exception e) { // shouldn't be thrown
> e.printStackTrace();
> }
> }
> }
>
>
> When I launch this sample I got a exception:
> Loading resources.
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFe atureType(XMLHandler.java:2132)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:2010)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHa ndler.java:131)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1789)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1013)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:991)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:711)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2516)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2397)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1275)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1444)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1009)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:991)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:711)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2516)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2397)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1275)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1444)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1009)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:991)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:711)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2516)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:2397)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:1275)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:1444)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:1009)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:87)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:991)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:711)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHa ndler.java:167)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDriver.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerIm pl.next(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
> Source)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
> Source)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
> Source)
> at
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSA XParser.parse(Unknown
> Source)
> at javax.xml.parsers.SAXParser.parse(Unknown Source)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1414)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1210)
>
> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :320)
> at org.eclipse.emf.compare.util.ModelUtils.load(ModelUtils.java :218)
> at ExampleLauncher.main(ExampleLauncher.java:68)
>
> In fact, I CAN load .ecore models via this sample code... But
> apparently no .uml models.
>
> Any ideas ?
>
> Regards,
>
> Laurent
>
--------------040509020302060109050906
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Laurent,<br>
<br>
It's best to ask about UML things on the UML2 newsgroup (I've added it
to the "to" list of the reply) and ask about compare on the EMFT
newsgroup.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03269 seconds