Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Feature not found loading serialized resource
Feature not found loading serialized resource [message #423831] Tue, 07 October 2008 16:48 Go to next message
Greg Kirby is currently offline Greg KirbyFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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/
Re: Feature not found loading serialized resource [message #423842 is a reply to message #423835] Tue, 07 October 2008 19:40 Go to previous message
Greg Kirby is currently offline Greg KirbyFriend
Messages: 6
Registered: July 2009
Junior Member
Thanks, creating the DocumentRoot and adding that to the resource worked.

Greg Kirby
Previous Topic:Generated editor for XSD generated Ecore model
Next Topic:[EMF] [Teneo] : benchmarks ? And Return of Experience ?
Goto Forum:
  


Current Time: Fri Apr 26 10:17:22 GMT 2024

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

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

Back to the top