FileDocCategorySizeDatePackage
ClientContainer.javaAPI DocJBoss 4.2.114359Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.client

ClientContainer

public class ClientContainer extends Object implements org.jboss.injection.InjectionContainer
Injection of the application client main class is handled from here.
author
Carlo de Wolf
version
$Revision: $

Fields Summary
private static final Logger
log
private Class
mainClass
private org.jboss.ejb3.metamodel.ApplicationClientDD
xml
private String
applicationClientName
private List
injectors
private Map
encInjections
private Map
encInjectors
private Context
enc
private Context
encEnv
private List
postConstructs
Constructors Summary
public ClientContainer(org.jboss.ejb3.metamodel.ApplicationClientDD xml, Class mainClass, String applicationClientName)


           
   
      this.xml = xml;
      this.mainClass = mainClass;
      this.applicationClientName = applicationClientName;
      
      //Context ctx = getInitialContext();
      Context ctx = new InitialContext();
      enc = (Context) ctx.lookup(applicationClientName);
      NamingEnumeration<NameClassPair> e = enc.list("");
      while(e.hasMore())
      {
         NameClassPair ncp = e.next();
         log.debug("  " + ncp);
      }
      encEnv = (Context) enc.lookup("env");
//      enc = ThreadLocalENCFactory.create(ctx);
//      encEnv = Util.createSubcontext(enc, "env");
      
      processMetadata(null);
      
//      for (EncInjector injector : encInjectors.values())
//      {
//         log.trace("encInjector: " + injector);
//         injector.inject(this);
//      }
      
      for(Injector injector : injectors)
      {
         log.trace("injector: " + injector);
         injector.inject((Object) null);
      }
      
      postConstruct();
   
Methods Summary
public TgetAnnotation(java.lang.Class annotationClass, java.lang.Class clazz)

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

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

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

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

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

      //throw new RuntimeException("NYI");
      return Thread.currentThread().getContextClassLoader();
   
public org.jboss.ejb3.DependencyPolicygetDependencyPolicy()

      throw new RuntimeException("NYI");
   
public java.lang.StringgetDeploymentDescriptorType()

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

      throw new RuntimeException("NYI");
      //return null;
   
public java.lang.StringgetEjbJndiName(java.lang.String link, java.lang.Class businessInterface)

      throw new NotImplementedException();
      //return "java:comp/env/" + link + "/remote";
      //return applicationClientName + "/" + link + "/remote";
      //return null;
   
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()

//      throw new NotImplementedException;
      // FIXME: return the real identifier
      //return "client-identifier";
      return applicationClientName;
   
public java.util.ListgetInjectors()

      throw new NotImplementedException();
   
public java.lang.ClassgetMainClass()

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

      throw new NotImplementedException();
   
public voidinvokeMain(java.lang.String[] args)

      Class parameterTypes[] = { args.getClass() };
      Method method = mainClass.getDeclaredMethod("main", parameterTypes);
      method.invoke(null, (Object) args);
   
private voidpostConstruct()
Call post construct methods.

throws
IllegalAccessException
throws
InstantiationException
throws
InvocationTargetException
throws
IllegalArgumentException

      log.info("postConstructs = " + postConstructs);
      for(Method method : postConstructs)
      {
         method.setAccessible(true);
         Object instance;
         if(Modifier.isStatic(method.getModifiers()))
            instance = null;
         else
            instance = method.getDeclaringClass().newInstance();
         Object args[] = null;
         method.invoke(instance, args);
      }
   
private voidprocessMetadata(org.jboss.ejb3.DependencyPolicy dependencyPolicy)

      processPostConstructs();
      
      // TODO: check which handlers a client container should support
      Collection<InjectionHandler> handlers = new ArrayList<InjectionHandler>();
      handlers.add(new EJBHandler());
      //handlers.add(new ClientEJBHandler());
      handlers.add(new DependsHandler());
      handlers.add(new JndiInjectHandler());
      handlers.add(new PersistenceContextHandler());
      handlers.add(new PersistenceUnitHandler());
      handlers.add(new ResourceHandler());
      handlers.add(new WebServiceRefHandler());
      
      // TODO: we're going to use a jar class loader
//      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);
      }
   
private voidprocessPostConstructs()
Create dummy dd for PostConstruct annotations.

throws
ClassNotFoundException
throws
NoSuchMethodException
throws
SecurityException

      processPostConstructs(mainClass);
      
      for(LifecycleCallback callback : xml.getPostConstructs())
      {
         String className = callback.getLifecycleCallbackClass();
         String methodName = callback.getLifecycleCallbackMethod();
         Class lifecycleClass;
         if(className == null)
            lifecycleClass = mainClass;
         else
            lifecycleClass = Thread.currentThread().getContextClassLoader().loadClass(className);
         Class parameterTypes[] = new Class[0];
         Method method = lifecycleClass.getDeclaredMethod(methodName, parameterTypes);
         postConstructs.add(method);
      }
   
private voidprocessPostConstructs(java.lang.Class cls)

      if(cls == null)
         return;
      
      for(Method method : cls.getDeclaredMethods())
      {
         PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
         if(postConstruct != null)
         {
            // TODO: sure?
            // http://java.sun.com/javase/6/docs/api/javax/annotation/PostConstruct.html
            if(postConstructs.size() > 0)
               throw new IllegalStateException("only one @PostConstruct allowed");
            postConstructs.add(method);
         }
      }
      
      processPostConstructs(cls.getSuperclass());
   
public org.jboss.ejb3.ContainerresolveEjbContainer(java.lang.String link, java.lang.Class businessIntf)

      log.warn("resolveEjbContainer(" + link + ", " + businessIntf + ") not implemented");
      return null;
   
public org.jboss.ejb3.ContainerresolveEjbContainer(java.lang.Class businessIntf)

      return null;