Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Reading serialized model generated from multiple schemas throws FeatureNotFoundException
Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428406] Fri, 20 March 2009 11:20 Go to next message
Eclipse UserFriend
Hi,

I have an XSD that imports and uses types from my other XSD. Model
generation results in 2 ecore models, and I also generated the model,
edit, and tests. I then wrote up some sample code to populate the model
(with elemets defined in both schemas). All is well, it serializes as I
intended.

But, when trying to load the model in another standalone test class I
get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
'myFeature' not found when trying to load it back. Looking at the
generated tests it seems I get 2 packages with Model1Example and
Model2Example. Running Model1Example.main() complains that a feature
defined in Model2 is not found.

My question is, what do I need to add to Model1Example to make it read a
serialized file that makes use of both models? I tried adding (in the
Model1Example.java) the registration of the Model2 by:

// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put
(Model2Package.eNS_URI,
Model2Package.eINSTANCE);

Still get the FeatureNotFoundException. Have I done something incorrect
in my model generation or do I need to make the other model available
for the loading in some other way?

Thanks,

/Ola
Re: Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428407 is a reply to message #428406] Fri, 20 March 2009 12:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ola,

Comments below.


Ola Spjuth wrote:
> Hi,
>
> I have an XSD that imports and uses types from my other XSD. Model
> generation results in 2 ecore models, and I also generated the model,
> edit, and tests. I then wrote up some sample code to populate the
> model (with elemets defined in both schemas). All is well, it
> serializes as I intended.
>
> But, when trying to load the model in another standalone test class I
> get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'myFeature' not found when trying to load it back. Looking at the
> generated tests it seems I get 2 packages with Model1Example and
> Model2Example. Running Model1Example.main() complains that a feature
> defined in Model2 is not found.
Did you register the right resource factories?
>
> My question is, what do I need to add to Model1Example to make it read
> a serialized file that makes use of both models? I tried adding (in
> the Model1Example.java) the registration of the Model2 by:
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put
> (Model2Package.eNS_URI,
> Model2Package.eINSTANCE);
I'd expect this to work, but I wonder if either of these schema's are
null namespace schemas? Do their resource factory impls look different?
>
> Still get the FeatureNotFoundException. Have I done something
> incorrect in my model generation or do I need to make the other model
> available for the loading in some other way?
>
> Thanks,
>
> /Ola


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428409 is a reply to message #428407] Fri, 20 March 2009 14:04 Go to previous messageGo to next message
Eclipse UserFriend
Ed Merks skrev:
> Ola,
>
> Comments below.
>
>
> Ola Spjuth wrote:
>> Hi,
>>
>> I have an XSD that imports and uses types from my other XSD. Model
>> generation results in 2 ecore models, and I also generated the model,
>> edit, and tests. I then wrote up some sample code to populate the
>> model (with elemets defined in both schemas). All is well, it
>> serializes as I intended.
>>
>> But, when trying to load the model in another standalone test class I
>> get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>> 'myFeature' not found when trying to load it back. Looking at the
>> generated tests it seems I get 2 packages with Model1Example and
>> Model2Example. Running Model1Example.main() complains that a feature
>> defined in Model2 is not found.
> Did you register the right resource factories?

Can I register more than one? I do:

// Register the appropriate resource factory to handle all file extensions.
//

resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new QsarResourceFactoryImpl());


>>
>> My question is, what do I need to add to Model1Example to make it read
>> a serialized file that makes use of both models? I tried adding (in
>> the Model1Example.java) the registration of the Model2 by:
>>
>> // Register the package to ensure it is available during loading.
>> //
>> resourceSet.getPackageRegistry().put
>> (Model2Package.eNS_URI,
>> Model2Package.eINSTANCE);
> I'd expect this to work, but I wonder if either of these schema's are
> null namespace schemas? Do their resource factory impls look different?

As far as I can tell the schemas are not null-namespaced.

Here are the schemas:
http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.qsar.model/model/qsar.xsd?r evision=9437&view=markup
http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.bibtexml/model/bibtexmlHand written.xsd?revision=9416&view=markup

The resource factory impls only differ on this line:

XMLResource result = new QsarResourceImpl(uri);
--
XMLResource result = new BibtexmlResourceImpl(uri);


Here is how I read a serialized file:

// Register the package -- only needed for stand-alone!
QsarPackage qsarPackage=QsarPackage.eINSTANCE;

// Register the package -- only needed for stand-alone!
BibtexmlPackage bibPackage=BibtexmlPackage.eINSTANCE;

// Create a resource set to hold the resources.
//
ResourceSet resourceSet = new ResourceSetImpl();

// Register the appropriate resource factory to handle all file
extensions.
//
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new QsarResourceFactoryImpl());

// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put
(QsarPackage.eNS_URI,
QsarPackage.eINSTANCE);

// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put
(BibtexmlPackage.eNS_URI,
BibtexmlPackage.eINSTANCE);

EcoreUtil.resolveAll( resourceSet );

// Get the URI of the model file.
URI fileURI = URI.createFileURI(new
File("myQSAR2.xml").getAbsolutePath());

// Demand load the resource for this file.
Resource resource=null;
try{
resource = resourceSet.getResource(fileURI, true);
}catch (Exception e){
e.printStackTrace();
}
DocumentRoot root=(DocumentRoot) resource.getContents().get(0);
QsarType qsar=root.getQsar();


Many thanks for your help, Ed.

Cheers,

/Ola
Re: Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428412 is a reply to message #428409] Fri, 20 March 2009 14:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ola,

Comments below.


Ola Spjuth wrote:
> Ed Merks skrev:
>> Ola,
>>
>> Comments below.
>>
>>
>> Ola Spjuth wrote:
>>> Hi,
>>>
>>> I have an XSD that imports and uses types from my other XSD. Model
>>> generation results in 2 ecore models, and I also generated the
>>> model, edit, and tests. I then wrote up some sample code to populate
>>> the model (with elemets defined in both schemas). All is well, it
>>> serializes as I intended.
>>>
>>> But, when trying to load the model in another standalone test class
>>> I get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>>> 'myFeature' not found when trying to load it back. Looking at the
>>> generated tests it seems I get 2 packages with Model1Example and
>>> Model2Example. Running Model1Example.main() complains that a feature
>>> defined in Model2 is not found.
>> Did you register the right resource factories?
>
> Can I register more than one? I do:
>
> // Register the appropriate resource factory to handle all file
> extensions.
> //
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,
> new QsarResourceFactoryImpl());
You can register one per file extension. But likely both factories look
the same and it won't matter.
>
>
>>>
>>> My question is, what do I need to add to Model1Example to make it
>>> read a serialized file that makes use of both models? I tried adding
>>> (in the Model1Example.java) the registration of the Model2 by:
>>>
>>> // Register the package to ensure it is available during loading.
>>> //
>>> resourceSet.getPackageRegistry().put
>>> (Model2Package.eNS_URI,
>>> Model2Package.eINSTANCE);
>> I'd expect this to work, but I wonder if either of these schema's are
>> null namespace schemas? Do their resource factory impls look different?
>
> As far as I can tell the schemas are not null-namespaced.
>
> Here are the schemas:
> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.qsar.model/model/qsar.xsd?r evision=9437&view=markup
>
> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.bibtexml/model/bibtexmlHand written.xsd?revision=9416&view=markup
>
>
> The resource factory impls only differ on this line:
>
> XMLResource result = new QsarResourceImpl(uri);
> --
> XMLResource result = new BibtexmlResourceImpl(uri);
No, I was getting at what the createResource methods looked like, but
given the are both schemas with namespace, I expect they look the same.
>
>
> Here is how I read a serialized file:
>
> // Register the package -- only needed for stand-alone!
> QsarPackage qsarPackage=QsarPackage.eINSTANCE;
>
> // Register the package -- only needed for stand-alone!
> BibtexmlPackage bibPackage=BibtexmlPackage.eINSTANCE;
>
> // Create a resource set to hold the resources.
> //
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register the appropriate resource factory to handle all file
> extensions.
> //
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,
> new QsarResourceFactoryImpl());
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put
> (QsarPackage.eNS_URI,
> QsarPackage.eINSTANCE);
>
> // Register the package to ensure it is available during loading.
> //
> resourceSet.getPackageRegistry().put
> (BibtexmlPackage.eNS_URI,
> BibtexmlPackage.eINSTANCE);
>
> EcoreUtil.resolveAll( resourceSet );
>
> // Get the URI of the model file.
> URI fileURI = URI.createFileURI(new
> File("myQSAR2.xml").getAbsolutePath());
>
> // Demand load the resource for this file.
> Resource resource=null;
> try{
> resource = resourceSet.getResource(fileURI, true);
> }catch (Exception e){
> e.printStackTrace();
> }
> DocumentRoot root=(DocumentRoot) resource.getContents().get(0);
> QsarType qsar=root.getQsar();
So what does the document your document look like? It's starting to
sound like it doesn't conform to the schema. One way this might happen
is if you serialize without a DocumentRoot in the resource.getContents()
when you save....
>
>
> Many thanks for your help, Ed.
>
> Cheers,
>
> /Ola


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428419 is a reply to message #428412] Fri, 20 March 2009 16:04 Go to previous messageGo to next message
Eclipse UserFriend
Ed,

Thanks for your time. I posted info below.

Ed Merks skrev:
> Ola,
>
> Comments below.
>>> Ola Spjuth wrote:
>>>> Hi,
>>>>
>>>> I have an XSD that imports and uses types from my other XSD. Model
>>>> generation results in 2 ecore models, and I also generated the
>>>> model, edit, and tests. I then wrote up some sample code to populate
>>>> the model (with elemets defined in both schemas). All is well, it
>>>> serializes as I intended.
>>>>
>>>> But, when trying to load the model in another standalone test class
>>>> I get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>>>> 'myFeature' not found when trying to load it back. Looking at the
>>>> generated tests it seems I get 2 packages with Model1Example and
>>>> Model2Example. Running Model1Example.main() complains that a feature
>>>> defined in Model2 is not found.
>>> Did you register the right resource factories?
>>
>> Can I register more than one? I do:
>>
>> // Register the appropriate resource factory to handle all file
>> extensions.
>> //
>>
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>> new QsarResourceFactoryImpl());
> You can register one per file extension. But likely both factories look
> the same and it won't matter.
>>
>>
>>>>
>>>> My question is, what do I need to add to Model1Example to make it
>>>> read a serialized file that makes use of both models? I tried adding
>>>> (in the Model1Example.java) the registration of the Model2 by:
>>>>
>>>> // Register the package to ensure it is available during loading.
>>>> //
>>>> resourceSet.getPackageRegistry().put
>>>> (Model2Package.eNS_URI,
>>>> Model2Package.eINSTANCE);
>>> I'd expect this to work, but I wonder if either of these schema's are
>>> null namespace schemas? Do their resource factory impls look different?
>>
>> As far as I can tell the schemas are not null-namespaced.
>>
>> Here are the schemas:
>> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.qsar.model/model/qsar.xsd?r evision=9437&view=markup
>>
>> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.bibtexml/model/bibtexmlHand written.xsd?revision=9416&view=markup
>>
>>
>> The resource factory impls only differ on this line:
>>
>> XMLResource result = new QsarResourceImpl(uri);
>> --
>> XMLResource result = new BibtexmlResourceImpl(uri);
> No, I was getting at what the createResource methods looked like, but
> given the are both schemas with namespace, I expect they look the same.
>>
>>
>> Here is how I read a serialized file:
>>
>> // Register the package -- only needed for stand-alone!
>> QsarPackage qsarPackage=QsarPackage.eINSTANCE;
>>
>> // Register the package -- only needed for stand-alone!
>> BibtexmlPackage bibPackage=BibtexmlPackage.eINSTANCE;
>>
>> // Create a resource set to hold the resources.
>> //
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> // Register the appropriate resource factory to handle all file
>> extensions.
>> //
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>> new QsarResourceFactoryImpl());
>>
>> // Register the package to ensure it is available during loading.
>> //
>> resourceSet.getPackageRegistry().put
>> (QsarPackage.eNS_URI,
>> QsarPackage.eINSTANCE);
>>
>> // Register the package to ensure it is available during loading.
>> //
>> resourceSet.getPackageRegistry().put
>> (BibtexmlPackage.eNS_URI,
>> BibtexmlPackage.eINSTANCE);
>>
>> EcoreUtil.resolveAll( resourceSet );
>>
>> // Get the URI of the model file.
>> URI fileURI = URI.createFileURI(new
>> File("myQSAR2.xml").getAbsolutePath());
>> // Demand load the resource for this file.
>> Resource resource=null;
>> try{
>> resource = resourceSet.getResource(fileURI, true);
>> }catch (Exception e){
>> e.printStackTrace();
>> }
>> DocumentRoot root=(DocumentRoot) resource.getContents().get(0);
>> QsarType qsar=root.getQsar();
> So what does the document your document look like? It's starting to
> sound like it doesn't conform to the schema. One way this might happen
> is if you serialize without a DocumentRoot in the resource.getContents()
> when you save....

Here is my document:
============================

<?xml version="1.0" encoding="UTF-8"?>
<qsar:qsar xmlns:bibtexml="http://bibtexml.sf.net/"
xmlns:qsar="http://www.bioclipse.net/qsar">
<qsar:structurelist>
<qsar:resources checksum="N/A" file="polycarpol.mol" id="mol1"
name="polycarpol" type="text">
<qsar:structure id="struct1" inchi="N/A" resourceindex="0"/>
</qsar:resources>
<qsar:resources checksum="N/A" file="smallCollection.sdf" id="mol2"
name="smallCollection" type="text">
<qsar:structure id="struct2" inchi="N/A" resourceindex="0"/>
</qsar:resources>
<qsar:resources id="res3" name="reserpine" type="xml"
URL=" http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=5770 &amp;disopt=SaveXML"/>
</qsar:structurelist>
<qsar:descriptorlist>
<qsar:descriptors
id=" http://www.blueobelisk.org/ontologies/chemoinformatics-algor ithms/#xlogP"
namespace="http://www.blueobelisk.org" provider="cdk">
<qsar:parameter key="checkAromaticity" value="true"/>
<qsar:parameter key="salicylFlag" value="false"/>
</qsar:descriptors>
<qsar:descriptors
id=" http://www.blueobelisk.org/ontologies/chemoinformatics-algor ithms/#atomCount"
namespace="http://www.blueobelisk.org" provider="cdk"/>
</qsar:descriptorlist>
<qsar:descriptorproviders id="cdk" name="Chemistry Development Kit"
URL="http://cdk.sourceforge.net" vendor="Chemistry Development Kit"
version="1.1.0.20080808"/>
<qsar:descriptorproviders id="dragon" name="Dragon descriptor"
URL="http://talete.mi.it" vendor="Talete" version="5.14"/>
<qsar:preprocessing>
<qsar:preprocessingStep id="Smi23d" name="Generate 3D coordinates
with smi23d" namespace="http://www.chembiogrid.org/cheminfo/smi23d/"
order="1"/>
<qsar:preprocessingStep id="org.openscience.cdk.atomtype.sybyl"
name="Sybyl Atom Types" namespace="http://cdk.sf.net" order="2"/>
</qsar:preprocessing>
<qsar:responselist>
<qsar:response structureID="mol2" unit="ic50">
<qsar:value>11.45</qsar:value>
</qsar:response>
<qsar:response unit="ic50">
<qsar:value>15.45</qsar:value>
</qsar:response>
<qsar:response structureID="res3" unit="ic50">
<qsar:arrayValues>12.56,23.45,34.56</qsar:arrayValues>
</qsar:response>
</qsar:responselist>
<qsar:responseunit description="Measure of the effectiveness of a
compound in inhibiting biological or biochemical function" id="ic50"
name="half maximal inhibitory concentration (IC50)" shortname="IC50"
URL="http://en.wikipedia.org/wiki/IC50"/>
<qsar:metadata authors="Ola Spjuth" datasetname="olas dataset"
description="A dataset describing a lot of thins. Pretty much
everything." license="Creative Blah License" URL="http://www.bioclipse.net">
<bibtexml:entry id="article1">
<bibtexml:article>
<bibtexml:author>Spjuth, Ola and Helmus, Tobias and
Willighagen, Egon and Kuhn, Stefan and Eklund, Martin and Wagener,
Johannes and Murray-Rust, Peter and Steinbeck, Christoph and Wikberg,
Jarl</bibtexml:author>
<bibtexml:title>Bioclipse: an open source workbench for chemo-
and bioinformatics</bibtexml:title>
<bibtexml:journal>BMC Bioinformatics</bibtexml:journal>
<bibtexml:year>2007</bibtexml:year>
<bibtexml:volume>8</bibtexml:volume>
<bibtexml:number>1</bibtexml:number>
<bibtexml:pages>59</bibtexml:pages>
<bibtexml:doi>10.1186/1471-2105-8-59</bibtexml:doi>

<bibtexml:url>http://www.biomedcentral.com/1471-2105/8/59</bibtexml:url>
</bibtexml:article>
</bibtexml:entry>
</qsar:metadata>
</qsar:qsar>



Here is how I serialize it:
============================

//Create the super types
DocumentRoot root=QsarFactory.eINSTANCE.createDocumentRoot();

//Create editor type to hold everything else
QsarType qsar=QsarFactory.eINSTANCE.createQsarType();

root.setQsar(qsar);
//Add elements and attributes here...
//[SNIP]

ResourceSet resourceSet=new ResourceSetImpl();
URI fileURI;
try {
fileURI = URI.createFileURI(new File("myQSAR2.xml").getAbsolutePath());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xml",
new QsarResourceFactoryImpl());
Resource resource=resourceSet.createResource(fileURI);
resource.getContents().add(root);
Map opts=new HashMap();
opts.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
opts.put(XMLResource.OPTION_ENCODING, "UTF-8");

//Save to file
resource.save(opts);

//Serialize to byte[] and print to sysout
ByteArrayOutputStream os=new ByteArrayOutputStream();
resource.save(os, opts);
System.out.println(new String(os.toByteArray()));
} catch (IOException e) {
e.printStackTrace();
}

Thanks,

/Ola
Re: Reading serialized model generated from multiple schemas throws FeatureNotFoundException [message #428426 is a reply to message #428419] Fri, 20 March 2009 17:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ola,

It all looks okay. What's the exact exception? Can you export and
share the zipped projects so I could reproduce it?


Ola Spjuth wrote:
> Ed,
>
> Thanks for your time. I posted info below.
>
> Ed Merks skrev:
>> Ola,
>>
>> Comments below.
>>>> Ola Spjuth wrote:
>>>>> Hi,
>>>>>
>>>>> I have an XSD that imports and uses types from my other XSD. Model
>>>>> generation results in 2 ecore models, and I also generated the
>>>>> model, edit, and tests. I then wrote up some sample code to
>>>>> populate the model (with elemets defined in both schemas). All is
>>>>> well, it serializes as I intended.
>>>>>
>>>>> But, when trying to load the model in another standalone test
>>>>> class I get an org.eclipse.emf.ecore.xmi.FeatureNotFoundException:
>>>>> Feature 'myFeature' not found when trying to load it back. Looking
>>>>> at the generated tests it seems I get 2 packages with
>>>>> Model1Example and Model2Example. Running Model1Example.main()
>>>>> complains that a feature defined in Model2 is not found.
>>>> Did you register the right resource factories?
>>>
>>> Can I register more than one? I do:
>>>
>>> // Register the appropriate resource factory to handle all file
>>> extensions.
>>> //
>>>
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>> new QsarResourceFactoryImpl());
>> You can register one per file extension. But likely both factories
>> look the same and it won't matter.
>>>
>>>
>>>>>
>>>>> My question is, what do I need to add to Model1Example to make it
>>>>> read a serialized file that makes use of both models? I tried
>>>>> adding (in the Model1Example.java) the registration of the Model2 by:
>>>>>
>>>>> // Register the package to ensure it is available during loading.
>>>>> //
>>>>> resourceSet.getPackageRegistry().put
>>>>> (Model2Package.eNS_URI,
>>>>> Model2Package.eINSTANCE);
>>>> I'd expect this to work, but I wonder if either of these schema's
>>>> are null namespace schemas? Do their resource factory impls look
>>>> different?
>>>
>>> As far as I can tell the schemas are not null-namespaced.
>>>
>>> Here are the schemas:
>>> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.qsar.model/model/qsar.xsd?r evision=9437&view=markup
>>>
>>> http://bioclipse.svn.sourceforge.net/viewvc/bioclipse/biocli pse2/trunk/plugins/net.bioclipse.bibtexml/model/bibtexmlHand written.xsd?revision=9416&view=markup
>>>
>>>
>>> The resource factory impls only differ on this line:
>>>
>>> XMLResource result = new QsarResourceImpl(uri);
>>> --
>>> XMLResource result = new BibtexmlResourceImpl(uri);
>> No, I was getting at what the createResource methods looked like, but
>> given the are both schemas with namespace, I expect they look the same.
>>>
>>>
>>> Here is how I read a serialized file:
>>>
>>> // Register the package -- only needed for stand-alone!
>>> QsarPackage qsarPackage=QsarPackage.eINSTANCE;
>>>
>>> // Register the package -- only needed for stand-alone!
>>> BibtexmlPackage bibPackage=BibtexmlPackage.eINSTANCE;
>>>
>>> // Create a resource set to hold the resources.
>>> //
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>
>>> // Register the appropriate resource factory to handle all file
>>> extensions.
>>> //
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>
>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>> new QsarResourceFactoryImpl());
>>>
>>> // Register the package to ensure it is available during loading.
>>> //
>>> resourceSet.getPackageRegistry().put
>>> (QsarPackage.eNS_URI,
>>> QsarPackage.eINSTANCE);
>>>
>>> // Register the package to ensure it is available during loading.
>>> //
>>> resourceSet.getPackageRegistry().put
>>> (BibtexmlPackage.eNS_URI,
>>> BibtexmlPackage.eINSTANCE);
>>>
>>> EcoreUtil.resolveAll( resourceSet );
>>>
>>> // Get the URI of the model file.
>>> URI fileURI = URI.createFileURI(new
>>> File("myQSAR2.xml").getAbsolutePath());
>>> // Demand load the resource for this file.
>>> Resource resource=null;
>>> try{
>>> resource = resourceSet.getResource(fileURI, true);
>>> }catch (Exception e){
>>> e.printStackTrace();
>>> }
>>> DocumentRoot root=(DocumentRoot) resource.getContents().get(0);
>>> QsarType qsar=root.getQsar();
>> So what does the document your document look like? It's starting to
>> sound like it doesn't conform to the schema. One way this might
>> happen is if you serialize without a DocumentRoot in the
>> resource.getContents() when you save....
>
> Here is my document:
> ============================
>
> <?xml version="1.0" encoding="UTF-8"?>
> <qsar:qsar xmlns:bibtexml="http://bibtexml.sf.net/"
> xmlns:qsar="http://www.bioclipse.net/qsar">
> <qsar:structurelist>
> <qsar:resources checksum="N/A" file="polycarpol.mol" id="mol1"
> name="polycarpol" type="text">
> <qsar:structure id="struct1" inchi="N/A" resourceindex="0"/>
> </qsar:resources>
> <qsar:resources checksum="N/A" file="smallCollection.sdf"
> id="mol2" name="smallCollection" type="text">
> <qsar:structure id="struct2" inchi="N/A" resourceindex="0"/>
> </qsar:resources>
> <qsar:resources id="res3" name="reserpine" type="xml"
> URL=" http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=5770 &amp;disopt=SaveXML"/>
>
> </qsar:structurelist>
> <qsar:descriptorlist>
> <qsar:descriptors
> id=" http://www.blueobelisk.org/ontologies/chemoinformatics-algor ithms/#xlogP"
> namespace="http://www.blueobelisk.org" provider="cdk">
> <qsar:parameter key="checkAromaticity" value="true"/>
> <qsar:parameter key="salicylFlag" value="false"/>
> </qsar:descriptors>
> <qsar:descriptors
> id=" http://www.blueobelisk.org/ontologies/chemoinformatics-algor ithms/#atomCount"
> namespace="http://www.blueobelisk.org" provider="cdk"/>
> </qsar:descriptorlist>
> <qsar:descriptorproviders id="cdk" name="Chemistry Development Kit"
> URL="http://cdk.sourceforge.net" vendor="Chemistry Development Kit"
> version="1.1.0.20080808"/>
> <qsar:descriptorproviders id="dragon" name="Dragon descriptor"
> URL="http://talete.mi.it" vendor="Talete" version="5.14"/>
> <qsar:preprocessing>
> <qsar:preprocessingStep id="Smi23d" name="Generate 3D coordinates
> with smi23d" namespace="http://www.chembiogrid.org/cheminfo/smi23d/"
> order="1"/>
> <qsar:preprocessingStep id="org.openscience.cdk.atomtype.sybyl"
> name="Sybyl Atom Types" namespace="http://cdk.sf.net" order="2"/>
> </qsar:preprocessing>
> <qsar:responselist>
> <qsar:response structureID="mol2" unit="ic50">
> <qsar:value>11.45</qsar:value>
> </qsar:response>
> <qsar:response unit="ic50">
> <qsar:value>15.45</qsar:value>
> </qsar:response>
> <qsar:response structureID="res3" unit="ic50">
> <qsar:arrayValues>12.56,23.45,34.56</qsar:arrayValues>
> </qsar:response>
> </qsar:responselist>
> <qsar:responseunit description="Measure of the effectiveness of a
> compound in inhibiting biological or biochemical function" id="ic50"
> name="half maximal inhibitory concentration (IC50)" shortname="IC50"
> URL="http://en.wikipedia.org/wiki/IC50"/>
> <qsar:metadata authors="Ola Spjuth" datasetname="olas dataset"
> description="A dataset describing a lot of thins. Pretty much
> everything." license="Creative Blah License"
> URL="http://www.bioclipse.net">
> <bibtexml:entry id="article1">
> <bibtexml:article>
> <bibtexml:author>Spjuth, Ola and Helmus, Tobias and
> Willighagen, Egon and Kuhn, Stefan and Eklund, Martin and Wagener,
> Johannes and Murray-Rust, Peter and Steinbeck, Christoph and Wikberg,
> Jarl</bibtexml:author>
> <bibtexml:title>Bioclipse: an open source workbench for chemo-
> and bioinformatics</bibtexml:title>
> <bibtexml:journal>BMC Bioinformatics</bibtexml:journal>
> <bibtexml:year>2007</bibtexml:year>
> <bibtexml:volume>8</bibtexml:volume>
> <bibtexml:number>1</bibtexml:number>
> <bibtexml:pages>59</bibtexml:pages>
> <bibtexml:doi>10.1186/1471-2105-8-59</bibtexml:doi>
>
> <bibtexml:url>http://www.biomedcentral.com/1471-2105/8/59</bibtexml:url>
> </bibtexml:article>
> </bibtexml:entry>
> </qsar:metadata>
> </qsar:qsar>
>
>
>
> Here is how I serialize it:
> ============================
>
> //Create the super types
> DocumentRoot root=QsarFactory.eINSTANCE.createDocumentRoot();
>
> //Create editor type to hold everything else
> QsarType qsar=QsarFactory.eINSTANCE.createQsarType();
>
> root.setQsar(qsar);
> //Add elements and attributes here...
> //[SNIP]
>
> ResourceSet resourceSet=new ResourceSetImpl();
> URI fileURI;
> try {
> fileURI = URI.createFileURI(new
> File("myQSAR2.xml").getAbsolutePath());
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xml",
> new QsarResourceFactoryImpl());
> Resource resource=resourceSet.createResource(fileURI);
> resource.getContents().add(root);
> Map opts=new HashMap();
> opts.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
> opts.put(XMLResource.OPTION_ENCODING, "UTF-8");
>
> //Save to file
> resource.save(opts);
>
> //Serialize to byte[] and print to sysout
> ByteArrayOutputStream os=new ByteArrayOutputStream();
> resource.save(os, opts);
> System.out.println(new String(os.toByteArray()));
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> Thanks,
>
> /Ola


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo]how to avoid backticks in column and table names
Next Topic:Feature 'ecore' not found
Goto Forum:
  


Current Time: Mon Sep 23 04:51:03 GMT 2024

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

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

Back to the top