[webbeans-commits] Webbeans SVN: r30 - in ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test: components and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 08:54:48 -0400 (Tue, 01 Jul 2008)
New Revision: 30
Added:
ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Cow.java
ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Horse.java
ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Pig.java
Modified:
ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
Log:
Test component type restrictions
Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java 2008-07-01 12:49:00 UTC (rev 29)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java 2008-07-01 12:54:48 UTC (rev 30)
@@ -22,6 +22,7 @@
import org.jboss.webbeans.StereotypeMetaModel;
import org.jboss.webbeans.bindings.ConversationScopedBinding;
import org.jboss.webbeans.bindings.CurrentBinding;
+import org.jboss.webbeans.bindings.DependentBinding;
import org.jboss.webbeans.bindings.NamedBinding;
import org.jboss.webbeans.bindings.RequestScopedBinding;
import org.jboss.webbeans.bindings.StandardBinding;
@@ -49,11 +50,14 @@
import org.jboss.webbeans.test.components.Chair;
import org.jboss.webbeans.test.components.ComponentWithTooManyDeploymentTypes;
import org.jboss.webbeans.test.components.ComponentWithTooManyScopeTypes;
+import org.jboss.webbeans.test.components.Cow;
import org.jboss.webbeans.test.components.Goldfish;
import org.jboss.webbeans.test.components.Gorilla;
import org.jboss.webbeans.test.components.Haddock;
+import org.jboss.webbeans.test.components.Horse;
import org.jboss.webbeans.test.components.Moose;
import org.jboss.webbeans.test.components.Order;
+import org.jboss.webbeans.test.components.Pig;
import org.jboss.webbeans.test.components.Trout;
import org.jboss.webbeans.test.components.Tuna;
import org.jboss.webbeans.test.mock.MockContainerImpl;
@@ -488,4 +492,74 @@
assert exception;
}
+
+ @Test
+ public void testAbstractClassIsNotAllowed()
+ {
+ boolean exception = false;
+ try
+ {
+ new ComponentInstanceImpl<Cow>(new ClassAnnotatedItem(Cow.class), emptyAnnotatedItem, container);
+ }
+ catch (Exception e)
+ {
+ exception = true;
+ }
+ assert exception;
+ }
+
+ @Test
+ public void testFinalClassMustBeDependentScoped()
+ {
+ boolean exception = false;
+ try
+ {
+ new ComponentInstanceImpl<Horse>(new ClassAnnotatedItem(Horse.class), emptyAnnotatedItem, container);
+ }
+ catch (Exception e)
+ {
+ exception = true;
+ }
+ assert exception;
+
+ Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
+ annotations.put(Dependent.class, new DependentBinding());
+ AnnotatedItem annotatedItem = new MutableAnnotatedItem(Horse.class, annotations);
+ try
+ {
+ new ComponentInstanceImpl<Horse>(new ClassAnnotatedItem(Horse.class), annotatedItem, container);
+ }
+ catch (Exception e)
+ {
+ assert false;
+ }
+ }
+
+ @Test
+ public void testClassWithFinalMethodMustBeDependentScoped()
+ {
+ boolean exception = false;
+ try
+ {
+ new ComponentInstanceImpl<Pig>(new ClassAnnotatedItem(Pig.class), emptyAnnotatedItem, container);
+ }
+ catch (Exception e)
+ {
+ exception = true;
+ }
+ assert exception;
+
+ Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
+ annotations.put(Dependent.class, new DependentBinding());
+ AnnotatedItem annotatedItem = new MutableAnnotatedItem(Pig.class, annotations);
+ try
+ {
+ new ComponentInstanceImpl<Pig>(new ClassAnnotatedItem(Pig.class), annotatedItem, container);
+ }
+ catch (Exception e)
+ {
+ assert false;
+ }
+ }
+
}
Added: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Cow.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Cow.java (rev 0)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Cow.java 2008-07-01 12:54:48 UTC (rev 30)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Production;
+
+@Production
+public abstract class Cow
+{
+
+}
Property changes on: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Cow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Horse.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Horse.java (rev 0)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Horse.java 2008-07-01 12:54:48 UTC (rev 30)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+
+@Production
+@RequestScoped
+public final class Horse
+{
+
+}
Property changes on: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Horse.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Pig.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Pig.java (rev 0)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Pig.java 2008-07-01 12:54:48 UTC (rev 30)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+
+@Production
+@RequestScoped
+public class Pig
+{
+
+ public final void washPig()
+ {
+
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/components/Pig.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 5 months
[webbeans-commits] Webbeans SVN: r29 - ri/trunk/webbeans-api/src/main/java/javax/webbeans.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 08:49:00 -0400 (Tue, 01 Jul 2008)
New Revision: 29
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Dependent.java
Log:
Oops (too much copy and pasting!)
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Dependent.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Dependent.java 2008-07-01 12:14:57 UTC (rev 28)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Dependent.java 2008-07-01 12:49:00 UTC (rev 29)
@@ -13,7 +13,7 @@
@Target( { METHOD, FIELD, PARAMETER, TYPE })
@Retention(RUNTIME)
@Documented
-@BindingType
+@ScopeType
public @interface Dependent
{
16 years, 5 months
[webbeans-commits] Webbeans SVN: r28 - in ri/trunk/webbeans-impl: src/main/java/org/jboss/webbeans and 3 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 08:14:57 -0400 (Tue, 01 Jul 2008)
New Revision: 28
Added:
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
Modified:
ri/trunk/webbeans-impl/pom.xml
ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
Log:
Start on chapter 3.1, alter emma setup
Modified: ri/trunk/webbeans-impl/pom.xml
===================================================================
--- ri/trunk/webbeans-impl/pom.xml 2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/pom.xml 2008-07-01 12:14:57 UTC (rev 28)
@@ -31,34 +31,18 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
<inherited>true</inherited>
- <executions>
- <execution>
- <goals>
- <goal>instrument</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
+ <reportFormat>xml</reportFormat>
</configuration>
</plugin>
</plugins>
</build>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>emma-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
- <inherited>true</inherited>
- </plugin>
- </plugins>
- </reporting>
+
</project>
\ No newline at end of file
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+
+public abstract class AbstractInjectedThingMetaModel
+{
+
+ private Annotation[] bindingTypes;
+
+ public AbstractInjectedThingMetaModel(Annotation[] bindingTypes)
+ {
+ this.bindingTypes = bindingTypes;
+ }
+
+ public AbstractInjectedThingMetaModel()
+ {
+ this.bindingTypes = new Annotation[0];
+ }
+
+ public Annotation[] getBindingTypes()
+ {
+ return bindingTypes;
+ }
+
+ public abstract Class<?> getType();
+
+ @Override
+ public String toString()
+ {
+ return getType() + " with binding types " + getBindingTypes();
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/AbstractInjectedThingMetaModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java 2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ComponentInstanceImpl.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -1,6 +1,7 @@
package org.jboss.webbeans;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -9,6 +10,7 @@
import javax.webbeans.BindingType;
import javax.webbeans.ComponentInstance;
import javax.webbeans.Container;
+import javax.webbeans.Dependent;
import javax.webbeans.DeploymentType;
import javax.webbeans.Named;
import javax.webbeans.ScopeType;
@@ -16,8 +18,11 @@
import org.jboss.webbeans.bindings.CurrentBinding;
import org.jboss.webbeans.bindings.DependentBinding;
import org.jboss.webbeans.bindings.ProductionBinding;
+import org.jboss.webbeans.ejb.EJB;
import org.jboss.webbeans.util.AnnotatedItem;
import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* Web Beans Component meta model
@@ -28,24 +33,31 @@
public class ComponentInstanceImpl<T> extends ComponentInstance<T>
{
+ public enum ComponentType
+ {
+ SIMPLE,
+ EJB_SESSION
+ ;
+ }
-
public static final String LOGGER_NAME = "componentInstance";
private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
- private Class<?> type;
+ private Class<? extends T> type;
private Set<Annotation> bindingTypes;
- private Annotation componentType;
+ private Annotation deploymentType;
private String name;
private Annotation scopeType;
-
+ private ComponentType componentType;
+ private ConstructorMetaModel<T> constructor;
/**
*
* @param annotatedItem Annotations read from java classes
* @param xmlAnnotatedItem Annotations read from XML
* @param container
*/
+ @SuppressWarnings("unchecked")
public ComponentInstanceImpl(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
{
if (annotatedItem == null)
@@ -58,15 +70,18 @@
throw new NullPointerException("xmlAnnotatedItem must not be null. If the component is declared just in Java, pass in an empty xmlAnnotatedItem");
}
- this.type = getType(annotatedItem, xmlAnnotatedItem);
+ this.type = (Class<? extends T>) initType(annotatedItem, xmlAnnotatedItem);
log.fine("Building Web Bean component metadata for " + type);
+ this.componentType = initComponentType(type);
+ checkComponentImplementation(componentType, type);
+ this.constructor = new ConstructorMetaModel<T>(type);
MergedComponentStereotypes stereotypes = new MergedComponentStereotypes(annotatedItem, xmlAnnotatedItem, container);
this.bindingTypes = initBindingTypes(annotatedItem, xmlAnnotatedItem);
- this.componentType = initComponentType(stereotypes, annotatedItem, xmlAnnotatedItem, container);
+ this.deploymentType = initDeploymentType(stereotypes, annotatedItem, xmlAnnotatedItem, container);
this.scopeType = initScopeType(stereotypes, annotatedItem, xmlAnnotatedItem);
- this.name = initName(stereotypes, annotatedItem, xmlAnnotatedItem);
+ this.name = initName(stereotypes, annotatedItem, xmlAnnotatedItem, componentType, type);
checkRequiredTypesImplemented(stereotypes, type);
- checkScopeAllowed(stereotypes, scopeType);
+ checkScopeAllowed(stereotypes, scopeType, type);
// TODO Interceptors
}
@@ -74,8 +89,55 @@
* A series of static methods which implement the algorithms defined in the Web Beans spec for component meta data
*/
- protected static Class<?> getType(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+ protected static ComponentType initComponentType(Class<?> type)
{
+ if (EJB.isStatefulEjbComponent(type) || EJB.isStatelessEjbComponent(type))
+ {
+ return ComponentType.EJB_SESSION;
+ }
+ else
+ {
+ return ComponentType.SIMPLE;
+ }
+ }
+
+ protected static void checkComponentImplementation(ComponentType componentType, Class<?> type)
+ {
+ switch (componentType)
+ {
+ case SIMPLE:
+ checkSimpleComponentImplementation(type);
+ break;
+ }
+ }
+
+ protected static void checkSimpleComponentImplementation(Class<?> type)
+ {
+ if (Reflections.isAbstract(type))
+ {
+ throw new RuntimeException("Web Bean implementation class " + type + " cannot be declared abstract");
+ }
+ }
+
+ protected static boolean isDeclaredFinal(Class<?> type)
+ {
+ if (Reflections.isFinal(type))
+ {
+ return true;
+ }
+ for (Method method : type.getDeclaredMethods())
+ {
+ if (Reflections.isFinal(method))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected static Class<?> initType(AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+ {
if (annotatedItem.getAnnotatedClass() != null && xmlAnnotatedItem.getAnnotatedClass() != null && !annotatedItem.getAnnotatedClass().equals(xmlAnnotatedItem.getAnnotatedClass()))
{
throw new IllegalArgumentException("Cannot build a component which specifies different classes in XML and Java");
@@ -97,18 +159,23 @@
}
/**
- * Check that the scope type is allowed by the stereotypes on the component
+ * Check that the scope type is allowed by the stereotypes on the component and the component type
+ * @param type
*/
- protected static void checkScopeAllowed(MergedComponentStereotypes stereotypes, Annotation scopeType)
+ protected static void checkScopeAllowed(MergedComponentStereotypes stereotypes, Annotation scopeType, Class<?> type)
{
+ log.finest("Checking if " + scopeType + " is allowed");
if (stereotypes.getSupportedScopes().size() > 0)
{
- log.finest("Checking if " + scopeType + " is allowed");
if (!stereotypes.getSupportedScopes().contains(scopeType.annotationType()))
{
throw new RuntimeException("Scope " + scopeType + " is not an allowed by the component's stereotype");
}
}
+ if (isDeclaredFinal(type) && !scopeType.annotationType().equals(Dependent.class))
+ {
+ throw new RuntimeException("Scope " + scopeType + " is not allowed as the component is declared final or has methods declared final");
+ }
}
/**
@@ -172,7 +239,7 @@
return new DependentBinding();
}
- protected static Annotation initComponentType(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
+ protected static Annotation initDeploymentType(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ContainerImpl container)
{
Set<Annotation> xmlDeploymentTypes = xmlAnnotatedItem.getAnnotations(DeploymentType.class);
@@ -244,7 +311,7 @@
return bindingTypes;
}
- protected static String initName(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem)
+ protected static String initName(MergedComponentStereotypes stereotypes, AnnotatedItem annotatedItem, AnnotatedItem xmlAnnotatedItem, ComponentType componentType, Class<?> type)
{
boolean componentNameDefaulted = false;
String name = null;
@@ -276,7 +343,10 @@
}
if ("".equals(name) && (componentNameDefaulted || stereotypes.isComponentNameDefaulted()))
{
- // TODO Write default name alogorithm
+ if (ComponentType.SIMPLE.equals(componentType))
+ {
+ name = Strings.decapitalize(type.getName());
+ }
log.finest("Default name is TODO" );
}
return name;
@@ -297,7 +367,6 @@
@Override
public T create(Container container)
{
- // TODO Auto-generated method stub
return null;
}
@@ -315,9 +384,9 @@
}
@Override
- public Annotation getComponentType()
+ public Annotation getDeploymentType()
{
- return componentType;
+ return deploymentType;
}
@Override
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,122 @@
+package org.jboss.webbeans;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.webbeans.BindingType;
+import javax.webbeans.Container;
+import javax.webbeans.Initializer;
+
+import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
+
+public class ConstructorMetaModel<T>
+{
+
+public static final String LOGGER_NAME = "componentConstructor";
+
+ private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);
+
+ private Constructor<T> constructor;
+
+ private List<AbstractInjectedThingMetaModel> injectedParameters;
+
+ @SuppressWarnings("unchecked")
+ public ConstructorMetaModel(Class<? extends T> type)
+ {
+ this.injectedParameters = new ArrayList<AbstractInjectedThingMetaModel>();
+ if (type.getConstructors().length == 1)
+ {
+ this.constructor = type.getConstructors()[0];
+ log.finest("Exactly one constructor (" + constructor +") defined, using it as the component constructor for " + type);
+ }
+ else if (type.getConstructors().length > 1)
+ {
+
+ List<Constructor<T>> initializerAnnotatedConstructors = Reflections.getConstructors(type, Initializer.class);
+ List<Constructor<T>> bindingTypeAnnotatedConstructors = Reflections.getConstructorsForMetaAnnotatedParameter(type, BindingType.class);
+ if ((initializerAnnotatedConstructors.size() + bindingTypeAnnotatedConstructors.size()) > 1)
+ {
+ if (initializerAnnotatedConstructors.size() > 1)
+ {
+ throw new RuntimeException("Cannot have more than one constructor annotated with @Initializer for " + type);
+ }
+
+ else if (bindingTypeAnnotatedConstructors.size() > 1)
+ {
+ throw new RuntimeException("Cannot have more than one constructor with binding types specified on constructor parameters for " + type);
+ }
+
+ else
+ {
+ throw new RuntimeException("Specify a constructor either annotated with @Initializer or with parameters annotated with binding types for " + type);
+ }
+ }
+ else if (initializerAnnotatedConstructors.size() == 1)
+ {
+ this.constructor = initializerAnnotatedConstructors.get(0);
+ log.finest("Exactly one constructor (" + constructor +") annotated with @Initializer defined, using it as the component constructor for " + type);
+ }
+ else if (bindingTypeAnnotatedConstructors.size() == 1)
+ {
+ this.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);
+ }
+ }
+ else if (type.getConstructors().length == 0)
+ {
+ this.constructor = (Constructor<T>) Reflections.getConstructor(type);
+ log.finest("No constructor defined, using implicit no arguement constructor");
+ }
+
+ for (int i = 0; i < constructor.getParameterTypes().length; i++)
+ {
+ if (constructor.getParameterAnnotations()[i].length > 0)
+ {
+ InjectedParameterMetaModel parameter = new InjectedParameterMetaModel(constructor.getParameterAnnotations()[i], constructor.getParameterTypes()[i]);
+ injectedParameters.add(i, parameter);
+ }
+ else
+ {
+ InjectedParameterMetaModel parameter = new InjectedParameterMetaModel(constructor.getParameterTypes()[i]);
+ injectedParameters.add(i, parameter);
+ }
+ }
+ log.finest("Initialized metadata for " + constructor + " with injectable parameters " + injectedParameters);
+ if (this.constructor == null)
+ {
+ throw new RuntimeException("Cannot determine constructor to use");
+ }
+ }
+
+ public Constructor<T> getConstructor()
+ {
+ return constructor;
+ }
+
+ public List<AbstractInjectedThingMetaModel> getInjectedAttributes()
+ {
+ return injectedParameters;
+ }
+
+ public T newInstance(Container container)
+ {
+ Object[] parameters = new Object[injectedParameters.size()];
+ log.finest("Creating new instance of " + constructor.getDeclaringClass() + " with injected parameters " + injectedParameters);
+ for (int i = 0; i < injectedParameters.size(); i++)
+ {
+ parameters[i] = container.getInstanceByType(injectedParameters.get(i).getType(), injectedParameters.get(0).getBindingTypes());
+ }
+ try
+ {
+ return constructor.newInstance(parameters);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error instantiating " + constructor.getDeclaringClass(), e);
+ }
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ConstructorMetaModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,27 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+
+public class InjectedParameterMetaModel extends AbstractInjectedThingMetaModel
+{
+
+ private Class<?> type;
+
+ public InjectedParameterMetaModel(Annotation[] bindingTypes, Class<?> type)
+ {
+ super(bindingTypes);
+ this.type = type;
+ }
+
+ public InjectedParameterMetaModel(Class<?> type)
+ {
+ super();
+ this.type = type;
+ }
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/InjectedParameterMetaModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,72 @@
+package org.jboss.webbeans.ejb;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.webbeans.util.Reflections;
+
+
+@SuppressWarnings("unchecked")
+public class EJB
+{
+
+ public @interface Dummy {}
+
+ public static final Class<Annotation> STATELESS;
+ public static final Class<Annotation> STATEFUL;
+ public static final Class<Annotation> MESSAGE_DRIVEN;
+
+ static
+ {
+ STATELESS = classForName("javax.ejb.Stateless");
+ STATEFUL = classForName("javax.ejb.Stateful");
+ MESSAGE_DRIVEN = classForName("javax.ejb.MessageDriven");
+ }
+
+ private static Class classForName(String name)
+ {
+ try
+ {
+ return Reflections.classForName(name);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ return Dummy.class;
+ }
+ }
+
+ public static boolean isStatelessEjbComponent(Class<?> clazz)
+ {
+ EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+ if (ejbMetaData != null)
+ {
+ return ejbMetaData.isStateless();
+ }
+ return false;
+ }
+
+ public static boolean isStatefulEjbComponent(Class<?> clazz)
+ {
+ EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+ if (ejbMetaData != null)
+ {
+ return ejbMetaData.isStateful();
+ }
+ return false;
+ }
+
+ public static boolean isMessageDrivenEjbComponent(Class<?> clazz)
+ {
+ EjbMetaData ejbMetaData = getEjbMetaData(clazz);
+ if (ejbMetaData != null)
+ {
+ return ejbMetaData.isMessageDriven();
+ }
+ return false;
+ }
+
+ public static EjbMetaData getEjbMetaData(Class<?> clazz)
+ {
+ return null;
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EJB.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.ejb;
+
+public class EjbMetaData
+{
+
+ public boolean isStateless()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isStateful()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isMessageDriven()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,116 @@
+package org.jboss.webbeans.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class Reflections
+{
+
+ public static Class<?> classForName(String name) throws ClassNotFoundException
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ catch (Exception e)
+ {
+ return Class.forName(name);
+ }
+ }
+
+ public static boolean isFinal(Class<?> clazz)
+ {
+ return Modifier.isFinal(clazz.getModifiers());
+ }
+
+ public static boolean isFinal(Method method)
+ {
+ return Modifier.isFinal(method.getModifiers());
+ }
+
+ public static boolean isAbstract(Class<?> clazz)
+ {
+ return Modifier.isAbstract(clazz.getModifiers());
+ }
+
+ public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... parameterTypes)
+ {
+ try
+ {
+ return clazz.getConstructor(parameterTypes);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error accessing constructor (with parameters " + parameterTypes + ") of " + clazz, e);
+ }
+ }
+
+ public static List<Method> getMethods(Class<?> clazz, Class<? extends Annotation> annotationType)
+ {
+ List<Method> methods = new ArrayList<Method>();
+ for (Method method : clazz.getMethods())
+ {
+ if (method.isAnnotationPresent(annotationType))
+ {
+ methods.add(method);
+ }
+ }
+ return methods;
+ }
+
+ public static <T> List<Constructor<T>> getConstructors(Class<? extends T> clazz, Class<? extends Annotation> annotationType)
+ {
+ List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+ for (Constructor<T> constructor : constructors)
+ {
+ if (constructor.isAnnotationPresent(annotationType))
+ {
+ constructors.add(constructor);
+ }
+ }
+ return constructors;
+ }
+
+ public static <T> List<Constructor<T>> getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> parameterAnnotationType)
+ {
+ List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+ for (Constructor<T> constructor : constructors)
+ {
+ for (Annotation[] annotations : constructor.getParameterAnnotations())
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().equals(parameterAnnotationType))
+ {
+ constructors.add(constructor);
+ }
+ }
+ }
+ }
+ return constructors;
+ }
+
+ public static <T> List<Constructor<T>> getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> metaAnnotationType)
+ {
+ List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
+ for (Constructor<T> constructor : constructors)
+ {
+ for (Annotation[] annotations : constructor.getParameterAnnotations())
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ constructors.add(constructor);
+ }
+ }
+ }
+ }
+ return constructors;
+ }
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Reflections.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
===================================================================
--- ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java (rev 0)
+++ ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.util;
+
+import java.beans.Introspector;
+
+public class Strings
+{
+
+ public static String decapitalize(String camelCase)
+ {
+ return Introspector.decapitalize(camelCase);
+ }
+
+}
Property changes on: ri/trunk/webbeans-impl/src/main/java/org/jboss/webbeans/util/Strings.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java
===================================================================
--- ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java 2008-07-01 12:14:37 UTC (rev 27)
+++ ri/trunk/webbeans-impl/src/test/java/org/jboss/webbeans/test/ComponentInstanceTest.java 2008-07-01 12:14:57 UTC (rev 28)
@@ -119,7 +119,7 @@
AnnotatedItem xmlDefinedDeploymentTypeAnnotatedItem = new MutableAnnotatedItem(ComponentWithTooManyDeploymentTypes.class, xmlDefinedDeploymentTypeAnnotations);
ComponentInstance<ComponentWithTooManyDeploymentTypes> component = new ComponentInstanceImpl<ComponentWithTooManyDeploymentTypes>(new ClassAnnotatedItem(ComponentWithTooManyDeploymentTypes.class), xmlDefinedDeploymentTypeAnnotatedItem, container);
- assert component.getComponentType().annotationType().equals(AnotherDeploymentType.class);
+ assert component.getDeploymentType().annotationType().equals(AnotherDeploymentType.class);
}
@Test
@@ -127,7 +127,7 @@
{
AnnotatedItem antelopeAnnotatedItem = new MutableAnnotatedItem(Antelope.class, new HashMap<Class<? extends Annotation>, Annotation>());
ComponentInstance<Antelope> antelope = new ComponentInstanceImpl<Antelope>(emptyAnnotatedItem, antelopeAnnotatedItem, container);
- assert antelope.getComponentType().annotationType().equals(Production.class);
+ assert antelope.getDeploymentType().annotationType().equals(Production.class);
}
@Test
@@ -135,7 +135,7 @@
{
AnnotatedItem annotatedItem = new MutableAnnotatedItem(Tuna.class, new HashMap<Class<? extends Annotation>, Annotation>());
ComponentInstance<Tuna> tuna = new ComponentInstanceImpl<Tuna>(new ClassAnnotatedItem(Tuna.class), annotatedItem, container);
- assert tuna.getComponentType().annotationType().equals(Production.class);
+ assert tuna.getDeploymentType().annotationType().equals(Production.class);
}
@Test
@@ -146,7 +146,7 @@
AnnotatedItem annotatedItem = new MutableAnnotatedItem(Moose.class, annotations);
ComponentInstance<Moose> moose = new ComponentInstanceImpl<Moose>(new ClassAnnotatedItem(Moose.class), annotatedItem, container);
- assert moose.getComponentType().annotationType().equals(HornedAnimalDeploymentType.class);
+ assert moose.getDeploymentType().annotationType().equals(HornedAnimalDeploymentType.class);
}
@@ -411,7 +411,7 @@
AnnotatedItem currentSynchronousOrderAnnotatedItem = new MutableAnnotatedItem(Order.class, orderXmlAnnotations);
ComponentInstance<Order> order = new ComponentInstanceImpl<Order>(new ClassAnnotatedItem(Order.class), currentSynchronousOrderAnnotatedItem, container);
- assert Production.class.equals(order.getComponentType().annotationType());
+ assert Production.class.equals(order.getDeploymentType().annotationType());
assert "currentSynchronousOrder".equals(order.getName());
assert order.getBindingTypes().size() == 2;
assert annotationSetMatches(order.getBindingTypes(), Current.class, Synchronous.class);
@@ -423,7 +423,7 @@
{
ComponentInstance<Gorilla> gorilla = new ComponentInstanceImpl<Gorilla>(new ClassAnnotatedItem(Gorilla.class), emptyAnnotatedItem, container);
assert gorilla.getName() == null;
- assert gorilla.getComponentType().annotationType().equals(Production.class);
+ assert gorilla.getDeploymentType().annotationType().equals(Production.class);
assert gorilla.getBindingTypes().iterator().next().annotationType().equals(Current.class);
assert gorilla.getScopeType().annotationType().equals(RequestScoped.class);
}
16 years, 5 months
[webbeans-commits] Webbeans SVN: r27 - ri/trunk.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 08:14:37 -0400 (Tue, 01 Jul 2008)
New Revision: 27
Modified:
ri/trunk/pom.xml
Log:
move emma version to parent, add webdav wagon
Modified: ri/trunk/pom.xml
===================================================================
--- ri/trunk/pom.xml 2008-07-01 12:13:05 UTC (rev 26)
+++ ri/trunk/pom.xml 2008-07-01 12:14:37 UTC (rev 27)
@@ -60,6 +60,13 @@
</dependencyManagement>
<build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav</artifactId>
+ <version>1.0-beta-2</version>
+ </extension>
+ </extensions>
<pluginManagement>
<plugins>
<plugin>
@@ -71,6 +78,11 @@
<target>1.5</target>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>emma-maven-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>
16 years, 5 months
[webbeans-commits] Webbeans SVN: r26 - ri/trunk.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 08:13:05 -0400 (Tue, 01 Jul 2008)
New Revision: 26
Modified:
ri/trunk/pom.xml
Log:
add distribution management, metadata
Modified: ri/trunk/pom.xml
===================================================================
--- ri/trunk/pom.xml 2008-07-01 11:59:01 UTC (rev 25)
+++ ri/trunk/pom.xml 2008-07-01 12:13:05 UTC (rev 26)
@@ -9,6 +9,27 @@
<version>1.0.0-SNAPSHOT</version>
<name>Web Beans</name>
<url>http://www.seamframework.org/WebBeans</url>
+
+ <description>The reference implementation of JSR 299: Web Beans</description>
+
+ <developers>
+ <developer>
+ <name>Pete Muir</name>
+ <roles>
+ <role>Project Lead</role>
+ </roles>
+ <email>pete.muir(a)jboss.org</email>
+ <organization>JBoss, a division of Red Hat</organization>
+ <url>http://in.relation.to/Bloggers/Pete</url>
+ </developer>
+
+ <developer>
+ <name>Shane Bryzak</name>
+ <organization>JBoss, a division of Red Hat</organization>
+ </developer>
+ </developers>
+
+
<pluginRepositories>
<pluginRepository>
@@ -53,5 +74,45 @@
</plugins>
</pluginManagement>
</build>
+
+ <ciManagement>
+ <system>Hudson</system>
+ <url></url>
+ </ciManagement>
+
+ <issueManagement>
+ <system>JIRA</system>
+ <url>http://jira.jboss.org/browse/WBRI</url>
+ </issueManagement>
+
+ <inceptionYear>2008</inceptionYear>
+
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>http://anonsvn.jboss.org/repos/webbeans</connection>
+ <developerConnection>https://svn.jboss.org/repos/webbeans</developerConnection>
+ <url>http://fisheye.jboss.org/browse/WebBeans</url>
+ </scm>
+
+ <distributionManagement>
+ <repository>
+ <!-- Copy the dist to the local checkout of the JBoss maven2 repo ${maven.repository.root} -->
+ <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xml -->
+ <!-- todo : replace this with direct svn access once the svnkit providers are available -->
+ <id>repository.jboss.org</id>
+ <url>file://${maven.repository.root}</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <url>dav:https://snapshots.jboss.org/maven2</url>
+ </snapshotRepository>
+ </distributionManagement>
</project>
16 years, 5 months
[webbeans-commits] Webbeans SVN: r25 - ri/trunk/webbeans-api/src/main/java/javax/webbeans.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-07-01 07:59:01 -0400 (Tue, 01 Jul 2008)
New Revision: 25
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/ComponentInstance.java
Log:
Change name to deployment type (might be wrong)
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/ComponentInstance.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/ComponentInstance.java 2008-06-30 22:45:56 UTC (rev 24)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/ComponentInstance.java 2008-07-01 11:59:01 UTC (rev 25)
@@ -13,7 +13,7 @@
public abstract Set<Class> getTypes();
public abstract Set<Annotation> getBindingTypes();
public abstract Annotation getScopeType();
- public abstract Annotation getComponentType();
+ public abstract Annotation getDeploymentType();
public abstract String getName();
public abstract T create(Container container);
16 years, 5 months