Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Injection and Inheritance
Injection and Inheritance [message #671713] Wed, 18 May 2011 18:58 Go to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi,
I am playing around with the (for me) new concept of dependency injection. While that works without any problems when I inject into a concrete workbench part in e4, I get an exception (to be precicely a NullPointerException thrown by InjectorImpl.resolveArgs) injecting the same services into the abstract parent class. Because I am new to the concept of injection I would like to know if this is just not possible or if there is a way to do that. Thank you.
Re: Injection and Inheritance [message #671722 is a reply to message #671713] Wed, 18 May 2011 19:31 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You mean you have:

public abstract class Parent {
@Inject
protected SomethingUseful something;
//...
}

public class Child extends Parent {
// ...
}

// somewhere later:
ContextInjectionFactory.make(Child.class, context);


and you get that error?

Later,
PW


Re: Injection and Inheritance [message #671734 is a reply to message #671722] Wed, 18 May 2011 20:09 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
I use part A as a view and part B as editor. When the user selects an entry in the viewer in A, the selection is propagated via selectionservice. Editor B inherits from an abstract class c that is a generic type:

public abstract class AbstractEditor<T extends AbstractEntity>
{
}

The concrete editor B:

public class DescriptorTemplateEditor extends AbstractEditor<DescriptorTemplate>
{
}

I want to catch the propagated selection by a concrete method in the abstract class like:

@Inject
public void setModel(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) T model)
{
if (model != null)
{
this.getModel().setModel(model);
this.getPartService().getActivePart().setDirty(false);
}
}

Now the Exception is thrown in InjectorImpl.resolveArgs. ON line 476 in my current version is a parameter of that method evaluated:

Class<?> descriptorsClass = getDesiredClass(descriptors[i].getDesiredType());

where the desiredtype is a T. So the method getDesiredClass returns null.

Good Evening

Christian
Re: Injection and Inheritance [message #671748 is a reply to message #671734] Wed, 18 May 2011 21:02 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hm, I don't think this can work because of the typ erasure happening in
Java but I could be wrong.

Tom

Am 18.05.11 22:09, schrieb Christian Eugster:
> I use part A as a view and part B as editor. When the user selects an
> entry in the viewer in A, the selection is propagated via
> selectionservice. Editor B inherits from an abstract class c that is a
> generic type:
>
> public abstract class AbstractEditor<T extends AbstractEntity>
> {
> }
>
> The concrete editor B:
>
> public class DescriptorTemplateEditor extends
> AbstractEditor<DescriptorTemplate>
> {
> }
>
> I want to catch the propagated selection by a concrete method in the
> abstract class like:
>
> @Inject
> public void setModel(@Optional
> @Named(IServiceConstants.ACTIVE_SELECTION) T model)
> {
> if (model != null)
> {
> this.getModel().setModel(model);
> this.getPartService().getActivePart().setDirty(false);
> }
> }
>
> Now the Exception is thrown in InjectorImpl.resolveArgs. ON line 476 in
> my current version is a parameter of that method evaluated:
>
> Class<?> descriptorsClass =
> getDesiredClass(descriptors[i].getDesiredType());
>
> where the desiredtype is a T. So the method getDesiredClass returns null.
>
> Good Evening
>
> Christian
Re: Injection and Inheritance [message #671827 is a reply to message #671748] Thu, 19 May 2011 06:24 Go to previous message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
So I have to set the method abstract in the parent class and override it in the concrete class.

Thank you!
Previous Topic:Pure e4 Application with old UI extensions
Next Topic:Layout like Skype with e4
Goto Forum:
  


Current Time: Fri Apr 19 22:45:40 GMT 2024

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

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

Back to the top