Martin Fuzzey
2008-06-13 15:11:11 UTC
Hi,
I'm trying to use a generic factory injector like this:
public <T> void addService(final Class<T> interface_, Class
implementationClass, String instanceId) {
pico.addComponent(makeKey(interface_, instanceId), implementationClass);
class ServiceConnectionInjector extends FactoryInjector<T> {
public T getComponentInstance(PicoContainer container, Type into) {
System.out.println("**** injector called for " + into);
return null;
}
}
pico.addAdapter(new ServiceConnectionInjector());
}
Unfortunately I get an exception in the addAdapter method :
sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast
to java.lang.Class
at org.picocontainer.injectors.FactoryInjector.<init>(FactoryInjector.java:28)
at javadi.PicoContainerBasedServiceManager$1ServiceConnectionInjector.<init>(PicoContainerBasedServiceManager.java:29)
at javadi.PicoContainerBasedServiceManager.addService(PicoContainerBasedServiceManager.java:36)
at javadi.PicoContainerBasedServiceManagerTest.simpleInternalDependence(PicoContainerBasedServiceManagerTest.java:28)
It works ok with "directly" typed FactoryInjector subcleasses (like
the log example in the docs)
Looking at the source it seems the problem is that it assumes
getActualTypeArguments() will return the class and not another
parameterised type)
Has anyone else had / solved this problem? (unfortunately I'm not
currently very up to date with java generics having spent the last few
years working in python...)
Thanks,
Martin
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
I'm trying to use a generic factory injector like this:
public <T> void addService(final Class<T> interface_, Class
implementationClass, String instanceId) {
pico.addComponent(makeKey(interface_, instanceId), implementationClass);
class ServiceConnectionInjector extends FactoryInjector<T> {
public T getComponentInstance(PicoContainer container, Type into) {
System.out.println("**** injector called for " + into);
return null;
}
}
pico.addAdapter(new ServiceConnectionInjector());
}
Unfortunately I get an exception in the addAdapter method :
sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast
to java.lang.Class
at org.picocontainer.injectors.FactoryInjector.<init>(FactoryInjector.java:28)
at javadi.PicoContainerBasedServiceManager$1ServiceConnectionInjector.<init>(PicoContainerBasedServiceManager.java:29)
at javadi.PicoContainerBasedServiceManager.addService(PicoContainerBasedServiceManager.java:36)
at javadi.PicoContainerBasedServiceManagerTest.simpleInternalDependence(PicoContainerBasedServiceManagerTest.java:28)
It works ok with "directly" typed FactoryInjector subcleasses (like
the log example in the docs)
Looking at the source it seems the problem is that it assumes
getActualTypeArguments() will return the class and not another
parameterised type)
Has anyone else had / solved this problem? (unfortunately I'm not
currently very up to date with java generics having spent the last few
years working in python...)
Thanks,
Martin
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email