Author: pete.muir(a)jboss.org
Date: 2008-07-03 17:29:26 -0400 (Thu, 03 Jul 2008)
New Revision: 42
Added:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
Log:
Some WIP on remote components (which is wrong somewhere)
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-07-03
17:44:20 UTC (rev 41)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -14,17 +14,20 @@
import org.jboss.webbeans.bindings.ProductionBinding;
import org.jboss.webbeans.bindings.StandardBinding;
+import org.jboss.webbeans.ejb.EjbManager;
public class ContainerImpl implements Container
{
private List<Annotation> enabledDeploymentTypes;
private StereotypeManager stereotypeManager;
+ private EjbManager ejbLookupManager;
public ContainerImpl(List<Annotation> enabledDeploymentTypes)
{
initEnabledDeploymentTypes(enabledDeploymentTypes);
this.stereotypeManager = new StereotypeManager();
+ this.ejbLookupManager = new EjbManager();
}
private void initEnabledDeploymentTypes(List<Annotation>
enabledDeploymentTypes)
@@ -135,4 +138,9 @@
return this.stereotypeManager;
}
+ public EjbManager getEjbManager()
+ {
+ return ejbLookupManager;
+ }
+
}
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java 2008-07-03
17:44:20 UTC (rev 41)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -1,9 +1,8 @@
package org.jboss.webbeans.ejb;
import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
+
import org.jboss.webbeans.util.Reflections;
@@ -11,8 +10,6 @@
public class EJB
{
- private static Map<Class<?>, EjbMetaData> ejbMetaDataMap = new
HashMap<Class<?>, EjbMetaData>();
-
public @interface Dummy {}
public static final Class<Annotation> STATELESS_ANNOTATION;
@@ -42,20 +39,4 @@
}
}
- public static <T> EjbMetaData<T> getEjbMetaData(Class<? extends T>
clazz)
- {
- // TODO replace with an application lookup
- if (!ejbMetaDataMap.containsKey(clazz))
- {
- EjbMetaData<T> ejbMetaData = new EjbMetaData(clazz);
- ejbMetaDataMap.put(clazz, ejbMetaData);
- return ejbMetaData;
- }
- else
- {
- return ejbMetaDataMap.get(clazz);
- }
-
- }
-
}
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
(rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -0,0 +1,64 @@
+package org.jboss.webbeans.ejb;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.webbeans.EnterpriseBeanLookup;
+
+
+public class EjbManager
+{
+
+ private Map<Class<?>, EjbMetaData<?>> ejbMetaDataMap = new
HashMap<Class<?>, EjbMetaData<?>>();
+
+ private EnterpriseBeanLookup enterpriseBeanLookup;
+
+ public EjbManager()
+ {
+ // TODO Write enterpriseBeanLookup instantiation
+ }
+
+ // TODO Should this be static?
+ @SuppressWarnings("unchecked")
+ public <T> T lookup(EjbMetaData<T> ejb)
+ {
+ if (ejb.getEjbLinkJndiName() != null)
+ {
+ return (T) lookupInJndi(ejb.getEjbLinkJndiName());
+ }
+ try
+ {
+ // TODO How is a JNDI lookup failure shown to us?
+ return (T) lookupInJndi(ejb.getDefaultJndiName());
+ }
+ catch (Exception e)
+ {
+
+ }
+ return (T) enterpriseBeanLookup.lookup(ejb.getEjbName());
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> EjbMetaData<T> getEjbMetaData(Class<? extends T> clazz)
+ {
+ // TODO replace with an application lookup
+ if (!ejbMetaDataMap.containsKey(clazz))
+ {
+ EjbMetaData<T> ejbMetaData = new EjbMetaData<T>(clazz);
+ ejbMetaDataMap.put(clazz, ejbMetaData);
+ return ejbMetaData;
+ }
+ else
+ {
+ return (EjbMetaData<T>) ejbMetaDataMap.get(clazz);
+ }
+
+ }
+
+ protected Object lookupInJndi(String name)
+ {
+ // TODO Write JNDI lookup
+ return null;
+ }
+
+}
Property changes on:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-07-03
17:44:20 UTC (rev 41)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -29,8 +29,18 @@
private EjbType ejbType;
private List<Method> removeMethods;
+
+ // TODO Populate this from web.xml
+ private String ejbLinkJndiName;
+
+ // TODO Initialize this based on the EJB 3.1 spec
+ private String defaultJndiName;
+
+ // TODO Initialize the ejb name
+ private String ejbName;
+
- public EjbMetaData(Class<T> type)
+ public EjbMetaData(Class<? extends T> type)
{
// TODO Merge in ejb-jar.xml
if (type.isAnnotationPresent(STATELESS_ANNOTATION))
@@ -80,5 +90,20 @@
{
return removeMethods;
}
+
+ public String getEjbLinkJndiName()
+ {
+ return ejbLinkJndiName;
+ }
+ public String getDefaultJndiName()
+ {
+ return defaultJndiName;
+ }
+
+ public String getEjbName()
+ {
+ return ejbName;
+ }
+
}
Added:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
(rev 0)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans.injectable;
+
+import javax.webbeans.Container;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.ejb.EjbMetaData;
+
+
+public class EnterpriseConstructor<T> implements ComponentConstructor<T>
+{
+
+ private EjbMetaData<T> ejbMetaData;
+
+ public EnterpriseConstructor(EjbMetaData<T> ejbMetaData)
+ {
+ this.ejbMetaData = ejbMetaData;
+ }
+
+ public T invoke(Container container)
+ {
+ // TODO Hmm, this isn't right
+ if (container instanceof ContainerImpl)
+ {
+ ContainerImpl containerImpl = (ContainerImpl) container;
+ return containerImpl.getEjbManager().lookup(ejbMetaData);
+ }
+ else
+ {
+ throw new RuntimeException("Error accessing webbeans container");
+ }
+ }
+
+}
Property changes on:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/injectable/EnterpriseConstructor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-07-03
17:44:20 UTC (rev 41)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -238,62 +238,6 @@
return null;
}
- @SuppressWarnings("unchecked")
- protected static <T> SimpleConstructor<T> initConstructor(Class<?
extends T> type)
- {
- if (type.getConstructors().length == 1)
- {
- Constructor<T> constructor = type.getConstructors()[0];
- log.finest("Exactly one constructor (" + constructor +") defined,
using it as the component constructor for " + type);
- return new SimpleConstructor<T>(constructor);
- }
-
- if (type.getConstructors().length > 1)
- {
- List<Constructor<T>> initializerAnnotatedConstructors =
Reflections.getConstructors(type, Initializer.class);
- List<Constructor<T>> bindingTypeAnnotatedConstructors =
Reflections.getConstructorsForMetaAnnotatedParameter(type, BindingType.class);
- log.finest("Found " + initializerAnnotatedConstructors + "
constructors annotated with @Initializer for " + type);
- log.finest("Found " + bindingTypeAnnotatedConstructors + " with
parameters annotated with binding types for " + type);
- if ((initializerAnnotatedConstructors.size() +
bindingTypeAnnotatedConstructors.size()) > 1)
- {
- if (initializerAnnotatedConstructors.size() > 1)
- {
- throw new RuntimeException("Cannot have more than one constructor
annotated with @Initializer for " + type);
- }
-
- else if (bindingTypeAnnotatedConstructors.size() > 1)
- {
- throw new RuntimeException("Cannot have more than one constructor
with binding types specified on constructor parameters for " + type);
- }
- else
- {
- throw new RuntimeException("Specify a constructor either annotated
with @Initializer or with parameters annotated with binding types for " + type);
- }
- }
- else if (initializerAnnotatedConstructors.size() == 1)
- {
- Constructor<T> constructor = initializerAnnotatedConstructors.get(0);
- log.finest("Exactly one constructor (" + constructor +")
annotated with @Initializer defined, using it as the component constructor for " +
type);
- return new SimpleConstructor<T>(constructor);
- }
- else if (bindingTypeAnnotatedConstructors.size() == 1)
- {
- Constructor<T> constructor = bindingTypeAnnotatedConstructors.get(0);
- log.finest("Exactly one constructor (" + constructor +") with
parameters annotated with binding types defined, using it as the component constructor for
" + type);
- return new SimpleConstructor<T>(constructor);
- }
- }
-
- if (type.getConstructors().length == 0)
- {
- Constructor<T> constructor = (Constructor<T>)
Reflections.getConstructor(type);
- log.finest("No constructor defined, using implicit no arguement constructor
for " + type);
- return new SimpleConstructor<T>(constructor);
- }
-
- throw new RuntimeException("Cannot determine constructor to use for " +
type);
- }
-
protected static String initName(MergedStereotypesModel stereotypes, AnnotatedItem
annotatedItem, AnnotatedItem xmlAnnotatedItem, Class<?> type)
{
boolean componentNameDefaulted = false;
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-07-03
17:44:20 UTC (rev 41)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -6,28 +6,33 @@
import javax.webbeans.Dependent;
import org.jboss.webbeans.ContainerImpl;
-import org.jboss.webbeans.ejb.EJB;
import org.jboss.webbeans.ejb.EjbMetaData;
-import org.jboss.webbeans.injectable.SimpleConstructor;
+import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.EnterpriseConstructor;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.util.AnnotatedItem;
public class EnterpriseComponentModel<T> extends AbstractComponentModel<T>
{
- private SimpleConstructor<T> constructor;
+ private EnterpriseConstructor<T> constructor;
private InjectableMethod<?> removeMethod;
public EnterpriseComponentModel(AnnotatedItem annotatedItem,
AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
{
super(annotatedItem, xmlAnnotatedItem, container);
- this.constructor = initConstructor(getType());
- EjbMetaData<T> ejbMetaData = EJB.getEjbMetaData(getType());
+ EjbMetaData<T> ejbMetaData =
container.getEjbManager().getEjbMetaData(getType());
+ this.constructor = initConstructor(ejbMetaData, container);
EnterpriseComponentModel.checkScopeAllowed(getMergedStereotypes(), getScopeType(),
getType(), ejbMetaData);
this.removeMethod = initRemoveMethod(ejbMetaData, getType());
}
+ protected static <T> EnterpriseConstructor<T>
initConstructor(EjbMetaData<T> ejbMetaData, ContainerImpl container)
+ {
+ return new EnterpriseConstructor<T>(ejbMetaData);
+ }
+
/**
* Check that the scope type is allowed by the stereotypes on the component and the
component type
* @param type
@@ -44,7 +49,7 @@
}
}
- public SimpleConstructor<T> getConstructor()
+ public ComponentConstructor<T> getConstructor()
{
return constructor;
}
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-07-03
17:44:20 UTC (rev 41)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -1,26 +1,83 @@
package org.jboss.webbeans.model;
+import java.lang.annotation.Annotation;
+
+import javax.webbeans.ApplicationScoped;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Dependent;
+
import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.EnterpriseConstructor;
+import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.util.AnnotatedItem;
public class RemoteComponentModel<T> extends AbstractComponentModel<T>
{
+ private EnterpriseConstructor<T> constructor;
+ private InjectableMethod<?> removeMethod;
+ private String boundTo;
+
public RemoteComponentModel(AnnotatedItem annotatedItem,
AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
{
super(annotatedItem, xmlAnnotatedItem, container);
- // TODO Auto-generated constructor stub
+ EjbMetaData<T> ejbMetaData =
container.getEjbManager().getEjbMetaData(getType());
+ this.constructor = initConstructor(ejbMetaData, container);
+ EnterpriseComponentModel.checkScopeAllowed(getMergedStereotypes(), getScopeType(),
getType(), ejbMetaData);
+ this.removeMethod = initRemoveMethod(ejbMetaData, getType());
+ this.boundTo = initBoundTo(annotatedItem, xmlAnnotatedItem, getType());
}
+
+ protected static <T> EnterpriseConstructor<T>
initConstructor(EjbMetaData<T> ejbMetaData, ContainerImpl container)
+ {
+ return new EnterpriseConstructor<T>(ejbMetaData);
+ }
- @Override
+ /**
+ * Check that the scope type is allowed by the stereotypes on the component and the
component type
+ * @param type
+ */
+ protected static <T> void checkScopeAllowed(MergedStereotypesModel stereotypes,
Annotation scopeType, Class<?> type, EjbMetaData<T> ejbMetaData)
+ {
+ if (ejbMetaData.isStateless() &&
!scopeType.annotationType().equals(Dependent.class))
+ {
+ throw new RuntimeException("Scope " + scopeType + " is not
allowed on stateless enterpise bean components for " + type + ". Only @Dependent
is allowed on stateless enterprise bean components");
+ }
+ if (ejbMetaData.isSingleton() &&
(!scopeType.annotationType().equals(Dependent.class) ||
!scopeType.annotationType().equals(ApplicationScoped.class)))
+ {
+ throw new RuntimeException("Scope " + scopeType + " is not
allowed on singleton enterpise bean components for " + type + ". Only @Dependent
or @ApplicationScoped is allowed on singleton enterprise bean components");
+ }
+ }
+
+ protected static String initBoundTo(AnnotatedItem annotatedItem, AnnotatedItem
xmlAnnotatedItem, Class<?> type)
+ {
+ if (xmlAnnotatedItem.isAnnotationPresent(BoundTo.class))
+ {
+ return xmlAnnotatedItem.getAnnotation(BoundTo.class).value();
+ }
+ if (annotatedItem.isAnnotationPresent(BoundTo.class))
+ {
+ return annotatedItem.getAnnotation(BoundTo.class).value();
+ }
+ throw new RuntimeException("Remote component doesn't specify @BoundTo or
<bound-to /> for " + type);
+ }
+
public ComponentConstructor<T> getConstructor()
{
- // TODO Auto-generated method stub
- return null;
+ return constructor;
}
-
+ public InjectableMethod<?> getRemoveMethod()
+ {
+ return removeMethod;
+ }
+ public String getBoundTo()
+ {
+ return boundTo;
+ }
+
}
Modified:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
===================================================================
---
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-07-03
17:44:20 UTC (rev 41)
+++
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-07-03
21:29:26 UTC (rev 42)
@@ -1,13 +1,26 @@
package org.jboss.webbeans.model;
+import java.lang.reflect.Constructor;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.webbeans.BindingType;
+import javax.webbeans.Initializer;
+
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.SimpleConstructor;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.util.AnnotatedItem;
+import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
public class SimpleComponentModel<T> extends AbstractComponentModel<T>
{
+ public static final String LOGGER_NAME = "componentMetaModel";
+
+ private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
+
private SimpleConstructor<T> constructor;
private InjectableMethod<?> removeMethod;
@@ -24,6 +37,62 @@
this.constructor = initConstructor(getType());
// TODO Interceptors
}
+
+ @SuppressWarnings("unchecked")
+ protected static <T> SimpleConstructor<T> initConstructor(Class<?
extends T> type)
+ {
+ if (type.getConstructors().length == 1)
+ {
+ Constructor<T> constructor = type.getConstructors()[0];
+ log.finest("Exactly one constructor (" + constructor +") defined,
using it as the component constructor for " + type);
+ return new SimpleConstructor<T>(constructor);
+ }
+
+ if (type.getConstructors().length > 1)
+ {
+ List<Constructor<T>> initializerAnnotatedConstructors =
Reflections.getConstructors(type, Initializer.class);
+ List<Constructor<T>> bindingTypeAnnotatedConstructors =
Reflections.getConstructorsForMetaAnnotatedParameter(type, BindingType.class);
+ log.finest("Found " + initializerAnnotatedConstructors + "
constructors annotated with @Initializer for " + type);
+ log.finest("Found " + bindingTypeAnnotatedConstructors + " with
parameters annotated with binding types for " + type);
+ if ((initializerAnnotatedConstructors.size() +
bindingTypeAnnotatedConstructors.size()) > 1)
+ {
+ if (initializerAnnotatedConstructors.size() > 1)
+ {
+ throw new RuntimeException("Cannot have more than one constructor
annotated with @Initializer for " + type);
+ }
+
+ else if (bindingTypeAnnotatedConstructors.size() > 1)
+ {
+ throw new RuntimeException("Cannot have more than one constructor
with binding types specified on constructor parameters for " + type);
+ }
+ else
+ {
+ throw new RuntimeException("Specify a constructor either annotated
with @Initializer or with parameters annotated with binding types for " + type);
+ }
+ }
+ else if (initializerAnnotatedConstructors.size() == 1)
+ {
+ Constructor<T> constructor = initializerAnnotatedConstructors.get(0);
+ log.finest("Exactly one constructor (" + constructor +")
annotated with @Initializer defined, using it as the component constructor for " +
type);
+ return new SimpleConstructor<T>(constructor);
+ }
+ else if (bindingTypeAnnotatedConstructors.size() == 1)
+ {
+ Constructor<T> constructor = bindingTypeAnnotatedConstructors.get(0);
+ log.finest("Exactly one constructor (" + constructor +") with
parameters annotated with binding types defined, using it as the component constructor for
" + type);
+ return new SimpleConstructor<T>(constructor);
+ }
+ }
+
+ if (type.getConstructors().length == 0)
+ {
+ Constructor<T> constructor = (Constructor<T>)
Reflections.getConstructor(type);
+ log.finest("No constructor defined, using implicit no arguement constructor
for " + type);
+ return new SimpleConstructor<T>(constructor);
+ }
+
+ throw new RuntimeException("Cannot determine constructor to use for " +
type);
+ }
public SimpleConstructor<T> getConstructor()
{