You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Trejkaz <tr...@trypticon.org> on 2009/01/10 08:08:16 UTC
iPOJO and abstract component classes
Hi all.
I have a setup where a lot of concrete service classes happened to
have identical logic, so I wanted to abstract that logic to an
abstract class. But it looks like what happens is that iPOJO won't
inject parameters unless they are on the bottom-level concrete class.
In other words, I'm trying to do this:
public interface Service {
void doComplicatedStuff();
}
@Component
public class AbstractService implements Service {
@Requires
private OtherService otherService;
@Override
public void doComplicatedStuff() {
// ... complicated logic using otherService ...
}
}
@Component
@Provides
public class ConcreteService extends AbstractService {
}
And when I get to doComplicatedStuff(), otherService is always null.
Does the iPOJO voodoo just not support this situation? The same logic
with the same service on the concrete class works fine so I expected
it to work here too, and I didn't see any warnings at the time it
mangled the classes or at runtime, indicating any problem...
TX
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: iPOJO and abstract component classes
Posted by Clement Escoffier <cl...@gmail.com>.
Hi,
On 10.01.2009, at 08:08, Trejkaz wrote:
> Hi all.
>
> I have a setup where a lot of concrete service classes happened to
> have identical logic, so I wanted to abstract that logic to an
> abstract class. But it looks like what happens is that iPOJO won't
> inject parameters unless they are on the bottom-level concrete class.
That's true
>
>
> In other words, I'm trying to do this:
>
> public interface Service {
> void doComplicatedStuff();
> }
>
> @Component
> public class AbstractService implements Service {
> @Requires
> private OtherService otherService;
>
> @Override
> public void doComplicatedStuff() {
> // ... complicated logic using otherService ...
> }
> }
>
> @Component
> @Provides
> public class ConcreteService extends AbstractService {
> }
>
> And when I get to doComplicatedStuff(), otherService is always null.
iPOJO manipulates the implementation class to support field injection.
So, parent class fields are not injected. However, bind and unbind
methods are supported . So, you can change your class as follow :
> @Component
> public class AbstractService implements Service {
> private OtherService otherService;
public synchronized void bindOtherService(OtherService svc) {
otherService = svc;
}
public synchronized void unbindOtherService(OtherService svc) {
otherService = null;
}
>
> @Override
> public synchronized void doComplicatedStuff() {
> // ... complicated logic using otherService ...
> }
> }
With the following metadata:
<ipojo>
<component classname="...ConcreteService">
<requires interfqce="...OtherService">
<callback type="bind" method="bindOtherService"/>
<callback type="unbind" method="unbindOtherService"/>
</requires>
</component>
</ipojo>
>
>
> Does the iPOJO voodoo just not support this situation? The same logic
> with the same service on the concrete class works fine so I expected
> it to work here too, and I didn't see any warnings at the time it
> mangled the classes or at runtime, indicating any problem...
iPOJO should warn you that a field does not exist in the class, and
the component type cannot be started correctly. I will check it...
Regards,
Clement
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org