|
Re: Loading Platform Resource URI based XML Schema [message #69271 is a reply to message #69251] |
Fri, 18 August 2006 14:32 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Stuart,
You should get the URL within the jar that will access the resource.
I.e., java.lang.Class.getResource to determine the URL and use that
converted to a URI for loading the resource.
Stuart Stephen wrote:
> Hi,
>
> I have a standalone application and I have an XML Schema file which is
> built into the jar file in the package com.app.test. Unfortunately
> when I run this code I get a problem with regards to path mapping not
> being setup correctly. I do not know how I can set this up so that it
> may work. Can anybody help me?
>
> The error and the code I am using to load the XSDResourceImpl is
> detailed below.
>
> java.io.IOException: The path '/com/app/test/my.xsd' is unmapped
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createP latformResourceInputStream(Ljava/lang/String;)Ljava/io/Input Stream;(URIConverterImpl.java:551)
>
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(Lorg/eclipse/emf/common/util/URI;)Ljava/io/InputS tream;(URIConverterImpl.java:449)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Ljava/ util/Map;)V(ResourceImpl.java:892)
>
> at
> com.app.test.XmlSchemaLoading.load()V(OpenTwinsXmlSchemaLoad ing.java:49)
> at
> com.app.test.XmlSchemaLoading.<init>()V(OpenTwinsXmlSchemaLoading.java:29)
>
> at
> com.app.test.XmlSchemaLoading.main([Ljava/lang/String;)V(Ope nTwinsXmlSchemaLoading.java:110)
>
>
> ------------------
>
> //Create a resource set to manage the different resources
> ResourceSet resourceSet = new ResourceSetImpl();
>
> //Register XSD resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xsd",
> new XSDResourceFactoryImpl());
>
> //Create a resource for this file.
> XSDResourceImpl xsdResource =
> (XSDResourceImpl)resourceSet.createResource(URI.createPlatfo rmResourceURI( "com/app/test/my.xsd"));
>
>
> try {
> xsdResource.load(null);
> }
> catch (IOException e) {
> e.printStackTrace(); // fails here.
> }
> XSDSchema xsdSchema = xsdResource.getSchema();
>
>
|
|
|
|
Re: Loading Platform Resource URI based XML Schema [message #598565 is a reply to message #69251] |
Fri, 18 August 2006 14:32 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Stuart,
You should get the URL within the jar that will access the resource.
I.e., java.lang.Class.getResource to determine the URL and use that
converted to a URI for loading the resource.
Stuart Stephen wrote:
> Hi,
>
> I have a standalone application and I have an XML Schema file which is
> built into the jar file in the package com.app.test. Unfortunately
> when I run this code I get a problem with regards to path mapping not
> being setup correctly. I do not know how I can set this up so that it
> may work. Can anybody help me?
>
> The error and the code I am using to load the XSDResourceImpl is
> detailed below.
>
> java.io.IOException: The path '/com/app/test/my.xsd' is unmapped
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createP latformResourceInputStream(Ljava/lang/String;)Ljava/io/Input Stream;(URIConverterImpl.java:551)
>
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(Lorg/eclipse/emf/common/util/URI;)Ljava/io/InputS tream;(URIConverterImpl.java:449)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Ljava/ util/Map;)V(ResourceImpl.java:892)
>
> at
> com.app.test.XmlSchemaLoading.load()V(OpenTwinsXmlSchemaLoad ing.java:49)
> at
> com.app.test.XmlSchemaLoading.<init>()V(OpenTwinsXmlSchemaLoading.java:29)
>
> at
> com.app.test.XmlSchemaLoading.main([Ljava/lang/String;)V(Ope nTwinsXmlSchemaLoading.java:110)
>
>
> ------------------
>
> //Create a resource set to manage the different resources
> ResourceSet resourceSet = new ResourceSetImpl();
>
> //Register XSD resource factory
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xsd",
> new XSDResourceFactoryImpl());
>
> //Create a resource for this file.
> XSDResourceImpl xsdResource =
> (XSDResourceImpl)resourceSet.createResource(URI.createPlatfo rmResourceURI( "com/app/test/my.xsd"));
>
>
> try {
> xsdResource.load(null);
> }
> catch (IOException e) {
> e.printStackTrace(); // fails here.
> }
> XSDSchema xsdSchema = xsdResource.getSchema();
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04195 seconds