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