[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.mdt.uml2] Re: Add classes to my UML2 model via java code
|
Thanks Rafael. I used the example provided at the end of
http://www.eclipse.org/newsportal/thread.php?group=eclipse.modeling.mdt.uml2
I want to do exactly the same thing but instead of creating a new model, I
want to load an existing one. So I created this method :
protected static org.eclipse.uml2.uml.Model loadModel(URI uri) {
org.eclipse.uml2.uml.Model model_ = null;
try {
Resource resource = RESOURCE_SET.getResource(uri, true);
model_ = (org.eclipse.uml2.uml.Model) EcoreUtil
.getObjectByType(resource.getContents(),
UMLPackage.Literals.MODEL);
} catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}
return model_;
}
And in my Main method, I do :
Model model =
loadModel(URI.createFileURI("D:/workspace/EMFP/model/modeltest.uml"));
But I get this exception :
Exception in thread "main" java.lang.NullPointerException
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2132)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2010)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:131)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1789)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1013)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:991)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:711)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.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(XMLResourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1414)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2516)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2397)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1275)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1444)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1009)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:991)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:711)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.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(XMLResourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1414)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2516)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2397)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1275)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1444)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1009)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:991)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:711)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.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(XMLResourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1414)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2516)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2397)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1275)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1444)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1009)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:991)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:711)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:167)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.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(XMLResourceImpl.java:180)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1414)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1210)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at UML2Article.loadModel(UML2Article.java:114)
at GettingStartedWithUML2.main(GettingStartedWithUML2.java:223)
Notice that the line "Resource resource = RESOURCE_SET.getResource(uri,
true);" is very long to execute in debug mode. And the exception is got at
this line.
Any hint would be very appreciated.
Thanks !
Regards,
P.