Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.jboss.ejb3.client;
  /*     */ 
  /*     */ import java.lang.annotation.Annotation;
  /*     */ import java.lang.reflect.AccessibleObject;
  /*     */ import java.lang.reflect.Field;
  /*     */ import java.lang.reflect.Method;
  /*     */ import java.lang.reflect.Modifier;
  /*     */ import java.util.ArrayList;
 /*     */ import java.util.Collection;
 /*     */ import java.util.HashMap;
 /*     */ import java.util.Iterator;
 /*     */ import java.util.List;
 /*     */ import java.util.Map;
 /*     */ import javax.annotation.PostConstruct;
 /*     */ import javax.naming.Context;
 /*     */ import javax.naming.NameClassPair;
 /*     */ import javax.naming.NameNotFoundException;
 /*     */ import javax.naming.NamingEnumeration;
 /*     */ import org.jboss.ejb3.Container;
 /*     */ import org.jboss.ejb3.DependencyPolicy;
 /*     */ import org.jboss.ejb3.InitialContextFactory;
 /*     */ import org.jboss.injection.DependsHandler;
 /*     */ import org.jboss.injection.EncInjector;
 /*     */ import org.jboss.injection.InjectionContainer;
 /*     */ import org.jboss.injection.InjectionHandler;
 /*     */ import org.jboss.injection.InjectionUtil;
 /*     */ import org.jboss.injection.Injector;
 /*     */ import org.jboss.injection.JndiInjectHandler;
 /*     */ import org.jboss.injection.ResourceHandler;
 /*     */ import org.jboss.logging.Logger;
 /*     */ import org.jboss.util.NotImplementedException;
 /*     */ import org.jboss.virtual.VirtualFile;
 /*     */ 
 /*     */ public class ClientContainer
 /*     */   implements InjectionContainer
 /*     */ {
 /*  75 */   private static final Logger log = Logger.getLogger(ClientContainer.class);
 /*     */   private Class<?> mainClass;
 /*     */   private JBossClientMetaData xml;
 /*     */   private String applicationClientName;
 /*  82 */   private List<Injectorinjectors = new ArrayList();
 /*  83 */   private Map<StringMap<AccessibleObjectInjector>> encInjections = new HashMap();
 /*  84 */   private Map<StringEncInjectorencInjectors = new HashMap();
 /*     */   private Context enc;
 /*     */   private Context encEnv;
 /*  89 */   private List<MethodpostConstructs = new ArrayList();
 /*     */ 
 /*     */   public ClientContainer(JBossClientMetaData xmlClass<?> mainClassString applicationClientNamethrows Exception
 /*     */   {
 /*  93 */     this.xml = xml;
 /*  94 */     this.mainClass = mainClass;
 /*  95 */     this.applicationClientName = applicationClientName;
 /*     */ 
 /*  98 */     Context ctx = InitialContextFactory.getInitialContext();
 /*  99 */     this.enc = ((Context)ctx.lookup(applicationClientName));
 /* 100 */     log.debug("Client ENC(" + applicationClientName + "):");
 /* 101 */     NamingEnumeration e = this.enc.list("");
 /* 102 */     while (e.hasMore())
 /*     */     {
 /* 104 */       NameClassPair ncp = (NameClassPair)e.next();
 /* 105 */       log.debug("  " + ncp);
 /*     */     }
 /*     */ 
 /* 111 */     processMetadata(null);
 /*     */ 
 /* 113 */     for (EncInjector injector : this.encInjectors.values())
 /*     */     {
 /* 115 */       log.trace("encInjector: " + injector);
 /*     */     }
 /*     */ 
 /* 119 */     for (Injector injector : this.injectors)
 /*     */     {
 /* 121 */       log.trace("injector: " + injector);
 /* 122 */       injector.inject((Object)null);
 /*     */     }
 /*     */ 
 /* 125 */     postConstruct();
 /*     */   }
 /*     */ 
 /*     */   public <T extends Annotation> T getAnnotation(Class<T> annotationClassClass<?> clazz)
 /*     */   {
 /* 133 */     return clazz.getAnnotation(annotationClass);
 /*     */   }
 /*     */ 
 /*     */   public <T extends Annotation> T getAnnotation(Class<T> annotationClassClass<?> clazzMethod method)
 /*     */   {
 /* 141 */     return method.getAnnotation(annotationClass);
 /*     */   }
 /*     */ 
 /*     */   public <T extends Annotation> T getAnnotation(Class<T> annotationClassMethod method)
/*     */   {
/* 149 */     return method.getAnnotation(annotationClass);
/*     */   }
/*     */ 
/*     */   public <T extends Annotation> T getAnnotation(Class<T> annotationClassClass<?> clazzField field)
/*     */   {
/* 157 */     return field.getAnnotation(annotationClass);
/*     */   }
/*     */ 
/*     */   public <T extends Annotation> T getAnnotation(Class<T> annotationClassField field)
/*     */   {
/* 165 */     return field.getAnnotation(annotationClass);
/*     */   }
/*     */ 
/*     */   public ClassLoader getClassloader()
/*     */   {
/* 174 */     return Thread.currentThread().getContextClassLoader();
/*     */   }
/*     */ 
/*     */   public DependencyPolicy getDependencyPolicy()
/*     */   {
/* 182 */     throw new RuntimeException("NYI");
/*     */   }
/*     */ 
/*     */   public String getDeploymentDescriptorType()
/*     */   {
/* 190 */     return "application-client.xml";
/*     */   }
/*     */ 
/*     */   public String getEjbJndiName(Class businessInterface)
/*     */     throws NameNotFoundException
/*     */   {
/* 198 */     throw new RuntimeException("NYI");
/*     */   }
/*     */ 
/*     */   public String getEjbJndiName(String linkClass<?> businessInterface)
/*     */   {
/* 207 */     throw new NotImplementedException();
/*     */   }
/*     */ 
/*     */   public Context getEnc()
/*     */   {
/* 218 */     return this.enc;
/*     */   }
/*     */ 
/*     */   public Map<StringMap<AccessibleObjectInjector>> getEncInjections()
/*     */   {
/* 226 */     return this.encInjections;
/*     */   }
/*     */ 
/*     */   public Map<StringEncInjectorgetEncInjectors()
/*     */   {
/* 234 */     return this.encInjectors;
/*     */   }
/*     */ 
/*     */   public RemoteEnvironment getEnvironmentRefGroup()
/*     */   {
/* 242 */     return this.xml;
/*     */   }
/*     */ 
/*     */   public String getIdentifier()
/*     */   {
/* 253 */     return this.applicationClientName;
/*     */   }
/*     */ 
/*     */   public List<InjectorgetInjectors()
/*     */   {
/* 261 */     throw new NotImplementedException();
/*     */   }
/*     */ 
/*     */   public Class<?> getMainClass()
/*     */   {
/* 266 */     return this.mainClass;
/*     */   }
/*     */ 
/*     */   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName)
/*     */     throws NameNotFoundException
/*     */   {
/* 274 */     throw new NotImplementedException();
/*     */   }
/*     */ 
/*     */   public boolean hasJNDIBinding(String jndiName)
/*     */   {
/* 279 */     return false;
/*     */   }
/*     */ 
/*     */   {
/* 284 */     Class[] parameterTypes = { args.getClass() };
/* 285 */     Method method = this.mainClass.getDeclaredMethod("main", parameterTypes);
/* 286 */     method.invoke(nullnew Object[] { args });
/*     */   }
/*     */ 
/*     */   private void postConstruct()
/*     */   {
/* 299 */     log.info("postConstructs = " + this.postConstructs);
/* 300 */     for (Method method : this.postConstructs)
/*     */     {
/* 302 */       method.setAccessible(true);
/*     */       Object instance;
/*     */       Object instance;
/* 304 */       if (Modifier.isStatic(method.getModifiers()))
/* 305 */         instance = null;
/*     */       else
/* 307 */         instance = method.getDeclaringClass().newInstance();
/* 308 */       Object[] args = null;
/* 309 */       method.invoke(instance, args);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void processMetadata(DependencyPolicy dependencyPolicythrows Exception
/*     */   {
/* 315 */     log.debug("processMetadata");
/* 316 */     processPostConstructs();
/*     */ 
/* 319 */     Collection handlers = new ArrayList();
/* 320 */     handlers.add(new EJBInjectionHandler());
/*     */ 
/* 322 */     handlers.add(new DependsHandler());
/* 323 */     handlers.add(new JndiInjectHandler());
/* 324 */     handlers.add(new PersistenceUnitHandler());
/*     */ 
/* 326 */     handlers.add(new ResourceHandler(false));
/* 327 */     handlers.add(new WebServiceRefHandler());
/*     */     try
/*     */     {
/* 335 */       InjectionHandler handler;
/* 335 */       for (Iterator i$ = handlers.iterator(); i$.hasNext(); handler.loadXml(this.xml, this)) handler = (InjectionHandler)i$.next();
/*     */ 
/* 337 */       Map tmp = InjectionUtil.processAnnotations(this, handlers, getMainClass());
/* 338 */       this.injectors.addAll(tmp.values());
/*     */     }
/*     */     finally
/*     */     {
/*     */     }
/*     */   }
/*     */ 
/*     */   private void processPostConstructs()
/*     */   {
/* 370 */     processPostConstructs(this.mainClass);
/*     */ 
/* 372 */     LifecycleCallbacksMetaData callbacks = this.xml.getPostConstructs();
/* 373 */     if (callbacks != null)
/*     */     {
/* 375 */       for (LifecycleCallbackMetaData callback : callbacks)
/*     */       {
/* 377 */         String className = callback.getClassName();
/* 378 */         String methodName = callback.getMethodName();
/*     */         Class lifecycleClass;
/*     */         Class lifecycleClass;
/* 380 */         if (className == null)
/* 381 */           lifecycleClass = this.mainClass;
/*     */         else
/* 383 */           lifecycleClass = Thread.currentThread().getContextClassLoader().loadClass(className);
/* 384 */         Class[] parameterTypes = new Class[0];
/* 385 */         Method method = lifecycleClass.getDeclaredMethod(methodName, parameterTypes);
/* 386 */         this.postConstructs.add(method);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void processPostConstructs(Class<?> cls)
/*     */   {
/* 393 */     if (cls == null) {
/* 394 */       return;
/*     */     }
/* 396 */     for (Method method : cls.getDeclaredMethods())
/*     */     {
/* 398 */       PostConstruct postConstruct = (PostConstruct)method.getAnnotation(PostConstruct.class);
/* 399 */       if (postConstruct == null)
/*     */       {
/*     */         continue;
/*     */       }
/* 403 */       if (this.postConstructs.size() > 0)
/* 404 */         throw new IllegalStateException("only one @PostConstruct allowed");
/* 405 */       this.postConstructs.add(method);
/*     */     }
/*     */ 
/* 409 */     processPostConstructs(cls.getSuperclass());
/*     */   }
/*     */ 
/*     */   public Container resolveEjbContainer(String linkClass businessIntf)
/*     */   {
/* 417 */     log.warn("resolveEjbContainer(" + link + ", " + businessIntf + ") not implemented");
/* 418 */     return null;
/*     */   }
/*     */ 
/*     */   public Container resolveEjbContainer(Class businessIntf)
/*     */     throws NameNotFoundException
/*     */   {
/* 426 */     return null;
/*     */   }
/*     */ 
/*     */   public String resolveMessageDestination(String link)
/*     */   {
/* 432 */     return null;
/*     */   }
/*     */ 
/*     */   public VirtualFile getRootFile()
/*     */   {
/* 437 */     throw new NotImplementedException();
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.ejb3.client.ClientContainer
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X