[webbeans-commits] Webbeans SVN: r99 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/deployment and 7 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-09-10 14:22:39 -0400 (Wed, 10 Sep 2008)
New Revision: 99
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerExpressionComponent.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerExpressionComponentTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodComponentTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SpecAssertion.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Baboon.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/BlackWidow.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DaddyLongLegs.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlyAnimal.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlySpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DefangedTarantula.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/LadybirdSpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Spider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/SpiderProducer.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Tarantula.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TrapdoorSpider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithFinalProducerMethod.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithStaticProducerMethod.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/StereotypeManager.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ContainerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleComponentModelTest.java
Log:
Better Producer Method components, Producer Expression and Remote components
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -7,7 +7,6 @@
import javax.webbeans.ComponentInstance;
import javax.webbeans.Container;
-import org.jboss.webbeans.model.AbstractClassComponentModel;
import org.jboss.webbeans.model.AbstractComponentModel;
import org.jboss.webbeans.util.LoggerUtil;
@@ -18,9 +17,9 @@
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
- private AbstractComponentModel<T> componentMetaModel;
+ private AbstractComponentModel<T, ?> componentMetaModel;
- public ComponentInstanceImpl(AbstractComponentModel<T> componentMetaModel)
+ public ComponentInstanceImpl(AbstractComponentModel<T, ?> componentMetaModel)
{
this.componentMetaModel = componentMetaModel;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ContainerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ContainerImpl.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -1,6 +1,7 @@
package org.jboss.webbeans;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -23,7 +24,7 @@
{
private List<Annotation> enabledDeploymentTypes;
- private StereotypeManager stereotypeManager;
+ private ModelManager modelManager;
private EjbManager ejbLookupManager;
private ThreadLocal<Map<Class<Annotation>, Context>> contexts =
@@ -34,7 +35,7 @@
public ContainerImpl(List<Annotation> enabledDeploymentTypes)
{
initEnabledDeploymentTypes(enabledDeploymentTypes);
- this.stereotypeManager = new StereotypeManager();
+ this.modelManager = new ModelManager();
this.ejbLookupManager = new EjbManager();
this.components = new HashSet<ComponentInstance>();
}
@@ -139,6 +140,11 @@
// TODO Auto-generated method stub
return null;
}
+
+ public <T> Set<Method> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
+ {
+ return new HashSet<Method>();
+ }
public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
{
@@ -151,9 +157,9 @@
return enabledDeploymentTypes;
}
- public StereotypeManager getStereotypeManager()
+ public ModelManager getModelManager()
{
- return this.stereotypeManager;
+ return this.modelManager;
}
public EjbManager getEjbManager()
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java (from rev 78, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/StereotypeManager.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,38 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.webbeans.model.AbstractComponentModel;
+import org.jboss.webbeans.model.StereotypeModel;
+
+public class ModelManager
+{
+
+ // TODO Store these in the application context (when it exists)
+ private static Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
+ private static Map<Class<?>, AbstractComponentModel<?, ?>> componentModels = new HashMap<Class<?>, AbstractComponentModel<?,?>>();
+
+
+ public void addStereotype(StereotypeModel<?> stereotype)
+ {
+ stereotypes.put(stereotype.getStereotypeClass(), stereotype);
+ }
+
+ public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
+ {
+ return stereotypes.get(annotationType);
+ }
+
+ public void addComponentModel(AbstractComponentModel<?, ?> componentModel)
+ {
+ componentModels.put(componentModel.getType(), componentModel);
+ }
+
+ public <T> AbstractComponentModel<T, ?> getComponentModel(Class<T> clazz)
+ {
+ return (AbstractComponentModel<T, ?>) componentModels.get(clazz);
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/StereotypeManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/StereotypeManager.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/StereotypeManager.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -1,25 +0,0 @@
-package org.jboss.webbeans;
-
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.webbeans.model.StereotypeModel;
-
-public class StereotypeManager
-{
-
- // TODO Store these in the application context (when it exists)
- public static Map<Class<? extends Annotation>, StereotypeModel> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel>();
-
- public void addStereotype(StereotypeModel stereotype)
- {
- stereotypes.put(stereotype.getStereotypeClass(), stereotype);
- }
-
- public StereotypeModel getStereotype(Class<? extends Annotation> annotationType)
- {
- return stereotypes.get(annotationType);
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/deployment/DeploymentStrategy.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -106,7 +106,7 @@
if (stereotypeClass.isAnnotation())
{
StereotypeModel stereotypeModel = new StereotypeModel(new SimpleAnnotatedType(stereotypeClass));
- container.getStereotypeManager().addStereotype(stereotypeModel);
+ container.getModelManager().addStereotype(stereotypeModel);
log.info("Stereotype: " + stereotypeModel);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -8,7 +8,7 @@
* @author Pete Muir
*
*/
-public interface AnnotatedType<T> extends AnnotatedItem<Class<? extends T>>
+public interface AnnotatedType<T> extends AnnotatedItem<Class<T>>
{
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -10,18 +10,18 @@
* @author pmuir
*
*/
-public class SimpleAnnotatedType<T> extends AbstractAnnotatedItem<Class<? extends T>> implements AnnotatedType<T>
+public class SimpleAnnotatedType<T> extends AbstractAnnotatedItem<Class<T>> implements AnnotatedType<T>
{
- private Class<? extends T> annotatedClass;
+ private Class<T> annotatedClass;
- public SimpleAnnotatedType(Class<? extends T> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
+ public SimpleAnnotatedType(Class<T> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
{
super(annotationMap);
this.annotatedClass = annotatedClass;
}
- public SimpleAnnotatedType(Class<? extends T> annotatedClass)
+ public SimpleAnnotatedType(Class<T> annotatedClass)
{
this(annotatedClass, buildAnnotationMap(annotatedClass));
}
@@ -37,7 +37,7 @@
return annotatedClass + " " + super.getAnnotationMap().toString();
}
- public Class<? extends T> getDelegate()
+ public Class<T> getDelegate()
{
return annotatedClass;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -1,6 +1,9 @@
package org.jboss.webbeans.model;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.logging.Logger;
import javax.webbeans.Dependent;
@@ -19,12 +22,11 @@
* @author Pete Muir
*
*/
-public abstract class AbstractClassComponentModel<T> extends AbstractComponentModel<T, Class<? extends T>>
+public abstract class AbstractClassComponentModel<T> extends AbstractComponentModel<T, Class<T>>
{
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
- private Class<? extends T> type;
private AnnotatedType<T> annotatedItem;
private AnnotatedType<T> xmlAnnotatedItem;
@@ -166,10 +168,5 @@
throw new RuntimeException("Web Bean implementation class " + type + " cannot be declared abstract");
}
}
-
- protected Class<? extends T> getType()
- {
- return type;
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -1,6 +1,8 @@
package org.jboss.webbeans.model;
import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -16,6 +18,7 @@
import org.jboss.webbeans.bindings.DependentBinding;
import org.jboss.webbeans.bindings.ProductionBinding;
import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.util.LoggerUtil;
@@ -30,7 +33,10 @@
private String name;
private Annotation scopeType;
private MergedStereotypesModel<T, E> mergedStereotypes;
- private Annotation deploymentType;
+ protected Annotation deploymentType;
+ protected Class<T> type;
+ protected InjectableMethod<?> removeMethod;
+ private Set<Class> apiTypes;
protected void init(ContainerImpl container)
{
@@ -40,10 +46,32 @@
initBindingTypes();
initName();
initDeploymentType(container);
+ checkDeploymentType();
initScopeType();
+ initApiTypes();
}
protected abstract void initType();
+
+ protected void initApiTypes()
+ {
+ apiTypes = getTypeHierachy(getType());
+ }
+
+ protected Set<Class> getTypeHierachy(Class clazz)
+ {
+ Set<Class> classes = new HashSet<Class>();
+ if (!(clazz == null || clazz == Object.class))
+ {
+ classes.add(clazz);
+ classes.addAll(getTypeHierachy(clazz.getSuperclass()));
+ for (Class<?> c : clazz.getInterfaces())
+ {
+ classes.addAll(getTypeHierachy(c));
+ }
+ }
+ return classes;
+ }
protected abstract AnnotatedItem<E> getAnnotatedItem();
@@ -208,9 +236,16 @@
log.finest("Using default @Production deployment type");
return;
}
- throw new RuntimeException("type: " + getType() + " must specify a deployment type");
}
+ protected void checkDeploymentType()
+ {
+ if (deploymentType == null)
+ {
+ throw new RuntimeException("type: " + getType() + " must specify a deployment type");
+ }
+ }
+
public static Annotation getDeploymentType(List<Annotation> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
{
for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
@@ -239,11 +274,24 @@
{
return scopeType;
}
+
+ public Class<T> getType()
+ {
+ return type;
+ }
+ public Set<Class> getApiTypes()
+ {
+ return apiTypes;
+ }
- protected abstract E getType();
-
public abstract ComponentConstructor<T> getConstructor();
+
+ /**
+ * Convenience method that return's the component's "location" for logging
+ * and exception throwing
+ */
+ public abstract String getLocation();
public Annotation getDeploymentType()
{
@@ -254,5 +302,10 @@
{
return name;
}
+
+ public InjectableMethod<?> getRemoveMethod()
+ {
+ return removeMethod;
+ }
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -18,7 +18,6 @@
AbstractClassComponentModel<T>
{
- private InjectableMethod<?> removeMethod;
private EjbMetaData<T> ejbMetaData;
public AbstractEnterpriseComponentModel(AnnotatedType<T> annotatedItem,
@@ -33,15 +32,10 @@
{
super.init(container);
ejbMetaData = container.getEjbManager().getEjbMetaData(getType());
- initRemoveMethod();
+ initRemoveMethod(container);
checkEnterpriseScopeAllowed();
}
- public InjectableMethod<?> getRemoveMethod()
- {
- return removeMethod;
- }
-
protected EjbMetaData<T> getEjbMetaData()
{
return ejbMetaData;
@@ -64,13 +58,13 @@
}
// TODO loggigng
- protected void initRemoveMethod()
+ protected void initRemoveMethod(ContainerImpl container)
{
if (getEjbMetaData().isStateful())
{
if (getEjbMetaData().getRemoveMethods().size() == 1)
{
- this.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
+ super.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
}
else if (getEjbMetaData().getRemoveMethods().size() > 1)
{
@@ -84,7 +78,7 @@
}
if (possibleRemoveMethods.size() == 1)
{
- this.removeMethod = new InjectableMethod<Object>(possibleRemoveMethods.get(0));
+ super.removeMethod = new InjectableMethod<Object>(possibleRemoveMethods.get(0));
}
else if (possibleRemoveMethods.size() > 1)
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -9,6 +9,9 @@
{
private EnterpriseConstructor<T> constructor;
+
+ private String location;
+
public EnterpriseComponentModel(AnnotatedType<T> annotatedItem,
AnnotatedType<T> xmlAnnotatedItem, ContainerImpl container)
{
@@ -34,4 +37,14 @@
return "EnterpriseComponentModel[" + getType().getName() + "]";
}
+ @Override
+ public String getLocation()
+ {
+ if (location == null)
+ {
+ location = "type: Enterprise Component; declaring class: " + getType() +";";
+ }
+ return location;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -40,7 +40,7 @@
for (Annotation stereotypeAnnotation : stereotypeAnnotations)
{
// Retrieve and merge all metadata from stereotypes
- StereotypeModel<?> stereotype = container.getStereotypeManager().getStereotype(stereotypeAnnotation.annotationType());
+ StereotypeModel<?> stereotype = container.getModelManager().getStereotype(stereotypeAnnotation.annotationType());
if (stereotype == null)
{
throw new NullPointerException("Stereotype " + stereotypeAnnotation + " not registered with container");
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerExpressionComponent.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerExpressionComponent.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerExpressionComponent.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,89 @@
+package org.jboss.webbeans.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+
+import javax.webbeans.Dependent;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+
+public class ProducerExpressionComponent<T> extends AbstractProducerComponentModel<T>
+{
+
+ private AnnotatedItem<Method> xmlAnnotatedItem;
+ private AnnotatedItem<Method> annotatedItem = new SimpleAnnotatedItem<Method>(new HashMap<Class<? extends Annotation>, Annotation>());
+ private String location;
+
+ public ProducerExpressionComponent(AnnotatedItem<Method> xmlAnnotatedMethod, ContainerImpl container)
+ {
+ this.xmlAnnotatedItem = xmlAnnotatedMethod;
+ init(container);
+ }
+
+ protected void checkApiType()
+ {
+ if (!getScopeType().annotationType().equals(Dependent.class))
+ {
+ if (Modifier.isFinal(getType().getModifiers()))
+ {
+ throw new RuntimeException(getLocation() + "Final producer method must have @Dependent scope");
+ }
+ }
+
+ }
+
+ @Override
+ protected void init(ContainerImpl container)
+ {
+ super.init(container);
+ }
+
+
+ @Override
+ protected AnnotatedItem<Method> getAnnotatedItem()
+ {
+ return annotatedItem;
+ }
+
+ @Override
+ public ComponentConstructor<T> getConstructor()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected String getDefaultName()
+ {
+ throw new RuntimeException(getLocation() + " Cannot set a default name on producer expressions");
+ }
+
+ @Override
+ public String getLocation()
+ {
+ if (location == null)
+ {
+ location = "type: Producer Expression; declaring document: TODO;";
+ }
+ return location;
+ }
+
+ @Override
+ protected AnnotatedItem<Method> getXmlAnnotatedItem()
+ {
+ return xmlAnnotatedItem;
+ }
+
+ @Override
+ protected void initType()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerExpressionComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -3,26 +3,36 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.HashMap;
+import java.util.Set;
import javax.webbeans.Dependent;
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.injectable.MethodConstructor;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+import org.jboss.webbeans.util.Reflections;
public class ProducerMethodComponentModel<T> extends AbstractProducerComponentModel<T>
{
- private Method type;
private ComponentConstructor<T> constructor;
private AnnotatedItem<Method> xmlAnnotatedItem = new SimpleAnnotatedItem<Method>(new HashMap<Class<? extends Annotation>, Annotation>());
private AnnotatedMethod annotatedMethod;
+ private AbstractComponentModel<?, Class<?>> declaringComponent;
+
+ // Cached values
+ private String location;
+ private Type declaredComponentType;
+
@SuppressWarnings("unchecked")
public ProducerMethodComponentModel(AnnotatedMethod annotatedMethod, ContainerImpl container)
{
@@ -35,9 +45,29 @@
{
super.init(container);
checkProducerMethod();
- this.constructor = new MethodConstructor<T>(type);
+ this.constructor = new MethodConstructor<T>(getAnnotatedItem().getDelegate());
+ initRemoveMethod(container);
}
+
+ @Override
+ protected void initDeploymentType(ContainerImpl container)
+ {
+ super.initDeploymentType(container);
+ if (getDeploymentType() == null)
+ {
+ if (getDeclaringComponent() == null)
+ {
+ initDeclaringComponent(container);
+ }
+ deploymentType = declaringComponent.getDeploymentType();
+ }
+ }
+ protected void initDeclaringComponent(ContainerImpl container)
+ {
+ declaringComponent = (AbstractComponentModel<?, Class<?>>) container.getModelManager().getComponentModel(getAnnotatedItem().getDelegate().getDeclaringClass());
+ }
+
@Override
public ComponentConstructor<T> getConstructor()
{
@@ -51,12 +81,27 @@
throw new RuntimeException("Producer method cannot be static " + annotatedMethod);
}
// TODO Check if declaring class is a WB component
- if (Modifier.isFinal(getAnnotatedItem().getDelegate().getModifiers()) || getScopeType().annotationType().equals(Dependent.class))
+ if (!getScopeType().annotationType().equals(Dependent.class) && Modifier.isFinal(getAnnotatedItem().getDelegate().getModifiers()))
{
throw new RuntimeException("Final producer method must have @Dependent scope " + annotatedMethod);
}
}
+ @SuppressWarnings("unchecked")
+ protected void initRemoveMethod(ContainerImpl container)
+ {
+ Set<Method> disposalMethods = container.resolveDisposalMethods(getType(), getBindingTypes().toArray(new Annotation[0]));
+ if (disposalMethods.size() == 1)
+ {
+ removeMethod = new InjectableMethod(disposalMethods.iterator().next());
+ }
+ else if (disposalMethods.size() > 1)
+ {
+ // TODO List out found disposal methods
+ throw new RuntimeException(getLocation() + "Cannot declare multiple disposal methods for this producer method");
+ }
+ }
+
@Override
public String toString()
{
@@ -72,26 +117,72 @@
@Override
protected String getDefaultName()
{
- // TODO Auto-generated method stub
- return null;
+ String propertyName = Reflections.getPropertyName(getAnnotatedItem().getDelegate());
+ if (propertyName != null)
+ {
+ return propertyName;
+ }
+ else
+ {
+ return getAnnotatedItem().getDelegate().getName();
+ }
}
@Override
- protected Method getType()
- {
- return type;
- }
-
- @Override
protected AnnotatedItem<Method> getXmlAnnotatedItem()
{
return xmlAnnotatedItem;
}
+ @SuppressWarnings("unchecked")
@Override
protected void initType()
{
- this.type = annotatedMethod.getAnnotatedMethod();
+ try
+ {
+ this.type = (Class<T>) annotatedMethod.getAnnotatedMethod().getReturnType();
+ }
+ catch (ClassCastException e)
+ {
+ throw new RuntimeException(getLocation() + " Cannot cast producer method return type " + annotatedMethod.getAnnotatedMethod().getReturnType() + " to component type " + (getDeclaredComponentType() == null ? " unknown " : getDeclaredComponentType()), e);
+ }
}
+
+ private Type getDeclaredComponentType()
+ {
+ if (declaredComponentType == null)
+ {
+ Type type = getClass();
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ if (parameterizedType.getActualTypeArguments().length == 1)
+ {
+ declaredComponentType = parameterizedType.getActualTypeArguments()[0];
+ }
+ }
+ }
+ return declaredComponentType;
+ }
+
+ @Override
+ public String getLocation()
+ {
+ if (location == null)
+ {
+ location = "type: Producer Method; declaring class: " + annotatedMethod.getAnnotatedMethod().getDeclaringClass() +"; producer method: " + annotatedMethod.getAnnotatedMethod().toString() + ";";
+ }
+ return location;
+ }
+
+ public InjectableMethod<?> getDisposalMethod()
+ {
+ return removeMethod;
+ }
+
+ public AbstractComponentModel<?, Class<?>> getDeclaringComponent()
+ {
+ return declaringComponent;
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -5,20 +5,20 @@
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
import org.jboss.webbeans.injectable.EnterpriseConstructor;
-import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
public class RemoteComponentModel<T> extends AbstractEnterpriseComponentModel<T>
{
private EnterpriseConstructor<T> constructor;
- private InjectableMethod<?> removeMethod;
private String boundTo;
+ private String location;
- public RemoteComponentModel(AnnotatedType<T> annotatedItem,
- AnnotatedType<T> xmlAnnotatedItem)
+ public RemoteComponentModel(AnnotatedType annotatedItem,
+ AnnotatedType xmlAnnotatedItem, ContainerImpl container)
{
super(annotatedItem, xmlAnnotatedItem);
+ init(container);
}
@Override
@@ -49,10 +49,6 @@
return constructor;
}
- public InjectableMethod<?> getRemoveMethod()
- {
- return removeMethod;
- }
public String getBoundTo()
{
@@ -65,4 +61,14 @@
return "RemoteComponentModel[" + getType().getName() + "]";
}
+ @Override
+ public String getLocation()
+ {
+ if (location == null)
+ {
+ location = "type: Remote Enterprise Component; declaring class: " + getType() +";";
+ }
+ return location;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -9,7 +9,6 @@
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.SimpleConstructor;
-import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.LoggerUtil;
import org.jboss.webbeans.util.Reflections;
@@ -20,7 +19,8 @@
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
private SimpleConstructor<T> constructor;
- private InjectableMethod<?> removeMethod;
+
+ private String location;
/**
*
@@ -117,11 +117,6 @@
return constructor;
}
- public InjectableMethod<?> getRemoveMethod()
- {
- return removeMethod;
- }
-
@Override
public String toString()
@@ -129,4 +124,14 @@
return "SimpleComponentModel[" + getType().getName() + "]";
}
+ @Override
+ public String getLocation()
+ {
+ if (location == null)
+ {
+ location = "type: Simple Component; declaring class: " + getType() +";";
+ }
+ return location;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.util;
+import java.beans.Introspector;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -24,6 +25,24 @@
return Class.forName(name);
}
}
+
+ public static String getPropertyName(Method method)
+ {
+ String methodName = method.getName();
+ if ( methodName.matches("^(get).*") && method.getParameterTypes().length==0 )
+ {
+ return Introspector.decapitalize( methodName.substring(3) );
+ }
+ else if (methodName.matches("^(is).*") && method.getParameterTypes().length==0 )
+ {
+ return Introspector.decapitalize( methodName.substring(2) );
+ }
+ else
+ {
+ return null;
+ }
+
+ }
public static boolean isFinal(Class<?> clazz)
{
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerExpressionComponentTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerExpressionComponentTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerExpressionComponentTest.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,32 @@
+package org.jboss.webbeans.test;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.test.mock.MockContainerImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ProducerExpressionComponentTest
+{
+
+ private ContainerImpl container;
+ private AnnotatedType<?> emptyAnnotatedItem;
+
+ @Before
+ public void before()
+ {
+ emptyAnnotatedItem = new SimpleAnnotatedType(null, new HashMap<Class<? extends Annotation>, Annotation>());
+ container = new MockContainerImpl(null);
+ }
+
+ @Test
+ public void testApiTypes()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerExpressionComponentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodComponentTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodComponentTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodComponentTest.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,159 @@
+package org.jboss.webbeans.test;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+import javax.webbeans.Current;
+import javax.webbeans.Dependent;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.introspector.SimpleAnnotatedMethod;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.ProducerMethodComponentModel;
+import org.jboss.webbeans.model.SimpleComponentModel;
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.components.Animal;
+import org.jboss.webbeans.test.components.BlackWidow;
+import org.jboss.webbeans.test.components.DaddyLongLegs;
+import org.jboss.webbeans.test.components.DeadlyAnimal;
+import org.jboss.webbeans.test.components.DeadlySpider;
+import org.jboss.webbeans.test.components.LadybirdSpider;
+import org.jboss.webbeans.test.components.Spider;
+import org.jboss.webbeans.test.components.SpiderProducer;
+import org.jboss.webbeans.test.components.Tarantula;
+import org.jboss.webbeans.test.components.TrapdoorSpider;
+import org.jboss.webbeans.test.components.broken.ComponentWithFinalProducerMethod;
+import org.jboss.webbeans.test.components.broken.ComponentWithStaticProducerMethod;
+import org.jboss.webbeans.test.mock.MockContainerImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ProducerMethodComponentTest
+{
+
+ private ContainerImpl container;
+ private AnnotatedType<?> emptyAnnotatedItem;
+
+ @Before
+ public void before()
+ {
+ emptyAnnotatedItem = new SimpleAnnotatedType(null, new HashMap<Class<? extends Annotation>, Annotation>());
+ container = new MockContainerImpl(null);
+ }
+
+ @Test @SpecAssertion(section="3.3")
+ public void testStaticMethod() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<ComponentWithStaticProducerMethod> componentModel = new SimpleComponentModel<ComponentWithStaticProducerMethod>(new SimpleAnnotatedType<ComponentWithStaticProducerMethod>(ComponentWithStaticProducerMethod.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = ComponentWithStaticProducerMethod.class.getMethod("getString");
+ boolean exception = false;
+ try
+ {
+ new ProducerMethodComponentModel<String>(new SimpleAnnotatedMethod(method), container);
+ }
+ catch (Exception e)
+ {
+ exception = true;
+ }
+ assert exception;
+ }
+
+ @Test @SpecAssertion(section="3.3")
+ public void testApiTypes() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceTarantula");
+ ProducerMethodComponentModel<Tarantula> tarantulaModel = new ProducerMethodComponentModel<Tarantula>(new SimpleAnnotatedMethod(method), container);
+ assert tarantulaModel.getApiTypes().contains(Tarantula.class);
+ assert tarantulaModel.getApiTypes().contains(DeadlySpider.class);
+ assert tarantulaModel.getApiTypes().contains(Spider.class);
+ assert tarantulaModel.getApiTypes().contains(Animal.class);
+ assert tarantulaModel.getApiTypes().contains(DeadlyAnimal.class);
+ assert !tarantulaModel.getApiTypes().contains(Object.class);
+ }
+
+ @Test @SpecAssertion(section="3.3.1")
+ public void testDefaultBindingType() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceTarantula");
+ ProducerMethodComponentModel<Tarantula> tarantulaModel = new ProducerMethodComponentModel<Tarantula>(new SimpleAnnotatedMethod(method), container);
+ assert tarantulaModel.getBindingTypes().size() == 1;
+ assert tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Current.class);
+ }
+
+ @Test
+ public void testBindingType() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceTameTarantula");
+ ProducerMethodComponentModel<Tarantula> tarantulaModel = new ProducerMethodComponentModel<Tarantula>(new SimpleAnnotatedMethod(method), container);
+ assert tarantulaModel.getBindingTypes().size() == 1;
+ assert tarantulaModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
+ }
+
+ @Test @SpecAssertion(section="3.3")
+ public void testFinalMethod() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<ComponentWithFinalProducerMethod> componentModel = new SimpleComponentModel<ComponentWithFinalProducerMethod>(new SimpleAnnotatedType<ComponentWithFinalProducerMethod>(ComponentWithFinalProducerMethod.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = ComponentWithFinalProducerMethod.class.getMethod("getString");
+ boolean exception = false;
+ try
+ {
+ new ProducerMethodComponentModel<String>(new SimpleAnnotatedMethod(method), container);
+ }
+ catch (Exception e)
+ {
+ exception = true;
+ }
+ assert exception;
+ }
+
+ @Test @SpecAssertion(section="3.3")
+ public void testFinalMethodWithDependentScope() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceTrapdoorSpider");
+ ProducerMethodComponentModel<TrapdoorSpider> trapdoorSpiderModel = new ProducerMethodComponentModel<TrapdoorSpider>(new SimpleAnnotatedMethod(method), container);
+ assert trapdoorSpiderModel.getScopeType().annotationType().equals(Dependent.class);
+ }
+
+ @Test @SpecAssertion(section="3.3.6")
+ public void testNamedMethod() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceBlackWidow");
+ ProducerMethodComponentModel<BlackWidow> blackWidowSpiderModel = new ProducerMethodComponentModel<BlackWidow>(new SimpleAnnotatedMethod(method), container);
+ assert blackWidowSpiderModel.getName().equals("blackWidow");
+ }
+
+ @Test @SpecAssertion(section="3.3.6")
+ public void testDefaultNamedMethod() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("produceDaddyLongLegs");
+ ProducerMethodComponentModel<DaddyLongLegs> daddyLongLegsSpiderModel = new ProducerMethodComponentModel<DaddyLongLegs>(new SimpleAnnotatedMethod(method), container);
+ assert daddyLongLegsSpiderModel.getName().equals("produceDaddyLongLegs");
+ }
+
+ @Test @SpecAssertion(section="3.3.6")
+ public void testDefaultNamedJavaBeanMethod() throws SecurityException, NoSuchMethodException
+ {
+ SimpleComponentModel<SpiderProducer> componentModel = new SimpleComponentModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), emptyAnnotatedItem, container);
+ container.getModelManager().addComponentModel(componentModel);
+ Method method = SpiderProducer.class.getMethod("getLadybirdSpider");
+ ProducerMethodComponentModel<LadybirdSpider> ladybirdSpiderModel = new ProducerMethodComponentModel<LadybirdSpider>(new SimpleAnnotatedMethod(method), container);
+ assert ladybirdSpiderModel.getName().equals("ladybirdSpider");
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodComponentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentTest.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,64 @@
+package org.jboss.webbeans.test;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+
+import javax.webbeans.Current;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.RemoteComponentModel;
+import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.components.Animal;
+import org.jboss.webbeans.test.components.Baboon;
+import org.jboss.webbeans.test.components.TameApe;
+import org.jboss.webbeans.test.mock.MockContainerImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RemoteComponentTest
+{
+
+ private ContainerImpl container;
+ private AnnotatedType<?> emptyAnnotatedItem;
+
+ @Before
+ public void before()
+ {
+ emptyAnnotatedItem = new SimpleAnnotatedType(null, new HashMap<Class<? extends Annotation>, Annotation>());
+ container = new MockContainerImpl(null);
+ }
+
+ @Test @SpecAssertion(section="3.5")
+ public void testApiTypes() throws SecurityException, NoSuchMethodException
+ {
+ RemoteComponentModel<Baboon> baboonModel = new RemoteComponentModel<Baboon>(new SimpleAnnotatedType<Baboon>(Baboon.class), emptyAnnotatedItem, container);
+ assert baboonModel.getApiTypes().contains(Baboon.class);
+ assert baboonModel.getApiTypes().contains(Animal.class);
+ }
+
+ @Test @SpecAssertion(section="3.5.4")
+ public void testDefaultName() throws SecurityException, NoSuchMethodException
+ {
+ RemoteComponentModel<TameApe> tameApeModel = new RemoteComponentModel<TameApe>(new SimpleAnnotatedType<TameApe>(TameApe.class), emptyAnnotatedItem, container);
+ assert tameApeModel.getName().equals("tameApe");
+ }
+
+ @Test @SpecAssertion(section="3.5.1")
+ public void testDefaultBindingType() throws SecurityException, NoSuchMethodException
+ {
+ RemoteComponentModel<Baboon> baboonModel = new RemoteComponentModel<Baboon>(new SimpleAnnotatedType<Baboon>(Baboon.class), emptyAnnotatedItem, container);
+ assert baboonModel.getBindingTypes().size() == 1;
+ assert baboonModel.getBindingTypes().iterator().next().annotationType().equals(Current.class);
+ }
+
+ @Test
+ public void testBindingType() throws SecurityException, NoSuchMethodException
+ {
+ RemoteComponentModel<TameApe> tameApeModel = new RemoteComponentModel<TameApe>(new SimpleAnnotatedType<TameApe>(TameApe.class), emptyAnnotatedItem, container);
+ assert tameApeModel.getBindingTypes().size() == 1;
+ assert tameApeModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleComponentModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleComponentModelTest.java 2008-09-08 18:57:12 UTC (rev 98)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleComponentModelTest.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -89,12 +89,12 @@
private void initStereotypes(ContainerImpl container)
{
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(AnimalStereotype.class)));
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(HornedMammalStereotype.class)));
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(MammalStereotype.class)));
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(FishStereotype.class)));
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(RiverFishStereotype.class)));
- container.getStereotypeManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(RequestScopedAnimalStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(AnimalStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(HornedMammalStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(MammalStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(FishStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(RiverFishStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel(new SimpleAnnotatedType(RequestScopedAnimalStereotype.class)));
}
// **** TESTS FOR DEPLOYMENT TYPE **** //
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SpecAssertion.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SpecAssertion.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SpecAssertion.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+(a)Target(ElementType.METHOD)
+public @interface SpecAssertion
+{
+
+ public String section();
+
+ public String note() default "";
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SpecAssertion.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Tame
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Baboon.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Baboon.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Baboon.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.components;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Production;
+
+@Remote
+@Production
+@BoundTo("/beans/baboon")
+public interface Baboon extends Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Baboon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/BlackWidow.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/BlackWidow.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/BlackWidow.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class BlackWidow extends Spider implements DeadlySpider
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/BlackWidow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DaddyLongLegs.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DaddyLongLegs.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DaddyLongLegs.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class DaddyLongLegs extends Spider
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DaddyLongLegs.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlyAnimal.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlyAnimal.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlyAnimal.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public interface DeadlyAnimal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlyAnimal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlySpider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlySpider.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlySpider.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public interface DeadlySpider extends DeadlyAnimal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DeadlySpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DefangedTarantula.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DefangedTarantula.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DefangedTarantula.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class DefangedTarantula extends Tarantula
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/DefangedTarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/LadybirdSpider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/LadybirdSpider.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/LadybirdSpider.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class LadybirdSpider extends Spider
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/LadybirdSpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Spider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Spider.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Spider.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class Spider implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Spider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/SpiderProducer.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/SpiderProducer.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,44 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.Named;
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+@Production
+public class SpiderProducer
+{
+
+ @Produces @Tame public Tarantula produceTameTarantula()
+ {
+ return new DefangedTarantula();
+ }
+
+ @Produces public Tarantula produceTarantula()
+ {
+ return new Tarantula();
+ }
+
+ @Produces @Dependent public final TrapdoorSpider produceTrapdoorSpider()
+ {
+ return new TrapdoorSpider();
+ }
+
+ @Produces @Named("blackWidow") public BlackWidow produceBlackWidow()
+ {
+ return new BlackWidow();
+ }
+
+ @Produces @Named public DaddyLongLegs produceDaddyLongLegs()
+ {
+ return new DaddyLongLegs();
+ }
+
+ @Produces @Named public LadybirdSpider getLadybirdSpider()
+ {
+ return new LadybirdSpider();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/SpiderProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,18 @@
+package org.jboss.webbeans.test.components;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Named;
+import javax.webbeans.Production;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+@Remote
+@Production
+@BoundTo("/beans/ape")
+@Tame
+@Named
+public interface TameApe extends Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Tarantula.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Tarantula.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Tarantula.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class Tarantula extends Spider implements DeadlySpider
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Tarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TrapdoorSpider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TrapdoorSpider.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TrapdoorSpider.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.components;
+
+public class TrapdoorSpider
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TrapdoorSpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithFinalProducerMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithFinalProducerMethod.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithFinalProducerMethod.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.components.broken;
+
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+
+@Production
+public class ComponentWithFinalProducerMethod
+{
+
+ @Produces @RequestScoped public final String getString()
+ {
+ return "Pete";
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithFinalProducerMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithStaticProducerMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithStaticProducerMethod.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithStaticProducerMethod.java 2008-09-10 18:22:39 UTC (rev 99)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.components.broken;
+
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+
+@Production
+public class ComponentWithStaticProducerMethod
+{
+
+ @Produces public static String getString()
+ {
+ return "Pete";
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/ComponentWithStaticProducerMethod.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 2 months
[webbeans-commits] Webbeans SVN: r98 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/model and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-09-08 14:57:12 -0400 (Mon, 08 Sep 2008)
New Revision: 98
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractProducerComponentModel.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ConstructorMetaModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java
Log:
Use object orientation properly
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java (from rev 95, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -0,0 +1,99 @@
+package org.jboss.webbeans.introspector;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+public abstract class AbstractAnnotatedItem<E> implements AnnotatedItem<E>
+{
+
+ private Map<Class<? extends Annotation>, Annotation> annotationMap;
+ private Map<Class<? extends Annotation>, Set<Annotation>> metaAnnotations;
+ private Set<Annotation> annotationSet;
+
+ public AbstractAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
+ {
+ if (annotationMap == null)
+ {
+ throw new NullPointerException("annotationMap cannot be null");
+ }
+ this.annotationMap = annotationMap;
+ }
+
+ protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(AnnotatedElement element)
+ {
+ Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
+ for (Annotation annotation : element.getAnnotations())
+ {
+ annotationMap.put(annotation.annotationType(), annotation);
+ }
+ return annotationMap;
+ }
+
+ protected static Set<Annotation> populateAnnotationSet(Set<Annotation> annotationSet, Map<Class<? extends Annotation>, Annotation> annotationMap)
+ {
+ for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
+ {
+ annotationSet.add(entry.getValue());
+ }
+ return annotationSet;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<? extends T> annotationType)
+ {
+ return (T) annotationMap.get(annotationType);
+ }
+
+ public Set<Annotation> getAnnotations(Class<? extends Annotation> metaAnnotationType)
+ {
+ if (metaAnnotations == null)
+ {
+ metaAnnotations = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
+ }
+ populateMetaAnnotationMap(metaAnnotationType, metaAnnotations, annotationMap);
+ return metaAnnotations.get(metaAnnotationType);
+ }
+
+ public Set<Annotation> getAnnotations()
+ {
+ if (annotationSet == null)
+ {
+ annotationSet = populateAnnotationSet(new HashSet<Annotation>(), annotationMap);
+ }
+ return annotationSet;
+ }
+
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotatedType)
+ {
+ return annotationMap.containsKey(annotatedType);
+ }
+
+ protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<Annotation>> populateMetaAnnotationMap(
+ Class<T> metaAnnotationType, Map<Class<? extends Annotation>, Set<Annotation>> metaAnnotations, Map<Class<? extends Annotation>, Annotation> annotationMap)
+ {
+ if (!metaAnnotations.containsKey(metaAnnotationType))
+ {
+ Set<Annotation> s = new HashSet<Annotation>();
+ for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
+ {
+ if (entry.getValue().annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ s.add(entry.getValue());
+ }
+ }
+ metaAnnotations.put(metaAnnotationType, s);
+ }
+ return metaAnnotations;
+ }
+
+ protected Map<Class<? extends Annotation>, Annotation> getAnnotationMap()
+ {
+ return annotationMap;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -11,7 +11,7 @@
* @author Pete Muir
*
*/
-public interface AnnotatedItem
+public interface AnnotatedItem<E>
{
/**
@@ -19,7 +19,7 @@
*
* An empty set is returned if no annotations are present
*/
- public abstract <T extends Annotation> Set<T> getAnnotations();
+ public <A extends Annotation> Set<A> getAnnotations();
/**
* Get all annotations which are annotated with the given meta annotation
@@ -28,21 +28,23 @@
* If no annotations are present which are annotated with the given meta
* annotation an empty set is returned
*/
- public abstract <T extends Annotation> Set<Annotation> getAnnotations(
- Class<T> metaAnnotationType);
+ public Set<Annotation> getAnnotations(
+ Class<? extends Annotation> metaAnnotationType);
/**
* Get an annotation for the annotation type specified.
*
* If the annotation isn't present, null is returned
*/
- public abstract <T extends Annotation> T getAnnotation(
- Class<T> annotationType);
+ public <A extends Annotation> A getAnnotation(
+ Class<? extends A> annotationType);
/**
* Return true if the annotation type specified is present
*/
- public abstract boolean isAnnotationPresent(
+ public boolean isAnnotationPresent(
Class<? extends Annotation> annotationType);
+
+ public E getDelegate();
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -9,7 +9,7 @@
* @author Pete Muir
*
*/
-public interface AnnotatedMethod extends AnnotatedItem
+public interface AnnotatedMethod extends AnnotatedItem<Method>
{
public Method getAnnotatedMethod();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -8,13 +8,13 @@
* @author Pete Muir
*
*/
-public interface AnnotatedType extends AnnotatedItem
+public interface AnnotatedType<T> extends AnnotatedItem<Class<? extends T>>
{
/**
* Return the class of the annotated item. If this annotatedItem isn't in use
* then this method should return null
*/
- public Class<?> getAnnotatedClass();
+ public Class<? extends T> getAnnotatedClass();
}
\ No newline at end of file
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,99 +0,0 @@
-package org.jboss.webbeans.introspector;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-public class SimpleAnnotatedItem implements AnnotatedItem
-{
-
- private Map<Class<? extends Annotation>, Annotation> annotationMap;
- private Map<Class<? extends Annotation>, Set<Annotation>> metaAnnotations;
- private Set<Annotation> annotationSet;
-
- public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
- {
- if (annotationMap == null)
- {
- throw new NullPointerException("annotationMap cannot be null");
- }
- this.annotationMap = annotationMap;
- }
-
- protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap(AnnotatedElement element)
- {
- Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
- for (Annotation annotation : element.getAnnotations())
- {
- annotationMap.put(annotation.annotationType(), annotation);
- }
- return annotationMap;
- }
-
- protected static Set<Annotation> populateAnnotationSet(Set<Annotation> annotationSet, Map<Class<? extends Annotation>, Annotation> annotationMap)
- {
- for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
- {
- annotationSet.add(entry.getValue());
- }
- return annotationSet;
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Annotation> T getAnnotation(Class<T> annotationType)
- {
- return (T) annotationMap.get(annotationType);
- }
-
- public <T extends Annotation> Set<Annotation> getAnnotations(Class<T> metaAnnotationType)
- {
- if (metaAnnotations == null)
- {
- metaAnnotations = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
- }
- populateMetaAnnotationMap(metaAnnotationType, metaAnnotations, annotationMap);
- return metaAnnotations.get(metaAnnotationType);
- }
-
- public Set<Annotation> getAnnotations()
- {
- if (annotationSet == null)
- {
- annotationSet = populateAnnotationSet(new HashSet<Annotation>(), annotationMap);
- }
- return annotationSet;
- }
-
- public boolean isAnnotationPresent(Class<? extends Annotation> annotatedType)
- {
- return annotationMap.containsKey(annotatedType);
- }
-
- protected static <T extends Annotation> Map<Class<? extends Annotation>, Set<Annotation>> populateMetaAnnotationMap(
- Class<T> metaAnnotationType, Map<Class<? extends Annotation>, Set<Annotation>> metaAnnotations, Map<Class<? extends Annotation>, Annotation> annotationMap)
- {
- if (!metaAnnotations.containsKey(metaAnnotationType))
- {
- Set<Annotation> s = new HashSet<Annotation>();
- for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
- {
- if (entry.getValue().annotationType().isAnnotationPresent(metaAnnotationType))
- {
- s.add(entry.getValue());
- }
- }
- metaAnnotations.put(metaAnnotationType, s);
- }
- return metaAnnotations;
- }
-
- protected Map<Class<? extends Annotation>, Annotation> getAnnotationMap()
- {
- return annotationMap;
- }
-
-}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -0,0 +1,19 @@
+package org.jboss.webbeans.introspector;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+public class SimpleAnnotatedItem<E> extends AbstractAnnotatedItem<E>
+{
+
+ public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
+ {
+ super(annotationMap);
+ }
+
+ public E getDelegate()
+ {
+ return null;
+ }
+
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -2,7 +2,7 @@
import java.lang.reflect.Method;
-public class SimpleAnnotatedMethod extends SimpleAnnotatedItem implements AnnotatedMethod
+public class SimpleAnnotatedMethod extends AbstractAnnotatedItem<Method> implements AnnotatedMethod
{
private Method annotatedMethod;
@@ -24,4 +24,9 @@
return annotatedMethod + " " + getAnnotatedMethod().toString();
}
+ public Method getDelegate()
+ {
+ return annotatedMethod;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -10,23 +10,23 @@
* @author pmuir
*
*/
-public class SimpleAnnotatedType extends SimpleAnnotatedItem implements AnnotatedType
+public class SimpleAnnotatedType<T> extends AbstractAnnotatedItem<Class<? extends T>> implements AnnotatedType<T>
{
- private Class<?> annotatedClass;
+ private Class<? extends T> annotatedClass;
- public SimpleAnnotatedType(Class<?> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
+ public SimpleAnnotatedType(Class<? extends T> annotatedClass, Map<Class<? extends Annotation>, Annotation> annotationMap)
{
super(annotationMap);
this.annotatedClass = annotatedClass;
}
- public SimpleAnnotatedType(Class<?> annotatedClass)
+ public SimpleAnnotatedType(Class<? extends T> annotatedClass)
{
this(annotatedClass, buildAnnotationMap(annotatedClass));
}
- public Class<?> getAnnotatedClass()
+ public Class<? extends T> getAnnotatedClass()
{
return annotatedClass;
}
@@ -36,5 +36,10 @@
{
return annotatedClass + " " + super.getAnnotationMap().toString();
}
+
+ public Class<? extends T> getDelegate()
+ {
+ return annotatedClass;
+ }
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractClassComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,26 +1,11 @@
package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.logging.Logger;
import javax.webbeans.Dependent;
-import javax.webbeans.DeploymentType;
-import javax.webbeans.Destroys;
-import javax.webbeans.Named;
-import javax.webbeans.ScopeType;
import org.jboss.webbeans.ContainerImpl;
-import org.jboss.webbeans.bindings.DependentBinding;
-import org.jboss.webbeans.bindings.ProductionBinding;
-import org.jboss.webbeans.ejb.EjbMetaData;
-import org.jboss.webbeans.injectable.InjectableMethod;
-import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.LoggerUtil;
import org.jboss.webbeans.util.Reflections;
@@ -34,17 +19,14 @@
* @author Pete Muir
*
*/
-public abstract class AbstractClassComponentModel<T> extends AbstractComponentModel<T>
+public abstract class AbstractClassComponentModel<T> extends AbstractComponentModel<T, Class<? extends T>>
{
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
- private Annotation deploymentType;
- private MergedStereotypesModel mergedStereotypes;
- private String name;
- private Annotation scopeType;
private Class<? extends T> type;
- private Set<Annotation> bindingTypes;
+ private AnnotatedType<T> annotatedItem;
+ private AnnotatedType<T> xmlAnnotatedItem;
/**
*
@@ -53,7 +35,7 @@
* @param container
*/
@SuppressWarnings("unchecked")
- public AbstractClassComponentModel(AnnotatedType annotatedItem, AnnotatedType xmlAnnotatedItem, ContainerImpl container)
+ public AbstractClassComponentModel(AnnotatedType<T> annotatedItem, AnnotatedType xmlAnnotatedItem)
{
if (annotatedItem == null)
{
@@ -64,36 +46,51 @@
{
throw new NullPointerException("xmlAnnotatedItem must not be null. If the component is declared just in Java, pass in an empty xmlAnnotatedItem");
}
- this.type = (Class<? extends T>) initType(annotatedItem, xmlAnnotatedItem);
- log.fine("Building Web Bean component metadata for " + type);
- this.bindingTypes = initBindingTypes(annotatedItem, xmlAnnotatedItem);
- mergedStereotypes = new MergedStereotypesModel(annotatedItem, xmlAnnotatedItem, container);
- this.deploymentType = initDeploymentType(mergedStereotypes, annotatedItem, xmlAnnotatedItem, container);
- this.scopeType = initScopeType(mergedStereotypes, annotatedItem, xmlAnnotatedItem);
- this.name = initName(getMergedStereotypes(), annotatedItem, xmlAnnotatedItem, getType());
- checkRequiredTypesImplemented(getMergedStereotypes(), getType());
- checkScopeAllowed(getMergedStereotypes(), getScopeType(), getType());
+ this.annotatedItem = annotatedItem;
+ this.xmlAnnotatedItem = xmlAnnotatedItem;
+ }
+
+ @Override
+ protected void init(ContainerImpl container)
+ {
+ super.init(container);
+ checkRequiredTypesImplemented();
+ checkScopeAllowed();
// TODO This is too high
checkComponentImplementation(getType());
// TODO Interceptors
}
+ @Override
+ protected AnnotatedType<T> getAnnotatedItem()
+ {
+ return annotatedItem;
+ }
+
+ @Override
+ protected AnnotatedType<T> getXmlAnnotatedItem()
+ {
+ return xmlAnnotatedItem;
+ }
+
@SuppressWarnings("unchecked")
- protected static Class<?> initType(AnnotatedType annotatedItem, AnnotatedType xmlAnnotatedItem)
+ protected void initType()
{
- if (annotatedItem.getAnnotatedClass() != null && xmlAnnotatedItem.getAnnotatedClass() != null && !annotatedItem.getAnnotatedClass().equals(xmlAnnotatedItem.getAnnotatedClass()))
+ if (getAnnotatedItem().getDelegate() != null && getXmlAnnotatedItem().getDelegate() != null && !getAnnotatedItem().getDelegate().equals(getXmlAnnotatedItem().getDelegate()))
{
throw new IllegalArgumentException("Cannot build a component which specifies different classes in XML and Java");
}
- else if (xmlAnnotatedItem.getAnnotatedClass() != null)
+ else if (getXmlAnnotatedItem().getDelegate() != null)
{
log.finest("Component type specified in XML");
- return xmlAnnotatedItem.getAnnotatedClass();
+ this.type = getXmlAnnotatedItem().getDelegate();
+ return;
}
- else if (annotatedItem.getAnnotatedClass() != null)
+ else if (getAnnotatedItem().getDelegate() != null)
{
log.finest("Component type specified in Java");
- return annotatedItem.getAnnotatedClass();
+ this.type = getAnnotatedItem().getDelegate();
+ return;
}
else
{
@@ -101,156 +98,20 @@
}
}
- protected static Annotation initDeploymentType(MergedStereotypesModel stereotypes, AnnotatedType annotatedItem, AnnotatedType xmlAnnotatedItem, ContainerImpl container)
+ @Override
+ protected String getDefaultName()
{
- Set<Annotation> xmlDeploymentTypes = xmlAnnotatedItem.getAnnotations(DeploymentType.class);
-
- if (xmlDeploymentTypes.size() > 1)
- {
- throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
- }
-
- if (xmlDeploymentTypes.size() == 1)
- {
- Annotation deploymentType = xmlDeploymentTypes.iterator().next();
- log.finest("Deployment type " + deploymentType + " specified in XML");
- return deploymentType;
- }
-
- if (xmlAnnotatedItem.getAnnotatedClass() == null)
- {
-
- Set<Annotation> deploymentTypes = annotatedItem.getAnnotations(DeploymentType.class);
-
- if (deploymentTypes.size() > 1)
- {
- throw new RuntimeException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + annotatedItem.getAnnotatedClass());
- }
- if (deploymentTypes.size() == 1)
- {
- Annotation deploymentType = deploymentTypes.iterator().next();
- log.finest("Deployment type " + deploymentType + " specified by annotation");
- return deploymentType;
- }
- }
-
- if (stereotypes.getPossibleDeploymentTypes().size() > 0)
- {
- Annotation deploymentType = getDeploymentType(container.getEnabledDeploymentTypes(), stereotypes.getPossibleDeploymentTypes());
- log.finest("Deployment type " + deploymentType + " specified by stereotype");
- return deploymentType;
- }
-
- if (xmlAnnotatedItem.getAnnotatedClass() != null)
- {
- log.finest("Using default @Production deployment type");
- return new ProductionBinding();
- }
- throw new RuntimeException("All Java annotated classes have a deployment type");
- }
-
- /**
- * Return the scope of the component
- */
- protected static Annotation initScopeType(MergedStereotypesModel stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
- {
- Set<Annotation> xmlScopes = xmlAnnotatedItem.getAnnotations(ScopeType.class);
- if (xmlScopes.size() > 1)
- {
- throw new RuntimeException("At most one scope may be specified in XML");
- }
-
- if (xmlScopes.size() == 1)
- {
- Annotation scope = xmlScopes.iterator().next();
- log.finest("Scope " + scope + " specified in XML");
- return scope;
- }
-
- Set<Annotation> scopes = annotatedItem.getAnnotations(ScopeType.class);
- if (scopes.size() > 1)
- {
- throw new RuntimeException("At most one scope may be specified");
- }
-
- if (scopes.size() == 1)
- {
- Annotation scope = scopes.iterator().next();
- log.finest("Scope " + scope + " specified b annotation");
- return scope;
- }
-
- if (stereotypes.getPossibleScopeTypes().size() == 1)
- {
- Annotation scope = stereotypes.getPossibleScopeTypes().iterator().next();
- log.finest("Scope " + scope + " specified by stereotype");
- return scope;
- }
- else if (stereotypes.getPossibleScopeTypes().size() > 1)
- {
- throw new RuntimeException("All stereotypes must specify the same scope OR a scope must be specified on the component");
- }
-
- log.finest("Using default @Dependent scope");
- return new DependentBinding();
- }
-
- public static Annotation getDeploymentType(List<Annotation> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
- {
- for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
- {
- if (possibleDeploymentTypes.containsKey((enabledDeploymentTypes.get(i).annotationType())))
- {
- return enabledDeploymentTypes.get(i);
- }
- }
- return null;
- }
-
- protected static String initName(MergedStereotypesModel stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, Class<?> type)
- {
- boolean componentNameDefaulted = false;
- String name = null;
- if (xmlAnnotatedItem.isAnnotationPresent(Named.class))
- {
- name = xmlAnnotatedItem.getAnnotation(Named.class).value();
- if ("".equals(name))
- {
- log.finest("Using default name (specified in XML)");
- componentNameDefaulted = true;
- }
- else
- {
- log.finest("Using name " + name + " specified in XML");
- }
- }
- else if (annotatedItem.isAnnotationPresent(Named.class))
- {
- name = annotatedItem.getAnnotation(Named.class).value();
- if ("".equals(name))
- {
- log.finest("Using default name (specified by annotations)");
- componentNameDefaulted = true;
- }
- else
- {
- log.finest("Using name " + name + " specified in XML");
- }
- }
- if ("".equals(name) && (componentNameDefaulted || stereotypes.isComponentNameDefaulted()))
- {
- name = Strings.decapitalize(type.getSimpleName());
- log.finest("Default name of " + type + " is " + name );
- }
+ String name = Strings.decapitalize(getType().getSimpleName());
+ log.finest("Default name of " + type + " is " + name );
return name;
}
/**
* Check that the types required by the stereotypes on the component are implemented
*/
- protected static void checkRequiredTypesImplemented(MergedStereotypesModel stereotypes, Class<?> type)
+ protected void checkRequiredTypesImplemented()
{
- for (Class<?> requiredType : stereotypes.getRequiredTypes())
+ for (Class<?> requiredType : getMergedStereotypes().getRequiredTypes())
{
log.finest("Checking if required type " + requiredType + " is implemented");
if (!requiredType.isAssignableFrom(type))
@@ -264,19 +125,19 @@
* Check that the scope type is allowed by the stereotypes on the component and the component type
* @param type
*/
- protected static void checkScopeAllowed(MergedStereotypesModel stereotypes, Annotation scopeType, Class<?> type)
+ protected void checkScopeAllowed()
{
- log.finest("Checking if " + scopeType + " is allowed for " + type);
- if (stereotypes.getSupportedScopes().size() > 0)
+ log.finest("Checking if " + getScopeType() + " is allowed for " + type);
+ if (getMergedStereotypes().getSupportedScopes().size() > 0)
{
- if (!stereotypes.getSupportedScopes().contains(scopeType.annotationType()))
+ if (!getMergedStereotypes().getSupportedScopes().contains(getScopeType().annotationType()))
{
- throw new RuntimeException("Scope " + scopeType + " is not an allowed by the stereotype for " + type);
+ throw new RuntimeException("Scope " + getScopeType() + " is not an allowed by the stereotype for " + type);
}
}
- if (isDeclaredFinal(type) && !scopeType.annotationType().equals(Dependent.class))
+ if (isDeclaredFinal(type) && !getScopeType().annotationType().equals(Dependent.class))
{
- throw new RuntimeException("Scope " + scopeType + " is not allowed as the class is declared final or has methods declared final for " + type + ". Only @Dependent is allowed for final components");
+ throw new RuntimeException("Scope " + getScopeType() + " is not allowed as the class is declared final or has methods declared final for " + type + ". Only @Dependent is allowed for final components");
}
}
@@ -296,53 +157,8 @@
return false;
}
- protected static <T> InjectableMethod<?> initRemoveMethod(EjbMetaData<T> ejbMetaData, Class<? extends T> type)
- {
- if (ejbMetaData.isStateful())
- {
- if (ejbMetaData.getRemoveMethods().size() == 1)
- {
- return new InjectableMethod<Object>(ejbMetaData.getRemoveMethods().get(0));
- }
- else if (ejbMetaData.getRemoveMethods().size() > 1)
- {
- List<Method> possibleRemoveMethods = new ArrayList<Method>();
- for (Method removeMethod : ejbMetaData.getRemoveMethods())
- {
- if (removeMethod.isAnnotationPresent(Destroys.class))
- {
- possibleRemoveMethods.add(removeMethod);
- }
- }
- if (possibleRemoveMethods.size() == 1)
- {
- return new InjectableMethod<Object>(possibleRemoveMethods.get(0));
- }
- else if (possibleRemoveMethods.size() > 1)
- {
- throw new RuntimeException("Multiple remove methods are annotated @Destroys for " + type);
- }
- else if (possibleRemoveMethods.size() == 0)
- {
- throw new RuntimeException("Multiple remove methods are declared, and none are annotated @Destroys for " + type);
- }
- }
- else if (ejbMetaData.getRemoveMethods().size() == 0)
- {
- throw new RuntimeException("Stateful enterprise bean component has no remove methods declared for " + type);
- }
- }
- else
- {
- List<Method> destroysMethods = Reflections.getMethods(type, Destroys.class);
- if (destroysMethods.size() > 0)
- {
- throw new RuntimeException("Only stateful enterprise bean components can have methods annotated @Destroys; " + type + " is not a stateful enterprise bean component");
- }
- }
- return null;
- }
+
protected static void checkComponentImplementation(Class<?> type)
{
if (Reflections.isAbstract(type))
@@ -350,36 +166,10 @@
throw new RuntimeException("Web Bean implementation class " + type + " cannot be declared abstract");
}
}
-
- public Annotation getDeploymentType()
- {
- return deploymentType;
- }
-
- public String getName()
- {
- return name;
- }
- @Override
- public Annotation getScopeType()
- {
- return scopeType;
- }
-
- protected MergedStereotypesModel getMergedStereotypes()
- {
- return mergedStereotypes;
- }
-
protected Class<? extends T> getType()
{
return type;
}
-
- public Set<Annotation> getBindingTypes()
- {
- return bindingTypes;
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,57 +1,258 @@
package org.jboss.webbeans.model;
import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import javax.webbeans.BindingType;
+import javax.webbeans.DeploymentType;
+import javax.webbeans.Named;
+import javax.webbeans.ScopeType;
+import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.bindings.CurrentBinding;
+import org.jboss.webbeans.bindings.DependentBinding;
+import org.jboss.webbeans.bindings.ProductionBinding;
import org.jboss.webbeans.injectable.ComponentConstructor;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.util.LoggerUtil;
-public abstract class AbstractComponentModel<T>
+public abstract class AbstractComponentModel<T, E>
{
public static final String LOGGER_NAME = "componentModel";
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
+
+ private Set<Annotation> bindingTypes;
+ private String name;
+ private Annotation scopeType;
+ private MergedStereotypesModel<T, E> mergedStereotypes;
+ private Annotation deploymentType;
+
+ protected void init(ContainerImpl container)
+ {
+ mergedStereotypes = new MergedStereotypesModel<T, E>(getAnnotatedItem(), getXmlAnnotatedItem(), container);
+ initType();
+ log.fine("Building Web Bean component metadata for " + getType());
+ initBindingTypes();
+ initName();
+ initDeploymentType(container);
+ initScopeType();
+ }
+
+ protected abstract void initType();
- protected static Set<Annotation> initBindingTypes(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+ protected abstract AnnotatedItem<E> getAnnotatedItem();
+
+ protected abstract AnnotatedItem<E> getXmlAnnotatedItem();
+
+ protected void initBindingTypes()
{
- Set<Annotation> xmlBindingTypes = xmlAnnotatedItem.getAnnotations(BindingType.class);
+ Set<Annotation> xmlBindingTypes = getXmlAnnotatedItem().getAnnotations(BindingType.class);
if (xmlBindingTypes.size() > 0)
{
// TODO support producer expression default binding type
log.finest("Using binding types " + xmlBindingTypes + " specified in XML");
- return xmlBindingTypes;
+ this.bindingTypes= xmlBindingTypes;
+ return;
}
+ else
+ {
+ Set<Annotation> bindingTypes = getAnnotatedItem().getAnnotations(BindingType.class);
+
+ if (bindingTypes.size() == 0)
+ {
+ log.finest("Adding default @Current binding type");
+ bindingTypes.add(new CurrentBinding());
+ }
+ else
+ {
+ log.finest("Using binding types " + bindingTypes + " specified by annotations");
+ }
+ this.bindingTypes = bindingTypes;
+ return;
+ }
+ }
+
+ /**
+ * Return the scope of the component
+ */
+ protected void initScopeType()
+ {
+ Set<Annotation> xmlScopes = getXmlAnnotatedItem().getAnnotations(ScopeType.class);
+ if (xmlScopes.size() > 1)
+ {
+ throw new RuntimeException("At most one scope may be specified in XML");
+ }
- Set<Annotation> bindingTypes = annotatedItem.getAnnotations(BindingType.class);
+ if (xmlScopes.size() == 1)
+ {
+ this.scopeType = xmlScopes.iterator().next();
+ log.finest("Scope " + scopeType + " specified in XML");
+ return;
+ }
- if (bindingTypes.size() == 0)
+ Set<Annotation> scopes = getAnnotatedItem().getAnnotations(ScopeType.class);
+ if (scopes.size() > 1)
{
- log.finest("Adding default @Current binding type");
- bindingTypes.add(new CurrentBinding());
+ throw new RuntimeException("At most one scope may be specified");
}
- else
+
+ if (scopes.size() == 1)
{
- log.finest("Using binding types " + bindingTypes + " specified by annotations");
+ this.scopeType = scopes.iterator().next();
+ log.finest("Scope " + scopeType + " specified b annotation");
+ return;
}
+
+ if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
+ {
+ this.scopeType = getMergedStereotypes().getPossibleScopeTypes().iterator().next();
+ log.finest("Scope " + scopeType + " specified by stereotype");
+ return;
+ }
+ else if (getMergedStereotypes().getPossibleScopeTypes().size() > 1)
+ {
+ throw new RuntimeException("All stereotypes must specify the same scope OR a scope must be specified on the component");
+ }
+ this.scopeType = new DependentBinding();
+ log.finest("Using default @Dependent scope");
+ }
+
+ protected void initName()
+ {
+ boolean componentNameDefaulted = false;
+ if (getXmlAnnotatedItem().isAnnotationPresent(Named.class))
+ {
+ String xmlName = getXmlAnnotatedItem().getAnnotation(Named.class).value();
+ if ("".equals(xmlName))
+ {
+ log.finest("Using default name (specified in XML)");
+ componentNameDefaulted = true;
+ }
+ else
+ {
+ log.finest("Using name " + xmlName + " specified in XML");
+ this.name = xmlName;
+ return;
+ }
+ }
+ else if (getAnnotatedItem().isAnnotationPresent(Named.class))
+ {
+ String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
+ if ("".equals(javaName))
+ {
+ log.finest("Using default name (specified by annotations)");
+ componentNameDefaulted = true;
+ }
+ else
+ {
+ log.finest("Using name " + javaName + " specified in XML");
+ this.name = javaName;
+ return;
+ }
+ }
+ if (componentNameDefaulted || getMergedStereotypes().isComponentNameDefaulted())
+ {
+ this.name = getDefaultName();
+ return;
+ }
+ }
+
+ protected void initDeploymentType(ContainerImpl container)
+ {
+ Set<Annotation> xmlDeploymentTypes = getXmlAnnotatedItem().getAnnotations(DeploymentType.class);
+
+ if (xmlDeploymentTypes.size() > 1)
+ {
+ throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
+ }
+
+ if (xmlDeploymentTypes.size() == 1)
+ {
+ this.deploymentType = xmlDeploymentTypes.iterator().next();
+ log.finest("Deployment type " + deploymentType + " specified in XML");
+ return;
+ }
+
+ if (getXmlAnnotatedItem().getDelegate() == null)
+ {
+
+ Set<Annotation> deploymentTypes = getAnnotatedItem().getAnnotations(DeploymentType.class);
+
+ if (deploymentTypes.size() > 1)
+ {
+ throw new RuntimeException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().getDelegate());
+ }
+ if (deploymentTypes.size() == 1)
+ {
+ this.deploymentType = deploymentTypes.iterator().next();
+ log.finest("Deployment type " + deploymentType + " specified by annotation");
+ return;
+ }
+ }
+
+ if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
+ {
+ this.deploymentType = getDeploymentType(container.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
+ log.finest("Deployment type " + deploymentType + " specified by stereotype");
+ return;
+ }
+
+ if (getXmlAnnotatedItem().getDelegate() != null)
+ {
+ this.deploymentType = new ProductionBinding();
+ log.finest("Using default @Production deployment type");
+ return;
+ }
+ throw new RuntimeException("type: " + getType() + " must specify a deployment type");
+ }
+
+ public static Annotation getDeploymentType(List<Annotation> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
+ {
+ for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
+ {
+ if (possibleDeploymentTypes.containsKey((enabledDeploymentTypes.get(i).annotationType())))
+ {
+ return enabledDeploymentTypes.get(i);
+ }
+ }
+ return null;
+ }
+
+ protected MergedStereotypesModel<T, E> getMergedStereotypes()
+ {
+ return mergedStereotypes;
+ }
+
+ protected abstract String getDefaultName();
+
+ public Set<Annotation> getBindingTypes()
+ {
return bindingTypes;
}
- public abstract Set<Annotation> getBindingTypes();
+ public Annotation getScopeType()
+ {
+ return scopeType;
+ }
+
- public abstract Annotation getScopeType();
+ protected abstract E getType();
- protected abstract Class<? extends T> getType();
-
public abstract ComponentConstructor<T> getConstructor();
- public abstract Annotation getDeploymentType();
+ public Annotation getDeploymentType()
+ {
+ return deploymentType;
+ }
- public abstract String getName();
+ public String getName()
+ {
+ return name;
+ }
}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -0,0 +1,113 @@
+package org.jboss.webbeans.model;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.webbeans.ApplicationScoped;
+import javax.webbeans.Dependent;
+import javax.webbeans.Destroys;
+
+import org.jboss.webbeans.ContainerImpl;
+import org.jboss.webbeans.ejb.EjbMetaData;
+import org.jboss.webbeans.injectable.InjectableMethod;
+import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Reflections;
+
+public abstract class AbstractEnterpriseComponentModel<T> extends
+ AbstractClassComponentModel<T>
+{
+
+ private InjectableMethod<?> removeMethod;
+ private EjbMetaData<T> ejbMetaData;
+
+ public AbstractEnterpriseComponentModel(AnnotatedType<T> annotatedItem,
+ AnnotatedType<T> xmlAnnotatedItem)
+ {
+ super(annotatedItem, xmlAnnotatedItem);
+
+ }
+
+ @Override
+ protected void init(ContainerImpl container)
+ {
+ super.init(container);
+ ejbMetaData = container.getEjbManager().getEjbMetaData(getType());
+ initRemoveMethod();
+ checkEnterpriseScopeAllowed();
+ }
+
+ public InjectableMethod<?> getRemoveMethod()
+ {
+ return removeMethod;
+ }
+
+ protected EjbMetaData<T> getEjbMetaData()
+ {
+ return ejbMetaData;
+ }
+
+ /**
+ * Check that the scope type is allowed by the stereotypes on the component and the component type
+ * @param type
+ */
+ protected void checkEnterpriseScopeAllowed()
+ {
+ if (getEjbMetaData().isStateless() && !getScopeType().annotationType().equals(Dependent.class))
+ {
+ throw new RuntimeException("Scope " + getScopeType() + " is not allowed on stateless enterpise bean components for " + getType() + ". Only @Dependent is allowed on stateless enterprise bean components");
+ }
+ if (getEjbMetaData().isSingleton() && (!getScopeType().annotationType().equals(Dependent.class) || !getScopeType().annotationType().equals(ApplicationScoped.class)))
+ {
+ throw new RuntimeException("Scope " + getScopeType() + " is not allowed on singleton enterpise bean components for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise bean components");
+ }
+ }
+
+ // TODO loggigng
+ protected void initRemoveMethod()
+ {
+ if (getEjbMetaData().isStateful())
+ {
+ if (getEjbMetaData().getRemoveMethods().size() == 1)
+ {
+ this.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
+ }
+ else if (getEjbMetaData().getRemoveMethods().size() > 1)
+ {
+ List<Method> possibleRemoveMethods = new ArrayList<Method>();
+ for (Method removeMethod : getEjbMetaData().getRemoveMethods())
+ {
+ if (removeMethod.isAnnotationPresent(Destroys.class))
+ {
+ possibleRemoveMethods.add(removeMethod);
+ }
+ }
+ if (possibleRemoveMethods.size() == 1)
+ {
+ this.removeMethod = new InjectableMethod<Object>(possibleRemoveMethods.get(0));
+ }
+ else if (possibleRemoveMethods.size() > 1)
+ {
+ throw new RuntimeException("Multiple remove methods are annotated @Destroys for " + getType());
+ }
+ else if (possibleRemoveMethods.size() == 0)
+ {
+ throw new RuntimeException("Multiple remove methods are declared, and none are annotated @Destroys for " + getType());
+ }
+ }
+ else if (getEjbMetaData().getRemoveMethods().size() == 0)
+ {
+ throw new RuntimeException("Stateful enterprise bean component has no remove methods declared for " + getType());
+ }
+ }
+ else
+ {
+ List<Method> destroysMethods = Reflections.getMethods(getType(), Destroys.class);
+ if (destroysMethods.size() > 0)
+ {
+ throw new RuntimeException("Only stateful enterprise bean components can have methods annotated @Destroys; " + getType() + " is not a stateful enterprise bean component");
+ }
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractProducerComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractProducerComponentModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractProducerComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.model;
+
+import java.lang.reflect.Method;
+
+public abstract class AbstractProducerComponentModel<T> extends
+ AbstractComponentModel<T, Method>
+{
+
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractProducerComponentModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,62 +1,37 @@
package org.jboss.webbeans.model;
-import java.lang.annotation.Annotation;
-
-import javax.webbeans.ApplicationScoped;
-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.introspector.AnnotatedType;
-public class EnterpriseComponentModel<T> extends AbstractClassComponentModel<T>
+public class EnterpriseComponentModel<T> extends AbstractEnterpriseComponentModel<T>
{
private EnterpriseConstructor<T> constructor;
- private InjectableMethod<?> removeMethod;
-
- public EnterpriseComponentModel(AnnotatedType annotatedItem,
- AnnotatedType xmlAnnotatedItem, ContainerImpl container)
+ public EnterpriseComponentModel(AnnotatedType<T> annotatedItem,
+ AnnotatedType<T> xmlAnnotatedItem, ContainerImpl container)
{
- super(annotatedItem, xmlAnnotatedItem, container);
- EjbMetaData<T> ejbMetaData = container.getEjbManager().getEjbMetaData(getType());
- this.constructor = initConstructor(ejbMetaData, container);
- EnterpriseComponentModel.checkScopeAllowed(getMergedStereotypes(), getScopeType(), getType(), ejbMetaData);
- this.removeMethod = initRemoveMethod(ejbMetaData, getType());
+ super(annotatedItem, xmlAnnotatedItem);
+ init(container);
}
- protected static <T> EnterpriseConstructor<T> initConstructor(EjbMetaData<T> ejbMetaData, ContainerImpl container)
+ @Override
+ protected void init(ContainerImpl container)
{
- return new EnterpriseConstructor<T>(ejbMetaData);
+ super.init(container);
+ this.constructor = new EnterpriseConstructor<T>(getEjbMetaData());
}
-
- /**
- * 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");
- }
- }
public ComponentConstructor<T> getConstructor()
{
return constructor;
}
- public InjectableMethod<?> getRemoveMethod()
+ @Override
+ public String toString()
{
- return removeMethod;
+ return "EnterpriseComponentModel[" + getType().getName() + "]";
}
}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/JmsComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,113 +0,0 @@
-package org.jboss.webbeans.model;
-
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Set;
-
-import javax.webbeans.Current;
-import javax.webbeans.Dependent;
-import javax.webbeans.ScopeType;
-
-import org.jboss.webbeans.ContainerImpl;
-import org.jboss.webbeans.injectable.ComponentConstructor;
-import org.jboss.webbeans.injectable.JMSConstructor;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
-import org.jboss.webbeans.util.Reflections;
-
-// TODO Work out what to return on methods we don't support
-
-public class JmsComponentModel<T> extends AbstractComponentModel<T>
-{
-
- // TODO Work out how to handle xml elements which don't correspond to annotations
-
- private String jndiName;
- private ComponentConstructor<T> constructor;
- private Set<Annotation> bindingTypes;
- private Annotation scopeType;
-
- @SuppressWarnings("unchecked")
- public JmsComponentModel(AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
- {
- AnnotatedItem annotatedItem = new SimpleAnnotatedItem(new HashMap<Class<? extends Annotation>, Annotation>());
- bindingTypes = initBindingTypes(annotatedItem, xmlAnnotatedItem);
- //scopeType = new DependentBiding();
- checkBindingTypesAllowed(bindingTypes, null);
- checkScopeAllowed(xmlAnnotatedItem, null);
- // TODO Initialize queue. topic
- this.constructor = new JMSConstructor<T>(jndiName);
- }
-
- @SuppressWarnings("unchecked")
- protected static void checkBindingTypesAllowed(Set<Annotation> bindingTypes,
- String type)
- {
- if (bindingTypes.size() == 0)
- {
- throw new RuntimeException("Must declare at least one binding type for JMS Component " + type);
- }
- if (Reflections.annotationSetMatches(bindingTypes, Current.class))
- {
- throw new RuntimeException("Cannot declared the binding type @Current for JMS Component " + type);
- }
-
- }
-
- protected static <T> Class<? extends T> initType(AnnotatedItem xmlAnnotatedItem)
- {
- // TODO return TopicPublisher if its a topic or QueueSession if its a queue
- return null;
- }
-
- protected static void checkScopeAllowed(AnnotatedItem xmlAnnotatedItem, Class<?> type)
- {
- Set<Annotation> scopeTypeAnnotations = xmlAnnotatedItem.getAnnotations(ScopeType.class);
- if (scopeTypeAnnotations.size() > 0 && ! scopeTypeAnnotations.iterator().next().annotationType().equals(Dependent.class))
- {
- throw new RuntimeException("JMS component may only have scope @Dependent for " + type);
- }
- }
-
- @Override
- public ComponentConstructor<T> getConstructor()
- {
- return constructor;
- }
-
- @Override
- public Set<Annotation> getBindingTypes()
- {
- return bindingTypes;
- }
-
- @Override
- protected Class<? extends T> getType()
- {
- return null;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- @Override
- public Annotation getScopeType()
- {
- return scopeType;
- }
-
- @Override
- public Annotation getDeploymentType()
- {
- return null;
- }
-
- @Override
- public String getName()
- {
- return null;
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -16,7 +16,7 @@
* @author pmuir
*
*/
-public class MergedStereotypesModel
+public class MergedStereotypesModel<T, E>
{
private Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes;
@@ -25,7 +25,7 @@
private Set<Class<?>> requiredTypes;
private Set<Class<? extends Annotation>> supportedScopes;
- public MergedStereotypesModel(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
+ public MergedStereotypesModel(AnnotatedItem<E> annotatedItem, AnnotatedItem<E> xmlAnnotatedItem, ContainerImpl container)
{
possibleDeploymentTypes = new HashMap<Class<? extends Annotation>, Annotation>();
possibleScopeTypes = new HashSet<Annotation>();
@@ -40,7 +40,7 @@
for (Annotation stereotypeAnnotation : stereotypeAnnotations)
{
// Retrieve and merge all metadata from stereotypes
- StereotypeModel stereotype = container.getStereotypeManager().getStereotype(stereotypeAnnotation.annotationType());
+ StereotypeModel<?> stereotype = container.getStereotypeManager().getStereotype(stereotypeAnnotation.annotationType());
if (stereotype == null)
{
throw new NullPointerException("Stereotype " + stereotypeAnnotation + " not registered with container");
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ProducerMethodComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,72 +1,97 @@
package org.jboss.webbeans.model;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.Set;
+import java.util.HashMap;
+import javax.webbeans.Dependent;
+
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
+import org.jboss.webbeans.injectable.MethodConstructor;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
-public class ProducerMethodComponentModel<T> extends AbstractComponentModel<T>
+public class ProducerMethodComponentModel<T> extends AbstractProducerComponentModel<T>
{
+ private Method type;
+ private ComponentConstructor<T> constructor;
+
+ private AnnotatedItem<Method> xmlAnnotatedItem = new SimpleAnnotatedItem<Method>(new HashMap<Class<? extends Annotation>, Annotation>());
+ private AnnotatedMethod annotatedMethod;
+
@SuppressWarnings("unchecked")
- public ProducerMethodComponentModel(AnnotatedMethod annotatedItem, ContainerImpl container)
+ public ProducerMethodComponentModel(AnnotatedMethod annotatedMethod, ContainerImpl container)
{
- checkProducerMethod(annotatedItem, container);
+ this.annotatedMethod = annotatedMethod;
+ init(container);
}
+
+ @Override
+ protected void init(ContainerImpl container)
+ {
+ super.init(container);
+ checkProducerMethod();
+ this.constructor = new MethodConstructor<T>(type);
+ }
@Override
- public ComponentConstructor getConstructor()
+ public ComponentConstructor<T> getConstructor()
{
- // TODO Auto-generated method stub
- return null;
+ return constructor;
}
- public static void checkProducerMethod(AnnotatedMethod annotatedItem, ContainerImpl container)
+ protected void checkProducerMethod()
{
- if (Modifier.isStatic(annotatedItem.getAnnotatedMethod().getModifiers()))
+ if (Modifier.isStatic(getAnnotatedItem().getDelegate().getModifiers()))
{
- throw new RuntimeException("Producer method cannot be static " + annotatedItem);
+ throw new RuntimeException("Producer method cannot be static " + annotatedMethod);
}
// TODO Check if declaring class is a WB component
-
+ if (Modifier.isFinal(getAnnotatedItem().getDelegate().getModifiers()) || getScopeType().annotationType().equals(Dependent.class))
+ {
+ throw new RuntimeException("Final producer method must have @Dependent scope " + annotatedMethod);
+ }
}
+
+ @Override
+ public String toString()
+ {
+ return "ProducerMethodComponentModel[" + getType().getName() + "]";
+ }
@Override
- public Set<Annotation> getBindingTypes()
+ protected AnnotatedItem<Method> getAnnotatedItem()
{
- // TODO Auto-generated method stub
- return null;
+ return annotatedMethod;
}
@Override
- public Annotation getDeploymentType()
+ protected String getDefaultName()
{
// TODO Auto-generated method stub
return null;
}
@Override
- public String getName()
+ protected Method getType()
{
- // TODO Auto-generated method stub
- return null;
+ return type;
}
@Override
- public Annotation getScopeType()
+ protected AnnotatedItem<Method> getXmlAnnotatedItem()
{
- // TODO Auto-generated method stub
- return null;
+ return xmlAnnotatedItem;
}
@Override
- protected Class<? extends T> getType()
+ protected void initType()
{
- // TODO Auto-generated method stub
- return null;
+ this.type = annotatedMethod.getAnnotatedMethod();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -1,69 +1,47 @@
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.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedType;
-public class RemoteComponentModel<T> extends AbstractClassComponentModel<T>
+public class RemoteComponentModel<T> extends AbstractEnterpriseComponentModel<T>
{
private EnterpriseConstructor<T> constructor;
private InjectableMethod<?> removeMethod;
private String boundTo;
- public RemoteComponentModel(AnnotatedType annotatedItem,
- AnnotatedType xmlAnnotatedItem, ContainerImpl container)
+ public RemoteComponentModel(AnnotatedType<T> annotatedItem,
+ AnnotatedType<T> xmlAnnotatedItem)
{
- super(annotatedItem, xmlAnnotatedItem, container);
- 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());
+ super(annotatedItem, xmlAnnotatedItem);
}
- protected static <T> EnterpriseConstructor<T> initConstructor(EjbMetaData<T> ejbMetaData, ContainerImpl container)
+ @Override
+ protected void init(ContainerImpl container)
{
- return new EnterpriseConstructor<T>(ejbMetaData);
+ super.init(container);
+ // TODO initialize constructor
+ initBoundTo();
}
-
- /**
- * 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)
+ protected void initBoundTo()
{
- if (xmlAnnotatedItem.isAnnotationPresent(BoundTo.class))
+ if (getXmlAnnotatedItem().isAnnotationPresent(BoundTo.class))
{
- return xmlAnnotatedItem.getAnnotation(BoundTo.class).value();
+ this.boundTo = getXmlAnnotatedItem().getAnnotation(BoundTo.class).value();
+ return;
}
- if (annotatedItem.isAnnotationPresent(BoundTo.class))
+ if (getAnnotatedItem().isAnnotationPresent(BoundTo.class))
{
- return annotatedItem.getAnnotation(BoundTo.class).value();
+ this.boundTo = getAnnotatedItem().getAnnotation(BoundTo.class).value();
+ return;
}
- throw new RuntimeException("Remote component doesn't specify @BoundTo or <bound-to /> for " + type);
+ throw new RuntimeException("Remote component doesn't specify @BoundTo or <bound-to /> for " + getType());
}
public ComponentConstructor<T> getConstructor()
@@ -80,5 +58,11 @@
{
return boundTo;
}
+
+ @Override
+ public String toString()
+ {
+ return "RemoteComponentModel[" + getType().getName() + "]";
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -17,8 +17,6 @@
public class SimpleComponentModel<T> extends AbstractClassComponentModel<T>
{
- public static final String LOGGER_NAME = "componentMetaModel";
-
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
private SimpleConstructor<T> constructor;
@@ -33,8 +31,15 @@
@SuppressWarnings("unchecked")
public SimpleComponentModel(AnnotatedType annotatedItem, AnnotatedType xmlAnnotatedItem, ContainerImpl container)
{
- super(annotatedItem, xmlAnnotatedItem, container);
- this.constructor = initConstructor(getType());
+ super(annotatedItem, xmlAnnotatedItem);
+ init(container);
+ }
+
+ @Override
+ protected void init(ContainerImpl container)
+ {
+ super.init(container);
+ initConstructor();
checkType(getType());
// TODO Interceptors
}
@@ -48,59 +53,63 @@
}
@SuppressWarnings("unchecked")
- protected static <T> SimpleConstructor<T> initConstructor(Class<? extends T> type)
+ protected void initConstructor()
{
- if (type.getConstructors().length == 1)
+ if (getType().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);
+ Constructor<T> constructor = getType().getConstructors()[0];
+ log.finest("Exactly one constructor (" + constructor +") defined, using it as the component constructor for " + getType());
+ this.constructor = new SimpleConstructor<T>(constructor);
+ return;
}
- if (type.getConstructors().length > 1)
+ if (getType().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);
+ List<Constructor<T>> initializerAnnotatedConstructors = Reflections.getConstructors(getType(), Initializer.class);
+ List<Constructor<T>> bindingTypeAnnotatedConstructors = Reflections.getConstructorsForMetaAnnotatedParameter(getType(), BindingType.class);
+ log.finest("Found " + initializerAnnotatedConstructors + " constructors annotated with @Initializer for " + getType());
+ log.finest("Found " + bindingTypeAnnotatedConstructors + " with parameters annotated with binding types for " + getType());
if ((initializerAnnotatedConstructors.size() + bindingTypeAnnotatedConstructors.size()) > 1)
{
if (initializerAnnotatedConstructors.size() > 1)
{
- throw new RuntimeException("Cannot have more than one constructor annotated with @Initializer for " + type);
+ throw new RuntimeException("Cannot have more than one constructor annotated with @Initializer for " + getType());
}
else if (bindingTypeAnnotatedConstructors.size() > 1)
{
- throw new RuntimeException("Cannot have more than one constructor with binding types specified on constructor parameters for " + type);
+ throw new RuntimeException("Cannot have more than one constructor with binding types specified on constructor parameters for " + getType());
}
else
{
- throw new RuntimeException("Specify a constructor either annotated with @Initializer or with parameters annotated with binding types for " + type);
+ throw new RuntimeException("Specify a constructor either annotated with @Initializer or with parameters annotated with binding types for " + getType());
}
}
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);
+ log.finest("Exactly one constructor (" + constructor +") annotated with @Initializer defined, using it as the component constructor for " + getType());
+ this.constructor = new SimpleConstructor<T>(constructor);
+ return;
}
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);
+ log.finest("Exactly one constructor (" + constructor +") with parameters annotated with binding types defined, using it as the component constructor for " + getType());
+ this.constructor = new SimpleConstructor<T>(constructor);
+ return;
}
}
- if (type.getConstructors().length == 0)
+ if (getType().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);
+ Constructor<T> constructor = (Constructor<T>) Reflections.getConstructor(getType());
+ log.finest("No constructor defined, using implicit no arguement constructor for " + getType());
+ this.constructor = new SimpleConstructor<T>(constructor);
+ return;
}
- throw new RuntimeException("Cannot determine constructor to use for " + type);
+ throw new RuntimeException("Cannot determine constructor to use for " + getType());
}
public SimpleConstructor<T> getConstructor()
@@ -119,6 +128,5 @@
{
return "SimpleComponentModel[" + getType().getName() + "]";
}
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -12,7 +12,6 @@
import javax.webbeans.ScopeType;
import javax.webbeans.Stereotype;
-import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedType;
/**
@@ -21,7 +20,7 @@
* @author pmuir
*
*/
-public class StereotypeModel
+public class StereotypeModel<T>
{
private Class<? extends Annotation> stereotypeClass;
@@ -33,7 +32,7 @@
private Set<Annotation> interceptorBindings;
@SuppressWarnings("unchecked")
- public StereotypeModel(AnnotatedType annotatedClass)
+ public StereotypeModel(AnnotatedType<T> annotatedClass)
{
initStereotypeClass(annotatedClass);
Stereotype stereotype = annotatedClass.getAnnotation(Stereotype.class);
@@ -46,7 +45,7 @@
checkBindingTypes(annotatedClass);
}
- private void checkBindingTypes(AnnotatedItem annotatedClass)
+ private void checkBindingTypes(AnnotatedType<T> annotatedClass)
{
Set<Annotation> bindingTypes = annotatedClass.getAnnotations(BindingType.class);
if (bindingTypes.size() > 0)
@@ -56,7 +55,7 @@
}
@SuppressWarnings("unchecked")
- private void initStereotypeClass(AnnotatedType annotatedClass)
+ private void initStereotypeClass(AnnotatedType<T> annotatedClass)
{
if (Annotation.class.isAssignableFrom(annotatedClass.getAnnotatedClass()))
{
@@ -68,12 +67,12 @@
}
}
- private void initInterceptorBindings(AnnotatedItem annotatedClass)
+ private void initInterceptorBindings(AnnotatedType<T> annotatedClass)
{
interceptorBindings = annotatedClass.getAnnotations(InterceptorBindingType.class);
}
- private void initSupportedScopes(AnnotatedItem annotatedElement, Stereotype stereotype)
+ private void initSupportedScopes(AnnotatedType<T> annotatedElement, Stereotype stereotype)
{
this.supportedScopes = new HashSet<Class<? extends Annotation>>();
Class<? extends Annotation>[] supportedScopes = stereotype.supportedScopes();
@@ -83,7 +82,7 @@
}
}
- private void initRequiredTypes(AnnotatedItem annotatedElement, Stereotype stereotype)
+ private void initRequiredTypes(AnnotatedType<T> annotatedElement, Stereotype stereotype)
{
this.requiredTypes = new HashSet<Class<?>>();
Class<?>[] requiredTypes = stereotype.requiredTypes();
@@ -93,7 +92,7 @@
}
}
- private void initComponentNameDefaulted(AnnotatedItem annotatedElement)
+ private void initComponentNameDefaulted(AnnotatedType<T> annotatedElement)
{
if (annotatedElement.isAnnotationPresent(Named.class))
{
@@ -105,7 +104,7 @@
}
}
- private void initDefaultScopeType(AnnotatedItem annotatedElement)
+ private void initDefaultScopeType(AnnotatedType<T> annotatedElement)
{
Set<Annotation> scopeTypes = annotatedElement.getAnnotations(ScopeType.class);
if (scopeTypes.size() > 1)
@@ -118,7 +117,7 @@
}
}
- private void initDefaultDeploymentType(AnnotatedItem annotatedElement)
+ private void initDefaultDeploymentType(AnnotatedType<T> annotatedElement)
{
Set<Annotation> deploymentTypes = annotatedElement.getAnnotations(DeploymentType.class);
if (deploymentTypes.size() > 1)
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ConstructorMetaModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ConstructorMetaModelTest.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ConstructorMetaModelTest.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -41,7 +41,7 @@
@Test
public void testImplicitConstructor()
{
- SimpleConstructor<Order> constructor = new SimpleComponentModel<Order>(new SimpleAnnotatedType(Order.class), emptyAnnotatedItem, container).getConstructor();
+ SimpleConstructor<Order> constructor = new SimpleComponentModel<Order>(new SimpleAnnotatedType<Order>(Order.class), emptyAnnotatedItem, container).getConstructor();
assert constructor.getConstructor().getDeclaringClass().equals(Order.class);
assert constructor.getConstructor().getParameterTypes().length == 0;
assert constructor.getParameters().size() == 0;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java 2008-09-08 18:56:33 UTC (rev 97)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EnterpriseComponentModelTest.java 2008-09-08 18:57:12 UTC (rev 98)
@@ -10,6 +10,7 @@
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.AbstractEnterpriseComponentModel;
import org.jboss.webbeans.model.EnterpriseComponentModel;
import org.jboss.webbeans.test.annotations.Synchronous;
import org.jboss.webbeans.test.components.Bear;
@@ -69,7 +70,7 @@
boolean exception = false;
try
{
- new EnterpriseComponentModel<Bear>(new SimpleAnnotatedType(Bear.class), emptyAnnotatedItem, container);
+ new EnterpriseComponentModel<Bear>(new SimpleAnnotatedType<Bear>(Bear.class), emptyAnnotatedItem, container);
}
catch (Exception e)
{
@@ -99,7 +100,7 @@
public void testStateful()
{
- EnterpriseComponentModel<Tiger> tiger = new EnterpriseComponentModel<Tiger>(new SimpleAnnotatedType(Tiger.class), emptyAnnotatedItem, container);
+ AbstractEnterpriseComponentModel<Tiger> tiger = new EnterpriseComponentModel<Tiger>(new SimpleAnnotatedType(Tiger.class), emptyAnnotatedItem, container);
Reflections.annotationSetMatches(tiger.getBindingTypes(), Synchronous.class);
assert tiger.getRemoveMethod().getMethod().getName().equals("remove");
assert tiger.getName() == null;
@@ -110,7 +111,7 @@
public void testMultipleRemoveMethodsWithDestroys()
{
- EnterpriseComponentModel<Elephant> elephant = new EnterpriseComponentModel<Elephant>(new SimpleAnnotatedType(Elephant.class), emptyAnnotatedItem, container);
+ AbstractEnterpriseComponentModel<Elephant> elephant = new EnterpriseComponentModel<Elephant>(new SimpleAnnotatedType(Elephant.class), emptyAnnotatedItem, container);
assert elephant.getRemoveMethod().getMethod().getName().equals("remove2");
}
@@ -166,7 +167,7 @@
public void testRemoveMethodWithDefaultBinding()
{
- EnterpriseComponentModel<Panther> panther = new EnterpriseComponentModel<Panther>(new SimpleAnnotatedType(Panther.class), emptyAnnotatedItem, container);
+ AbstractEnterpriseComponentModel<Panther> panther = new EnterpriseComponentModel<Panther>(new SimpleAnnotatedType(Panther.class), emptyAnnotatedItem, container);
assert panther.getRemoveMethod().getMethod().getName().equals("remove");
assert panther.getRemoveMethod().getParameters().size() == 1;
@@ -179,7 +180,7 @@
@Test
public void testMessageDriven()
{
- EnterpriseComponentModel<Leopard> leopard = new EnterpriseComponentModel<Leopard>(new SimpleAnnotatedType(Leopard.class), emptyAnnotatedItem, container);
+ AbstractEnterpriseComponentModel<Leopard> leopard = new EnterpriseComponentModel<Leopard>(new SimpleAnnotatedType(Leopard.class), emptyAnnotatedItem, container);
Reflections.annotationSetMatches(leopard.getBindingTypes(), Current.class);
}
16 years, 2 months
[webbeans-commits] Webbeans SVN: r97 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-09-08 14:56:33 -0400 (Mon, 08 Sep 2008)
New Revision: 97
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java
Log:
a ComponentConstructor which calls a method
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java 2008-09-08 18:56:33 UTC (rev 97)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.injectable;
+
+import java.lang.reflect.Method;
+
+import javax.webbeans.Container;
+
+public class MethodConstructor<T> extends InjectableMethod<T> implements
+ ComponentConstructor<T>
+{
+
+ public MethodConstructor(Method method)
+ {
+ super(method);
+ }
+
+ public T invoke(Container container)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/MethodConstructor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 2 months
[webbeans-commits] Webbeans SVN: r96 - ri/trunk/webbeans-api/src/main/java/javax/webbeans.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-09-08 14:56:00 -0400 (Mon, 08 Sep 2008)
New Revision: 96
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Current.java
Log:
Can be applied to parameters
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Current.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Current.java 2008-08-11 16:32:44 UTC (rev 95)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Current.java 2008-09-08 18:56:00 UTC (rev 96)
@@ -20,6 +20,7 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
@@ -31,7 +32,7 @@
* @author Pete Muir
*/
-@Target( { TYPE, METHOD, PARAMETER })
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@BindingType
16 years, 2 months