JndiInject and confused use of generics for polymorphism
adrian.brock Nov 12, 2007 2:51 PMA number of tests were failing because the @JndiInject handler was commented out.
There are 43 references in the ejb3 testsuite.
This looks like a confused use of the generic parameter to try to do some type
of polymorphism, which obviously isn't supported since the type isn't even
available at runtime (well unless you use reflection and do it yourself :-).
I don't see why these classes should be generic?
Shouldn't all these take some jboss extension interface
to the spec defined Environment that both the
jboss ejb and interceptors metadata implement?
Relatedly, I don't understand why you cannot annotate interceptors
with @JndiInject?
Also, shouldn't all the annotations have equivalent xml,
e.g. DependsHandler doesn't look at the xml model at all,
there are only annotations???
I've reinstated the handler, but "fixed" the fact that it wants
JBossEnterpriseMetaData only with a hack that checks the type in loadXml()
Index: src/main/org/jboss/injection/JndiInjectHandler.java =================================================================== --- src/main/org/jboss/injection/JndiInjectHandler.java (revision 66950) +++ src/main/org/jboss/injection/JndiInjectHandler.java (working copy) @@ -29,7 +29,10 @@ import org.jboss.annotation.JndiInject; import org.jboss.logging.Logger; import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData; +import org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData; import org.jboss.metadata.javaee.jboss.JndiRefMetaData; +import org.jboss.metadata.javaee.jboss.JndiRefsMetaData; +import org.jboss.metadata.javaee.spec.Environment; /** * Searches bean class for all @Inject and create Injectors @@ -37,7 +40,7 @@ * @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @version $Revision$ */ -public class JndiInjectHandler<X extends JBossEnterpriseBeanMetaData> implements InjectionHandler<X> +public class JndiInjectHandler<X extends Environment> implements InjectionHandler<X> { @SuppressWarnings("unused") private static final Logger log = Logger.getLogger(JndiInjectHandler.class); @@ -45,8 +48,10 @@ public void loadXml(X xml, InjectionContainer container) { if (xml == null) return; - if (xml.getJndiRefs() == null) return; - for (JndiRefMetaData ref : xml.getJndiRefs()) + if (xml instanceof JBossEnterpriseBeanMetaData == false) return; + JndiRefsMetaData jndiRefs = ((JBossEnterpriseBeanMetaData) xml).getJndiRefs(); + if (jndiRefs == null) return; + for (JndiRefMetaData ref : jndiRefs) { if (ref.getMappedName() == null || ref.getMappedName().equals("")) throw new RuntimeException("mapped-name is required for " + ref.getJndiRefName() + " of container " + container.getIdentifier());