[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| [emf-dev] deserializing partial xml document into eobject | 
Hi,
I successfully created an EMF model from a schema and am able to load my 
xml files into the model.  What I want to do is to deserialize part of 
the document into its corresponding generated EObject.  The schema I 
used to generate the model is the Mpeg7 schema 
(http://m7itb.nist.gov/M7Validation.html).  For example, I can load the 
following file no problem:
<?xml version="1.0" encoding="iso-8859-1"?>
<Mpeg7 xmlns="urn:mpeg:mpeg7:schema:2001" 
xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="urn:mpeg:mpeg7:schema:2001 Mpeg7-2001.xsd">
<Description xsi:type="SummaryDescriptionType">
<Summarization>
<Header xsi:type="DescriptionMetadataType">
<LastUpdate>2006-03-28</LastUpdate>
<Comment><FreeTextAnnotation>Summarization of a Dive based on Event log 
and associated frame grabs</FreeTextAnnotation></Comment>
<Creator>
<Role href="MARC_Relator"><Name>Programmer</Name></Role>
<Agent xsi:type="PersonType">
<Name><GivenName>First</GivenName><FamilyName>Last</FamilyName></Name>
<Affiliation><Organization><Name>Organization 
Name</Name></Organization></Affiliation>
</Agent>
</Creator>
<Instrument>
<Tool><Name>XSL Transform</Name></Tool></Instrument>
</Header>
<Summary hierarchy="independent" components="keyFrames keyThemes" 
xsi:type="HierarchicalSummaryType">
<SourceID>J2-171</SourceID>
<SummaryThemeList>
<SummaryTheme id="EVT">Events manually annotated by 
operators.</SummaryTheme>
<SummaryTheme id="ASNAP">Events automatically registered by software.  
No textual annotation</SummaryTheme>
</SummaryThemeList>
<SummarySegmentGroup level="0" themeIDs="EVT ASNAP" id="summary-J2-171">
<Name>Events for Dive J2-171</Name>
<Caption>Events captured by SD cameras</Caption>
    <SummarySegment themeIDs="EVT">
<Header xsi:type="DescriptionMetadataType">
<CreationLocation>
<GeographicPosition>
<Point altitude="-1.328" latitude="49.44816468" longitude="-128.89364908"/>
</GeographicPosition>
</CreationLocation>
</Header>
<Name>Light elevator in water (Vvan)</Name>
<KeyFrame>
<MediaUri>SubSea1.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea2.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea3.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea4.20050913_174051.jpg</MediaUri>
<MediaTimePoint>2005-09-13T17:40:51</MediaTimePoint>
</KeyFrame>
</SummarySegment>
<SummarySegment>
.......
</SummarySegment>
</SummarySegmentGroup>
</Summary>
</Summarization>
</Description>
</Mpeg7>
There are actually several thousand SummarySegment's.  When I load the 
whole file, everything works fine.  But what I really want to do is to 
take one of the SummarySegments and deserialize it into its 
corresponding EObject.  In my case, it's called SummarySegmentType.  I 
want to do this because I retrieve a select number of the 
SummarySegments from an xml database (based on search) and I don't want 
to have to return the whole document to get just the part I'm interested 
in.  Basically, I want to have a SummarySegmentType object that was been 
created from something like:
<SummarySegment xmlns="urn:mpeg:mpeg7:schema:2001" themeIDs="ASNAP">
<Header xsi:type="DescriptionMetadataType" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CreationLocation>
<GeographicPosition>
<Point altitude="-2198.128" latitude="47.95012874" 
longitude="-129.09741143"/>
</GeographicPosition>
</CreationLocation>
</Header>
<KeyFrame>
<MediaUri>SubSea1.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea2.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea3.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
<KeyFrame>
<MediaUri>SubSea4.20050914_025933.jpg</MediaUri>
<MediaTimePoint>2005-09-14T02:59:33</MediaTimePoint>
</KeyFrame>
</SummarySegment>
I have tried:
           Mpeg7XMLProcessor processor = new Mpeg7XMLProcessor();
           Map options = new HashMap();
           XMLResource.XMLMap xmlMap = new XMLMapImpl();
           // xmlMap.setNoNamespacePackage(Mpeg7Package.eINSTANCE);
           options.put(XMLResource.OPTION_XML_MAP, xmlMap);
           processor.load(new FileInputStream(new File("C:/test.xml")), 
options);
          
and
           Mpeg7ResourceImpl resource = new 
Mpeg7ResourceImpl(URI.createFileURI(f.getAbsolutePath()));
           XMLResource.XMLMap xmlMap = new XMLMapImpl();
           xmlMap.setNoNamespacePackage(Mpeg7Package.eINSTANCE);
           Map options = new HashMap();
           options.put(XMLResource.OPTION_XML_MAP, xmlMap);
           
options.put(XMLResource.OPTION_EXTENDED_META_DATA,ExtendedMetaData.INSTANCE);
           resource.load(options);
Both produce the following error:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Class 
'SummarySegment' not found. (file:/C:/test.xml, 1, 112)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:80)
   at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:189)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:179)
   at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1089)
   at 
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:895)
   at edu.washington.cev.jasonii.Test.test2(Test.java:101)
   at edu.washington.cev.jasonii.Test.main(Test.java:33)
Caused by: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 
'SummarySegment' not found. (file:/C:/test.xml, 1, 112)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:1977)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1618)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createDocumentRoot(XMLHandler.java:1224)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1152)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1234)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:872)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:854)
   at 
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:626)
   at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
   at 
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:798)
   at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
   at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:1157)
   at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
   at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
   at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
   at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
   at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
   at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
   at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
   at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:179)
   ... 5 more
Any help is appreciated.