[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.emf] Re: NEWBIE. Question. [Loading xmi]

Mary,

I would just add LibraryPackage.eINSTANCE to your code below.  Did you try
that?  Did you try checking if


EPackage.Registry.INSTANCE.getEPackage(URI.createURI(http:///org/eclipse/example/library.ecore))

returns the package?


Mary Zen wrote:

> I was not able to get it to work.
> A code snippet from you guys might help.
> Here is the xmi format
> <?xml version="1.0" encoding="ASCII"?>
>
> <org.eclipse.example.library:Library xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI";
> xmlns:org.eclipse.example.library="http:///org/eclipse/example/library.ecore
> " name="Howard">
>
> <writers/>
>
> </org.eclipse.example.library:Library>
>
> Thanks!!
>
> "Ed Merks" <merks@xxxxxxxxxx> wrote in message
> news:3F48B4E3.13E8D059@xxxxxxxxxxxxx
> > Mary,
> >
> > It looks like it can't find the EPackage  for your model.  You need to
> make sure
> > the package is registered, i.e., EPackage.Registry.INSTANCE.getEPackage
> should
> > be able to fetch it.  When running in Eclipse, this is done by the
> registration
> > in the plugin.xml file which are processing during startup.  When running
> > standalone, you have to do it some other way.  Accessing
> YourPackage.eINSTANCE
> > will ensure that it's registered...
> >
> >
> > Mary Zen wrote:
> >
> > > Using the tutorial I generated 'My.library' as the instance xmi file.
> > > I am now trying to read this file using EMF API's and it gives errors.
> > >
> > > Here is the sample code:-
> > > public class TestLoad {
> > >
> > > public static void main(String args[]) {
> > >
> > > Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*",
> new
> > > XMIResourceFactoryImpl() {
> > >
> > > public Resource createResource(URI uri) {
> > >
> > > XMIResource xmiResource= new XMIResourceImpl(uri);
> > >
> > > return xmiResource;
> > >
> > > }
> > >
> > > });
> > >
> > > EcorePackage pkg = EcorePackage.eINSTANCE;
> > >
> > > ResourceSet resSet= new ResourceSetImpl();
> > >
> > > Resource res=
> > >
> resSet.getResource(URI.createFileURI("C:\\programs\\Eclipse\\eclipse\\test\\
> > > My.library"), true);
> > >
> > > Iterator it= res.getContents().iterator();
> > >
> > > while (it.hasNext()) {
> > >
> > > System.out.println("object in resource: " + (EObject) it.next());
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > It throws this exception:-
> > >
> > > Wrapped exception
> > >
> > > Wrapped exception
> > >
> > > java.net.ConnectException: Connection refused: connect
> > >
> > > at java.net.PlainSocketImpl.socketConnect(Native Method)
> > >
> > > at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:350)
> > >
> > > at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
> > >
> > > at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
> > >
> > > at java.net.Socket.<init>(Socket.java:268)
> > >
> > > at java.net.Socket.<init>(Socket.java:95)
> > >
> > > at sun.net.NetworkClient.doConnect(NetworkClient.java:45)
> > >
> > > at sun.net.www.http.HttpClient.openServer(HttpClient.java:334)
> > >
> > > at sun.net.www.http.HttpClient.openServer(HttpClient.java:520)
> > >
> > > at sun.net.www.http.HttpClient.<init>(HttpClient.java:270)
> > >
> > > at sun.net.www.http.HttpClient.<init>(HttpClient.java:280)
> > >
> > > at sun.net.www.http.HttpClient.New(HttpClient.java:292)
> > >
> > > at
> > >
> sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:4
> > > 17)
> > >
> > > at
> > >
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
> > > .java:510)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createURLInputStream(UR
> > > IConverterImpl.java:463)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createInputStream(URICo
> > > nverterImpl.java:401)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:752)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetIm
> > > pl.java:220)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetI
> > > mpl.java:286)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:7
> > > 79)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.jav
> > > a:722)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:41
> > > 9)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:346
> > > )
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:62)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:333)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWrapper.java:71)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.j
> > > ava:446)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXML
> > > DocumentParser.java:216)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBinder.ja
> > > va:594)
> > >
> > > at
> > >
> org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java
> > > :830)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDo
> > > cumentFragmentScannerImpl.java:748)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElem
> > > entHook(XMLDocumentScannerImpl.java:926)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc
> > > her.dispatch(XMLDocumentFragmentScannerImpl.java:1523)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocume
> > > ntFragmentScannerImpl.java:333)
> > >
> > > at
> > >
> org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserCo
> > > nfiguration.java:525)
> > >
> > > at
> > >
> org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserCo
> > > nfiguration.java:581)
> > >
> > > at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:115
> > > 8)
> > >
> > > at javax.xml.parsers.SAXParser.parse(SAXParser.java:394)
> > >
> > > at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:76)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:1
> > > 35)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:881)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:755)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetIm
> > > pl.java:220)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetI
> > > mpl.java:286)
> > >
> > > at Tst01.main(Tst01.java:29)
> > >
> > > Wrapped by
> > >
> > > org.eclipse.emf.common.util.WrappedException: Connection refused:
> connect
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetI
> > > mpl.java:294)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:7
> > > 79)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.jav
> > > a:722)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:41
> > > 9)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:346
> > > )
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:62)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:333)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWrapper.java:71)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.j
> > > ava:446)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXML
> > > DocumentParser.java:216)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBinder.ja
> > > va:594)
> > >
> > > at
> > >
> org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java
> > > :830)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDo
> > > cumentFragmentScannerImpl.java:748)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElem
> > > entHook(XMLDocumentScannerImpl.java:926)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatc
> > > her.dispatch(XMLDocumentFragmentScannerImpl.java:1523)
> > >
> > > at
> > >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocume
> > > ntFragmentScannerImpl.java:333)
> > >
> > > at
> > >
> org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserCo
> > > nfiguration.java:525)
> > >
> > > at
> > >
> org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardParserCo
> > > nfiguration.java:581)
> > >
> > > at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
> > >
> > > at
> > >
> org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:115
> > > 8)
> > >
> > > at javax.xml.parsers.SAXParser.parse(SAXParser.java:394)
> > >
> > > at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:76)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:1
> > > 35)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:881)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:755)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetIm
> > > pl.java:220)
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetI
> > > mpl.java:286)
> > >
> > > at Tst01.main(Tst01.java:29)
> > >
> > > Wrapped by
> > >
> > > org.eclipse.emf.common.util.WrappedException: Connection refused:
> connect
> > >
> > > at
> > >
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetI
> > > mpl.java:290)
> > >
> > > at Tst01.main(Tst01.java:29)
> > >
> > > Exception in thread "main"
> >