Feature not found loading serialized resource [message #423831] |
Tue, 07 October 2008 16:48 |
Greg Kirby Messages: 6 Registered: July 2009 |
Junior Member |
|
|
I have created a emf project from a set of xsds and I'm trying to load a
serialized resource. I have generated the model code and the test code.
I am able to save a resource to an xml file without any problem, but when
I try to load that xml file, I get a FeatureNotFoundException. I am using
the generated resource factories and registering the ePackage prior to
calling getResource(). I was following the example code in
xxxExample.java generated with the test code.
Save code( pjcpr was created from TcfPackage.eINSTANCE.createXXX() ):
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "tcf",
new TcfResourceFactoryImpl());
resourceSet.getPackageRegistry().put(TcfPackage.eNS_URI,
TcfPackage.eINSTANCE);
File file = new File(fileName);
URI uri = URI.createFileURI(file.getAbsolutePath());
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(pjcpr);
resource.save(Collections.EMPTY_MAP);
Load code:
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "tcf",
new TcfResourceFactoryImpl());
resourceSet.getPackageRegistry().put(TcfPackage.eNS_URI,
TcfPackage.eINSTANCE);
File file = new File(fileName);
URI uri = URI.createFileURI(file.getAbsolutePath());
Resource resource = resourceSet.getResource(uri, true);
System.out.println("loaded " + resource.getContents().size() + " resources
from " + file.getAbsolutePath() );
PlotterJobCpr pjcpr = (PlotterJobCpr)resource.getContents().get(0);
Exception thrown when calling getResource():
org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
'PlotterJobCpr' not found.
(file:/Users/calibrate/src/eclipsedev/TestModeling/test/-145 0256654009633910.tcf,
2, 62)
First few lines of -1450256654009633910.tcf:
<?xml version="1.0" encoding="ASCII"?>
<tcf:PlotterJobCpr xmlns:tcf="http://www.kodak.com/2008/TCF">
<tcf:plotterId>-1450256654009633910</tcf:plotterId>
<tcf:plotterName>ebdfa741c89bf38a</tcf:plotterName>
<tcf:plotterJobDefId>-1450256654009633910</tcf:plotterJobDefId >
...
I am using Eclipse 3.4.0 and EMF 2.4.0. Any help you can give would be
appreciated.
Greg Kirby
|
|
|
Re: Feature not found loading serialized resource [message #423835 is a reply to message #423831] |
Tue, 07 October 2008 18:41 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Greg,
Comments below.
Greg Kirby wrote:
> I have created a emf project from a set of xsds and I'm trying to load
> a serialized resource. I have generated the model code and the test
> code. I am able to save a resource to an xml file without any
> problem, but when I try to load that xml file, I get a
> FeatureNotFoundException. I am using the generated resource factories
> and registering the ePackage prior to calling getResource(). I was
> following the example code in xxxExample.java generated with the test
> code.
>
> Save code( pjcpr was created from TcfPackage.eINSTANCE.createXXX() ):
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "tcf",
> new TcfResourceFactoryImpl());
> resourceSet.getPackageRegistry().put(TcfPackage.eNS_URI,
> TcfPackage.eINSTANCE);
> File file = new File(fileName);
> URI uri = URI.createFileURI(file.getAbsolutePath());
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(pjcpr);
Is there a document root needed?
> resource.save(Collections.EMPTY_MAP);
> Load code:
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "tcf",
> new TcfResourceFactoryImpl());
> resourceSet.getPackageRegistry().put(TcfPackage.eNS_URI,
> TcfPackage.eINSTANCE);
> File file = new File(fileName);
> URI uri = URI.createFileURI(file.getAbsolutePath());
> Resource resource = resourceSet.getResource(uri, true);
> System.out.println("loaded " + resource.getContents().size() + "
> resources from " + file.getAbsolutePath() );
> PlotterJobCpr pjcpr = (PlotterJobCpr)resource.getContents().get(0);
>
> Exception thrown when calling getResource():
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'PlotterJobCpr' not found.
> (file:/Users/calibrate/src/eclipsedev/TestModeling/test/-145 0256654009633910.tcf,
> 2, 62)
>
> First few lines of -1450256654009633910.tcf:
> <?xml version="1.0" encoding="ASCII"?>
> <tcf:PlotterJobCpr xmlns:tcf="http://www.kodak.com/2008/TCF">
> <tcf:plotterId>-1450256654009633910</tcf:plotterId>
> <tcf:plotterName>ebdfa741c89bf38a</tcf:plotterName>
> <tcf:plotterJobDefId>-1450256654009633910</tcf:plotterJobDefId >
> ...
>
> I am using Eclipse 3.4.0 and EMF 2.4.0. Any help you can give would
> be appreciated.
I'll bet you need to use
DocumentRoot documentRoot = TcfFactory.eINSTANCe.createDocumentRoot();
documentRoot.setPJCPR(pjcpr)
and add the document root to the resource rather than directly an
instance of a complex type. (Like the generated example does.)
>
> Greg Kirby
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02840 seconds