Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem loading a resource with renamed feature
Problem loading a resource with renamed feature [message #718441] Wed, 24 August 2011 10:41 Go to next message
Torkild Resheim is currently offline Torkild ResheimFriend
Messages: 16
Registered: July 2009
Junior Member
Hi,

I'm working on an EMF-based data model which is serialized to XML. This file must follow the OPF specification which means that certain features must be renamed. This is solved using ExtendedMetaData in the ECore model. as such:

    <eStructuralFeatures xsi:type="ecore:EAttribute" name="uniqueIdentifier" lowerBound="1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="name" value="unique-identifier"/>
      </eAnnotations>
    </eStructuralFeatures>


An example result file looks like this (generated by existing code):

<?xml version="1.0" encoding="UTF-8"?>
<opf:package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="uuid">
  <opf:metadata>
    <dc:title>Mylyn Docs Test EPUB</dc:title>
    <dc:creator opf:role="aut" opf:file-as="Resheim, Torkild U.">Torkild U. Resheim</dc:creator>
    <dc:subject>Testing</dc:subject>
    <dc:contributor opf:role="red">Eclipse Committers and Contributors</dc:contributor>
    <dc:date opf:event="creation">2011-08-24</dc:date>
    <dc:format>application/epub+zip</dc:format>
    <dc:identifier id="uuid" opf:scheme="UUID">f47799a9-3d87-41ff-a7ac-5df16632e7be</dc:identifier>
    <dc:source>Eclipse</dc:source>
    <dc:language>en</dc:language>
  </opf:metadata>
  <opf:manifest>
    <opf:item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
    <opf:item id="plain-page" href="plain-page.xhtml" media-type="application/xhtml+xml"/>
  </opf:manifest>
  <opf:spine toc="ncx">
    <opf:itemref idref="plain-page"/>
  </opf:spine>
  <opf:guide/>
</opf:package>


Now, the problem arises when I want to load the same file. It appears that the loading mechanism figures out how to start as I do get an instance of OPFPackage which represents opf:package. However the parser barfs at "unique-identifier" with the message "org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'unique-identifier' not found". I cannot see why the ExtendedMetaData for the package are not applied.

I would be grateful for any help resolving this.
Re: Problem loading a resource with renamed feature [message #718573 is a reply to message #718441] Wed, 24 August 2011 17:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Torkild,

Comments below.

On 24/08/2011 3:41 AM, Torkild U. Resheim wrote:
> Hi,
> I'm working on an EMF-based data model which is serialized to XML.
> This file must follow the OPF specification which means that certain
> features must be renamed. This is solved using ExtendedMetaData in the
> ECore model. as such:
>
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="uniqueIdentifier" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="unique-identifier"/>
> </eAnnotations>
> </eStructuralFeatures>
>
>
> An example result file looks like this (generated by existing code):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <opf:package xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns:opf="http://www.idpf.org/2007/opf" version="2.0"
> unique-identifier="uuid">
> <opf:metadata>
> <dc:title>Mylyn Docs Test EPUB</dc:title>
> <dc:creator opf:role="aut" opf:file-as="Resheim, Torkild U.">Torkild
> U. Resheim</dc:creator>
> <dc:subject>Testing</dc:subject>
> <dc:contributor opf:role="red">Eclipse Committers and
> Contributors</dc:contributor>
> <dc:date opf:event="creation">2011-08-24</dc:date>
> <dc:format>application/epub+zip</dc:format>
> <dc:identifier id="uuid"
> opf:scheme="UUID">f47799a9-3d87-41ff-a7ac-5df16632e7be</dc:identifier>
> <dc:source>Eclipse</dc:source>
> <dc:language>en</dc:language>
> </opf:metadata>
> <opf:manifest>
> <opf:item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
> <opf:item id="plain-page" href="plain-page.xhtml"
> media-type="application/xhtml+xml"/>
> </opf:manifest>
> <opf:spine toc="ncx">
> <opf:itemref idref="plain-page"/>
> </opf:spine>
> <opf:guide/>
> </opf:package>
>
>
> Now, the problem arises when I want to load the same file. It appears
> that the loading mechanism figures out how to start as I do get an
> instance of OPFPackage which represents opf:package. However the
> parser barfs at "unique-identifier" with the message
> "org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'unique-identifier' not found". I cannot see why the ExtendedMetaData
> for the package are not applied.
What load options are you adding to your resource in your resource
factory? (They should look like the ones generated for the Library.xsd
tutorial example.)
>
> I would be grateful for any help resolving this.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem loading a resource with renamed feature [message #718711 is a reply to message #718573] Thu, 25 August 2011 06:35 Go to previous messageGo to next message
Torkild Resheim is currently offline Torkild ResheimFriend
Messages: 16
Registered: July 2009
Junior Member
Thanks Ed,

The load options are as follows:

loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);


I suspect that part of the problem is that I'm running this code standalone, that is not on top of the Eclipse platform. The loading code looks like this:

ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(opfFile.getAbsolutePath());
Resource resource = resourceSet.createResource(fileURI);
resource.load(null);
Re: Problem loading a resource with renamed feature [message #718725 is a reply to message #718711] Thu, 25 August 2011 07:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Torkild,

You've used the debugger to verify that it's really using those options?


On 24/08/2011 11:35 PM, Torkild U. Resheim wrote:
> Thanks Ed,
>
> The load options are as follows:
>
> loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
> loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
>
> I suspect that part of the problem is that I'm running this code
> standalone, that is not on top of the Eclipse platform. The loading
> code looks like this:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI = URI.createFileURI(opfFile.getAbsolutePath());
> Resource resource = resourceSet.createResource(fileURI);
> resource.load(null);
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem loading a resource with renamed feature [message #718782 is a reply to message #718725] Thu, 25 August 2011 10:33 Go to previous messageGo to next message
Torkild Resheim is currently offline Torkild ResheimFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Ed,

Yes. defaultLoadOptions contain {USE_ENCODED_ATTRIBUTE_STYLE=true, EXTENDED_META_DATA=true} and the root of the Resource contents is a org.eclipse.mylyn.docs.epub.opf.impl.PackageImpl as expected.

I am able to load the XML file when not using extended metadata.

[Updated on: Thu, 25 August 2011 13:48]

Report message to a moderator

Re: Problem loading a resource with renamed feature [message #718906 is a reply to message #718782] Thu, 25 August 2011 15:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Torkild,

You've set a breakpoint where the exception is thrown and trace through
the logic with the debugger that gets you to that point? The problem
might be as simple as the fact that you've not included a
kind='attribute' annotation. Try that or perhaps
OPTION_LAX_FEATURE_PROCESSING will be another thing to try.


On 25/08/2011 3:33 AM, Torkild U. Resheim wrote:
> Hi Ed,
>
> Yes. defaultLoadOptions contain {USE_ENCODED_ATTRIBUTE_STYLE=true,
> EXTENDED_META_DATA=true} and the root of the Resource contents is a
> org.eclipse.mylyn.docs.epub.opf.impl.PackageImpl as expected.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem loading a resource with renamed feature [message #718987 is a reply to message #718906] Thu, 25 August 2011 17:33 Go to previous message
Torkild Resheim is currently offline Torkild ResheimFriend
Messages: 16
Registered: July 2009
Junior Member
Ed,

Yes, that was what I did. And you were also right about the solution. Setting OPTION_LAX_FEATURE_PROCESSING did the trick. Thanks a lot!
Previous Topic:Building a model programmatically (handle null/empty node)
Next Topic:No annotated model element present for: XYZ for type EClass has its epackage been regist
Goto Forum:
  


Current Time: Mon Sep 23 20:48:04 GMT 2024

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

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

Back to the top