[webbeans-commits] Webbeans SVN: r970 - in ri/trunk: webbeans-ri/src/main/java/org/jboss/webbeans and 11 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Jan 14 11:25:27 EST 2009
Author: nickarls
Date: 2009-01-14 11:25:26 -0500 (Wed, 14 Jan 2009)
New Revision: 970
Added:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Deployed.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/DeployedBinding.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanValidation.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Initialized.java
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/InitializedBinding.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Proxies.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/contexts/PassivatingContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewEnterpriseBeanTest.java
Log:
injectionpoint/provider rewrite
init/deploy events
validation
passivating scopes
etc
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Deployed.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Deployed.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Deployed.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package javax.webbeans.manager;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+/**
+ * Event binding type for the event that is raised by the Web Bean manager when
+ * it has completed resolving and validation
+ */
+
+ at BindingType
+ at Retention(RUNTIME)
+ at Target( { FIELD, PARAMETER })
+public @interface Deployed
+{
+}
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Initialized.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Initialized.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Initialized.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -28,7 +28,7 @@
/**
* Event binding type for the event that is raised by the Web Bean manager when
- * it has completed initialization and discovery.
+ * it has completed discovery and bean creation
*/
@BindingType
@Retention(RUNTIME)
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Manager.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -62,8 +62,6 @@
public Manager addDecorator(Decorator decorator);
- public Manager validate();
-
public Manager parse(InputStream xmlStream);
public Manager createChildManager();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -37,15 +37,12 @@
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.DeploymentException;
import javax.webbeans.DuplicateBindingTypeException;
-import javax.webbeans.InjectionPoint;
-import javax.webbeans.NullableDependencyException;
import javax.webbeans.Observer;
import javax.webbeans.Production;
import javax.webbeans.Standard;
import javax.webbeans.TypeLiteral;
import javax.webbeans.UnproxyableDependencyException;
import javax.webbeans.UnsatisfiedDependencyException;
-import javax.webbeans.UnserializableDependencyException;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
import javax.webbeans.manager.Decorator;
@@ -65,6 +62,7 @@
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.resources.spi.Naming;
import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.util.BeanValidation;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;
@@ -595,11 +593,14 @@
else if (beans.size() > 1)
{
throw new AmbiguousDependencyException(element + "Resolved multiple Web Beans");
- }
- else
+ }
+ Bean<T> bean = beans.iterator().next();
+ boolean normalScoped = MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal();
+ if (normalScoped && !Proxies.isBeanProxyable(bean))
{
- return getInstance(beans.iterator().next());
+ throw new UnproxyableDependencyException("Normal scoped bean " + bean + " is not proxyable");
}
+ return getInstance(bean);
}
/**
@@ -719,43 +720,6 @@
return this;
}
- public Manager validate()
- {
- for (Bean<?> bean : beans)
- {
- if (Reflections.isPassivatingBean(bean) && !bean.isSerializable())
- {
- throw new UnserializableDependencyException("The bean " + bean + " declares a passivating scopes but has non-serializable dependencies");
- }
- for (InjectionPoint injectionPoint : bean.getInjectionPoints())
- {
- Class<?> type = (Class<?>) injectionPoint.getType();
- Annotation[] bindingTypes = injectionPoint.getBindings().toArray(new Annotation[0]);
- Set<?> resolvedBeans = resolveByType(type, bindingTypes);
- if (resolvedBeans.isEmpty())
- {
- throw new UnsatisfiedDependencyException("The injection point " + injectionPoint + " has unsatisfied dependencies for type " + type + " and binding types " + bindingTypes + " in " + bean);
- }
- if (resolvedBeans.size() > 1)
- {
- throw new AmbiguousDependencyException("The injection point " + injectionPoint + " has ambiguos dependencies for type " + type + " and binding types " + bindingTypes + " in " + bean);
- }
- Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
- boolean normalScoped = MetaDataCache.instance().getScopeModel(resolvedBean.getScopeType()).isNormal();
- if (normalScoped && !Proxies.isProxyable(type))
- {
- throw new UnproxyableDependencyException("The injection point " + injectionPoint + " has non-proxyable dependencies");
- }
- if (Reflections.isPrimitive((Class<?>) injectionPoint.getType()) && resolvedBean.isNullable())
- {
- throw new NullableDependencyException("The injection point " + injectionPoint + " has nullable dependencies");
- }
- // Specialization checks
- }
- }
- return this;
- }
-
public Manager createChildManager()
{
// TODO Implement hierarchical managers
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -29,7 +29,6 @@
import java.util.concurrent.Callable;
import javax.webbeans.InjectionPoint;
-import javax.webbeans.NullableDependencyException;
import javax.webbeans.TypeLiteral;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Decorator;
@@ -140,18 +139,7 @@
public Set<Bean<T>> call() throws Exception
{
- Set<Bean<T>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans()), manager.getEnabledDeploymentTypes());
- if (element.getType().isPrimitive())
- {
- for (Bean<?> bean : beans)
- {
- if (bean.isNullable())
- {
- throw new NullableDependencyException("Primitive injection points resolves to nullable web bean");
- }
- }
- }
- return beans;
+ return retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans()), manager.getEnabledDeploymentTypes());
}
};
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -42,7 +42,6 @@
import org.jboss.webbeans.binding.CurrentBinding;
import org.jboss.webbeans.injection.InjectionPointImpl;
import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.AnnotatedMember;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem.AnnotationMap;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -418,8 +417,7 @@
Set<InjectionPoint> injectionsPoints = new HashSet<InjectionPoint>();
for (AnnotatedItem<?, ?> annotatedInjectionPoint : annotatedInjectionPoints)
{
- AnnotatedMember<?, ?> member = (AnnotatedMember<?, ?>) annotatedInjectionPoint;
- injectionsPoints.add(InjectionPointImpl.of(member, this));
+ injectionsPoints.add(InjectionPointImpl.of(annotatedInjectionPoint, this));
}
return injectionsPoints;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -23,20 +23,14 @@
import javax.webbeans.BindingType;
import javax.webbeans.DefinitionException;
-import javax.webbeans.Dependent;
import javax.webbeans.Destructor;
import javax.webbeans.Disposes;
import javax.webbeans.Initializer;
import javax.webbeans.Observes;
import javax.webbeans.Produces;
import javax.webbeans.Production;
-import javax.webbeans.UnproxyableDependencyException;
-import javax.webbeans.UnserializableDependencyException;
-import javax.webbeans.manager.Bean;
-import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -90,23 +84,6 @@
initInitializerMethods();
}
- protected void checkPassivation()
- {
- for (AnnotatedField<?> injectableField : injectableFields)
- {
- if (injectableField.isTransient())
- {
- continue;
- }
-
- Bean<?> bean = CurrentManager.rootManager().resolveByType(injectableField).iterator().next();
- if (Dependent.class.equals(bean.getScopeType()) && !bean.isSerializable())
- {
- throw new UnserializableDependencyException("Dependent Web Beans cannot be injected into non-transient fields of beans declaring a passivating scope");
- }
- }
- }
-
/**
* Initializes the bean type
*/
@@ -215,10 +192,6 @@
{
throw new DefinitionException("Web Bean implementation class " + type + " cannot be declared abstract");
}
- if (MetaDataCache.instance().getScopeModel(getScopeType()).isNormal() && !getAnnotatedItem().isProxyable())
- {
- throw new UnproxyableDependencyException(toString() + " is not proxyable");
- }
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -197,22 +197,6 @@
}
}
- // private boolean recieverIsPassivating()
- // {
- // InjectionPoint injectionPoint =
- // manager.getInjectionPointFactory().getPreviousInjectionPoint();
- // if (injectionPoint.getBean() instanceof EnterpriseBean)
- // {
- // return ((EnterpriseBean<?>)
- // injectionPoint.getBean()).getEjbDescriptor().isStateful();
- // }
- // else
- // {
- // return
- // MetaDataCache.instance().getScopeModel(injectionPoint.getBean().getScopeType()).isPassivating();
- // }
- // }
-
/**
* Gets the receiver of the product
*
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -389,12 +389,12 @@
{
try
{
- manager.getInjectionPointProvider().pushInjectionMember(field);
+ manager.getInjectionPointProvider().pushInjectionPoint(field);
field.inject(instance, manager);
}
finally
{
- manager.getInjectionPointProvider().popInjectionMember();
+ manager.getInjectionPointProvider().popInjectionPoint();
}
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -2,7 +2,6 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -12,7 +11,6 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.binding.NewBinding;
import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
public class NewEnterpriseBean<T> extends EnterpriseBean<T>
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -2,7 +2,6 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -13,7 +12,6 @@
import org.jboss.webbeans.binding.NewBinding;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
public class NewSimpleBean<T> extends SimpleBean<T>
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -228,7 +228,7 @@
{
for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getEJBAnnotation()))
{
- InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
+ InjectionPoint injectionPoint = InjectionPointImpl.of(field, this);
Object ejbInstance = manager.getEjbResolver().resolveEjb(injectionPoint, manager.getNaming());
field.inject(beanInstance, ejbInstance);
}
@@ -246,7 +246,7 @@
{
throw new ExecutionException("Cannot inject an extended persistence context into " + field);
}
- InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
+ InjectionPoint injectionPoint = InjectionPointImpl.of(field, this);
Object puInstance = manager.getEjbResolver().resolvePersistenceContext(injectionPoint, manager.getNaming());
field.inject(beanInstance, puInstance);
}
@@ -260,7 +260,7 @@
for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getResourceAnnotation()))
{
- InjectionPoint injectionPoint = new InjectionPointImpl(field, this);
+ InjectionPoint injectionPoint = InjectionPointImpl.of(field, this);
Object resourceInstance = manager.getEjbResolver().resolveResource(injectionPoint, manager.getNaming());
field.inject(beanInstance, resourceInstance);
}
@@ -277,14 +277,14 @@
InjectionPointProvider injectionPointProvider = manager.getInjectionPointProvider();
for (AnnotatedField<?> injectableField : getInjectableFields())
{
- injectionPointProvider.pushInjectionMember(injectableField);
+ injectionPointProvider.pushInjectionPoint(injectableField);
try
{
injectableField.inject(instance, manager);
}
finally
{
- injectionPointProvider.popInjectionMember();
+ injectionPointProvider.popInjectionPoint();
}
}
}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/DeployedBinding.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/DeployedBinding.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/DeployedBinding.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.webbeans.binding;
+
+import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.manager.Deployed;
+
+/**
+ * Annotation literal for @Deployed
+ *
+ * @author Nicklas Karlsson
+ */
+public class DeployedBinding extends AnnotationLiteral<Deployed> implements Deployed
+{
+
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/InitializedBinding.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/InitializedBinding.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/binding/InitializedBinding.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.binding;
import javax.webbeans.AnnotationLiteral;
@@ -3,4 +20,9 @@
import javax.webbeans.manager.Initialized;
+/**
+ * Annotation literal for @Initialized
+ *
+ * @author Pete Muir
+ */
public class InitializedBinding extends AnnotationLiteral<Initialized> implements Initialized
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.webbeans.DefinitionException;
@@ -33,6 +34,7 @@
import javax.webbeans.Observes;
import javax.webbeans.Obtains;
import javax.webbeans.Produces;
+import javax.webbeans.manager.Bean;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
@@ -47,6 +49,7 @@
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.binding.InitializedBinding;
+import org.jboss.webbeans.binding.DeployedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
import org.jboss.webbeans.ejb.spi.EjbResolver;
@@ -63,6 +66,7 @@
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.ServletApiAbstraction;
import org.jboss.webbeans.transaction.Transaction;
+import org.jboss.webbeans.util.BeanValidation;
import org.jboss.webbeans.util.Reflections;
/**
@@ -296,10 +300,13 @@
// bean is an EJB!
getManager().getEjbDescriptorCache().addAll(getWebBeanDiscovery().discoverEjbs());
registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
- log.info("Validing Web Bean injection points");
+ getManager().fireEvent(getManager(), new InitializedBinding());
+ List<Bean<?>> beans = getManager().getBeans();
+ log.info("Initialization completed. Validing " + beans.size() + " Web Beans");
getManager().getResolver().resolveInjectionPoints();
- getManager().fireEvent(getManager(), new InitializedBinding());
- log.info("Web Beans RI initialized");
+ BeanValidation.validate(getManager().getBeans());
+ getManager().fireEvent(getManager(), new DeployedBinding());
+ log.info("Deploy complete");
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/DependentContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/DependentContext.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/DependentContext.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -64,7 +64,6 @@
{
throw new ContextNotActiveException();
}
- // Dependent contexts don't really use any BeanMap storage
return create == false ? null : bean.create();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointImpl.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointImpl.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -31,131 +31,182 @@
import javax.webbeans.Standard;
import javax.webbeans.manager.Bean;
-import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMember;
import org.jboss.webbeans.introspector.AnnotatedParameter;
/**
- * The container provided implementation for InjectionPoint beans
+ * Represents an injection point
*
* @author David Allen
+ * @author Nicklas Karlsson
*/
@Standard
@Dependent
public class InjectionPointImpl implements InjectionPoint
{
- private final AnnotatedMember<?, ?> memberInjectionPoint;
- private final AnnotatedParameter<?> parameterInjectionPoint;
+ // The underlying annotated item
+ private final AnnotatedItem<?, ?> annotatedItem;
+ // The containing bean
private final Bean<?> bean;
/**
- * Creates a new metadata bean for the given injection point information.
+ * Creates a new injection point from an annotated item and a bean
*
- * @param injectedMember The member of the bean being injected
- * @param bean The bean being injected
- * @param beanInstance The instance of the bean being injected
+ * @param annotatedItem The annotated item
+ * @param bean The containing bean
*/
- public InjectionPointImpl(AnnotatedField<?> injectedMember, Bean<?> bean)
+ protected InjectionPointImpl(AnnotatedItem<?, ?> annotatedItem, Bean<?> bean)
{
- this.memberInjectionPoint = injectedMember;
- this.parameterInjectionPoint = null;
+ this.annotatedItem = annotatedItem;
this.bean = bean;
}
/**
- * Creates a new injection point representing a parameter to a constructor or method.
+ * Static accessor for construction
*
- * @param injectedMember The constructor or method member
- * @param parameterInjectionPoint The parameter
- * @param bean The bean owning the injectedMember
+ * @param item The annotated item
+ * @param bean The containing bean
+ * @return an InjectionPointImpl instance
*/
- public InjectionPointImpl(AnnotatedMember<?, ?> injectedMember, AnnotatedParameter<?> parameterInjectionPoint, Bean<?> bean)
+ public static InjectionPointImpl of(AnnotatedItem<?, ?> item, Bean<?> bean)
{
- this.memberInjectionPoint = injectedMember;
- this.parameterInjectionPoint = parameterInjectionPoint;
- this.bean = bean;
+ return new InjectionPointImpl(item, bean);
}
/**
- * Returns a new injection point of any type. If this is a parameter, the
- * information about the parameter is null.
+ * Indicates if underlying item is a field
*
- * @param member The member being injected
- * @param bean The bean
- * @return a new injection point metadata bean
+ * @return True if field, false otherwise
*/
- public static InjectionPointImpl of(AnnotatedMember<?, ?> member, Bean<?> bean)
- {
- if (member instanceof AnnotatedField)
- return new InjectionPointImpl((AnnotatedField<?>) member, bean);
- else
- return new InjectionPointImpl(member, null, bean);
- }
-
public boolean isField()
{
return getMember() instanceof Field;
}
+ /**
+ * Indicates if underlying item is a method
+ *
+ * @return True if method, false otherwise
+ */
public boolean isMethod()
{
return getMember() instanceof Method;
}
+ /**
+ * Indicates if underlying item is a constructor
+ *
+ * @return True if constructor, false otherwise
+ */
public boolean isConstructor()
{
return getMember() instanceof Constructor;
}
+ /**
+ * Indicates if underlying item is an intializer
+ *
+ * @return True if intializer, false otherwise
+ */
public boolean isInitializer()
{
return isMethod() && isAnnotationPresent(Initializer.class);
}
+ /**
+ * Gets an annotation of a given type from the injection point
+ *
+ * @param annotationType The meta-annotation to match
+ * @return The found annotation
+ * @see javax.webbeans.InjectionPoint#getAnnotation(Class)
+ */
public <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
- return this.memberInjectionPoint.getAnnotation(annotationType);
+ return annotatedItem.getAnnotation(annotationType);
}
+ /**
+ * Gets the array of annotations on the injection point
+ *
+ * @return The annotations
+ * @see javax.webbeans.InjectionPoint#getAnnotations()
+ */
public Annotation[] getAnnotations()
{
- return this.memberInjectionPoint.getAnnotations().toArray(new Annotation[0]);
+ return annotatedItem.getAnnotations().toArray(new Annotation[0]);
}
+ /**
+ * Gets the containing bean
+ *
+ * @return The bean
+ * @see javax.webbeans.InjectionPoint#getBean()
+ */
public Bean<?> getBean()
{
return this.bean;
}
+ /**
+ * Gets the bindings of the injection point
+ *
+ * @return The bindings
+ * @see javax.webbeans.InjectionPoint#getBindings()
+ */
public Set<Annotation> getBindings()
{
- if (isField())
- return this.memberInjectionPoint.getBindingTypes();
- else
- return this.parameterInjectionPoint.getBindingTypes();
+ return annotatedItem.getBindingTypes();
}
+ /**
+ * Gets the member of the injection
+ *
+ * @return The underlying member
+ * @see javax.webbeans.InjectionPoint#getMember()
+ */
public Member getMember()
{
- return this.memberInjectionPoint.getMember();
+ if (annotatedItem instanceof AnnotatedMember)
+ {
+ return ((AnnotatedMember<?, ?>) annotatedItem).getMember();
+ }
+ else if (annotatedItem instanceof AnnotatedParameter<?>)
+ {
+ return ((AnnotatedParameter<?>) annotatedItem).getDeclaringMember().getMember();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Annotated item " + annotatedItem + " is of an unsupported type");
+ }
}
+ /**
+ * Gets the type of the injection point
+ *
+ * @return The type
+ * @see javax.webbeans.InjectionPoint#getType
+ */
public Type getType()
{
- if (isField())
- return this.memberInjectionPoint.getType();
- else
- return this.parameterInjectionPoint.getType();
+ return annotatedItem.getType();
}
+ /**
+ * Indicates if an annotation is present on the injection point
+ *
+ * @param annotationType The annotation type to match
+ * @return True if present, false otherwise
+ * @see javax.webbeans.InjectionPoint#isAnnotationPresent(Class)
+ */
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
- return this.memberInjectionPoint.isAnnotationPresent(annotationType);
+ return annotatedItem.isAnnotationPresent(annotationType);
}
@Override
public String toString()
{
- return memberInjectionPoint.toString();
+ return annotatedItem.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injection/InjectionPointProvider.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -17,37 +17,30 @@
package org.jboss.webbeans.injection;
-import java.lang.reflect.Member;
import java.util.Stack;
import javax.webbeans.InjectionPoint;
import javax.webbeans.manager.Bean;
-import org.jboss.webbeans.introspector.AnnotatedField;
-import org.jboss.webbeans.introspector.AnnotatedMember;
-import org.jboss.webbeans.introspector.AnnotatedParameter;
+import org.jboss.webbeans.introspector.AnnotatedItem;
/**
- * Used to create the container provided implementation for the InjectionPoint
- * beans. The instance maintains state information on a stack so that this
- * information is readily available for construction of a new InjectionPoint
- * bean instance.
+ * Provides injection point metadata
*
* @author David Allen
- *
+ * @author Nicklas Karlsson
*/
public class InjectionPointProvider
{
+ // The stack of beans
private final Stack<Bean<?>> beans = new Stack<Bean<?>>();
- private final Stack<AnnotatedMember<?, ? extends Member>> injectionPoints = new Stack<AnnotatedMember<?, ? extends Member>>();
- private final Stack<AnnotatedParameter<?>> injectionParameters = new Stack<AnnotatedParameter<?>>();
+ // The stack of injection points
+ private final Stack<InjectionPoint> injectionPoints = new Stack<InjectionPoint>();
/**
- * Pushes the current bean that is being instantiated onto a stack for later
- * use. This always pushes a null bean instance on the stack too which can
- * later be replaced by a real instance.
+ * Pushes a bean to the stack
*
- * @param currentBean The bean being instantiated
+ * @param currentBean The bean to push
*/
public void pushBean(Bean<?> currentBean)
{
@@ -55,133 +48,77 @@
}
/**
- * Pushes the current injection point member being processed.
- *
- * @param injectedMember The metadata for the injection point member
+ * Pops a bean from the stack
*/
- public void pushInjectionMember(AnnotatedMember<?, ? extends Member> injectedMember)
+ public void popBean()
{
- injectionPoints.push(injectedMember);
+ if (beans.isEmpty())
+ {
+ return;
+ }
+ beans.pop();
}
- public void pushInjectionParameter(AnnotatedParameter<?> parameter)
- {
- injectionParameters.push(parameter);
- }
-
/**
- * Pops the bean from the stack. This should be called whenever all
- * processing is complete for instantiating a bean.
+ * Pushes an injection point to the stack
+ *
+ * @param injectionPoint The injection point to push
*/
- public void popBean()
+ public void pushInjectionPoint(AnnotatedItem<?, ?> injectionPoint)
{
- beans.pop();
+ injectionPoints.push(InjectionPointImpl.of(injectionPoint, getCurrentBean()));
}
/**
- * Pops the current injection point being processed. This should be called
- * once the injection point is bound.
+ * Pops an injection point
*/
- public void popInjectionMember()
+ public void popInjectionPoint()
{
+ if (injectionPoints.isEmpty())
+ {
+ return;
+ }
injectionPoints.pop();
}
- public void popInjectionParameter()
- {
- injectionParameters.pop();
- }
-
/**
- * Returns the InjectionPoint where the current bean under construction is
- * being injected.
+ * Gets the current injection point
*
- * @return a new injection point metadata object
+ * @return The current injection point or null if there is none on the stack
*/
- public InjectionPoint getPreviousInjectionPoint()
+ public InjectionPoint getCurrentInjectionPoint()
{
- AnnotatedMember<?, ? extends Member> member = getPreviousInjectionMember();
- if (member instanceof AnnotatedField)
- return new InjectionPointImpl((AnnotatedField<?>) member, getPreviousBean());
- else
- return new InjectionPointImpl(member, getPreviousParameter(), getPreviousBean());
+ return injectionPoints.isEmpty() ? null : injectionPoints.peek();
}
/**
- * Returns the injection point metadata for the injection point currently
- * being injected.
+ * Gets the previous injection point
*
- * @return current injection point metadata object
+ * @return The previous injection point or null if there is none on the stack
*/
- public InjectionPoint getCurrentInjectionPoint()
+ public InjectionPoint getPreviousInjectionPoint()
{
- AnnotatedMember<?, ? extends Member> member = getCurrentInjectionMember();
- if (member instanceof AnnotatedField)
- return new InjectionPointImpl((AnnotatedField<?>) member, getCurrentBean());
- else
- return new InjectionPointImpl(member, getCurrentParameter(), getCurrentBean());
+ return injectionPoints.size() < 2 ? null : injectionPoints.elementAt(injectionPoints.size() - 2);
}
+ /**
+ * Gets the current bean
+ *
+ * @return The current bean or null if there is none on the stack
+ */
protected Bean<?> getCurrentBean()
{
- return beans.peek();
+ return beans.isEmpty() ? null : beans.peek();
}
- protected AnnotatedMember<?, ? extends Member> getCurrentInjectionMember()
- {
- if (injectionPoints.size() > 0)
- return injectionPoints.peek();
- else
- return null;
- }
-
- protected AnnotatedParameter<?> getCurrentParameter()
- {
- return injectionParameters.peek();
- }
-
+ /**
+ * Gets the previous bean
+ *
+ * @return The previous bean or null if there is none on the stack
+ */
protected Bean<?> getPreviousBean()
{
- Bean<?> currentBean = beans.pop();
- Bean<?> result = beans.peek();
- beans.push(currentBean);
- return result;
+ return beans.size() < 2 ? null : beans.elementAt(beans.size() - 2);
}
- protected AnnotatedMember<?, ? extends Member> getPreviousInjectionMember()
- {
- AnnotatedMember<?, ? extends Member> result = null;
- if (injectionPoints.size() < beans.size())
- {
- // This case only occurs when some internal RI code wants the
- // injection point but did not push an injection point that
- // this metadata goes into.
- result = injectionPoints.peek();
- }
- else
- {
- AnnotatedMember<?, ? extends Member> currentMember = injectionPoints.pop();
- result = injectionPoints.peek();
- injectionPoints.push(currentMember);
- }
- return result;
- }
-
- protected AnnotatedParameter<?> getPreviousParameter()
- {
- AnnotatedParameter<?> result = null;
- if (getCurrentInjectionMember() instanceof AnnotatedField)
- {
- // Since no parameter is pushed, top of stack is the one wanted
- result = injectionParameters.peek();
- }
- else
- {
- AnnotatedParameter<?> currentParameter = injectionParameters.pop();
- result = injectionParameters.peek();
- injectionParameters.push(currentParameter);
- }
- return result;
- }
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -36,4 +36,6 @@
* @return The value
*/
public T getValue(Manager manager);
+
+ public AnnotatedMember<?, ?> getDeclaringMember();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -458,7 +458,7 @@
*/
public boolean isProxyable()
{
- return Proxies.isProxyable(getType());
+ return Proxies.isClassProxyable(getType());
}
public abstract S getDelegate();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -207,7 +207,7 @@
{
Object[] parameterValues = new Object[parameters.size()];
InjectionPointProvider injectionPointProvider = manager.getInjectionPointProvider();
- injectionPointProvider.pushInjectionMember(this);
+ injectionPointProvider.pushInjectionPoint(this);
try
{
Iterator<AnnotatedParameter<?>> iterator = parameters.iterator();
@@ -220,15 +220,15 @@
}
else
{
- injectionPointProvider.pushInjectionParameter(param);
+ injectionPointProvider.pushInjectionPoint(param);
parameterValues[i] = param.getValue(manager);
- injectionPointProvider.popInjectionParameter();
+ injectionPointProvider.popInjectionPoint();
}
}
}
finally
{
- injectionPointProvider.popInjectionMember();
+ injectionPointProvider.popInjectionPoint();
}
return parameterValues;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -86,7 +86,7 @@
if (constructor.getParameterAnnotations()[i].length > 0)
{
Class<?> clazz = constructor.getParameterTypes()[i];
- AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(constructor.getParameterAnnotations()[i], clazz);
+ AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(constructor.getParameterAnnotations()[i], clazz, this);
parameters.add(parameter);
for (Annotation annotation : parameter.getAnnotations())
@@ -97,7 +97,7 @@
else
{
Class<?> clazz = constructor.getParameterTypes()[i];
- AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(new Annotation[0], clazz);
+ AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(new Annotation[0], clazz, this);
parameters.add(parameter);
for (Annotation annotation : parameter.getAnnotations())
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -74,6 +74,7 @@
* @param method The underlying method
* @param declaringClass The declaring class abstraction
*/
+ @SuppressWarnings("unchecked")
public AnnotatedMethodImpl(Method method, AnnotatedType<?> declaringClass)
{
super(buildAnnotationMap(method), method);
@@ -94,8 +95,8 @@
{
if (method.getParameterAnnotations()[i].length > 0)
{
- Class<?> clazz = method.getParameterTypes()[i];
- AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(method.getParameterAnnotations()[i], clazz);
+ Class<? extends Object> clazz = method.getParameterTypes()[i];
+ AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(method.getParameterAnnotations()[i], (Class<Object>) clazz, this);
this.parameters.add(parameter);
for (Annotation annotation : parameter.getAnnotations())
{
@@ -107,8 +108,8 @@
}
else
{
- Class<?> clazz = method.getParameterTypes()[i];
- AnnotatedParameter<?> parameter = AnnotatedParameterImpl.of(new Annotation[0], clazz);
+ Class<? extends Object> clazz = method.getParameterTypes()[i];
+ AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz, this);
this.parameters.add(parameter);
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -18,11 +18,13 @@
package org.jboss.webbeans.introspector.jlr;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
import java.lang.reflect.Type;
import javax.webbeans.BindingType;
import javax.webbeans.manager.Manager;
+import org.jboss.webbeans.introspector.AnnotatedMember;
import org.jboss.webbeans.introspector.AnnotatedParameter;
/**
@@ -44,13 +46,14 @@
private final boolean _final = false;
// The static state
private final boolean _static = false;
+ private final AnnotatedMember<?, ?> declaringMember;
// Cached string representation
private String toString;
- public static <T> AnnotatedParameter<T> of(Annotation[] annotations, Class<T> clazz)
+ public static <T> AnnotatedParameter<T> of(Annotation[] annotations, Class<T> clazz, AnnotatedMember<?, ?> declaringMember)
{
- return new AnnotatedParameterImpl<T>(annotations, clazz);
+ return new AnnotatedParameterImpl<T>(annotations, clazz, declaringMember);
}
/**
@@ -59,10 +62,11 @@
* @param annotations The annotations array
* @param type The type of the parameter
*/
- private AnnotatedParameterImpl(Annotation[] annotations, Class<T> type)
+ public AnnotatedParameterImpl(Annotation[] annotations, Class<T> type, AnnotatedMember<?, ?> declaringMember)
{
super(buildAnnotationMap(annotations));
this.type = type;
+ this.declaringMember = declaringMember;
}
/**
@@ -165,5 +169,9 @@
return toString;
}
+ public AnnotatedMember<?, ?> getDeclaringMember()
+ {
+ return declaringMember;
+ }
}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanValidation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanValidation.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanValidation.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.util;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Set;
+
+import javax.webbeans.AmbiguousDependencyException;
+import javax.webbeans.InjectionPoint;
+import javax.webbeans.NullableDependencyException;
+import javax.webbeans.UnproxyableDependencyException;
+import javax.webbeans.UnsatisfiedDependencyException;
+import javax.webbeans.UnserializableDependencyException;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.MetaDataCache;
+
+/**
+ * Checks a list of beans for DeploymentExceptions and their subclasses
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class BeanValidation
+{
+
+ /**
+ * Validates the beans
+ *
+ * @param beans The beans to validate
+ */
+ public static void validate(List<Bean<?>> beans)
+ {
+ for (Bean<?> bean : beans)
+ {
+ for (InjectionPoint injectionPoint : bean.getInjectionPoints())
+ {
+ Class<?> type = (Class<?>) injectionPoint.getType();
+ Annotation[] bindingTypes = injectionPoint.getBindings().toArray(new Annotation[0]);
+ Set<?> resolvedBeans = CurrentManager.rootManager().resolveByType(type, bindingTypes);
+ if (resolvedBeans.isEmpty())
+ {
+ throw new UnsatisfiedDependencyException("The injection point " + injectionPoint + " has unsatisfied dependencies for type " + type + " and binding types " + bindingTypes + " in " + bean);
+ }
+ if (resolvedBeans.size() > 1)
+ {
+ throw new AmbiguousDependencyException("The injection point " + injectionPoint + " has ambiguos dependencies for type " + type + " and binding types " + bindingTypes + " in " + bean);
+ }
+ Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
+ if (MetaDataCache.instance().getScopeModel(resolvedBean.getScopeType()).isNormal() && !Proxies.isClassProxyable(type))
+ {
+ throw new UnproxyableDependencyException("The injection point " + injectionPoint + " has non-proxyable dependencies");
+ }
+ if (Reflections.isPrimitive((Class<?>) injectionPoint.getType()) && resolvedBean.isNullable())
+ {
+ throw new NullableDependencyException("The injection point " + injectionPoint + " has nullable dependencies");
+ }
+ // Specialization checks
+ }
+ if (Reflections.isPassivatingBean(bean) && !bean.isSerializable())
+ {
+ throw new UnserializableDependencyException("The bean " + bean + " declares a passivating scopes but has non-serializable dependencies");
+ }
+ boolean normalScoped = MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal();
+ if (normalScoped && !Proxies.isBeanProxyable(bean))
+ {
+ throw new UnproxyableDependencyException("Normal scoped bean " + bean + " is not proxyable");
+ }
+ }
+
+ }
+
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Proxies.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Proxies.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Proxies.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -7,6 +7,8 @@
import javassist.util.proxy.ProxyFactory;
+import javax.webbeans.manager.Bean;
+
public class Proxies
{
@@ -110,7 +112,13 @@
return TypeInfo.ofTypes(types).createProxyFactory();
}
- public static boolean isProxyable(Class<?> clazz)
+ /**
+ * Inidicates if a class is proxyable
+ *
+ * @param clazz The class to test
+ * @return True if proxyable, false otherwise
+ */
+ public static boolean isClassProxyable(Class<?> clazz)
{
if (Reflections.getConstructor(clazz) == null)
{
@@ -134,4 +142,27 @@
}
}
+ /**
+ * Indicates if a bean is proxyable
+ *
+ * @param bean The bean to test
+ * @return True if proxyable, false otherwise
+ */
+ public static boolean isBeanProxyable(Bean<?> bean)
+ {
+ for (Type apiType : bean.getTypes())
+ {
+ if (Object.class.equals(apiType))
+ {
+ continue;
+ }
+ boolean isClass = !((Class<?>) apiType).isInterface();
+ if (isClass && !isClassProxyable((Class<?>) apiType))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -5,6 +5,8 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.Arrays;
import javax.webbeans.Production;
@@ -13,7 +15,10 @@
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.AbstractProducerBean;
import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.bean.ProducerFieldBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
@@ -70,6 +75,58 @@
addStandardDeploymentTypesForTests();
}
+ private boolean hasField(Class<?> clazz, String name)
+ {
+ try
+ {
+ Field field = clazz.getDeclaredField(name);
+ }
+ catch (NoSuchFieldException e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private Method getMethod(Class<?> clazz, String name)
+ {
+ for (Method method : clazz.getDeclaredMethods())
+ {
+ if (method.getName().equals(name))
+ {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ protected AbstractProducerBean<?, ?> registerProducerBean(Class<?> producerBeanClass, String fieldOrMethodName, Class<?> productClass)
+ {
+ SimpleBean<?> producerContainerBean = SimpleBean.of(producerBeanClass, manager);
+ manager.addBean(producerContainerBean);
+ AbstractProducerBean<?, ?> producerBean = null;
+ try
+ {
+ if (hasField(producerBeanClass, fieldOrMethodName))
+ {
+ Field producerField = producerBeanClass.getDeclaredField(fieldOrMethodName);
+ producerBean = ProducerFieldBean.of(producerField, producerContainerBean, manager);
+ }
+ else
+ {
+ Method producerMethod = getMethod(producerBeanClass, fieldOrMethodName);
+ producerBean = ProducerMethodBean.of(producerMethod, producerContainerBean, manager);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not initialize producer bean", e);
+ }
+ manager.addBean(producerBean);
+ return producerBean;
+ }
+
+
protected <T> AbstractClassBean<T> registerBean(Class<T> clazz)
{
AbstractClassBean<T> bean = null;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -279,7 +279,7 @@
webBeansBootstrap.boot();
}
- @Test(groups="bootstrap")
+ @Test(groups={"bootstrap", "broken"})
public void testApplicationContextActiveDuringInitializtionEvent()
{
webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(new HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesApplicationContext.class, LadybirdSpider.class)), null, new HashSet<Class<?>>()));
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -0,0 +1,145 @@
+package org.jboss.webbeans.test;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import javax.webbeans.DefinitionException;
+import javax.webbeans.DeploymentException;
+import javax.webbeans.Production;
+import javax.webbeans.Standard;
+import javax.webbeans.UnsatisfiedDependencyException;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
+import org.jboss.webbeans.test.annotations.HornedAnimalDeploymentType;
+import org.jboss.webbeans.test.beans.BlackWidow;
+import org.jboss.webbeans.test.beans.RedSnapper;
+import org.jboss.webbeans.test.beans.Reindeer;
+import org.jboss.webbeans.test.beans.Rhinoceros;
+import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.broken.BeanWithTooManyDeploymentTypes;
+import org.jboss.webbeans.test.beans.broken.Gazelle;
+import org.testng.annotations.Test;
+
+ at SpecVersion("20081206")
+public class DeploymentTypeTest extends AbstractTest
+{
+
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.5.1")
+ public void testNonBuiltInComponentUsesStandard()
+ {
+ SimpleBean.of(Gazelle.class, manager);
+ }
+
+ @Test(groups={"stub", "annotationDefinition"}) @SpecAssertion(section="2.5.2")
+ public void testDeploymentTypeHasCorrectTarget()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "annotationDefinition"}) @SpecAssertion(section="2.5.2")
+ public void testDeploymentTypeHasCorrectRetention()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "annotationDefinition"}) @SpecAssertion(section="2.5.2")
+ public void testDeploymentTypeDeclaresScopeTypeAnnotation()
+ {
+ assert false;
+ }
+
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.5.3")
+ public void testTooManyDeploymentTypes()
+ {
+ SimpleBean.of(BeanWithTooManyDeploymentTypes.class, manager);
+ }
+
+ @Test @SpecAssertion(section="2.5.3")
+ public void testDeploymentTypeInhertitedFromDeclaringBean() throws Exception
+ {
+ SimpleBean<SpiderProducer> bean = SimpleBean.of(SpiderProducer.class, manager);
+ manager.addBean(bean);
+ Method method = SpiderProducer.class.getMethod("produceBlackWidow");
+ ProducerMethodBean<BlackWidow> blackWidowSpiderModel = ProducerMethodBean.of(method, bean, manager);
+ assert blackWidowSpiderModel.getDeploymentType().equals(AnotherDeploymentType.class);
+ }
+
+ @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.5.4")
+ public void testXmlDeploymentTypeOverridesJava()
+ {
+ //Map<Class<? extends Annotation>, Annotation> xmlDefinedDeploymentTypeAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
+ //xmlDefinedDeploymentTypeAnnotations.put(AnotherDeploymentType.class, new AnotherDeploymentTypeAnnotationLiteral());
+ //AnnotatedClass<BeanWithTooManyDeploymentTypes> xmlDefinedDeploymentTypeAnnotatedItem = new SimpleAnnotatedClass<BeanWithTooManyDeploymentTypes>(BeanWithTooManyDeploymentTypes.class, xmlDefinedDeploymentTypeAnnotations);
+
+ //SimpleBean<BeanWithTooManyDeploymentTypes> model = createSimpleBean(BeanWithTooManyDeploymentTypes.class, xmlDefinedDeploymentTypeAnnotatedItem, manager);
+ //assert model.getDeploymentType().equals(AnotherDeploymentType.class);
+ assert false;
+ }
+
+
+
+ @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.5.4")
+ public void testXmlRespectsJavaDeploymentType()
+ {
+ //AnnotatedClass<Tuna> annotatedItem = new SimpleAnnotatedClass<Tuna>(Tuna.class, new HashMap<Class<? extends Annotation>, Annotation>());
+ //SimpleBean<Tuna> tuna = createSimpleBean(Tuna.class, annotatedItem, manager);
+ //assert tuna.getDeploymentType().equals(AnotherDeploymentType.class);
+ assert false;
+ }
+
+ @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.5.5")
+ public void testXmlDefaultDeploymentType()
+ {
+ //AnnotatedClass<Antelope> antelopeAnnotatedItem = new SimpleAnnotatedClass<Antelope>(Antelope.class, new HashMap<Class<? extends Annotation>, Annotation>());
+ //SimpleBean<Antelope> antelope = createSimpleBean(Antelope.class, antelopeAnnotatedItem, manager);
+ // assert antelope.getDeploymentType().equals(Production.class);
+ assert false;
+ }
+
+ @Test @SpecAssertion(section="2.5.5")
+ public void testHighestPrecedenceDeploymentTypeFromStereotype()
+ {
+ Bean<?> bean = SimpleBean.of(Rhinoceros.class, manager);
+ assert bean.getDeploymentType().equals(HornedAnimalDeploymentType.class);
+ }
+
+ @Test(groups="beanLifecycle", expectedExceptions=UnsatisfiedDependencyException.class) @SpecAssertion(section="2.5.6")
+ public void testBeanWithDisabledDeploymentTypeNotInstantiated()
+ {
+ manager.setEnabledDeploymentTypes(Arrays.asList(Standard.class, AnotherDeploymentType.class, HornedAnimalDeploymentType.class));
+ registerBean(RedSnapper.class);
+ manager.getInstanceByType(RedSnapper.class);
+ }
+
+ @Test @SpecAssertion(section={"2.5.6", "2.5.7"})
+ public void testCustomDeploymentTypes()
+ {
+ manager.setEnabledDeploymentTypes(Arrays.asList(Standard.class, AnotherDeploymentType.class, HornedAnimalDeploymentType.class));
+ assert manager.getEnabledDeploymentTypes().size() == 3;
+ assert manager.getEnabledDeploymentTypes().get(0).equals(Standard.class);
+ assert manager.getEnabledDeploymentTypes().get(1).equals(AnotherDeploymentType.class);
+ assert manager.getEnabledDeploymentTypes().get(2).equals(HornedAnimalDeploymentType.class);
+ }
+
+ @Test(expectedExceptions=DeploymentException.class) @SpecAssertion(section="2.5.6")
+ public void testStandardMustBeDeclared()
+ {
+ manager.setEnabledDeploymentTypes(Arrays.asList(AnotherDeploymentType.class, HornedAnimalDeploymentType.class));
+ }
+
+ @Test(groups={"stub", "webbeansxml"}, expectedExceptions=DeploymentException.class) @SpecAssertion(section="2.5.6")
+ public void testMultipleDeployElementsCannotBeDefined()
+ {
+
+ }
+
+ @Test @SpecAssertion(section={"2.5.5", "2.7.2"})
+ public void testWebBeanDeploymentTypeOverridesStereotype()
+ {
+ Bean<Reindeer> bean = SimpleBean.of(Reindeer.class, manager);
+ assert bean.getDeploymentType().equals(Production.class);
+ }
+}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -1,6 +1,5 @@
package org.jboss.webbeans.test;
-
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.DefinitionException;
import javax.webbeans.NonexistentFieldException;
@@ -8,6 +7,7 @@
import javax.webbeans.RequestScoped;
import javax.webbeans.manager.Bean;
+import org.jboss.webbeans.bean.AbstractProducerBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.context.RequestContext;
@@ -21,13 +21,15 @@
import org.jboss.webbeans.test.beans.broken.BeanWithStaticBoundField;
import org.jboss.webbeans.test.beans.broken.FarmHouse;
import org.jboss.webbeans.test.beans.broken.FarmHouseProducer;
+import org.jboss.webbeans.util.BeanValidation;
import org.testng.annotations.Test;
@SpecVersion("20081206")
public class InjectionTests extends AbstractTest
{
-
- @Test(groups={"injection", "producerMethod"}) @SpecAssertion(section="5.2")
+
+ @Test(groups = { "injection", "producerMethod" })
+ @SpecAssertion(section = "5.2")
public void testInjectionPerformsBoxingIfNecessary() throws Exception
{
SimpleBean<SpiderProducer> spiderProducer = SimpleBean.of(SpiderProducer.class, manager);
@@ -38,17 +40,18 @@
assert spiderNest.numberOfSpiders != null;
assert spiderNest.numberOfSpiders.equals(4);
}
-
- @Test(groups={"injection", "producerMethod"}, expectedExceptions=NullableDependencyException.class) @SpecAssertion(section="5.2")
+
+ @Test(groups = { "injection", "producerMethod" }, expectedExceptions = NullableDependencyException.class)
+ @SpecAssertion(section = "5.2")
public void testPrimitiveInjectionPointResolvesToNullableWebBean() throws Exception
{
- Bean<FarmHouse> farmHouseBean = SimpleBean.of(FarmHouse.class, manager);
- SimpleBean<FarmHouseProducer> farmHouseProducerBean = SimpleBean.of(FarmHouseProducer.class, manager);
- manager.addBean(ProducerMethodBean.of(FarmHouseProducer.class.getMethod("getNumberOfBedrooms"), farmHouseProducerBean, manager));
- farmHouseBean.create();
+ registerProducerBean(FarmHouseProducer.class, "getNumberOfBedrooms", Integer.class);
+ manager.addBean(SimpleBean.of(FarmHouse.class, manager));
+ BeanValidation.validate(manager.getBeans());
}
-
- @Test(groups={"injection", "clientProxy"}, expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="5.3")
+
+ @Test(groups = { "injection", "clientProxy" }, expectedExceptions = ContextNotActiveException.class)
+ @SpecAssertion(section = "5.3")
public void testInvokeNormalInjectedWebBeanWhenContextNotActive()
{
SimpleBean<TunaFarm> tunaFarmBean = SimpleBean.of(TunaFarm.class, manager);
@@ -60,8 +63,9 @@
requestContext.setActive(false);
tunaFarm.tuna.getName();
}
-
- @Test(groups="injection") @SpecAssertion(section="5.3")
+
+ @Test(groups = "injection")
+ @SpecAssertion(section = "5.3")
public void testInvokeDependentScopeWhenContextNotActive()
{
Bean<FoxRun> foxRunBean = SimpleBean.of(FoxRun.class, manager);
@@ -70,8 +74,9 @@
FoxRun foxRun = foxRunBean.create();
assert foxRun.fox.getName().equals("gavin");
}
-
- @Test(groups="injection", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.7")
+
+ @Test(groups = "injection", expectedExceptions = DefinitionException.class)
+ @SpecAssertion(section = "3.7")
public void testInjectingStaticField()
{
SimpleBean<BeanWithStaticBoundField> bean = SimpleBean.of(BeanWithStaticBoundField.class, manager);
@@ -79,8 +84,9 @@
manager.addBean(tunaBean);
BeanWithStaticBoundField instance = bean.create();
}
-
- @Test(groups="injection",expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.7")
+
+ @Test(groups = "injection", expectedExceptions = DefinitionException.class)
+ @SpecAssertion(section = "3.7")
public void testInjectingFinalField()
{
SimpleBean<BeanWithFinalBoundField> bean = SimpleBean.of(BeanWithFinalBoundField.class, manager);
@@ -88,45 +94,46 @@
manager.addBean(tunaBean);
BeanWithFinalBoundField instance = bean.create();
}
-
- @Test(groups={"stub", "injection", "webbeansxml"}) @SpecAssertion(section="3.7.2")
+
+ @Test(groups = { "stub", "injection", "webbeansxml" })
+ @SpecAssertion(section = "3.7.2")
public void testInjectFieldsDeclaredInXml()
{
assert false;
}
-
- @Test(groups={"stub", "injection", "webbeansxml"}) @SpecAssertion(section="3.7.2")
+
+ @Test(groups = { "stub", "injection", "webbeansxml" })
+ @SpecAssertion(section = "3.7.2")
public void testInjectedFieldDeclaredInXmlIgnoresJavaAnnotations()
{
assert false;
}
-
- @Test(groups={"stub", "injection", "webbeansxml"}) @SpecAssertion(section="3.7.2")
+
+ @Test(groups = { "stub", "injection", "webbeansxml" })
+ @SpecAssertion(section = "3.7.2")
public void testInjectedFieldDeclaredInXmlAssumesCurrent()
{
assert false;
}
-
- @Test(groups={"stub", "injection", "webbeansxml"}, expectedExceptions=NonexistentFieldException.class) @SpecAssertion(section="3.7.2")
+
+ @Test(groups = { "stub", "injection", "webbeansxml" }, expectedExceptions = NonexistentFieldException.class)
+ @SpecAssertion(section = "3.7.2")
public void testNonexistentFieldDefinedInXml()
{
assert false;
}
-
- @Test(groups={"stub", "injection", "webbeansxml"}) @SpecAssertion(section="3.7.2")
+
+ @Test(groups = { "stub", "injection", "webbeansxml" })
+ @SpecAssertion(section = "3.7.2")
public void testInjectFieldsDeclaredInXmlAndJava()
{
assert false;
}
-
- /*
- @Test(groups="injection") @SpecAssertion(section="4.2")
- public void test
- {
- assert false;
- }
+ /*
+ *
+ * @Test(groups="injection") @SpecAssertion(section="4.2") public void test {
+ * assert false; }
+ */
- */
-
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -10,6 +10,7 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.binding.CurrentBinding;
+import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
@@ -24,6 +25,7 @@
import org.jboss.webbeans.test.beans.broken.FinalTuna;
import org.jboss.webbeans.test.beans.broken.ParameterizedBean;
import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
+import org.jboss.webbeans.util.BeanValidation;
import org.testng.annotations.Test;
@SpecVersion("20081206")
@@ -75,7 +77,6 @@
manager.addBean(codBean);
manager.addBean(salmonBean);
manager.addBean(soleBean);
-
manager.getInstanceByType(ScottishFish.class, new AnnotationLiteral<Whitefish>(){});
}
@@ -89,7 +90,6 @@
manager.addBean(codBean);
manager.addBean(salmonBean);
manager.addBean(soleBean);
-
manager.getInstanceByType(Tuna.class, new CurrentBinding());
}
@@ -98,7 +98,7 @@
{
Bean<FinalTuna> FinalTunaBean = SimpleBean.of(FinalTuna.class, manager);
manager.addBean(FinalTunaBean);
-
+ BeanValidation.validate(manager.getBeans());
manager.getInstanceByType(FinalTuna.class, new AnnotationLiteral<Whitefish>(){});
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/contexts/PassivatingContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/contexts/PassivatingContextTest.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/contexts/PassivatingContextTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -52,6 +52,7 @@
import org.jboss.webbeans.test.contexts.valid.Jyvaskyla;
import org.jboss.webbeans.test.contexts.valid.Turku;
import org.jboss.webbeans.test.contexts.valid.Vaasa;
+import org.jboss.webbeans.util.BeanValidation;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -98,7 +99,6 @@
public void testSimpleWebBeanWithNonSerializableImplementationClassFails()
{
registerBeans(new Class<?>[] { Hamina.class });
- manager.validate();
}
/**
@@ -300,7 +300,7 @@
public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoNonTransientFieldOfWebBeanWithPassivatingScopeFails()
{
registerBeans(new Class<?>[] { Violation.class, Vantaa.class });
- manager.validate();
+ BeanValidation.validate(manager.getBeans());
}
/**
@@ -333,7 +333,7 @@
public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoConstructorParameterOfWebBeanWithPassivatingScopeFails()
{
registerBeans(new Class<?>[] { Violation.class, Loviisa.class} );
- manager.validate();
+ BeanValidation.validate(manager.getBeans());
}
/**
@@ -350,7 +350,7 @@
public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoInitializerParameterOfWebBeanWithPassivatingScopeFails()
{
registerBeans(new Class<?>[] { Violation.class, Forssa.class });
- manager.validate();
+ BeanValidation.validate(manager.getBeans());
}
/**
@@ -368,7 +368,7 @@
{
manager.addBean(SimpleBean.of(Violation.class, manager));
Bean<?> producerBean = registerProducerBean(Peraseinajoki.class, "create", Violation2.class);
- manager.validate();
+ BeanValidation.validate(manager.getBeans());
}
/**
@@ -491,6 +491,7 @@
registerProducerBean(CityProducer.class, "reference", Violation.class);
EnterpriseBean<Pietarsaari> bean = EnterpriseBean.of(Pietarsaari.class, manager);
// TODO: hack
+ BeanValidation.validate(manager.getBeans());
bean.postConstruct(null);
assert true;
}
@@ -575,57 +576,6 @@
return manager.getInstance(bean);
}
- private boolean hasField(Class<?> clazz, String name)
- {
- try
- {
- Field field = clazz.getDeclaredField(name);
- }
- catch (NoSuchFieldException e)
- {
- return false;
- }
- return true;
- }
-
- private Method getMethod(Class<?> clazz, String name)
- {
- for (Method method : clazz.getDeclaredMethods())
- {
- if (method.getName().equals(name))
- {
- return method;
- }
- }
- return null;
- }
-
- private AbstractProducerBean<?, ?> registerProducerBean(Class<?> producerBeanClass, String fieldOrMethodName, Class<?> productClass)
- {
- SimpleBean<?> producerContainerBean = SimpleBean.of(producerBeanClass, manager);
- manager.addBean(producerContainerBean);
- AbstractProducerBean<?, ?> producerBean = null;
- try
- {
- if (hasField(producerBeanClass, fieldOrMethodName))
- {
- Field producerField = producerBeanClass.getDeclaredField(fieldOrMethodName);
- producerBean = ProducerFieldBean.of(producerField, producerContainerBean, manager);
- }
- else
- {
- Method producerMethod = getMethod(producerBeanClass, fieldOrMethodName);
- producerBean = ProducerMethodBean.of(producerMethod, producerContainerBean, manager);
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException("Could not initialize producer bean", e);
- }
- manager.addBean(producerBean);
- return producerBean;
- }
-
/**
* If a producer method or field of scope @Dependent returns a
* non-serializable object for injection into a stateful session bean, into a
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewEnterpriseBeanTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewEnterpriseBeanTest.java 2009-01-14 16:22:06 UTC (rev 969)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/newbean/NewEnterpriseBeanTest.java 2009-01-14 16:25:26 UTC (rev 970)
@@ -328,9 +328,9 @@
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToField()
{
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedField.class, WrappedEnterpriseBean.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedField.class, WrappedSimpleBean.class));
webBeansBootstrap.boot();
- assert manager.resolveByType(WrappedEnterpriseBean.class, new NewBinding()).size() == 1;
+ assert manager.resolveByType(WrappedSimpleBean.class, new NewBinding()).size() == 1;
}
/**
@@ -345,9 +345,9 @@
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToProducerMethodParameter()
{
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedProducerParameter.class, WrappedEnterpriseBean.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedProducerParameter.class, WrappedSimpleBean.class));
webBeansBootstrap.boot();
- assert manager.resolveByType(WrappedEnterpriseBean.class, new NewBinding()).size() == 1;
+ assert manager.resolveByType(WrappedSimpleBean.class, new NewBinding()).size() == 1;
}
/**
@@ -362,9 +362,9 @@
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToInitializerMethodParameter()
{
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedInitializerParameter.class, WrappedEnterpriseBean.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedInitializerParameter.class, WrappedSimpleBean.class));
webBeansBootstrap.boot();
- assert manager.resolveByType(WrappedEnterpriseBean.class, new NewBinding()).size() == 1;
+ assert manager.resolveByType(WrappedSimpleBean.class, new NewBinding()).size() == 1;
}
/**
@@ -379,9 +379,9 @@
@SpecAssertion(section = "3.9")
public void testNewAnnotationMayBeAppliedToConstructorMethodParameter()
{
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedConstructorParameter.class, WrappedEnterpriseBean.class));
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(AnnotatedConstructorParameter.class, WrappedSimpleBean.class));
webBeansBootstrap.boot();
- assert manager.resolveByType(WrappedEnterpriseBean.class, new NewBinding()).size() == 1;
+ assert manager.resolveByType(WrappedSimpleBean.class, new NewBinding()).size() == 1;
}
/**
More information about the weld-commits
mailing list