FileDocCategorySizeDatePackage
ClientENCInjectionContainer.javaAPI DocJBoss 4.2.111374Fri Jul 13 20:53:54 BST 2007org.jboss.ejb3.clientmodule

ClientENCInjectionContainer

public class ClientENCInjectionContainer extends Object implements org.jboss.injection.InjectionContainer
This class builds up the java:comp namespace for JavaEE 5 application clients. It uses the existing injection framework to get this done.
author
Carlo de Wolf
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private org.jboss.ejb3.DeploymentUnit
ejb3Unit
private org.jboss.ejb3.metamodel.ApplicationClientDD
xml
private Class
mainClass
private String
applicationClientName
private ClassLoader
classLoader
private List
injectors
private Map
encInjections
private Map
encInjectors
private Context
enc
private org.jboss.ejb3.enc.DeploymentEjbResolver
ejbResolver
private ObjectName
objectName
private org.jboss.ejb3.DependencyPolicy
dependencyPolicy
Constructors Summary
public ClientENCInjectionContainer(org.jboss.deployers.spi.deployer.DeploymentUnit unit, org.jboss.ejb3.metamodel.ApplicationClientDD xml, Class mainClass, String applicationClientName, ClassLoader classLoader, Context encCtx)


                 
   
      if(mainClass == null)
         throw new NullPointerException("mainClass is mandatory");
      if(applicationClientName == null)
         throw new NullPointerException("applicationClientName is mandatory");
      if(classLoader == null)
         throw new NullPointerException("classLoader is mandatory");
      
      this.ejb3Unit = new JBoss5DeploymentUnit(unit);
      this.xml = xml;
      this.mainClass = mainClass;
      this.applicationClientName = applicationClientName;
      this.classLoader = classLoader;
      
      this.enc = encCtx;
      
      /*
      EAR ear = null;

      if (di.parent != null)
      {
         if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
         {
            synchronized (di.parent.context)
            {
               ear = (EAR) di.parent.context.get("EJB3_EAR_METADATA");
               if (ear == null)
               {
                  ear = new JmxEARImpl(di.parent.shortName);
                  di.parent.context.put("EJB3_EAR_METADATA", ear);
               }
            }
         }
      }
      */
      
      DeploymentScope scope = null;
      if (unit.getDeploymentContext().getParent() != null)
      {
         scope = new JBoss5DeploymentScope(unit.getDeploymentContext().getParent());
      }
      
      ejbResolver = new ClientEjbResolver(scope, unit.getDeploymentContext().getRoot().getName());
      
      String on = Ejb3Module.BASE_EJB3_JMX_NAME + createScopeKernelName(unit, scope) + ",name=" + applicationClientName;
      try
      {
         this.objectName = new ObjectName(on);
      }
      catch(MalformedObjectNameException e)
      {
         // should not happen
         throw new RuntimeException(e);
      }
      
      processMetaData();
   
Methods Summary
private java.lang.StringcreateScopeKernelName(org.jboss.deployers.spi.deployer.DeploymentUnit unit, org.jboss.ejb3.DeploymentScope ear)

      String scopedKernelName = "";
      if (ear != null) scopedKernelName += ",ear=" + ear.getShortName();
      scopedKernelName += ",jar=" + unit.getDeploymentContext().getRoot().getName();
      return scopedKernelName;
   
public TgetAnnotation(java.lang.Class annotationType, java.lang.Class clazz)

      return clazz.getAnnotation(annotationType);
   
public TgetAnnotation(java.lang.Class annotationType, java.lang.Class clazz, java.lang.reflect.Method method)

      return method.getAnnotation(annotationType);
   
public TgetAnnotation(java.lang.Class annotationType, java.lang.reflect.Method method)

      return method.getAnnotation(annotationType);
   
public TgetAnnotation(java.lang.Class annotationType, java.lang.Class clazz, java.lang.reflect.Field field)

      return field.getAnnotation(annotationType);
   
public TgetAnnotation(java.lang.Class annotationType, java.lang.reflect.Field field)

      return field.getAnnotation(annotationType);
   
public java.lang.ClassLoadergetClassloader()

      return classLoader;
   
public org.jboss.ejb3.DependencyPolicygetDependencyPolicy()

      return dependencyPolicy;
   
public java.lang.StringgetDeploymentDescriptorType()

      return "application-client.xml";
   
public java.lang.StringgetEjbJndiName(java.lang.Class businessInterface)

      return ejbResolver.getEjbJndiName(businessInterface);
   
public java.lang.StringgetEjbJndiName(java.lang.String link, java.lang.Class businessInterface)

      return ejbResolver.getEjbJndiName(link, businessInterface);
   
public javax.naming.ContextgetEnc()

      return enc;
   
public java.util.MapgetEncInjections()

      return encInjections;
   
public java.util.MapgetEncInjectors()

      return encInjectors;
   
public org.jboss.metamodel.descriptor.EnvironmentRefGroupgetEnvironmentRefGroup()

      return xml;
   
public java.lang.StringgetIdentifier()

      return applicationClientName;
   
public java.util.ListgetInjectors()
A client enc injection container doesn't support injectors, because these must be run client side.

      //throw new RuntimeException("not supported");
      return injectors;
   
public java.lang.ClassgetMainClass()

      return mainClass;
   
public javax.management.ObjectNamegetObjectName()

      return objectName;
   
public org.jboss.ejb3.entity.PersistenceUnitDeploymentgetPersistenceUnitDeployment(java.lang.String unitName)

      throw new RuntimeException("NYI");
   
private voidpopulateEnc()

      for (EncInjector injector : encInjectors.values())
      {
         log.trace("encInjector: " + injector);
         injector.inject(this);
      }
   
private voidprocessMetaData()

      for(String dependency : xml.getDependencies())
      {
         getDependencyPolicy().addDependency(dependency);
      }
      
      // TODO: check which handlers an application client should support
      Collection<InjectionHandler> handlers = new ArrayList<InjectionHandler>();
      handlers.add(new EJBHandler());
      handlers.add(new DependsHandler());
      handlers.add(new JndiInjectHandler());
      handlers.add(new PersistenceContextHandler());
      handlers.add(new PersistenceUnitHandler());
      handlers.add(new ResourceHandler());
      handlers.add(new WebServiceRefHandler());
      
      ClassLoader old = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(classLoader);
      try
      {
         // EJB container's XML must be processed before interceptor's as it may override interceptor's references
         for (InjectionHandler handler : handlers) handler.loadXml(xml, this);

         Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(this, handlers, getMainClass());
         injectors.addAll(tmp.values());

//         initialiseInterceptors();
//         for (InterceptorInfo interceptorInfo : applicableInterceptors)
//         {
//            for (InjectionHandler handler : handlers)
//            {
//               handler.loadXml(interceptorInfo.getXml(), this);
//            }
//         }
//         for (InterceptorInfo interceptorInfo : applicableInterceptors)
//         {
//            Map<AccessibleObject, Injector> tmpInterceptor = InjectionUtil.processAnnotations(this, handlers, interceptorInfo.getClazz());
//            InterceptorInjector injector = new InterceptorInjector(this, interceptorInfo, tmpInterceptor);
//            interceptorInjectors.put(interceptorInfo.getClazz(), injector);
//         }
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(old);
      }
   
public org.jboss.ejb3.ContainerresolveEjbContainer(java.lang.String link, java.lang.Class businessIntf)

      return ejbResolver.getEjbContainer(link, businessIntf);
   
public org.jboss.ejb3.ContainerresolveEjbContainer(java.lang.Class businessIntf)

      return ejbResolver.getEjbContainer(businessIntf);
   
public voidstart()

      log.trace("start");
      
      populateEnc();
      
      // Don't run any injectors, they must be run client side
   
public voidstop()

      log.trace("stop");