Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Dynamic mapping using XSDEcoreBuilder
[Teneo] Dynamic mapping using XSDEcoreBuilder [message #71113] Fri, 09 February 2007 03:37 Go to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
I've been trying to use XSDEcoreBuilder to generate the EPackages rather than use the generated Java implementation classes. I've run into a bunch of problems doing this and wondered if anyone else has done this successfully and has a recipe for success.

My learning experience has been that I need to make sure that the same package is not presented twice to Teneo's HbDataStore.setEPackages() method. When doing so, I ran into several null pointer exceptions. I have 3 XSDs that are imported by 3 other XSDs. When I use XSDEcoreBuilder.generate(), it returns each of the imported XSDs in addition with each call to generate on the XSDs that import them.

I'm still having a set of issues that may or be related to each other. The first is that after the mapping is complete, I tend to see 4 instances of the same table, but with "1"'s appended for each of the duplicates. This occurs for every type in the imported namespaces. For example:

ziptypes_device, ziptypes_device1, ziptypes_device11, and ziptypes_device111

I'm presuming that the problem is has to do with how the ecore packages are getting created making each of the dependent packages look like unique packages even though the namespaces and all of the underlying objects are the same.

When an instance of one of these schemas is loaded and then persisted using Teneo/hibernate, I get the following NPE. I'm presuming that it is caused by this same issue with the packages but I am unsure.

Exception in thread "main" java.lang.NullPointerException
at org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
at org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
at org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
at org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
at org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
at org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
at org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
at org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)

Any advice on how to handle dynamically loading packages and using them within Teneo are greatly appreciated. Everything thing seems to be working OK using the generated Java packages.

Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71132 is a reply to message #71113] Fri, 09 February 2007 11:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
I think Ed can best answer the questions related to how to import related epackages from multiple
xsd's. My impression (but I am not sure) is that the XSDEcoreBuilder does not register the epackage
in the global epackage registry. This is at least required for Teneo.

Related to the table naming, can you upload the generated hibernate mapping?

gr. Martin

Brian Vetter wrote:
> I've been trying to use XSDEcoreBuilder to generate the EPackages rather
> than use the generated Java implementation classes. I've run into a
> bunch of problems doing this and wondered if anyone else has done this
> successfully and has a recipe for success.
>
> My learning experience has been that I need to make sure that the same
> package is not presented twice to Teneo's HbDataStore.setEPackages()
> method. When doing so, I ran into several null pointer exceptions. I
> have 3 XSDs that are imported by 3 other XSDs. When I use
> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
> addition with each call to generate on the XSDs that import them.
>
> I'm still having a set of issues that may or be related to each other.
> The first is that after the mapping is complete, I tend to see 4
> instances of the same table, but with "1"'s appended for each of the
> duplicates. This occurs for every type in the imported namespaces. For
> example:
>
> ziptypes_device, ziptypes_device1, ziptypes_device11, and
> ziptypes_device111
>
> I'm presuming that the problem is has to do with how the ecore packages
> are getting created making each of the dependent packages look like
> unique packages even though the namespaces and all of the underlying
> objects are the same.
>
> When an instance of one of these schemas is loaded and then persisted
> using Teneo/hibernate, I get the following NPE. I'm presuming that it is
> caused by this same issue with the packages but I am unsure.
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
> at
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at
> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
> at
> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>
> Any advice on how to handle dynamically loading packages and using them
> within Teneo are greatly appreciated. Everything thing seems to be
> working OK using the generated Java packages.
>
> Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71152 is a reply to message #71113] Fri, 09 February 2007 11:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Brian,

Comments below.


Brian Vetter wrote:
> I've been trying to use XSDEcoreBuilder to generate the EPackages
> rather than use the generated Java implementation classes. I've run
> into a bunch of problems doing this and wondered if anyone else has
> done this successfully and has a recipe for success.
>
> My learning experience has been that I need to make sure that the same
> package is not presented twice to Teneo's HbDataStore.setEPackages()
> method. When doing so, I ran into several null pointer exceptions. I
> have 3 XSDs that are imported by 3 other XSDs. When I use
> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
> addition with each call to generate on the XSDs that import them.
It sounds like you want to call "Collection<Object>
generate(Collection<URI> uris)" so that a single resource set is used to
process all the schemas and hence a single set of packages representing
them all will be produced.
>
> I'm still having a set of issues that may or be related to each other.
> The first is that after the mapping is complete, I tend to see 4
> instances of the same table, but with "1"'s appended for each of the
> duplicates. This occurs for every type in the imported namespaces.
> For example:
>
> ziptypes_device, ziptypes_device1, ziptypes_device11, and
> ziptypes_device111
>
> I'm presuming that the problem is has to do with how the ecore
> packages are getting created making each of the dependent packages
> look like unique packages even though the namespaces and all of the
> underlying objects are the same.
Yes, it sounds likely that you are getting duplicate packages if you are
calling "Collection<EObject> generate(URI uri)" multiple times.
>
> When an instance of one of these schemas is loaded and then persisted
> using Teneo/hibernate, I get the following NPE. I'm presuming that it
> is caused by this same issue with the packages but I am unsure.
With regard to Martin's comment about global registration, the
XSDEcoreBuilder has a constructor that allow you to pass in an
ExtendedMetaData instance. The default constructor just creates a new
empty instance of it. So if you use new
XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
registered in the global registry as a side effect of generating them...
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
> at
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at
> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
> at
> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>
> Any advice on how to handle dynamically loading packages and using
> them within Teneo are greatly appreciated. Everything thing seems to
> be working OK using the generated Java packages.
>
> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71256 is a reply to message #71152] Sat, 10 February 2007 23:24 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
The trick to get this to work was to use the generate(Collection<URI> uris) method and not individual calls to generate(uri).

The problem had nothing to do with the registration. I had been registering the packages manually. I had taken care to not register the same namespace more than once, but that didn't seem to matter. I also changed it to use the ExtendedMetaData.INSTANCE argument to the builder constructor and got the same incorrect results.

While I have it working correctly today, I'd like to understand how I could do this more "dynamically" in the future as opposed to having to batch up all of the potential namespaces in a single call to generate(). More specifically, I'd like my server to be handed a URI to an XSD while it is running and then "magically" do the appropriate registrations and such to then persist new documents using that XSD. I'd like to do this without having to restart the server.

At present, I have two obstacles. One, Teneo only has a setPackages() method that can be called on the datastore. The packages are mapped when the datastore is initialized. While I haven't tried it, I figure that to be able to dynamically add new packages after the server is up and running, I'd have to destroy the current datastore and create a new one with the new packages that were added. Not the best answer, but it sounds doable. I'm presuming I can make it work somehow.

However, the second problem is with the global registry. If I can't add new packages on the fly, is there a similar (or better) way to rebuild the list of packages in the global registry? If not, is there some reason why separate generate() calls could not reuse any dependent packages that are already in the global registry?

Thanks,

Brian

Ed Merks wrote:
> Brian,
>
> Comments below.
>
>
> Brian Vetter wrote:
>> I've been trying to use XSDEcoreBuilder to generate the EPackages
>> rather than use the generated Java implementation classes. I've run
>> into a bunch of problems doing this and wondered if anyone else has
>> done this successfully and has a recipe for success.
>>
>> My learning experience has been that I need to make sure that the same
>> package is not presented twice to Teneo's HbDataStore.setEPackages()
>> method. When doing so, I ran into several null pointer exceptions. I
>> have 3 XSDs that are imported by 3 other XSDs. When I use
>> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
>> addition with each call to generate on the XSDs that import them.
> It sounds like you want to call "Collection<Object>
> generate(Collection<URI> uris)" so that a single resource set is used to
> process all the schemas and hence a single set of packages representing
> them all will be produced.
>>
>> I'm still having a set of issues that may or be related to each other.
>> The first is that after the mapping is complete, I tend to see 4
>> instances of the same table, but with "1"'s appended for each of the
>> duplicates. This occurs for every type in the imported namespaces.
>> For example:
>>
>> ziptypes_device, ziptypes_device1, ziptypes_device11, and
>> ziptypes_device111
>>
>> I'm presuming that the problem is has to do with how the ecore
>> packages are getting created making each of the dependent packages
>> look like unique packages even though the namespaces and all of the
>> underlying objects are the same.
> Yes, it sounds likely that you are getting duplicate packages if you are
> calling "Collection<EObject> generate(URI uri)" multiple times.
>>
>> When an instance of one of these schemas is loaded and then persisted
>> using Teneo/hibernate, I get the following NPE. I'm presuming that it
>> is caused by this same issue with the packages but I am unsure.
> With regard to Martin's comment about global registration, the
> XSDEcoreBuilder has a constructor that allow you to pass in an
> ExtendedMetaData instance. The default constructor just creates a new
> empty instance of it. So if you use new
> XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
> registered in the global registry as a side effect of generating them...
>>
>> Exception in thread "main" java.lang.NullPointerException
>> at
>> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
>> at
>> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>>
>> at
>> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>>
>> at
>> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>>
>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>
>> at
>> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
>> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
>> at
>> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
>> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
>> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
>> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>
>> at
>> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>
>> at
>> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>
>> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
>> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
>> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>>
>> Any advice on how to handle dynamically loading packages and using
>> them within Teneo are greatly appreciated. Everything thing seems to
>> be working OK using the generated Java packages.
>>
>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71277 is a reply to message #71132] Sun, 11 February 2007 08:33 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Martin & Ed,

I got past the original issues by implementing Ed's suggestion to generate all of the ecore mappings at once using a collection instead of generating each individually. I have been able to persist XML documents of various XSDs without the need to generate and compile supporting Java classes.

However if I try to load these objects using a hibernate query, I get a null pointer exception. I've run two variations of the program exactly equal but with one difference - one utilizes the Java classes when registering the packages with Teneo and the other uses the packages generated using the XSDEcoreBuilder (this time using the generate(collection) method that works for persisting the same XML documents).

In looking at the stack trace, it gets a long ways down the query path before it hits an NPE in a Teneo setter method from the hibernate tuplizer. It is tripping in the convert() method in EAttributePropertyHandler over a null instanceClass. The actual type is an attribute on a simple type that extends long. The attribute has an enumerated list of potential values.

In trying to determine what was different between the dynamic version and the one using the generated Java classes, I found the following:

1) The order of the registered packages passed to Teneo varied between the two.
2) After forcing the order of the packages to be the same in both, I found that the hibernate mappings varied in many ways.
2a) The names in the typedef elements were frequently (but not always) different. In particular, in the working version where the java classes are used, the names typically started with the NsPrefix of the package. In the auto-generated version, it used a transformed version of the fully qualified namespace.
2b) Some of the property mappings were different. In fact, it appears that almost all of the mappings that were different were those that were dealing with the elements or attributes that had restrictions of Strings with an enumeration list.

It is 2b above that I think is causing me my trouble: Here is an example of the type mapping (in this case, it is the one that the NPE is being thrown, but it is the first one that the mapping has run up against):

In the case where it is using the generated Java classes:
<property name="unit" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`unit`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
<param name="enumClass">org.ziptie._1._0.basictypes.UnitType1</param >
</type>
</property>

In the case where it is dynamically created:
<property name="unit" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`unit`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.DynamicENumUserType ">
<param name="eclassifier">UnitType1</param>
<param name="epackage">http://www.ziptie.org/1.0/basictypes</param>
</type>
</property>

Notice that the type mapping is quite different. In the second case, the method called by the tuplizer gets an NPE.

I'm not sure if ecore is treating these as different or if Teneo is not handling a particular ecore mapping properly. I'm presuming that there is some issue with Teneo handling the dynamic enum case since no class is there to implement it directly.

I noticed a couple of statements about problems with enumerates on the Teneo troubleshooting page. I didn't see any issues w.r.t. dynamic mapping vs. using generated java classes so it wasn't clear that there is any relation (especially since it appears to work using the generated java).

Brian


Martin Taal wrote:
> Brian,
> I think Ed can best answer the questions related to how to import
> related epackages from multiple xsd's. My impression (but I am not sure)
> is that the XSDEcoreBuilder does not register the epackage in the global
> epackage registry. This is at least required for Teneo.
>
> Related to the table naming, can you upload the generated hibernate
> mapping?
>
> gr. Martin

>
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71297 is a reply to message #71256] Sun, 11 February 2007 13:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Brian,

If you look at the two generate methods, you'll see that they
effectively just create a resource set, load one or more schema
resources, and then call generate(XSDSchema) for each schema. So you
could define a derived builder that maintains a resource set as a field
and keeps reusing it for each call (perhaps just by overriding
createResourceSet to return the same one each time).


Brian Vetter wrote:
> The trick to get this to work was to use the generate(Collection<URI>
> uris) method and not individual calls to generate(uri).
>
> The problem had nothing to do with the registration. I had been
> registering the packages manually. I had taken care to not register
> the same namespace more than once, but that didn't seem to matter. I
> also changed it to use the ExtendedMetaData.INSTANCE argument to the
> builder constructor and got the same incorrect results.
>
> While I have it working correctly today, I'd like to understand how I
> could do this more "dynamically" in the future as opposed to having to
> batch up all of the potential namespaces in a single call to
> generate(). More specifically, I'd like my server to be handed a URI
> to an XSD while it is running and then "magically" do the appropriate
> registrations and such to then persist new documents using that XSD.
> I'd like to do this without having to restart the server.
>
> At present, I have two obstacles. One, Teneo only has a setPackages()
> method that can be called on the datastore. The packages are mapped
> when the datastore is initialized. While I haven't tried it, I figure
> that to be able to dynamically add new packages after the server is up
> and running, I'd have to destroy the current datastore and create a
> new one with the new packages that were added. Not the best answer,
> but it sounds doable. I'm presuming I can make it work somehow.
>
> However, the second problem is with the global registry. If I can't
> add new packages on the fly, is there a similar (or better) way to
> rebuild the list of packages in the global registry? If not, is there
> some reason why separate generate() calls could not reuse any
> dependent packages that are already in the global registry?
>
> Thanks,
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> Comments below.
>>
>>
>> Brian Vetter wrote:
>>> I've been trying to use XSDEcoreBuilder to generate the EPackages
>>> rather than use the generated Java implementation classes. I've run
>>> into a bunch of problems doing this and wondered if anyone else has
>>> done this successfully and has a recipe for success.
>>>
>>> My learning experience has been that I need to make sure that the
>>> same package is not presented twice to Teneo's
>>> HbDataStore.setEPackages() method. When doing so, I ran into several
>>> null pointer exceptions. I have 3 XSDs that are imported by 3 other
>>> XSDs. When I use XSDEcoreBuilder.generate(), it returns each of the
>>> imported XSDs in addition with each call to generate on the XSDs
>>> that import them.
>> It sounds like you want to call "Collection<Object>
>> generate(Collection<URI> uris)" so that a single resource set is used
>> to process all the schemas and hence a single set of packages
>> representing them all will be produced.
>>>
>>> I'm still having a set of issues that may or be related to each
>>> other. The first is that after the mapping is complete, I tend to
>>> see 4 instances of the same table, but with "1"'s appended for each
>>> of the duplicates. This occurs for every type in the imported
>>> namespaces. For example:
>>>
>>> ziptypes_device, ziptypes_device1, ziptypes_device11, and
>>> ziptypes_device111
>>>
>>> I'm presuming that the problem is has to do with how the ecore
>>> packages are getting created making each of the dependent packages
>>> look like unique packages even though the namespaces and all of the
>>> underlying objects are the same.
>> Yes, it sounds likely that you are getting duplicate packages if you
>> are calling "Collection<EObject> generate(URI uri)" multiple times.
>>>
>>> When an instance of one of these schemas is loaded and then
>>> persisted using Teneo/hibernate, I get the following NPE. I'm
>>> presuming that it is caused by this same issue with the packages but
>>> I am unsure.
>> With regard to Martin's comment about global registration, the
>> XSDEcoreBuilder has a constructor that allow you to pass in an
>> ExtendedMetaData instance. The default constructor just creates a
>> new empty instance of it. So if you use new
>> XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
>> registered in the global registry as a side effect of generating them...
>>>
>>> Exception in thread "main" java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
>>> at
>>> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>>>
>>> at
>>> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>>>
>>> at
>>> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>>>
>>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>>
>>> at
>>> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
>>> at
>>> org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
>>> at
>>> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
>>>
>>> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
>>> at
>>> org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
>>> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
>>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>>
>>> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
>>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
>>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
>>> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
>>> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>>>
>>> Any advice on how to handle dynamically loading packages and using
>>> them within Teneo are greatly appreciated. Everything thing seems to
>>> be working OK using the generated Java packages.
>>>
>>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71317 is a reply to message #71277] Sun, 11 February 2007 19:24 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
The npe has been solved and committed to cvs (we also encountered it this week).

gr. Martin

Brian Vetter wrote:
> Martin & Ed,
>
> I got past the original issues by implementing Ed's suggestion to
> generate all of the ecore mappings at once using a collection instead of
> generating each individually. I have been able to persist XML documents
> of various XSDs without the need to generate and compile supporting Java
> classes.
>
> However if I try to load these objects using a hibernate query, I get a
> null pointer exception. I've run two variations of the program exactly
> equal but with one difference - one utilizes the Java classes when
> registering the packages with Teneo and the other uses the packages
> generated using the XSDEcoreBuilder (this time using the
> generate(collection) method that works for persisting the same XML
> documents).
>
> In looking at the stack trace, it gets a long ways down the query path
> before it hits an NPE in a Teneo setter method from the hibernate
> tuplizer. It is tripping in the convert() method in
> EAttributePropertyHandler over a null instanceClass. The actual type is
> an attribute on a simple type that extends long. The attribute has an
> enumerated list of potential values.
>
> In trying to determine what was different between the dynamic version
> and the one using the generated Java classes, I found the following:
>
> 1) The order of the registered packages passed to Teneo varied between
> the two.
> 2) After forcing the order of the packages to be the same in both, I
> found that the hibernate mappings varied in many ways.
> 2a) The names in the typedef elements were frequently (but not
> always) different. In particular, in the working version where the java
> classes are used, the names typically started with the NsPrefix of the
> package. In the auto-generated version, it used a transformed version of
> the fully qualified namespace.
> 2b) Some of the property mappings were different. In fact, it
> appears that almost all of the mappings that were different were those
> that were dealing with the elements or attributes that had restrictions
> of Strings with an enumeration list.
>
> It is 2b above that I think is causing me my trouble: Here is an example
> of the type mapping (in this case, it is the one that the NPE is being
> thrown, but it is the first one that the mapping has run up against):
>
> In the case where it is using the generated Java classes:
> <property name="unit" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`unit`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie._1._0.basictypes.UnitType1</param >
> </type>
> </property>
>
> In the case where it is dynamically created:
> <property name="unit" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`unit`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.DynamicENumUserType ">
> <param name="eclassifier">UnitType1</param>
> <param
> name="epackage">http://www.ziptie.org/1.0/basictypes</param>
> </type>
> </property>
>
> Notice that the type mapping is quite different. In the second case, the
> method called by the tuplizer gets an NPE.
>
> I'm not sure if ecore is treating these as different or if Teneo is not
> handling a particular ecore mapping properly. I'm presuming that there
> is some issue with Teneo handling the dynamic enum case since no class
> is there to implement it directly.
>
> I noticed a couple of statements about problems with enumerates on the
> Teneo troubleshooting page. I didn't see any issues w.r.t. dynamic
> mapping vs. using generated java classes so it wasn't clear that there
> is any relation (especially since it appears to work using the generated
> java).
>
> Brian
>
>
> Martin Taal wrote:
>> Brian,
>> I think Ed can best answer the questions related to how to import
>> related epackages from multiple xsd's. My impression (but I am not
>> sure) is that the XSDEcoreBuilder does not register the epackage in
>> the global epackage registry. This is at least required for Teneo.
>>
>> Related to the table naming, can you upload the generated hibernate
>> mapping?
>>
>> gr. Martin
>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71396 is a reply to message #71297] Mon, 12 February 2007 23:59 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Ed,

I've implemented things this way and it worked for the case when I load up a bunch of XSDs at once. However, if I want to create a dynamic package and add it to this list, how exactly would I do it? There is no ResourceSet for the dynamic calls (at least I didn't see it, but then I'm pretty blind these days).

Is there some special api/trick to registering the dynamic package I created so that it is included with the others?

The particular issue I'm having is that when I combine the dynamic package with the others that are loaded, Teneo is giving me an exception complaining about a null EClass. The error message is:

Passed eclass is null.This can occur if epackages which refer to eachother are placed in different ecore/xsd files and they are not read using one resource set. The reference from one epackage to another must be resolvable by EMF.

My generated packages are referring to types in the ones loaded from the file uri.

Brian

Ed Merks wrote:
> Brian,
>
> If you look at the two generate methods, you'll see that they
> effectively just create a resource set, load one or more schema
> resources, and then call generate(XSDSchema) for each schema. So you
> could define a derived builder that maintains a resource set as a field
> and keeps reusing it for each call (perhaps just by overriding
> createResourceSet to return the same one each time).
>
>
> Brian Vetter wrote:
>> The trick to get this to work was to use the generate(Collection<URI>
>> uris) method and not individual calls to generate(uri).
>>
>> The problem had nothing to do with the registration. I had been
>> registering the packages manually. I had taken care to not register
>> the same namespace more than once, but that didn't seem to matter. I
>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>> builder constructor and got the same incorrect results.
>>
>> While I have it working correctly today, I'd like to understand how I
>> could do this more "dynamically" in the future as opposed to having to
>> batch up all of the potential namespaces in a single call to
>> generate(). More specifically, I'd like my server to be handed a URI
>> to an XSD while it is running and then "magically" do the appropriate
>> registrations and such to then persist new documents using that XSD.
>> I'd like to do this without having to restart the server.
>>
>> At present, I have two obstacles. One, Teneo only has a setPackages()
>> method that can be called on the datastore. The packages are mapped
>> when the datastore is initialized. While I haven't tried it, I figure
>> that to be able to dynamically add new packages after the server is up
>> and running, I'd have to destroy the current datastore and create a
>> new one with the new packages that were added. Not the best answer,
>> but it sounds doable. I'm presuming I can make it work somehow.
>>
>> However, the second problem is with the global registry. If I can't
>> add new packages on the fly, is there a similar (or better) way to
>> rebuild the list of packages in the global registry? If not, is there
>> some reason why separate generate() calls could not reuse any
>> dependent packages that are already in the global registry?
>>
>> Thanks,
>>
>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71414 is a reply to message #71396] Tue, 13 February 2007 13:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Brian,

It's not entirely clear to me the relationship between the dynamic
packages created (generated?) by the XSDEcoreBuilder and these other
dynamic ones or how these other ones are created. When you say the
"generated" packages refer to types in the one loaded from the file
URI. Do you really mean a static generated package or a dynamic one
created by the XSDEcoreBuilder? It doesn't seem possible for a
generated static package to refer to a dynamic one, so that's confusing.
Maybe you could paint a very simple scenario so that I understand better
the question you are asking...


Brian Vetter wrote:
> Ed,
>
> I've implemented things this way and it worked for the case when I
> load up a bunch of XSDs at once. However, if I want to create a
> dynamic package and add it to this list, how exactly would I do it?
> There is no ResourceSet for the dynamic calls (at least I didn't see
> it, but then I'm pretty blind these days).
>
> Is there some special api/trick to registering the dynamic package I
> created so that it is included with the others?
>
> The particular issue I'm having is that when I combine the dynamic
> package with the others that are loaded, Teneo is giving me an
> exception complaining about a null EClass. The error message is:
>
> Passed eclass is null.This can occur if epackages which refer to
> eachother are placed in different ecore/xsd files and they are not
> read using one resource set. The reference from one epackage to
> another must be resolvable by EMF.
>
> My generated packages are referring to types in the ones loaded from
> the file uri.
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> If you look at the two generate methods, you'll see that they
>> effectively just create a resource set, load one or more schema
>> resources, and then call generate(XSDSchema) for each schema. So you
>> could define a derived builder that maintains a resource set as a
>> field and keeps reusing it for each call (perhaps just by overriding
>> createResourceSet to return the same one each time).
>>
>>
>> Brian Vetter wrote:
>>> The trick to get this to work was to use the
>>> generate(Collection<URI> uris) method and not individual calls to
>>> generate(uri).
>>>
>>> The problem had nothing to do with the registration. I had been
>>> registering the packages manually. I had taken care to not register
>>> the same namespace more than once, but that didn't seem to matter. I
>>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>>> builder constructor and got the same incorrect results.
>>>
>>> While I have it working correctly today, I'd like to understand how
>>> I could do this more "dynamically" in the future as opposed to
>>> having to batch up all of the potential namespaces in a single call
>>> to generate(). More specifically, I'd like my server to be handed a
>>> URI to an XSD while it is running and then "magically" do the
>>> appropriate registrations and such to then persist new documents
>>> using that XSD. I'd like to do this without having to restart the
>>> server.
>>>
>>> At present, I have two obstacles. One, Teneo only has a
>>> setPackages() method that can be called on the datastore. The
>>> packages are mapped when the datastore is initialized. While I
>>> haven't tried it, I figure that to be able to dynamically add new
>>> packages after the server is up and running, I'd have to destroy the
>>> current datastore and create a new one with the new packages that
>>> were added. Not the best answer, but it sounds doable. I'm presuming
>>> I can make it work somehow.
>>>
>>> However, the second problem is with the global registry. If I can't
>>> add new packages on the fly, is there a similar (or better) way to
>>> rebuild the list of packages in the global registry? If not, is
>>> there some reason why separate generate() calls could not reuse any
>>> dependent packages that are already in the global registry?
>>>
>>> Thanks,
>>>
>>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71433 is a reply to message #71414] Tue, 13 February 2007 13:57 Go to previous messageGo to next message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Sorry for the confusing terms. Everything was dynamic. Here's the
steps/scenario:

I have a list of xsds in the file system that I load and generate the
ecore model using a subclass of the XSDEcoreBuilder.

In addition, I need to create a new EPackage and associated EClasses
that contain EReferences to types that are defined in the previously
generated ECore classes using EMF's dynamic APIs.

When I try to use Teneo to help persist instance of these packages, it
urps out an error message saying that they must be created in the same
resource.

Besides the basic registration with the package registry (which didn't
work), how do I register or associate the package created using the
dynamic APIs with the ones generated using the XSDEcoreBuilder class?

I've maintained the ResourceSet but I couldn't see how I could associate
it with the package I created using createEPackage(). Is there a
different factory I should use? A different registration function?

Brian

Ed Merks wrote:
> Brian,
>
> It's not entirely clear to me the relationship between the dynamic
> packages created (generated?) by the XSDEcoreBuilder and these other
> dynamic ones or how these other ones are created. When you say the
> "generated" packages refer to types in the one loaded from the file
> URI. Do you really mean a static generated package or a dynamic one
> created by the XSDEcoreBuilder? It doesn't seem possible for a
> generated static package to refer to a dynamic one, so that's confusing.
> Maybe you could paint a very simple scenario so that I understand better
> the question you are asking...
>
>
> Brian Vetter wrote:
>> Ed,
>>
>> I've implemented things this way and it worked for the case when I
>> load up a bunch of XSDs at once. However, if I want to create a
>> dynamic package and add it to this list, how exactly would I do it?
>> There is no ResourceSet for the dynamic calls (at least I didn't see
>> it, but then I'm pretty blind these days).
>>
>> Is there some special api/trick to registering the dynamic package I
>> created so that it is included with the others?
>>
>> The particular issue I'm having is that when I combine the dynamic
>> package with the others that are loaded, Teneo is giving me an
>> exception complaining about a null EClass. The error message is:
>>
>> Passed eclass is null.This can occur if epackages which refer to
>> eachother are placed in different ecore/xsd files and they are not
>> read using one resource set. The reference from one epackage to
>> another must be resolvable by EMF.
>>
>> My generated packages are referring to types in the ones loaded from
>> the file uri.
>>
>> Brian
>>
>> Ed Merks wrote:
>>> Brian,
>>>
>>> If you look at the two generate methods, you'll see that they
>>> effectively just create a resource set, load one or more schema
>>> resources, and then call generate(XSDSchema) for each schema. So you
>>> could define a derived builder that maintains a resource set as a
>>> field and keeps reusing it for each call (perhaps just by overriding
>>> createResourceSet to return the same one each time).
>>>
>>>
>>> Brian Vetter wrote:
>>>> The trick to get this to work was to use the
>>>> generate(Collection<URI> uris) method and not individual calls to
>>>> generate(uri).
>>>>
>>>> The problem had nothing to do with the registration. I had been
>>>> registering the packages manually. I had taken care to not register
>>>> the same namespace more than once, but that didn't seem to matter. I
>>>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>>>> builder constructor and got the same incorrect results.
>>>>
>>>> While I have it working correctly today, I'd like to understand how
>>>> I could do this more "dynamically" in the future as opposed to
>>>> having to batch up all of the potential namespaces in a single call
>>>> to generate(). More specifically, I'd like my server to be handed a
>>>> URI to an XSD while it is running and then "magically" do the
>>>> appropriate registrations and such to then persist new documents
>>>> using that XSD. I'd like to do this without having to restart the
>>>> server.
>>>>
>>>> At present, I have two obstacles. One, Teneo only has a
>>>> setPackages() method that can be called on the datastore. The
>>>> packages are mapped when the datastore is initialized. While I
>>>> haven't tried it, I figure that to be able to dynamically add new
>>>> packages after the server is up and running, I'd have to destroy the
>>>> current datastore and create a new one with the new packages that
>>>> were added. Not the best answer, but it sounds doable. I'm presuming
>>>> I can make it work somehow.
>>>>
>>>> However, the second problem is with the global registry. If I can't
>>>> add new packages on the fly, is there a similar (or better) way to
>>>> rebuild the list of packages in the global registry? If not, is
>>>> there some reason why separate generate() calls could not reuse any
>>>> dependent packages that are already in the global registry?
>>>>
>>>> Thanks,
>>>>
>>>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71471 is a reply to message #71433] Tue, 13 February 2007 16:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------030803020707030600040503
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Brian,

I'm not sure specifically what's causing Teneo to hiccup, so I'm not
sure what the best way to avoid that is...

If you look at this method in the XSDEcoreBuilder, you'll see that it
puts the EPackage into resources:

public Collection<Resource> generateResources(Collection<URI> uris)
{
ResourceSet resourceSet = createResourceSet();
for (URI uri : uris)
{
Resource resource = resourceSet.getResource(uri, true);
if (!resource.getContents().isEmpty() &&
resource.getContents().get(0) instanceof XSDSchema)
{
generate((XSDSchema)resource.getContents().get(0));
}
}
*
for (EPackage ePackage : targetNamespaceToEPackageMap.values())
{
if (ePackage.eResource() == null)
{
Resource ecoreResource =
resourceSet.createResource(URI.createURI("*.ecore"));
ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));
ecoreResource.getContents().add(ePackage);
}*
*}*

return new ArrayList<Resource>(resourceSet.getResources());
}

You don't necessarily have to call this method nor do you necessarily
have to put the packages in the same resource set as the schemas.

Perhaps all that's needed is for the packages to be registered in the
package registry of the resource set that you are using for your
manually constructed dynamic models. Given these constructors:

public XSDEcoreBuilder()
{
this(new BasicExtendedMetaData(new EPackageRegistryImpl()));
}

public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)
{
this.extendedMetaData = extendedMetaData;
populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);
populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);
}

one way to do that would be to do new XSDEcoreBuilder(new
BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).
The XSDEcoreBuilder will as a side effect register the EPackages it
creates in that package registry.


Brian Vetter wrote:
> Sorry for the confusing terms. Everything was dynamic. Here's the
> steps/scenario:
>
> I have a list of xsds in the file system that I load and generate the
> ecore model using a subclass of the XSDEcoreBuilder.
>
> In addition, I need to create a new EPackage and associated EClasses
> that contain EReferences to types that are defined in the previously
> generated ECore classes using EMF's dynamic APIs.
>
> When I try to use Teneo to help persist instance of these packages, it
> urps out an error message saying that they must be created in the same
> resource.
>
> Besides the basic registration with the package registry (which didn't
> work), how do I register or associate the package created using the
> dynamic APIs with the ones generated using the XSDEcoreBuilder class?
>
> I've maintained the ResourceSet but I couldn't see how I could
> associate it with the package I created using createEPackage(). Is
> there a different factory I should use? A different registration
> function?
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> It's not entirely clear to me the relationship between the dynamic
>> packages created (generated?) by the XSDEcoreBuilder and these other
>> dynamic ones or how these other ones are created. When you say the
>> "generated" packages refer to types in the one loaded from the file
>> URI. Do you really mean a static generated package or a dynamic one
>> created by the XSDEcoreBuilder? It doesn't seem possible for a
>> generated static package to refer to a dynamic one, so that's
>> confusing. Maybe you could paint a very simple scenario so that I
>> understand better the question you are asking...
>>
>>
>> Brian Vetter wrote:
>>> Ed,
>>>
>>> I've implemented things this way and it worked for the case when I
>>> load up a bunch of XSDs at once. However, if I want to create a
>>> dynamic package and add it to this list, how exactly would I do it?
>>> There is no ResourceSet for the dynamic calls (at least I didn't see
>>> it, but then I'm pretty blind these days).
>>>
>>> Is there some special api/trick to registering the dynamic package I
>>> created so that it is included with the others?
>>>
>>> The particular issue I'm having is that when I combine the dynamic
>>> package with the others that are loaded, Teneo is giving me an
>>> exception complaining about a null EClass. The error message is:
>>>
>>> Passed eclass is null.This can occur if epackages which refer to
>>> eachother are placed in different ecore/xsd files and they are not
>>> read using one resource set. The reference from one epackage to
>>> another must be resolvable by EMF.
>>>
>>> My generated packages are referring to types in the ones loaded from
>>> the file uri.
>>>
>>> Brian
>>>
>>> Ed Merks wrote:
>>>> Brian,
>>>>
>>>> If you look at the two generate methods, you'll see that they
>>>> effectively just create a resource set, load one or more schema
>>>> resources, and then call generate(XSDSchema) for each schema. So
>>>> you could define a derived builder that maintains a resource set as
>>>> a field and keeps reusing it for each call (perhaps just by
>>>> overriding createResourceSet to return the same one each time).
>>>>
>>>>
>>>> Brian Vetter wrote:
>>>>> The trick to get this to work was to use the
>>>>> generate(Collection<URI> uris) method and not individual calls to
>>>>> generate(uri).
>>>>>
>>>>> The problem had nothing to do with the registration. I had been
>>>>> registering the packages manually. I had taken care to not
>>>>> register the same namespace more than once, but that didn't seem
>>>>> to matter. I also changed it to use the ExtendedMetaData.INSTANCE
>>>>> argument to the builder constructor and got the same incorrect
>>>>> results.
>>>>>
>>>>> While I have it working correctly today, I'd like to understand
>>>>> how I could do this more "dynamically" in the future as opposed to
>>>>> having to batch up all of the potential namespaces in a single
>>>>> call to generate(). More specifically, I'd like my server to be
>>>>> handed a URI to an XSD while it is running and then "magically" do
>>>>> the appropriate registrations and such to then persist new
>>>>> documents using that XSD. I'd like to do this without having to
>>>>> restart the server.
>>>>>
>>>>> At present, I have two obstacles. One, Teneo only has a
>>>>> setPackages() method that can be called on the datastore. The
>>>>> packages are mapped when the datastore is initialized. While I
>>>>> haven't tried it, I figure that to be able to dynamically add new
>>>>> packages after the server is up and running, I'd have to destroy
>>>>> the current datastore and create a new one with the new packages
>>>>> that were added. Not the best answer, but it sounds doable. I'm
>>>>> presuming I can make it work somehow.
>>>>>
>>>>> However, the second problem is with the global registry. If I
>>>>> can't add new packages on the fly, is there a similar (or better)
>>>>> way to rebuild the list of packages in the global registry? If
>>>>> not, is there some reason why separate generate() calls could not
>>>>> reuse any dependent packages that are already in the global registry?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Brian


--------------030803020707030600040503
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Brian,<br>
<br>
I'm not sure specifically what's causing Teneo to hiccup, so I'm not
sure what the best way to avoid that is...&nbsp; <br>
<br>
If you look at this method in the XSDEcoreBuilder, you'll see that it
puts the EPackage into resources:<br>
<blockquote><small>&nbsp; public Collection&lt;Resource&gt;
generateResources(Collection&lt;URI&gt; uris)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; ResourceSet resourceSet = createResourceSet();</small><br>
<small>&nbsp;&nbsp;&nbsp; for (URI uri : uris)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource resource = resourceSet.getResource(uri, true);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!resource.getContents().isEmpty() &amp;&amp;
resource.getContents().get(0) instanceof XSDSchema)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; generate((XSDSchema)resource.getContents().get(0));</small> <br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<b><br>
<small>&nbsp;&nbsp;&nbsp; for (EPackage ePackage :
targetNamespaceToEPackageMap.values())</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ePackage.eResource() == null)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Resource ecoreResource =
resourceSet.createResource(URI.createURI("*.ecore"));</small ><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));</small ><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ecoreResource.getContents().add(ePackage);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small></b><br>
<small>&nbsp;&nbsp;&nbsp; <b>}</b></small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; return new
ArrayList&lt;Resource&gt;(resourceSet.getResources() ); </small><br>
<small>&nbsp; }</small><br>
</blockquote>
You don't necessarily have to call this method nor do you necessarily
have to put the packages in the same resource set as the schemas.&nbsp; <br>
<br>
Perhaps all that's needed is for the packages to be registered in the
package registry of the resource set that you are using for your
manually constructed dynamic models. Given these constructors:<br>
<blockquote><small>&nbsp; public XSDEcoreBuilder()<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; this(new BasicExtendedMetaData(new EPackageRegistryImpl()));<br>
&nbsp; }<br>
<br>
&nbsp; public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; this.extendedMetaData = extendedMetaData;<br>
&nbsp;&nbsp;&nbsp; populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);<br>
&nbsp;&nbsp;&nbsp; populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);<br >
&nbsp; }</small><br>
</blockquote>
one way to do that would be to do new XSDEcoreBuilder(new
BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).&nbsp;
The XSDEcoreBuilder will as a side effect register the EPackages it
creates in that package registry.<br>
<br>
<br>
Brian Vetter wrote:
<blockquote cite="mideqsg16$f6t$1@utils.eclipse.org" type="cite">Sorry
for the confusing terms. Everything was dynamic. Here's the
steps/scenario:
<br>
<br>
I have a list of xsds in the file system that I load and generate the
ecore model using a subclass of the XSDEcoreBuilder.
<br>
<br>
In addition, I need to create a new EPackage and associated EClasses
that contain EReferences to types that are defined in the previously
generated ECore classes using EMF's dynamic APIs.
<br>
<br>
When I try to use Teneo to help persist instance of these packages, it
urps out an error message saying that they must be created in the same
resource.
<br>
<br>
Besides the basic registration with the package registry (which didn't
work), how do I register or associate the package created using the
dynamic APIs with the ones generated using the XSDEcoreBuilder class?
<br>
<br>
I've maintained the ResourceSet but I couldn't see how I could
associate it with the package I created using createEPackage(). Is
there a different factory I should use? A different registration
function?
<br>
<br>
Brian
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Brian,
<br>
<br>
It's not entirely clear to me the relationship between the dynamic
packages created (generated?) by the XSDEcoreBuilder and these other
dynamic ones or how these other ones are created.&nbsp;&nbsp;&nbsp; When you say the
"generated" packages refer to types in the one loaded from the file
URI.&nbsp; Do you really mean a static generated package or a dynamic one
created by the XSDEcoreBuilder?&nbsp;&nbsp; It doesn't seem possible for a
generated static package to refer to a dynamic one, so that's
confusing. Maybe you could paint a very simple scenario so that I
understand better the question you are asking...
<br>
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">Ed,
<br>
<br>
I've implemented things this way and it worked for the case when I load
up a bunch of XSDs at once. However, if I want to create a dynamic
package and add it to this list, how exactly would I do it? There is no
ResourceSet for the dynamic calls (at least I didn't see it, but then
I'm pretty blind these days).
<br>
<br>
Is there some special api/trick to registering the dynamic package I
created so that it is included with the others?
<br>
<br>
The particular issue I'm having is that when I combine the dynamic
package with the others that are loaded, Teneo is giving me an
exception complaining about a null EClass. The error message is:
<br>
<br>
Passed eclass is null.This can occur if epackages which refer to
eachother are placed in different ecore/xsd files and they are not read
using one resource set. The reference from one epackage to another must
be resolvable by EMF.
<br>
<br>
My generated packages are referring to types in the ones loaded from
the file uri.
<br>
<br>
Brian
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Brian,
<br>
<br>
If you look at the two generate methods, you'll see that they
effectively just create a resource set, load one or more schema
resources, and then call generate(XSDSchema) for each schema.&nbsp; So you
could define a derived builder that maintains a resource set as a field
and keeps reusing it for each call (perhaps just by overriding
createResourceSet to return the same one each time).
<br>
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">The trick to get this to work was to
use the generate(Collection&lt;URI&gt; uris) method and not individual
calls to generate(uri).
<br>
<br>
The problem had nothing to do with the registration. I had been
registering the packages manually. I had taken care to not register the
same namespace more than once, but that didn't seem to matter. I also
changed it to use the ExtendedMetaData.INSTANCE argument to the builder
constructor and got the same incorrect results.
<br>
<br>
While I have it working correctly today, I'd like to understand how I
could do this more "dynamically" in the future as opposed to having to
batch up all of the potential namespaces in a single call to
generate(). More specifically, I'd like my server to be handed a URI to
an XSD while it is running and then "magically" do the appropriate
registrations and such to then persist new documents using that XSD.
I'd like to do this without having to restart the server.
<br>
<br>
At present, I have two obstacles. One, Teneo only has a setPackages()
method that can be called on the datastore. The packages are mapped
when the datastore is initialized. While I haven't tried it, I figure
that to be able to dynamically add new packages after the server is up
and running, I'd have to destroy the current datastore and create a new
one with the new packages that were added. Not the best answer, but it
sounds doable. I'm presuming I can make it work somehow.
<br>
<br>
However, the second problem is with the global registry. If I can't add
new packages on the fly, is there a similar (or better) way to rebuild
the list of packages in the global registry? If not, is there some
reason why separate generate() calls could not reuse any dependent
packages that are already in the global registry?
<br>
<br>
Thanks,
<br>
<br>
Brian
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------030803020707030600040503--
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #71488 is a reply to message #71471] Tue, 13 February 2007 21:14 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Thanks. Getting them registered with the correct package registry did the trick.

Brian

Ed Merks wrote:
> Brian,
>
> I'm not sure specifically what's causing Teneo to hiccup, so I'm not
> sure what the best way to avoid that is...
>
> If you look at this method in the XSDEcoreBuilder, you'll see that it
> puts the EPackage into resources:
>
> public Collection<Resource> generateResources(Collection<URI> uris)
> {
> ResourceSet resourceSet = createResourceSet();
> for (URI uri : uris)
> {
> Resource resource = resourceSet.getResource(uri, true);
> if (!resource.getContents().isEmpty() &&
> resource.getContents().get(0) instanceof XSDSchema)
> {
> generate((XSDSchema)resource.getContents().get(0));
> }
> }
> *
> for (EPackage ePackage : targetNamespaceToEPackageMap.values())
> {
> if (ePackage.eResource() == null)
> {
> Resource ecoreResource =
> resourceSet.createResource(URI.createURI("*.ecore"));
> ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));
> ecoreResource.getContents().add(ePackage);
> }*
> *}*
>
> return new ArrayList<Resource>(resourceSet.getResources());
> }
>
> You don't necessarily have to call this method nor do you necessarily
> have to put the packages in the same resource set as the schemas.
>
> Perhaps all that's needed is for the packages to be registered in the
> package registry of the resource set that you are using for your
> manually constructed dynamic models. Given these constructors:
>
> public XSDEcoreBuilder()
> {
> this(new BasicExtendedMetaData(new EPackageRegistryImpl()));
> }
>
> public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)
> {
> this.extendedMetaData = extendedMetaData;
> populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);
> populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);
> }
>
> one way to do that would be to do new XSDEcoreBuilder(new
> BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).
> The XSDEcoreBuilder will as a side effect register the EPackages it
> creates in that package registry.
>
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602399 is a reply to message #71113] Fri, 09 February 2007 11:22 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
I think Ed can best answer the questions related to how to import related epackages from multiple
xsd's. My impression (but I am not sure) is that the XSDEcoreBuilder does not register the epackage
in the global epackage registry. This is at least required for Teneo.

Related to the table naming, can you upload the generated hibernate mapping?

gr. Martin

Brian Vetter wrote:
> I've been trying to use XSDEcoreBuilder to generate the EPackages rather
> than use the generated Java implementation classes. I've run into a
> bunch of problems doing this and wondered if anyone else has done this
> successfully and has a recipe for success.
>
> My learning experience has been that I need to make sure that the same
> package is not presented twice to Teneo's HbDataStore.setEPackages()
> method. When doing so, I ran into several null pointer exceptions. I
> have 3 XSDs that are imported by 3 other XSDs. When I use
> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
> addition with each call to generate on the XSDs that import them.
>
> I'm still having a set of issues that may or be related to each other.
> The first is that after the mapping is complete, I tend to see 4
> instances of the same table, but with "1"'s appended for each of the
> duplicates. This occurs for every type in the imported namespaces. For
> example:
>
> ziptypes_device, ziptypes_device1, ziptypes_device11, and
> ziptypes_device111
>
> I'm presuming that the problem is has to do with how the ecore packages
> are getting created making each of the dependent packages look like
> unique packages even though the namespaces and all of the underlying
> objects are the same.
>
> When an instance of one of these schemas is loaded and then persisted
> using Teneo/hibernate, I get the following NPE. I'm presuming that it is
> caused by this same issue with the packages but I am unsure.
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
> at
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at
> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
> at
> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>
> Any advice on how to handle dynamically loading packages and using them
> within Teneo are greatly appreciated. Everything thing seems to be
> working OK using the generated Java packages.
>
> Brian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602410 is a reply to message #71113] Fri, 09 February 2007 11:46 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Brian,

Comments below.


Brian Vetter wrote:
> I've been trying to use XSDEcoreBuilder to generate the EPackages
> rather than use the generated Java implementation classes. I've run
> into a bunch of problems doing this and wondered if anyone else has
> done this successfully and has a recipe for success.
>
> My learning experience has been that I need to make sure that the same
> package is not presented twice to Teneo's HbDataStore.setEPackages()
> method. When doing so, I ran into several null pointer exceptions. I
> have 3 XSDs that are imported by 3 other XSDs. When I use
> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
> addition with each call to generate on the XSDs that import them.
It sounds like you want to call "Collection<Object>
generate(Collection<URI> uris)" so that a single resource set is used to
process all the schemas and hence a single set of packages representing
them all will be produced.
>
> I'm still having a set of issues that may or be related to each other.
> The first is that after the mapping is complete, I tend to see 4
> instances of the same table, but with "1"'s appended for each of the
> duplicates. This occurs for every type in the imported namespaces.
> For example:
>
> ziptypes_device, ziptypes_device1, ziptypes_device11, and
> ziptypes_device111
>
> I'm presuming that the problem is has to do with how the ecore
> packages are getting created making each of the dependent packages
> look like unique packages even though the namespaces and all of the
> underlying objects are the same.
Yes, it sounds likely that you are getting duplicate packages if you are
calling "Collection<EObject> generate(URI uri)" multiple times.
>
> When an instance of one of these schemas is loaded and then persisted
> using Teneo/hibernate, I get the following NPE. I'm presuming that it
> is caused by this same issue with the packages but I am unsure.
With regard to Martin's comment about global registration, the
XSDEcoreBuilder has a constructor that allow you to pass in an
ExtendedMetaData instance. The default constructor just creates a new
empty instance of it. So if you use new
XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
registered in the global registry as a side effect of generating them...
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
> at
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>
> at
> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>
> at
> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at
> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
> at
> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
> at
> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>
> at
> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>
> at
> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>
> at
> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>
> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>
> Any advice on how to handle dynamically loading packages and using
> them within Teneo are greatly appreciated. Everything thing seems to
> be working OK using the generated Java packages.
>
> Brian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602441 is a reply to message #71152] Sat, 10 February 2007 23:24 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
The trick to get this to work was to use the generate(Collection<URI> uris) method and not individual calls to generate(uri).

The problem had nothing to do with the registration. I had been registering the packages manually. I had taken care to not register the same namespace more than once, but that didn't seem to matter. I also changed it to use the ExtendedMetaData.INSTANCE argument to the builder constructor and got the same incorrect results.

While I have it working correctly today, I'd like to understand how I could do this more "dynamically" in the future as opposed to having to batch up all of the potential namespaces in a single call to generate(). More specifically, I'd like my server to be handed a URI to an XSD while it is running and then "magically" do the appropriate registrations and such to then persist new documents using that XSD. I'd like to do this without having to restart the server.

At present, I have two obstacles. One, Teneo only has a setPackages() method that can be called on the datastore. The packages are mapped when the datastore is initialized. While I haven't tried it, I figure that to be able to dynamically add new packages after the server is up and running, I'd have to destroy the current datastore and create a new one with the new packages that were added. Not the best answer, but it sounds doable. I'm presuming I can make it work somehow.

However, the second problem is with the global registry. If I can't add new packages on the fly, is there a similar (or better) way to rebuild the list of packages in the global registry? If not, is there some reason why separate generate() calls could not reuse any dependent packages that are already in the global registry?

Thanks,

Brian

Ed Merks wrote:
> Brian,
>
> Comments below.
>
>
> Brian Vetter wrote:
>> I've been trying to use XSDEcoreBuilder to generate the EPackages
>> rather than use the generated Java implementation classes. I've run
>> into a bunch of problems doing this and wondered if anyone else has
>> done this successfully and has a recipe for success.
>>
>> My learning experience has been that I need to make sure that the same
>> package is not presented twice to Teneo's HbDataStore.setEPackages()
>> method. When doing so, I ran into several null pointer exceptions. I
>> have 3 XSDs that are imported by 3 other XSDs. When I use
>> XSDEcoreBuilder.generate(), it returns each of the imported XSDs in
>> addition with each call to generate on the XSDs that import them.
> It sounds like you want to call "Collection<Object>
> generate(Collection<URI> uris)" so that a single resource set is used to
> process all the schemas and hence a single set of packages representing
> them all will be produced.
>>
>> I'm still having a set of issues that may or be related to each other.
>> The first is that after the mapping is complete, I tend to see 4
>> instances of the same table, but with "1"'s appended for each of the
>> duplicates. This occurs for every type in the imported namespaces.
>> For example:
>>
>> ziptypes_device, ziptypes_device1, ziptypes_device11, and
>> ziptypes_device111
>>
>> I'm presuming that the problem is has to do with how the ecore
>> packages are getting created making each of the dependent packages
>> look like unique packages even though the namespaces and all of the
>> underlying objects are the same.
> Yes, it sounds likely that you are getting duplicate packages if you are
> calling "Collection<EObject> generate(URI uri)" multiple times.
>>
>> When an instance of one of these schemas is loaded and then persisted
>> using Teneo/hibernate, I get the following NPE. I'm presuming that it
>> is caused by this same issue with the packages but I am unsure.
> With regard to Martin's comment about global registration, the
> XSDEcoreBuilder has a constructor that allow you to pass in an
> ExtendedMetaData instance. The default constructor just creates a new
> empty instance of it. So if you use new
> XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
> registered in the global registry as a side effect of generating them...
>>
>> Exception in thread "main" java.lang.NullPointerException
>> at
>> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
>> at
>> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>
>> at
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>>
>> at
>> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>>
>> at
>> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>>
>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>
>> at
>> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
>> at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
>> at
>> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
>> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
>> at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
>> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>
>> at
>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>
>> at
>> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>
>> at
>> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>>
>> at
>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>
>> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
>> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
>> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>>
>> Any advice on how to handle dynamically loading packages and using
>> them within Teneo are greatly appreciated. Everything thing seems to
>> be working OK using the generated Java packages.
>>
>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602448 is a reply to message #71132] Sun, 11 February 2007 08:33 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Martin & Ed,

I got past the original issues by implementing Ed's suggestion to generate all of the ecore mappings at once using a collection instead of generating each individually. I have been able to persist XML documents of various XSDs without the need to generate and compile supporting Java classes.

However if I try to load these objects using a hibernate query, I get a null pointer exception. I've run two variations of the program exactly equal but with one difference - one utilizes the Java classes when registering the packages with Teneo and the other uses the packages generated using the XSDEcoreBuilder (this time using the generate(collection) method that works for persisting the same XML documents).

In looking at the stack trace, it gets a long ways down the query path before it hits an NPE in a Teneo setter method from the hibernate tuplizer. It is tripping in the convert() method in EAttributePropertyHandler over a null instanceClass. The actual type is an attribute on a simple type that extends long. The attribute has an enumerated list of potential values.

In trying to determine what was different between the dynamic version and the one using the generated Java classes, I found the following:

1) The order of the registered packages passed to Teneo varied between the two.
2) After forcing the order of the packages to be the same in both, I found that the hibernate mappings varied in many ways.
2a) The names in the typedef elements were frequently (but not always) different. In particular, in the working version where the java classes are used, the names typically started with the NsPrefix of the package. In the auto-generated version, it used a transformed version of the fully qualified namespace.
2b) Some of the property mappings were different. In fact, it appears that almost all of the mappings that were different were those that were dealing with the elements or attributes that had restrictions of Strings with an enumeration list.

It is 2b above that I think is causing me my trouble: Here is an example of the type mapping (in this case, it is the one that the NPE is being thrown, but it is the first one that the mapping has run up against):

In the case where it is using the generated Java classes:
<property name="unit" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`unit`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
<param name="enumClass">org.ziptie._1._0.basictypes.UnitType1</param >
</type>
</property>

In the case where it is dynamically created:
<property name="unit" lazy="false" not-null="false" insert="true" update="true" unique="false">
<column not-null="false" unique="false" name="`unit`"/>
<type name="org.eclipse.emf.teneo.hibernate.mapping.DynamicENumUserType ">
<param name="eclassifier">UnitType1</param>
<param name="epackage">http://www.ziptie.org/1.0/basictypes</param>
</type>
</property>

Notice that the type mapping is quite different. In the second case, the method called by the tuplizer gets an NPE.

I'm not sure if ecore is treating these as different or if Teneo is not handling a particular ecore mapping properly. I'm presuming that there is some issue with Teneo handling the dynamic enum case since no class is there to implement it directly.

I noticed a couple of statements about problems with enumerates on the Teneo troubleshooting page. I didn't see any issues w.r.t. dynamic mapping vs. using generated java classes so it wasn't clear that there is any relation (especially since it appears to work using the generated java).

Brian


Martin Taal wrote:
> Brian,
> I think Ed can best answer the questions related to how to import
> related epackages from multiple xsd's. My impression (but I am not sure)
> is that the XSDEcoreBuilder does not register the epackage in the global
> epackage registry. This is at least required for Teneo.
>
> Related to the table naming, can you upload the generated hibernate
> mapping?
>
> gr. Martin

>
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602455 is a reply to message #71256] Sun, 11 February 2007 13:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Brian,

If you look at the two generate methods, you'll see that they
effectively just create a resource set, load one or more schema
resources, and then call generate(XSDSchema) for each schema. So you
could define a derived builder that maintains a resource set as a field
and keeps reusing it for each call (perhaps just by overriding
createResourceSet to return the same one each time).


Brian Vetter wrote:
> The trick to get this to work was to use the generate(Collection<URI>
> uris) method and not individual calls to generate(uri).
>
> The problem had nothing to do with the registration. I had been
> registering the packages manually. I had taken care to not register
> the same namespace more than once, but that didn't seem to matter. I
> also changed it to use the ExtendedMetaData.INSTANCE argument to the
> builder constructor and got the same incorrect results.
>
> While I have it working correctly today, I'd like to understand how I
> could do this more "dynamically" in the future as opposed to having to
> batch up all of the potential namespaces in a single call to
> generate(). More specifically, I'd like my server to be handed a URI
> to an XSD while it is running and then "magically" do the appropriate
> registrations and such to then persist new documents using that XSD.
> I'd like to do this without having to restart the server.
>
> At present, I have two obstacles. One, Teneo only has a setPackages()
> method that can be called on the datastore. The packages are mapped
> when the datastore is initialized. While I haven't tried it, I figure
> that to be able to dynamically add new packages after the server is up
> and running, I'd have to destroy the current datastore and create a
> new one with the new packages that were added. Not the best answer,
> but it sounds doable. I'm presuming I can make it work somehow.
>
> However, the second problem is with the global registry. If I can't
> add new packages on the fly, is there a similar (or better) way to
> rebuild the list of packages in the global registry? If not, is there
> some reason why separate generate() calls could not reuse any
> dependent packages that are already in the global registry?
>
> Thanks,
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> Comments below.
>>
>>
>> Brian Vetter wrote:
>>> I've been trying to use XSDEcoreBuilder to generate the EPackages
>>> rather than use the generated Java implementation classes. I've run
>>> into a bunch of problems doing this and wondered if anyone else has
>>> done this successfully and has a recipe for success.
>>>
>>> My learning experience has been that I need to make sure that the
>>> same package is not presented twice to Teneo's
>>> HbDataStore.setEPackages() method. When doing so, I ran into several
>>> null pointer exceptions. I have 3 XSDs that are imported by 3 other
>>> XSDs. When I use XSDEcoreBuilder.generate(), it returns each of the
>>> imported XSDs in addition with each call to generate on the XSDs
>>> that import them.
>> It sounds like you want to call "Collection<Object>
>> generate(Collection<URI> uris)" so that a single resource set is used
>> to process all the schemas and hence a single set of packages
>> representing them all will be produced.
>>>
>>> I'm still having a set of issues that may or be related to each
>>> other. The first is that after the mapping is complete, I tend to
>>> see 4 instances of the same table, but with "1"'s appended for each
>>> of the duplicates. This occurs for every type in the imported
>>> namespaces. For example:
>>>
>>> ziptypes_device, ziptypes_device1, ziptypes_device11, and
>>> ziptypes_device111
>>>
>>> I'm presuming that the problem is has to do with how the ecore
>>> packages are getting created making each of the dependent packages
>>> look like unique packages even though the namespaces and all of the
>>> underlying objects are the same.
>> Yes, it sounds likely that you are getting duplicate packages if you
>> are calling "Collection<EObject> generate(URI uri)" multiple times.
>>>
>>> When an instance of one of these schemas is loaded and then
>>> persisted using Teneo/hibernate, I get the following NPE. I'm
>>> presuming that it is caused by this same issue with the packages but
>>> I am unsure.
>> With regard to Martin's comment about global registration, the
>> XSDEcoreBuilder has a constructor that allow you to pass in an
>> ExtendedMetaData instance. The default constructor just creates a
>> new empty instance of it. So if you use new
>> XSDEcoreBuilder(ExtendedMetaData.INSTANCE), the packages should be
>> registered in the global registry as a side effect of generating them...
>>>
>>> Exception in thread "main" java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.ecore.impl.EClassImpl.getFeatureID(EClassImp l.java:857)
>>> at
>>> org.eclipse.emf.ecore.impl.DynamicEObjectImpl.eDerivedStruct uralFeatureID(DynamicEObjectImpl.java:215)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:592)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eOpenGet(BasicEO bjectImpl.java:640)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:599)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:587)
>>>
>>> at
>>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:582)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.mapping.property.EReferenceP ropertyHandler.get(EReferencePropertyHandler.java:92)
>>>
>>> at
>>> org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropert yValue(AbstractEntityTuplizer.java:277)
>>>
>>> at
>>> org.hibernate.persister.entity.AbstractEntityPersister.getPr opertyValue(AbstractEntityPersister.java:3514)
>>>
>>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.per formSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>>
>>> at
>>> org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl. java:507)
>>> at
>>> org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java :499)
>>> at
>>> org.hibernate.engine.CascadingAction$1.cascade(CascadingActi on.java:217)
>>>
>>> at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
>>> at
>>> org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java :216)
>>> at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:16 9)
>>> at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.cascadeBef oreSave(AbstractSaveEventListener.java:412)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav eOrReplicate(AbstractSaveEventListener.java:261)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.performSav e(AbstractSaveEventListener.java:180)
>>>
>>> at
>>> org.hibernate.event.def.AbstractSaveEventListener.saveWithGe neratedId(AbstractSaveEventListener.java:108)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sav eWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener .java:186)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveEventListener.saveWithGen eratedOrRequestedId(DefaultSaveEventListener.java:33)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.ent ityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveEventListener.performSave OrUpdate(DefaultSaveEventListener.java:27)
>>>
>>> at
>>> org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onS aveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
>>>
>>> at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535 )
>>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
>>> at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
>>> at org.ziptie.persist.cs3800Load.doLoadDoc(cs3800Load.java:122)
>>> at org.ziptie.persist.cs3800Load.main(cs3800Load.java:47)
>>>
>>> Any advice on how to handle dynamically loading packages and using
>>> them within Teneo are greatly appreciated. Everything thing seems to
>>> be working OK using the generated Java packages.
>>>
>>> Brian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602460 is a reply to message #71277] Sun, 11 February 2007 19:24 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Brian,
The npe has been solved and committed to cvs (we also encountered it this week).

gr. Martin

Brian Vetter wrote:
> Martin & Ed,
>
> I got past the original issues by implementing Ed's suggestion to
> generate all of the ecore mappings at once using a collection instead of
> generating each individually. I have been able to persist XML documents
> of various XSDs without the need to generate and compile supporting Java
> classes.
>
> However if I try to load these objects using a hibernate query, I get a
> null pointer exception. I've run two variations of the program exactly
> equal but with one difference - one utilizes the Java classes when
> registering the packages with Teneo and the other uses the packages
> generated using the XSDEcoreBuilder (this time using the
> generate(collection) method that works for persisting the same XML
> documents).
>
> In looking at the stack trace, it gets a long ways down the query path
> before it hits an NPE in a Teneo setter method from the hibernate
> tuplizer. It is tripping in the convert() method in
> EAttributePropertyHandler over a null instanceClass. The actual type is
> an attribute on a simple type that extends long. The attribute has an
> enumerated list of potential values.
>
> In trying to determine what was different between the dynamic version
> and the one using the generated Java classes, I found the following:
>
> 1) The order of the registered packages passed to Teneo varied between
> the two.
> 2) After forcing the order of the packages to be the same in both, I
> found that the hibernate mappings varied in many ways.
> 2a) The names in the typedef elements were frequently (but not
> always) different. In particular, in the working version where the java
> classes are used, the names typically started with the NsPrefix of the
> package. In the auto-generated version, it used a transformed version of
> the fully qualified namespace.
> 2b) Some of the property mappings were different. In fact, it
> appears that almost all of the mappings that were different were those
> that were dealing with the elements or attributes that had restrictions
> of Strings with an enumeration list.
>
> It is 2b above that I think is causing me my trouble: Here is an example
> of the type mapping (in this case, it is the one that the NPE is being
> thrown, but it is the first one that the mapping has run up against):
>
> In the case where it is using the generated Java classes:
> <property name="unit" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`unit`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType" >
> <param
> name="enumClass">org.ziptie._1._0.basictypes.UnitType1</param >
> </type>
> </property>
>
> In the case where it is dynamically created:
> <property name="unit" lazy="false" not-null="false"
> insert="true" update="true" unique="false">
> <column not-null="false" unique="false" name="`unit`"/>
> <type
> name="org.eclipse.emf.teneo.hibernate.mapping.DynamicENumUserType ">
> <param name="eclassifier">UnitType1</param>
> <param
> name="epackage">http://www.ziptie.org/1.0/basictypes</param>
> </type>
> </property>
>
> Notice that the type mapping is quite different. In the second case, the
> method called by the tuplizer gets an NPE.
>
> I'm not sure if ecore is treating these as different or if Teneo is not
> handling a particular ecore mapping properly. I'm presuming that there
> is some issue with Teneo handling the dynamic enum case since no class
> is there to implement it directly.
>
> I noticed a couple of statements about problems with enumerates on the
> Teneo troubleshooting page. I didn't see any issues w.r.t. dynamic
> mapping vs. using generated java classes so it wasn't clear that there
> is any relation (especially since it appears to work using the generated
> java).
>
> Brian
>
>
> Martin Taal wrote:
>> Brian,
>> I think Ed can best answer the questions related to how to import
>> related epackages from multiple xsd's. My impression (but I am not
>> sure) is that the XSDEcoreBuilder does not register the epackage in
>> the global epackage registry. This is at least required for Teneo.
>>
>> Related to the table naming, can you upload the generated hibernate
>> mapping?
>>
>> gr. Martin
>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602483 is a reply to message #71297] Mon, 12 February 2007 23:59 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Ed,

I've implemented things this way and it worked for the case when I load up a bunch of XSDs at once. However, if I want to create a dynamic package and add it to this list, how exactly would I do it? There is no ResourceSet for the dynamic calls (at least I didn't see it, but then I'm pretty blind these days).

Is there some special api/trick to registering the dynamic package I created so that it is included with the others?

The particular issue I'm having is that when I combine the dynamic package with the others that are loaded, Teneo is giving me an exception complaining about a null EClass. The error message is:

Passed eclass is null.This can occur if epackages which refer to eachother are placed in different ecore/xsd files and they are not read using one resource set. The reference from one epackage to another must be resolvable by EMF.

My generated packages are referring to types in the ones loaded from the file uri.

Brian

Ed Merks wrote:
> Brian,
>
> If you look at the two generate methods, you'll see that they
> effectively just create a resource set, load one or more schema
> resources, and then call generate(XSDSchema) for each schema. So you
> could define a derived builder that maintains a resource set as a field
> and keeps reusing it for each call (perhaps just by overriding
> createResourceSet to return the same one each time).
>
>
> Brian Vetter wrote:
>> The trick to get this to work was to use the generate(Collection<URI>
>> uris) method and not individual calls to generate(uri).
>>
>> The problem had nothing to do with the registration. I had been
>> registering the packages manually. I had taken care to not register
>> the same namespace more than once, but that didn't seem to matter. I
>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>> builder constructor and got the same incorrect results.
>>
>> While I have it working correctly today, I'd like to understand how I
>> could do this more "dynamically" in the future as opposed to having to
>> batch up all of the potential namespaces in a single call to
>> generate(). More specifically, I'd like my server to be handed a URI
>> to an XSD while it is running and then "magically" do the appropriate
>> registrations and such to then persist new documents using that XSD.
>> I'd like to do this without having to restart the server.
>>
>> At present, I have two obstacles. One, Teneo only has a setPackages()
>> method that can be called on the datastore. The packages are mapped
>> when the datastore is initialized. While I haven't tried it, I figure
>> that to be able to dynamically add new packages after the server is up
>> and running, I'd have to destroy the current datastore and create a
>> new one with the new packages that were added. Not the best answer,
>> but it sounds doable. I'm presuming I can make it work somehow.
>>
>> However, the second problem is with the global registry. If I can't
>> add new packages on the fly, is there a similar (or better) way to
>> rebuild the list of packages in the global registry? If not, is there
>> some reason why separate generate() calls could not reuse any
>> dependent packages that are already in the global registry?
>>
>> Thanks,
>>
>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602494 is a reply to message #71396] Tue, 13 February 2007 13:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Brian,

It's not entirely clear to me the relationship between the dynamic
packages created (generated?) by the XSDEcoreBuilder and these other
dynamic ones or how these other ones are created. When you say the
"generated" packages refer to types in the one loaded from the file
URI. Do you really mean a static generated package or a dynamic one
created by the XSDEcoreBuilder? It doesn't seem possible for a
generated static package to refer to a dynamic one, so that's confusing.
Maybe you could paint a very simple scenario so that I understand better
the question you are asking...


Brian Vetter wrote:
> Ed,
>
> I've implemented things this way and it worked for the case when I
> load up a bunch of XSDs at once. However, if I want to create a
> dynamic package and add it to this list, how exactly would I do it?
> There is no ResourceSet for the dynamic calls (at least I didn't see
> it, but then I'm pretty blind these days).
>
> Is there some special api/trick to registering the dynamic package I
> created so that it is included with the others?
>
> The particular issue I'm having is that when I combine the dynamic
> package with the others that are loaded, Teneo is giving me an
> exception complaining about a null EClass. The error message is:
>
> Passed eclass is null.This can occur if epackages which refer to
> eachother are placed in different ecore/xsd files and they are not
> read using one resource set. The reference from one epackage to
> another must be resolvable by EMF.
>
> My generated packages are referring to types in the ones loaded from
> the file uri.
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> If you look at the two generate methods, you'll see that they
>> effectively just create a resource set, load one or more schema
>> resources, and then call generate(XSDSchema) for each schema. So you
>> could define a derived builder that maintains a resource set as a
>> field and keeps reusing it for each call (perhaps just by overriding
>> createResourceSet to return the same one each time).
>>
>>
>> Brian Vetter wrote:
>>> The trick to get this to work was to use the
>>> generate(Collection<URI> uris) method and not individual calls to
>>> generate(uri).
>>>
>>> The problem had nothing to do with the registration. I had been
>>> registering the packages manually. I had taken care to not register
>>> the same namespace more than once, but that didn't seem to matter. I
>>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>>> builder constructor and got the same incorrect results.
>>>
>>> While I have it working correctly today, I'd like to understand how
>>> I could do this more "dynamically" in the future as opposed to
>>> having to batch up all of the potential namespaces in a single call
>>> to generate(). More specifically, I'd like my server to be handed a
>>> URI to an XSD while it is running and then "magically" do the
>>> appropriate registrations and such to then persist new documents
>>> using that XSD. I'd like to do this without having to restart the
>>> server.
>>>
>>> At present, I have two obstacles. One, Teneo only has a
>>> setPackages() method that can be called on the datastore. The
>>> packages are mapped when the datastore is initialized. While I
>>> haven't tried it, I figure that to be able to dynamically add new
>>> packages after the server is up and running, I'd have to destroy the
>>> current datastore and create a new one with the new packages that
>>> were added. Not the best answer, but it sounds doable. I'm presuming
>>> I can make it work somehow.
>>>
>>> However, the second problem is with the global registry. If I can't
>>> add new packages on the fly, is there a similar (or better) way to
>>> rebuild the list of packages in the global registry? If not, is
>>> there some reason why separate generate() calls could not reuse any
>>> dependent packages that are already in the global registry?
>>>
>>> Thanks,
>>>
>>> Brian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602498 is a reply to message #71414] Tue, 13 February 2007 13:57 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Sorry for the confusing terms. Everything was dynamic. Here's the
steps/scenario:

I have a list of xsds in the file system that I load and generate the
ecore model using a subclass of the XSDEcoreBuilder.

In addition, I need to create a new EPackage and associated EClasses
that contain EReferences to types that are defined in the previously
generated ECore classes using EMF's dynamic APIs.

When I try to use Teneo to help persist instance of these packages, it
urps out an error message saying that they must be created in the same
resource.

Besides the basic registration with the package registry (which didn't
work), how do I register or associate the package created using the
dynamic APIs with the ones generated using the XSDEcoreBuilder class?

I've maintained the ResourceSet but I couldn't see how I could associate
it with the package I created using createEPackage(). Is there a
different factory I should use? A different registration function?

Brian

Ed Merks wrote:
> Brian,
>
> It's not entirely clear to me the relationship between the dynamic
> packages created (generated?) by the XSDEcoreBuilder and these other
> dynamic ones or how these other ones are created. When you say the
> "generated" packages refer to types in the one loaded from the file
> URI. Do you really mean a static generated package or a dynamic one
> created by the XSDEcoreBuilder? It doesn't seem possible for a
> generated static package to refer to a dynamic one, so that's confusing.
> Maybe you could paint a very simple scenario so that I understand better
> the question you are asking...
>
>
> Brian Vetter wrote:
>> Ed,
>>
>> I've implemented things this way and it worked for the case when I
>> load up a bunch of XSDs at once. However, if I want to create a
>> dynamic package and add it to this list, how exactly would I do it?
>> There is no ResourceSet for the dynamic calls (at least I didn't see
>> it, but then I'm pretty blind these days).
>>
>> Is there some special api/trick to registering the dynamic package I
>> created so that it is included with the others?
>>
>> The particular issue I'm having is that when I combine the dynamic
>> package with the others that are loaded, Teneo is giving me an
>> exception complaining about a null EClass. The error message is:
>>
>> Passed eclass is null.This can occur if epackages which refer to
>> eachother are placed in different ecore/xsd files and they are not
>> read using one resource set. The reference from one epackage to
>> another must be resolvable by EMF.
>>
>> My generated packages are referring to types in the ones loaded from
>> the file uri.
>>
>> Brian
>>
>> Ed Merks wrote:
>>> Brian,
>>>
>>> If you look at the two generate methods, you'll see that they
>>> effectively just create a resource set, load one or more schema
>>> resources, and then call generate(XSDSchema) for each schema. So you
>>> could define a derived builder that maintains a resource set as a
>>> field and keeps reusing it for each call (perhaps just by overriding
>>> createResourceSet to return the same one each time).
>>>
>>>
>>> Brian Vetter wrote:
>>>> The trick to get this to work was to use the
>>>> generate(Collection<URI> uris) method and not individual calls to
>>>> generate(uri).
>>>>
>>>> The problem had nothing to do with the registration. I had been
>>>> registering the packages manually. I had taken care to not register
>>>> the same namespace more than once, but that didn't seem to matter. I
>>>> also changed it to use the ExtendedMetaData.INSTANCE argument to the
>>>> builder constructor and got the same incorrect results.
>>>>
>>>> While I have it working correctly today, I'd like to understand how
>>>> I could do this more "dynamically" in the future as opposed to
>>>> having to batch up all of the potential namespaces in a single call
>>>> to generate(). More specifically, I'd like my server to be handed a
>>>> URI to an XSD while it is running and then "magically" do the
>>>> appropriate registrations and such to then persist new documents
>>>> using that XSD. I'd like to do this without having to restart the
>>>> server.
>>>>
>>>> At present, I have two obstacles. One, Teneo only has a
>>>> setPackages() method that can be called on the datastore. The
>>>> packages are mapped when the datastore is initialized. While I
>>>> haven't tried it, I figure that to be able to dynamically add new
>>>> packages after the server is up and running, I'd have to destroy the
>>>> current datastore and create a new one with the new packages that
>>>> were added. Not the best answer, but it sounds doable. I'm presuming
>>>> I can make it work somehow.
>>>>
>>>> However, the second problem is with the global registry. If I can't
>>>> add new packages on the fly, is there a similar (or better) way to
>>>> rebuild the list of packages in the global registry? If not, is
>>>> there some reason why separate generate() calls could not reuse any
>>>> dependent packages that are already in the global registry?
>>>>
>>>> Thanks,
>>>>
>>>> Brian
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602510 is a reply to message #71433] Tue, 13 February 2007 16:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030803020707030600040503
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Brian,

I'm not sure specifically what's causing Teneo to hiccup, so I'm not
sure what the best way to avoid that is...

If you look at this method in the XSDEcoreBuilder, you'll see that it
puts the EPackage into resources:

public Collection<Resource> generateResources(Collection<URI> uris)
{
ResourceSet resourceSet = createResourceSet();
for (URI uri : uris)
{
Resource resource = resourceSet.getResource(uri, true);
if (!resource.getContents().isEmpty() &&
resource.getContents().get(0) instanceof XSDSchema)
{
generate((XSDSchema)resource.getContents().get(0));
}
}
*
for (EPackage ePackage : targetNamespaceToEPackageMap.values())
{
if (ePackage.eResource() == null)
{
Resource ecoreResource =
resourceSet.createResource(URI.createURI("*.ecore"));
ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));
ecoreResource.getContents().add(ePackage);
}*
*}*

return new ArrayList<Resource>(resourceSet.getResources());
}

You don't necessarily have to call this method nor do you necessarily
have to put the packages in the same resource set as the schemas.

Perhaps all that's needed is for the packages to be registered in the
package registry of the resource set that you are using for your
manually constructed dynamic models. Given these constructors:

public XSDEcoreBuilder()
{
this(new BasicExtendedMetaData(new EPackageRegistryImpl()));
}

public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)
{
this.extendedMetaData = extendedMetaData;
populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);
populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);
}

one way to do that would be to do new XSDEcoreBuilder(new
BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).
The XSDEcoreBuilder will as a side effect register the EPackages it
creates in that package registry.


Brian Vetter wrote:
> Sorry for the confusing terms. Everything was dynamic. Here's the
> steps/scenario:
>
> I have a list of xsds in the file system that I load and generate the
> ecore model using a subclass of the XSDEcoreBuilder.
>
> In addition, I need to create a new EPackage and associated EClasses
> that contain EReferences to types that are defined in the previously
> generated ECore classes using EMF's dynamic APIs.
>
> When I try to use Teneo to help persist instance of these packages, it
> urps out an error message saying that they must be created in the same
> resource.
>
> Besides the basic registration with the package registry (which didn't
> work), how do I register or associate the package created using the
> dynamic APIs with the ones generated using the XSDEcoreBuilder class?
>
> I've maintained the ResourceSet but I couldn't see how I could
> associate it with the package I created using createEPackage(). Is
> there a different factory I should use? A different registration
> function?
>
> Brian
>
> Ed Merks wrote:
>> Brian,
>>
>> It's not entirely clear to me the relationship between the dynamic
>> packages created (generated?) by the XSDEcoreBuilder and these other
>> dynamic ones or how these other ones are created. When you say the
>> "generated" packages refer to types in the one loaded from the file
>> URI. Do you really mean a static generated package or a dynamic one
>> created by the XSDEcoreBuilder? It doesn't seem possible for a
>> generated static package to refer to a dynamic one, so that's
>> confusing. Maybe you could paint a very simple scenario so that I
>> understand better the question you are asking...
>>
>>
>> Brian Vetter wrote:
>>> Ed,
>>>
>>> I've implemented things this way and it worked for the case when I
>>> load up a bunch of XSDs at once. However, if I want to create a
>>> dynamic package and add it to this list, how exactly would I do it?
>>> There is no ResourceSet for the dynamic calls (at least I didn't see
>>> it, but then I'm pretty blind these days).
>>>
>>> Is there some special api/trick to registering the dynamic package I
>>> created so that it is included with the others?
>>>
>>> The particular issue I'm having is that when I combine the dynamic
>>> package with the others that are loaded, Teneo is giving me an
>>> exception complaining about a null EClass. The error message is:
>>>
>>> Passed eclass is null.This can occur if epackages which refer to
>>> eachother are placed in different ecore/xsd files and they are not
>>> read using one resource set. The reference from one epackage to
>>> another must be resolvable by EMF.
>>>
>>> My generated packages are referring to types in the ones loaded from
>>> the file uri.
>>>
>>> Brian
>>>
>>> Ed Merks wrote:
>>>> Brian,
>>>>
>>>> If you look at the two generate methods, you'll see that they
>>>> effectively just create a resource set, load one or more schema
>>>> resources, and then call generate(XSDSchema) for each schema. So
>>>> you could define a derived builder that maintains a resource set as
>>>> a field and keeps reusing it for each call (perhaps just by
>>>> overriding createResourceSet to return the same one each time).
>>>>
>>>>
>>>> Brian Vetter wrote:
>>>>> The trick to get this to work was to use the
>>>>> generate(Collection<URI> uris) method and not individual calls to
>>>>> generate(uri).
>>>>>
>>>>> The problem had nothing to do with the registration. I had been
>>>>> registering the packages manually. I had taken care to not
>>>>> register the same namespace more than once, but that didn't seem
>>>>> to matter. I also changed it to use the ExtendedMetaData.INSTANCE
>>>>> argument to the builder constructor and got the same incorrect
>>>>> results.
>>>>>
>>>>> While I have it working correctly today, I'd like to understand
>>>>> how I could do this more "dynamically" in the future as opposed to
>>>>> having to batch up all of the potential namespaces in a single
>>>>> call to generate(). More specifically, I'd like my server to be
>>>>> handed a URI to an XSD while it is running and then "magically" do
>>>>> the appropriate registrations and such to then persist new
>>>>> documents using that XSD. I'd like to do this without having to
>>>>> restart the server.
>>>>>
>>>>> At present, I have two obstacles. One, Teneo only has a
>>>>> setPackages() method that can be called on the datastore. The
>>>>> packages are mapped when the datastore is initialized. While I
>>>>> haven't tried it, I figure that to be able to dynamically add new
>>>>> packages after the server is up and running, I'd have to destroy
>>>>> the current datastore and create a new one with the new packages
>>>>> that were added. Not the best answer, but it sounds doable. I'm
>>>>> presuming I can make it work somehow.
>>>>>
>>>>> However, the second problem is with the global registry. If I
>>>>> can't add new packages on the fly, is there a similar (or better)
>>>>> way to rebuild the list of packages in the global registry? If
>>>>> not, is there some reason why separate generate() calls could not
>>>>> reuse any dependent packages that are already in the global registry?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Brian


--------------030803020707030600040503
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Brian,<br>
<br>
I'm not sure specifically what's causing Teneo to hiccup, so I'm not
sure what the best way to avoid that is...&nbsp; <br>
<br>
If you look at this method in the XSDEcoreBuilder, you'll see that it
puts the EPackage into resources:<br>
<blockquote><small>&nbsp; public Collection&lt;Resource&gt;
generateResources(Collection&lt;URI&gt; uris)</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; ResourceSet resourceSet = createResourceSet();</small><br>
<small>&nbsp;&nbsp;&nbsp; for (URI uri : uris)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource resource = resourceSet.getResource(uri, true);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!resource.getContents().isEmpty() &amp;&amp;
resource.getContents().get(0) instanceof XSDSchema)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; generate((XSDSchema)resource.getContents().get(0));</small> <br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<b><br>
<small>&nbsp;&nbsp;&nbsp; for (EPackage ePackage :
targetNamespaceToEPackageMap.values())</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ePackage.eResource() == null)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Resource ecoreResource =
resourceSet.createResource(URI.createURI("*.ecore"));</small ><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));</small ><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ecoreResource.getContents().add(ePackage);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small></b><br>
<small>&nbsp;&nbsp;&nbsp; <b>}</b></small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; return new
ArrayList&lt;Resource&gt;(resourceSet.getResources() ); </small><br>
<small>&nbsp; }</small><br>
</blockquote>
You don't necessarily have to call this method nor do you necessarily
have to put the packages in the same resource set as the schemas.&nbsp; <br>
<br>
Perhaps all that's needed is for the packages to be registered in the
package registry of the resource set that you are using for your
manually constructed dynamic models. Given these constructors:<br>
<blockquote><small>&nbsp; public XSDEcoreBuilder()<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; this(new BasicExtendedMetaData(new EPackageRegistryImpl()));<br>
&nbsp; }<br>
<br>
&nbsp; public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; this.extendedMetaData = extendedMetaData;<br>
&nbsp;&nbsp;&nbsp; populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);<br>
&nbsp;&nbsp;&nbsp; populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);<br >
&nbsp; }</small><br>
</blockquote>
one way to do that would be to do new XSDEcoreBuilder(new
BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).&nbsp;
The XSDEcoreBuilder will as a side effect register the EPackages it
creates in that package registry.<br>
<br>
<br>
Brian Vetter wrote:
<blockquote cite="mideqsg16$f6t$1@utils.eclipse.org" type="cite">Sorry
for the confusing terms. Everything was dynamic. Here's the
steps/scenario:
<br>
<br>
I have a list of xsds in the file system that I load and generate the
ecore model using a subclass of the XSDEcoreBuilder.
<br>
<br>
In addition, I need to create a new EPackage and associated EClasses
that contain EReferences to types that are defined in the previously
generated ECore classes using EMF's dynamic APIs.
<br>
<br>
When I try to use Teneo to help persist instance of these packages, it
urps out an error message saying that they must be created in the same
resource.
<br>
<br>
Besides the basic registration with the package registry (which didn't
work), how do I register or associate the package created using the
dynamic APIs with the ones generated using the XSDEcoreBuilder class?
<br>
<br>
I've maintained the ResourceSet but I couldn't see how I could
associate it with the package I created using createEPackage(). Is
there a different factory I should use? A different registration
function?
<br>
<br>
Brian
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Brian,
<br>
<br>
It's not entirely clear to me the relationship between the dynamic
packages created (generated?) by the XSDEcoreBuilder and these other
dynamic ones or how these other ones are created.&nbsp;&nbsp;&nbsp; When you say the
"generated" packages refer to types in the one loaded from the file
URI.&nbsp; Do you really mean a static generated package or a dynamic one
created by the XSDEcoreBuilder?&nbsp;&nbsp; It doesn't seem possible for a
generated static package to refer to a dynamic one, so that's
confusing. Maybe you could paint a very simple scenario so that I
understand better the question you are asking...
<br>
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">Ed,
<br>
<br>
I've implemented things this way and it worked for the case when I load
up a bunch of XSDs at once. However, if I want to create a dynamic
package and add it to this list, how exactly would I do it? There is no
ResourceSet for the dynamic calls (at least I didn't see it, but then
I'm pretty blind these days).
<br>
<br>
Is there some special api/trick to registering the dynamic package I
created so that it is included with the others?
<br>
<br>
The particular issue I'm having is that when I combine the dynamic
package with the others that are loaded, Teneo is giving me an
exception complaining about a null EClass. The error message is:
<br>
<br>
Passed eclass is null.This can occur if epackages which refer to
eachother are placed in different ecore/xsd files and they are not read
using one resource set. The reference from one epackage to another must
be resolvable by EMF.
<br>
<br>
My generated packages are referring to types in the ones loaded from
the file uri.
<br>
<br>
Brian
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Brian,
<br>
<br>
If you look at the two generate methods, you'll see that they
effectively just create a resource set, load one or more schema
resources, and then call generate(XSDSchema) for each schema.&nbsp; So you
could define a derived builder that maintains a resource set as a field
and keeps reusing it for each call (perhaps just by overriding
createResourceSet to return the same one each time).
<br>
<br>
<br>
Brian Vetter wrote:
<br>
<blockquote type="cite">The trick to get this to work was to
use the generate(Collection&lt;URI&gt; uris) method and not individual
calls to generate(uri).
<br>
<br>
The problem had nothing to do with the registration. I had been
registering the packages manually. I had taken care to not register the
same namespace more than once, but that didn't seem to matter. I also
changed it to use the ExtendedMetaData.INSTANCE argument to the builder
constructor and got the same incorrect results.
<br>
<br>
While I have it working correctly today, I'd like to understand how I
could do this more "dynamically" in the future as opposed to having to
batch up all of the potential namespaces in a single call to
generate(). More specifically, I'd like my server to be handed a URI to
an XSD while it is running and then "magically" do the appropriate
registrations and such to then persist new documents using that XSD.
I'd like to do this without having to restart the server.
<br>
<br>
At present, I have two obstacles. One, Teneo only has a setPackages()
method that can be called on the datastore. The packages are mapped
when the datastore is initialized. While I haven't tried it, I figure
that to be able to dynamically add new packages after the server is up
and running, I'd have to destroy the current datastore and create a new
one with the new packages that were added. Not the best answer, but it
sounds doable. I'm presuming I can make it work somehow.
<br>
<br>
However, the second problem is with the global registry. If I can't add
new packages on the fly, is there a similar (or better) way to rebuild
the list of packages in the global registry? If not, is there some
reason why separate generate() calls could not reuse any dependent
packages that are already in the global registry?
<br>
<br>
Thanks,
<br>
<br>
Brian
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------030803020707030600040503--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Dynamic mapping using XSDEcoreBuilder [message #602515 is a reply to message #71471] Tue, 13 February 2007 21:14 Go to previous message
Brian Vetter is currently offline Brian VetterFriend
Messages: 74
Registered: July 2009
Member
Thanks. Getting them registered with the correct package registry did the trick.

Brian

Ed Merks wrote:
> Brian,
>
> I'm not sure specifically what's causing Teneo to hiccup, so I'm not
> sure what the best way to avoid that is...
>
> If you look at this method in the XSDEcoreBuilder, you'll see that it
> puts the EPackage into resources:
>
> public Collection<Resource> generateResources(Collection<URI> uris)
> {
> ResourceSet resourceSet = createResourceSet();
> for (URI uri : uris)
> {
> Resource resource = resourceSet.getResource(uri, true);
> if (!resource.getContents().isEmpty() &&
> resource.getContents().get(0) instanceof XSDSchema)
> {
> generate((XSDSchema)resource.getContents().get(0));
> }
> }
> *
> for (EPackage ePackage : targetNamespaceToEPackageMap.values())
> {
> if (ePackage.eResource() == null)
> {
> Resource ecoreResource =
> resourceSet.createResource(URI.createURI("*.ecore"));
> ecoreResource.setURI(URI.createURI(ePackage.getNsURI()));
> ecoreResource.getContents().add(ePackage);
> }*
> *}*
>
> return new ArrayList<Resource>(resourceSet.getResources());
> }
>
> You don't necessarily have to call this method nor do you necessarily
> have to put the packages in the same resource set as the schemas.
>
> Perhaps all that's needed is for the packages to be registered in the
> package registry of the resource set that you are using for your
> manually constructed dynamic models. Given these constructors:
>
> public XSDEcoreBuilder()
> {
> this(new BasicExtendedMetaData(new EPackageRegistryImpl()));
> }
>
> public XSDEcoreBuilder(ExtendedMetaData extendedMetaData)
> {
> this.extendedMetaData = extendedMetaData;
> populateTypeToTypeObjectMap(XMLTypePackage.eINSTANCE);
> populateTypeToTypeObjectMap(XMLNamespacePackage.eINSTANCE);
> }
>
> one way to do that would be to do new XSDEcoreBuilder(new
> BasicExtendedMetaData(dynamicEPackageResourceSet.getPackageR egistry())).
> The XSDEcoreBuilder will as a side effect register the EPackages it
> creates in that package registry.
>
Previous Topic:[Teneo] EAttributePropertyHandler Warnings
Next Topic:copier.copyReferences() causes stack overflow
Goto Forum:
  


Current Time: Fri Mar 29 00:12:12 GMT 2024

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

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

Back to the top