Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » load a xml-model from memory
load a xml-model from memory [message #407843] Mon, 19 March 2007 12:30 Go to next message
Eclipse UserFriend
Originally posted by: h_breuer.gmx.net

Hi,

I have a problem to load my XML-Model out of memory. First of all I load
my model from a file (for testing), this works fine.

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION, new
VVRInMessageResourceFactoryImpl());

resourceSet.getPackageRegistry().put (VVRInMessagePackage.eNS_URI,
VVRInMessagePackage.eINSTANCE);

InputSource is = new InputSource (this.getClass().getClassLoader().
getResourceAsStream("test.xml"));

XMLProcessor xmlProcessor = new VVRInMessageXMLProcessor();
Resource resource = xmlProcessor.load(is, null);


Afterwards some internal processes on a WebSphere-Server are passed
through. At the end there is a method-call getting the root-element of the
underlying XSD-Description (formely read from file). This method must
return a ByteArrayOutputStream form the Model-Instance:

ResourceSet was initialized like above. Then I I have to create a
resource, but there is no file-URI. I don't know which URI to set to get a
valid resource.

Resource resource =
resourceSetVVR.createResource( URI.createURI("temp.message"));

Because of stand-alone application i try to register the package ...

VVRInMessagePackage vvrInMessagePackage = VVRInMessagePackage.eINSTANCE;

...and get the following Exception in VVRInMessagePackage.loadPackage()
calling resource.load(null):

"org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with
uri 'http://www.eclipse.org/emf/2002/Ecore' not found
(wsjar:file:c/.../message/message.ecore, 5, 63)"

(location of the model-file is in a jarfile)

In addition my concrete questions:

1) Is it possible to load a XML-Model from an formerly created Root-Object
without a persistent file?
2) Is the above the correct way to do this?
3) What resource-uRI must be specified if I don't have a file as model?
4) What about the exception? Did I have something mor to initialize? The
generated example-tests didn't help.

Used EMF-Version:
org.eclipse.emf.ecore_2.2.2.v200702121014.jar
org.eclipse.emf.ecore.xmi_2.2.2.v200702121014.jar
org.eclipse.xsd_2.2.2.v200702121014.jar
org.eclipse.emf.common_2.2.1.v200702121014.jar

Thx in advance
Holger Breuer
Re: load a xml-model from memory [message #407853 is a reply to message #407843] Mon, 19 March 2007 14:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26283
Registered: July 2009
Senior Member
Holger,

Comments below.

Holger Breuer wrote:
> Hi,
>
> I have a problem to load my XML-Model out of memory. First of all I
> load my model from a file (for testing), this works fine.
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION, new
> VVRInMessageResourceFactoryImpl());
> resourceSet.getPackageRegistry().put (VVRInMessagePackage.eNS_URI,
> VVRInMessagePackage.eINSTANCE);
> InputSource is = new InputSource
> (this.getClass().getClassLoader().
> getResourceAsStream("test.xml"));
>
> XMLProcessor xmlProcessor = new VVRInMessageXMLProcessor();
> Resource resource = xmlProcessor.load(is, null);
>
> Afterwards some internal processes on a WebSphere-Server are passed
> through. At the end there is a method-call getting the root-element of
> the underlying XSD-Description (formely read from file). This method
> must return a ByteArrayOutputStream form the Model-Instance:
>
> ResourceSet was initialized like above. Then I I have to create a
> resource, but there is no file-URI. I don't know which URI to set to
> get a valid resource.
>
> Resource resource = resourceSetVVR.createResource(
> URI.createURI("temp.message"));
> Because of stand-alone application i try to register the package ...
>
> VVRInMessagePackage vvrInMessagePackage = VVRInMessagePackage.eINSTANCE;
>
> ..and get the following Exception in VVRInMessagePackage.loadPackage()
> calling resource.load(null):
>
> "org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package
> with uri 'http://www.eclipse.org/emf/2002/Ecore' not found
> (wsjar:file:c/.../message/message.ecore, 5, 63)"
Accessing EcorePackage.eINSTANCE first should ensure that this namespace
is registered.
>
> (location of the model-file is in a jarfile)
>
> In addition my concrete questions:
>
> 1) Is it possible to load a XML-Model from an formerly created
> Root-Object without a persistent file?
Yes.
> 2) Is the above the correct way to do this?
It looks like a good way. Double check that the resource that's created
by VVRInMessageResourceFactoryImpl.
> 3) What resource-uRI must be specified if I don't have a file as model?
Relative resource references within the resource will be interpreted
relative to the URI you give, so if there are no relative reference, the
URI doesn't really matter, i.e., you might use *.message if message if
the fix extension you've registered your factory for.
> 4) What about the exception? Did I have something mor to initialize?
> The generated example-tests didn't help.
It sounds like perhaps you need to access EcorePackage.eINSTANCE first.
>
> Used EMF-Version: org.eclipse.emf.ecore_2.2.2.v200702121014.jar
> org.eclipse.emf.ecore.xmi_2.2.2.v200702121014.jar
> org.eclipse.xsd_2.2.2.v200702121014.jar
> org.eclipse.emf.common_2.2.1.v200702121014.jar
>
> Thx in advance
> Holger Breuer
>
>
>
>
Previous Topic:Emf application devellopement using emf extension point
Next Topic:Build Object Model - deploy as java
Goto Forum:
  


Current Time: Fri Dec 19 18:18:16 GMT 2014

Powered by FUDForum. Page generated in 0.11920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software