Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EPackage Global Registry problems
EPackage Global Registry problems [message #400463] Thu, 20 April 2006 17:14 Go to next message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
I have several statically declared EPackages which I am attempting to
access using EPackage.Registry.INSTANCE.values(). For this particular
problem, I am unable to locate the EPackages I want using the
INSTANCE.getEPackage(URI) API.

When running within the same JVM as Eclipse, these statically registered
EPackages as well as others are returned as expected from
INSTANCE.values(). Outside of Eclipse and inside my J2EE app server,
however, this values() method returns nothing. In this case, it appears
the registry is complicated by Delegates and Classloaders. Is there a way
running outside Eclipse I can traverse through all the delegates and
retrieve all the EPackages. Any help would be appreciated?

- Ron
Re: EPackage Global Registry problems [message #400465 is a reply to message #400463] Thu, 20 April 2006 18:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

As I understand it, when running inside Eclipse, the plugin.xml that the
generated code is in uses the extension point
org.eclipse.emf.ecore.generated_package extension point to register the
package with the URI. This puts a "delegate" into the registry and went
the registry looks for the URI it will resolve through the delegate,
finding the real package and putting that in its place and returning it.

The problem is when running outside of Eclipse there is no extension
point to provide this info. So the application has to know ahead of time
what packages can possibly be referenced and should do an

thepackage.EINSTANCE.get...;

Where get... is some valid get method on the package. This will then
cause that package to be registered.


R. Gavlin wrote:
> I have several statically declared EPackages which I am attempting to
> access using EPackage.Registry.INSTANCE.values(). For this particular
> problem, I am unable to locate the EPackages I want using the
> INSTANCE.getEPackage(URI) API.
>
> When running within the same JVM as Eclipse, these statically registered
> EPackages as well as others are returned as expected from
> INSTANCE.values(). Outside of Eclipse and inside my J2EE app server,
> however, this values() method returns nothing. In this case, it appears
> the registry is complicated by Delegates and Classloaders. Is there a
> way running outside Eclipse I can traverse through all the delegates and
> retrieve all the EPackages. Any help would be appreciated?
>
> - Ron
>

--
Thanks,
Rich Kulp
Re: EPackage Global Registry problems [message #400466 is a reply to message #400463] Thu, 20 April 2006 18:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ron,

Within Eclipse, EPackages are registered via the plugin.xml registration
mechanism which registers a descriptor rather than the EPackage directly
to support lazy plugin loading. When running outside of Eclipse, no
such plugin.xml-based registrations happen; the package registry will be
populated only as each XyzPackage.eINSTANCE is accessed the first time.



R. Gavlin wrote:
> I have several statically declared EPackages which I am attempting to
> access using EPackage.Registry.INSTANCE.values(). For this particular
> problem, I am unable to locate the EPackages I want using the
> INSTANCE.getEPackage(URI) API.
>
> When running within the same JVM as Eclipse, these statically
> registered EPackages as well as others are returned as expected from
> INSTANCE.values(). Outside of Eclipse and inside my J2EE app server,
> however, this values() method returns nothing. In this case, it
> appears the registry is complicated by Delegates and Classloaders. Is
> there a way running outside Eclipse I can traverse through all the
> delegates and retrieve all the EPackages. Any help would be appreciated?
>
> - Ron
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EPackage Global Registry problems [message #400467 is a reply to message #400465] Thu, 20 April 2006 18:16 Go to previous messageGo to next message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
Yes, I am already invoking xxxPackageImpl.eINSTANCE.eClass() to get the
static EPackages registered. Sometime later in the lifecycle of my
application, I need to interrogate all the registered EPackages. I am
attempting to use EPackage.Registry.INSTANCE.values() to access the
EPackages. Unfortunately, this list is empty. However, if I execute
EPackage.Registry.INSTANCE.getEPackage(uri) for one of my statically
declared packages, it is returned. I need to list all of them and the
delegate registries outside of Eclipse appear to be hidden within the
EPackageRegistryImpl Delegator. Thoughts?

- Ron
Re: EPackage Global Registry problems [message #400468 is a reply to message #400465] Thu, 20 April 2006 18:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Rich,

Thanks. Sametime interrupts caused my delayed send. I clearly should
wait longer and questions will answer themselves! ;-)


Rich Kulp wrote:
> As I understand it, when running inside Eclipse, the plugin.xml that
> the generated code is in uses the extension point
> org.eclipse.emf.ecore.generated_package extension point to register
> the package with the URI. This puts a "delegate" into the registry and
> went the registry looks for the URI it will resolve through the
> delegate, finding the real package and putting that in its place and
> returning it.
>
> The problem is when running outside of Eclipse there is no extension
> point to provide this info. So the application has to know ahead of
> time what packages can possibly be referenced and should do an
>
> thepackage.EINSTANCE.get...;
>
> Where get... is some valid get method on the package. This will then
> cause that package to be registered.
>
>
> R. Gavlin wrote:
>> I have several statically declared EPackages which I am attempting to
>> access using EPackage.Registry.INSTANCE.values(). For this particular
>> problem, I am unable to locate the EPackages I want using the
>> INSTANCE.getEPackage(URI) API.
>>
>> When running within the same JVM as Eclipse, these statically
>> registered EPackages as well as others are returned as expected from
>> INSTANCE.values(). Outside of Eclipse and inside my J2EE app server,
>> however, this values() method returns nothing. In this case, it
>> appears the registry is complicated by Delegates and Classloaders. Is
>> there a way running outside Eclipse I can traverse through all the
>> delegates and retrieve all the EPackages. Any help would be appreciated?
>>
>> - Ron
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EPackage Global Registry problems [message #400469 is a reply to message #400467] Thu, 20 April 2006 18:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ron,

With the class loader scoped registry, the values() or getEPackage
results you see will depend on the current thread's class loader. This
scoping mechanism was designed to support the type of visibility that
the class loaders themselves impose and was helpful to WebSphere for
supporting their desired visibility mechanisms. Likely this is the
source of your issues. The getEPackage method will walk up the
delegation chain (which mirrors the class loader hierarchy) to find the
package, but the values() method will just return the values in the
local registry(). The registry was never intended for folks to try to
enumerate all possible packages so I'm curious what you are trying to
achieve? Changing the current thread's class loader to be the parent,
and then the parent of the parent, and so on, calling values() each time
while walking all the way to the root is the only way you can find all
the packages currently visible in the starting scope.


R. Gavlin wrote:
> Yes, I am already invoking xxxPackageImpl.eINSTANCE.eClass() to get
> the static EPackages registered. Sometime later in the lifecycle of my
> application, I need to interrogate all the registered EPackages. I am
> attempting to use EPackage.Registry.INSTANCE.values() to access the
> EPackages. Unfortunately, this list is empty. However, if I execute
> EPackage.Registry.INSTANCE.getEPackage(uri) for one of my statically
> declared packages, it is returned. I need to list all of them and the
> delegate registries outside of Eclipse appear to be hidden within the
> EPackageRegistryImpl Delegator. Thoughts?
>
> - Ron
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EPackage Global Registry problems [message #400470 is a reply to message #400467] Thu, 20 April 2006 18:29 Go to previous messageGo to next message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
FYI, when I am running my application outside Eclipse and set the System
Property "org.eclipse.emf.ecore.EPackage.Registry.INSTANCE =
org.eclipse.emf.ecore.impl.EPackageRegistryImpl" on my appserver command
line, EPackage.Registry.INSTANCE.values() returns the EPackages as
expected. However, I'm not sure this is a good thing to do. Obviously, the
Delegator/Classloader stuff in EPackageRegistryImpl exists for a good
reason and this technique bypasses those mechanisms. Any thoughts?

- Ron
Re: EPackage Global Registry problems [message #400471 is a reply to message #400470] Thu, 20 April 2006 18:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ron,

Yes, as I said in my other note the Delegator implementation was
designed to support visibility based on class loader scope. I've begun
to regret that we provided that directly rather than insisting that
clients provide that themselves, if and when they want it. Since a
"normal runtime environment" doesn't have such nested class loaders,
it's typically not an issue either way, until a funky environment full
of nested class loaders comes into play...


R. Gavlin wrote:
> FYI, when I am running my application outside Eclipse and set the
> System Property "org.eclipse.emf.ecore.EPackage.Registry.INSTANCE =
> org.eclipse.emf.ecore.impl.EPackageRegistryImpl" on my appserver
> command line, EPackage.Registry.INSTANCE.values() returns the
> EPackages as expected. However, I'm not sure this is a good thing to
> do. Obviously, the Delegator/Classloader stuff in EPackageRegistryImpl
> exists for a good reason and this technique bypasses those mechanisms.
> Any thoughts?
>
> - Ron
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EPackage Global Registry problems [message #400473 is a reply to message #400465] Thu, 20 April 2006 18:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Only when running outside of Eclipse:

The global registry is replaced with a Delegator registry. This is
because you don't want a global registry for the entire VM when working
with J2EE. Instead it needs to be per-class loader because each
application will get its own classloader, even though it is in the same
JVM as other applications. This prevents one application's packages from
contaminating another application.

It uses the thread's context classloader (this is what many servers use
to maintain this separation). EMF maintains a registry per context
classloader.

Now as mentioned previously there are no default registrations when
running outside of Eclipse. So you can either do the calls to load,
activate, and register every package, or you can create a descriptor for
the packages that could possibly be referenced.

A descriptor is an implementation of EPackage.Descriptor. You would
implement the getEPackage and getEFactory methods. That way it would not
actually load and instantiate the package until referenced. You would
put this descriptor into the registry instead. For example:

EPackage.Registry.INSTANCE.put(MyPackage.eNS_URI, new
EPackage.Descriptor() {
public EPackage getEPackage() {
return MyPackage.EINSTANCE;
}

public EFactory getEFactory() {
return MyFactory.EINSTANCE;
}
});

I'm fairly sure this won't force the initialization of the package until
the call to it is made.

--
Thanks,
Rich Kulp
Re: EPackage Global Registry problems [message #400476 is a reply to message #400469] Thu, 20 April 2006 18:57 Go to previous messageGo to next message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
Ed,

Please see my other post then read on. I am attempting to solve the mixed
Dynamic/Static model problem I described a few weeks ago. In order to
solve the problem, I modified the XSDEcoreBuilder constructor to accept
one or more (presumably statically defined) EPackages. I also created a
custom XSDEcoreBuilder subclass to "pre-register" and leverage the
EPackages passed in the constructor when generating new dynamic schemas.

I have an SDO 2.0-like class XSDHelperImpl with the following constructor:

XSDHelperImpl(ExtendedMetaData extendedMetaData)
{
this.extendedMetaData = extendedMetaData;
EPackage.Registry registry = EPackage.Registry.INSTANCE;
Collection ePackages = new ArrayList(registry.values());
this.ecoreBuilder = (extendedMetaData == null)
? new MyXSDEcoreBuilder(ePackages)
: new MyXSDEcoreBuilder(extendedMetaData, ePackages);
}

This class is accessed via the XSDHelper.INSTANCE singleton so it is
usually invoked just once. When running in the app server,
registry.values() is empty unless I set the JVM property as described in
my previous note. Is your suggestion to walk the classloader tree and
interrogate the registry values in each?

- Ron
Re: EPackage Global Registry problems [message #400477 is a reply to message #400476] Thu, 20 April 2006 19:01 Go to previous messageGo to next message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
One correction. I didn't actually modify the XSDEcoreBuilder constructor.
Rather, I added an ePackages parameter to the constructor of my
XSDEcoreBuilder subclass.

- Ron
Re: EPackage Global Registry problems [message #400478 is a reply to message #400476] Thu, 20 April 2006 19:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ron,

A better approach might be to look up the namespace lazily by overriding
XSDEcoreBuilder.getEPackage. At that point you can determine the
namespace and try to find a static package for it. I'd certainly be
interested in incorporating useful ideas into the base builder...


R. Gavlin wrote:
> Ed,
>
> Please see my other post then read on. I am attempting to solve the
> mixed Dynamic/Static model problem I described a few weeks ago. In
> order to solve the problem, I modified the XSDEcoreBuilder constructor
> to accept one or more (presumably statically defined) EPackages. I
> also created a custom XSDEcoreBuilder subclass to "pre-register" and
> leverage the EPackages passed in the constructor when generating new
> dynamic schemas.
>
> I have an SDO 2.0-like class XSDHelperImpl with the following
> constructor:
>
> XSDHelperImpl(ExtendedMetaData extendedMetaData)
> {
> this.extendedMetaData = extendedMetaData;
> EPackage.Registry registry = EPackage.Registry.INSTANCE;
> Collection ePackages = new ArrayList(registry.values());
> this.ecoreBuilder = (extendedMetaData == null) ? new
> MyXSDEcoreBuilder(ePackages)
> : new MyXSDEcoreBuilder(extendedMetaData, ePackages);
> }
>
> This class is accessed via the XSDHelper.INSTANCE singleton so it is
> usually invoked just once. When running in the app server,
> registry.values() is empty unless I set the JVM property as described
> in my previous note. Is your suggestion to walk the classloader tree
> and interrogate the registry values in each?
> - Ron
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EPackage Global Registry problems [message #400480 is a reply to message #400478] Thu, 20 April 2006 20:10 Go to previous message
Ron Gavlin is currently offline Ron GavlinFriend
Messages: 91
Registered: July 2009
Member
Ed,

Thanks for the suggestion. Unfortunately, overloading
XSDEcoreBuilder.getEPackage() didn't help me. But I have a custom
XSDSchemaAdapterFactoryImpl class that contains a custom
XSDResourceImpl.SchemaLocator. I updated its locateSchema() method to
lazily load the EPackage and return its corresponding XSDSchema which did
the trick. I'm investigating whether I can contribute these enhancements
back to the community.

Thanks again,

- Ron
Previous Topic:How to copy a resource
Next Topic:anySimplyType in XML Schema to Ecore Mapping
Goto Forum:
  


Current Time: Sat Sep 21 06:02:55 GMT 2024

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

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

Back to the top