[jboss-user] [JBoss Microcontainer Users] - Re: How to get DeploymentUnit?
Juergen.Zimmermann
do-not-reply at jboss.com
Sun Nov 22 04:23:02 EST 2009
I've to implement a class as follows:
| import java.lang.reflect.Type;
| import javax.ejb.EJB;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
| import javax.ws.rs.ext.Provider;
| import com.sun.jersey.core.spi.component.ComponentContext;
| import com.sun.jersey.spi.inject.Injectable;
| import com.sun.jersey.spi.inject.InjectableProvider;
|
| @Provider
| public class EJBProvider implements InjectableProvider<EJB, Type> {
| public Injectable<Object> getInjectable(ComponentContext componentCtx,
| EJB ejbAnnotation,
| Type type) {
| if (!(type instanceof Class<?>))
| return null;
|
| Class<?> clazz = (Class<?>) type;
|
| String beanInterface = ejbAnnotation.beanInterface().getName();
| if (Object.class.getName().equals(beanInterface)) {
| beanInterface = clazz.getName();
| }
|
| String jndiName = ???; // get jndi name via beanInterface
|
| Context ctx = null;
| try {
| ctx = new InitialContext();
| Object obj = ctx.lookup(jndiName);
|
| return new Injectable<Object>() {
| public Object getValue() {
| return obj;
| }
| };
| }
| catch (NamingException e) { /* error handling */ }
| finally { /* close ctx */ }
| }
| }
So my 1st problem is: how to get the jndi name when the interface of an EJB is available?
I was trying the following where I only would need the DeploymentUnit object. Perhaps there are alternatives. Any hint is highly appreciated!
//import org.jboss.deployers.structure.spi.DeploymentUnit;
| //import org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver;
| //import org.jboss.ejb3.common.resolvers.spi.EjbReference;
| //import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
|
| EjbReference ref = new EjbReference(ejbAnnotation.beanName(),
| beanInterface,
| ejbAnnotation.mappedName());
| EjbReferenceResolver resolver = new FirstMatchEjbReferenceResolver();
|
| DeploymentUnit du = ???; // How to get DeploymentUnit? Via ClassLoader?
|
| String jndiName = resolver.resolveEjb(du, ref);
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4266911#4266911
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4266911
More information about the jboss-user
mailing list