Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ExecutableExtensionFactory#getBundle()(Why uses the factory its own bundle instead the bundle of the extension to load classes?)
ExecutableExtensionFactory#getBundle() [message #675355] Tue, 31 May 2011 09:00 Go to next message
gerit is currently offline geritFriend
Messages: 4
Registered: July 2009
Junior Member
Hi,
I'm using Xtext 1.0.2 and I tried to use the generated <MyModel>ExecutableExtensionFactory from another plugin than <mymodel>.ui like MyModelExecutableExtensionFactory:mymodel.otherplugin.ui.OtherPluginClass

Because the default implementation of the generated MyModelExecutableExtensionFactory loads the given 'mymodel.otherplugin.ui.OtherPluginClass' with its own classloader...
protected Bundle getBundle() {
    return mymodel.MyModelActivator.getInstance().getBundle();
  }

.. I get a ClassNotFoundException.

Is this a bug? Why not use the bundle of the given extension (IConfigurationElement)?
  @Override
  protected Bundle getBundle() {
    //config is AbstractGuiceAwareExecutableExtensionFactory#config:IConfigurationElement
    
    return Platform.getBundle(config.getContributor().getName());
  }


thanks,
gerit
Re: ExecutableExtensionFactory#getBundle() [message #675442 is a reply to message #675355] Tue, 31 May 2011 14:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gerit,

the exectuable extension factory is meant to be used only for classes
that are visible from a given bundle. However, you could use an own
ExecutableExtensionFactory in your second bundle that uses the injector
of your first bundle.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 31.05.11 11:00, schrieb gerit:
> Hi,
> I'm using Xtext 1.0.2 and I tried to use the generated
> <MyModel>ExecutableExtensionFactory from another plugin than
> <mymodel>.ui like
> MyModelExecutableExtensionFactory:mymodel.otherplugin.ui.OtherPluginClass
>
> Because the default implementation of the generated
> MyModelExecutableExtensionFactory loads the given
> 'mymodel.otherplugin.ui.OtherPluginClass' with its own classloader...
>
> protected Bundle getBundle() {
> return mymodel.MyModelActivator.getInstance().getBundle();
> }
>
> . I get a ClassNotFoundException.
>
> Is this a bug? Why not use the bundle of the given extension
> (IConfigurationElement)?
>
> @Override
> protected Bundle getBundle() {
> //config is
> AbstractGuiceAwareExecutableExtensionFactory#config:IConfigurationElement
> return Platform.getBundle(config.getContributor().getName());
> }
>
>
> thanks,
> gerit
>
Re: ExecutableExtensionFactory#getBundle() [message #675500 is a reply to message #675442] Tue, 31 May 2011 17:20 Go to previous messageGo to next message
gerit is currently offline geritFriend
Messages: 4
Registered: July 2009
Junior Member
Sebastian Zarnekow wrote on Tue, 31 May 2011 10:35

the exectuable extension factory is meant to be used only for classes
that are visible from a given bundle. However, you could use an own
ExecutableExtensionFactory in your second bundle that uses the injector
of your first bundle.

Hi Sebastian and thanks for the fast answer!
But I am a little bit confused... my mymodel.otherplugin.ui.OtherPluginClass is 'visible from a given bundle' because the given bundle of the extension is 'mymodel.otherplugin.ui' itself Wink
Why not use the given bundle to load the class like in the 2nd code-sample(post#1)? It would make the generated factory much more flexible. Why must the factory create the given extension-class in the own class loader? I though the job of the factory is to 'inject' the created (and maybe 'external') class with the required 'own'-classes?
Atm I use in mymodel.ui a derived factory with this modification and it works fine.
many thanks,
gerit
Re: ExecutableExtensionFactory#getBundle() [message #689741 is a reply to message #675500] Tue, 28 June 2011 09:11 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi Gerit,
Sebastian Z. is right, you have to use the Injector from the plugin you
depend on, and create a new Injector from it. See
http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Injector.html#createChildInjector%28com.google.inject.Module...%29

I am wondering why the Grammar core plugins do not build their own
Injector by default. This could be used in the UI plugin to create a
child Injector, instead of the current approach using Module overrides.

--
Best regards,
Sebastian Paul

Am 2011-05-31 19:20, schrieb gerit:
> Sebastian Zarnekow wrote on Tue, 31 May 2011 10:35
>> the exectuable extension factory is meant to be used only for classes
>> that are visible from a given bundle. However, you could use an own
>> ExecutableExtensionFactory in your second bundle that uses the
>> injector of your first bundle.
>
> Hi Sebastian and thanks for the fast answer!
> But I am a little bit confused... my
> mymodel.otherplugin.ui.OtherPluginClass is 'visible from a given bundle'
> because the given bundle of the extension is 'mymodel.otherplugin.ui'
> itself ;)
> Why not use the given bundle to load the class like in the 2nd
> code-sample(post#1)? It would make the generated factory much more
> flexible. Why must the factory create the given extension-class in the
> own class loader? I though the job of the factory is to 'inject' the
> created (and maybe 'external') class with the required 'own'-classes?
> Atm I use in mymodel.ui a derived factory with this modification and it
> works fine.
> many thanks,
> gerit
>
Re: ExecutableExtensionFactory#getBundle() [message #690948 is a reply to message #689741] Thu, 30 June 2011 12:51 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Sebastian,

creating an injector for the core plugins in an Eclipse equinox context
would lead to corrupt emf registries. The UI modules explicitly
overrides some of the runtime bindings to avoid instantiating the
runtime instances. Otherwise, you'd end up with wrong instances in some
of the EMF registries. That sounds more confusing than helpful to me ...

Let's try again: Creating an runtime injector in an equinox environment
interferes the eclipse extension mechanism and you wouldn't have to
possibility to override bindings that are requested by runtime
components with ui specific functionality.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 28.06.11 11:11, Sebastian Paul wrote:
> Hi Gerit,
> Sebastian Z. is right, you have to use the Injector from the plugin you
> depend on, and create a new Injector from it. See
> http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/inject/Injector.html#createChildInjector%28com.google.inject.Module...%29
>
>
> I am wondering why the Grammar core plugins do not build their own
> Injector by default. This could be used in the UI plugin to create a
> child Injector, instead of the current approach using Module overrides.
>
Re: ExecutableExtensionFactory#getBundle() [message #692903 is a reply to message #690948] Tue, 05 July 2011 12:15 Go to previous message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi Sebastian,
thanks for the explaination. The problem I see here only arises in more
complex scenarios where there are more than one core and UI plugin
involved. For example, an optional plugin which only depends on the
grammar core may also want to get dependencies injected by Guice. With
your approach, there are two choices:
a) create child injector from grammar UI plugin - this would create an
aditional coupling
b) create new injector, using the runtime module from grammar core - to
the cost of more memory consumption (and maybe other side effects)

I'm a but curios about what is exactly overridden by the UI module.
Isn't it possible to separate concerns so far that UI can use the Core
injector as parent? Is this actually an Equinox issue? I'm asking,
because we need some best practices for our own architecture which
already uses lots of Guice and Xtext functionality.

Am 2011-06-30 14:51, schrieb Sebastian Zarnekow:
> Hi Sebastian,
>
> creating an injector for the core plugins in an Eclipse equinox context
> would lead to corrupt emf registries. The UI modules explicitly
> overrides some of the runtime bindings to avoid instantiating the
> runtime instances. Otherwise, you'd end up with wrong instances in some
> of the EMF registries. That sounds more confusing than helpful to me ...
>
> Let's try again: Creating an runtime injector in an equinox environment
> interferes the eclipse extension mechanism and you wouldn't have to
> possibility to override bindings that are requested by runtime
> components with ui specific functionality.
>
> Regards,
> Sebastian


--
Best regards,
Sebastian Paul
Previous Topic:Flatten xtext grammar & ui projects?
Next Topic:Reflexive contentassist
Goto Forum:
  


Current Time: Fri Apr 26 21:36:50 GMT 2024

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

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

Back to the top