[jboss-cvs] JBossAS SVN: r58774 - trunk/ejb3/src/main/org/jboss/ejb3/client
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 30 11:19:11 EST 2006
Author: wolfc
Date: 2006-11-30 11:19:07 -0500 (Thu, 30 Nov 2006)
New Revision: 58774
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
Log:
EJBTHREE-718: post construct & getClassloader
Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java 2006-11-30 16:18:14 UTC (rev 58773)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java 2006-11-30 16:19:07 UTC (rev 58774)
@@ -26,12 +26,14 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
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.List;
import java.util.Map;
+import javax.annotation.PostConstruct;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
@@ -42,6 +44,7 @@
import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.ejb3.metamodel.ApplicationClientDD;
+import org.jboss.ejb3.metamodel.LifecycleCallback;
import org.jboss.injection.DependsHandler;
import org.jboss.injection.EJBHandler;
import org.jboss.injection.EncInjector;
@@ -79,6 +82,8 @@
private Context enc;
private Context encEnv;
+
+ private List<Method> postConstructs = new ArrayList<Method>();
public ClientContainer(ApplicationClientDD xml, Class<?> mainClass, String applicationClientName) throws Exception
{
@@ -112,6 +117,8 @@
log.trace("injector: " + injector);
injector.inject((Object) null);
}
+
+ postConstruct();
}
/* (non-Javadoc)
@@ -159,7 +166,8 @@
*/
public ClassLoader getClassloader()
{
- throw new RuntimeException("NYI");
+ //throw new RuntimeException("NYI");
+ return Thread.currentThread().getContextClassLoader();
}
/* (non-Javadoc)
@@ -277,8 +285,34 @@
method.invoke(null, (Object) args);
}
- private void processMetadata(DependencyPolicy dependencyPolicy)
+ /**
+ * Call post construct methods.
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws InvocationTargetException
+ * @throws IllegalArgumentException
+ *
+ */
+ private void postConstruct() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
+ 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 void processMetadata(DependencyPolicy dependencyPolicy) throws Exception
+ {
+ processPostConstructs();
+
// TODO: check which handlers a client container should support
Collection<InjectionHandler> handlers = new ArrayList<InjectionHandler>();
handlers.add(new EJBHandler());
@@ -322,6 +356,53 @@
}
}
+ /**
+ * Create dummy dd for PostConstruct annotations.
+ * @throws ClassNotFoundException
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ *
+ */
+ private void processPostConstructs() throws ClassNotFoundException, SecurityException, NoSuchMethodException
+ {
+ 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 void processPostConstructs(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());
+ }
+
/* (non-Javadoc)
* @see org.jboss.injection.InjectionContainer#resolveEjbContainer(java.lang.String, java.lang.Class)
*/
More information about the jboss-cvs-commits
mailing list