You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/02/08 13:43:24 UTC
svn commit: r742075 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
component/ component/xml/ config/ event/ inject/ inject/impl/ inject/xml/
util/ xml/
Author: gerdogdu
Date: Sun Feb 8 12:43:23 2009
New Revision: 742075
URL: http://svn.apache.org/viewvc?rev=742075&view=rev
Log:
Updating xml defined InjectionPoint validations.
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewComponentImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansResolver.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java Sun Feb 8 12:43:23 2009
@@ -95,6 +95,7 @@
/** The bean allows nullable object */
protected boolean nullable = true;
+ /**Beans injection points*/
protected Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>();
/**
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewComponentImpl.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewComponentImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/NewComponentImpl.java Sun Feb 8 12:43:23 2009
@@ -32,7 +32,7 @@
public NewComponentImpl(Class<T> returnType, WebBeansType definedType)
{
super(returnType);
- this.definedType = definedType;
+ this.definedType = definedType;
}
@Override
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerComponentImpl.java Sun Feb 8 12:43:23 2009
@@ -19,13 +19,12 @@
import javax.context.CreationalContext;
import javax.context.Dependent;
-import javax.context.ScopeType;
-import javax.inject.IllegalProductException;
import javax.inject.manager.Bean;
import org.apache.webbeans.container.ManagerImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.inject.InjectableMethods;
+import org.apache.webbeans.util.WebBeansUtil;
/**
* Concrete implementation of the {@link AbstractComponent}.
@@ -194,25 +193,14 @@
protected void checkNullInstance(Object instance)
{
- if (instance == null)
- {
- if (!this.getScopeType().equals(Dependent.class))
- {
- throw new IllegalProductException("WebBeans producer method : " + creatorMethod.getName() + " return type in the component implementation class : " + this.parent.getReturnType().getName() + " scope type must be @Dependent to create null instance");
- }
- }
+ String errorMessage = "WebBeans producer method : " + creatorMethod.getName() + " return type in the component implementation class : " + this.parent.getReturnType().getName() + " scope type must be @Dependent to create null instance";
+ WebBeansUtil.checkNullInstance(instance, this.getScopeType(), errorMessage);
}
protected void checkScopeType()
{
- // Scope type check
- ScopeType scope = this.getScopeType().getAnnotation(ScopeType.class);
- if (scope.passivating())
- {
- if (!this.isSerializable())
- {
- throw new IllegalProductException("WebBeans producer method : " + creatorMethod.getName() + " return type in the component implementation class : " + this.parent.getReturnType().getName() + " with passivating scope @" + scope.annotationType().getName() + " must be Serializable");
- }
- }
+ String errorMessage = "WebBeans producer method : " + creatorMethod.getName() + " return type in the component implementation class : " + this.parent.getReturnType().getName() + " with passivating scope @" + this.getScopeType().getName() + " must be Serializable";
+ WebBeansUtil.checkSerializableScopeType(this.getScopeType(), this.isSerializable(), errorMessage);
+
}
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java Sun Feb 8 12:43:23 2009
@@ -40,11 +40,20 @@
* For further details about the components, see Web Beans Specification
* Chapter-2.
* </p>
- *
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @since 1.0
*/
public enum WebBeansType
{
- SIMPLE, PRODUCER, NEW, ENTERPRISE, JMS, DEPENDENT, INTERCEPTOR, DECORATOR, OBSERVABLE, MANAGER, CONVERSATION
+ SIMPLE,
+ PRODUCER,
+ PRODUCERFIELD,
+ NEW,
+ ENTERPRISE,
+ JMS,
+ DEPENDENT,
+ INTERCEPTOR,
+ DECORATOR,
+ OBSERVABLE,
+ MANAGER,
+ CONVERSATION,
+ INSTANCE
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/xml/XMLComponentImpl.java Sun Feb 8 12:43:23 2009
@@ -35,6 +35,7 @@
public class XMLComponentImpl<T> extends ComponentImpl<T>
{
+ /**Logger instance*/
private static WebBeansLogger logger = WebBeansLogger.getLogger(XMLComponentImpl.class);
/** Constructor injection point decleration */
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Sun Feb 8 12:43:23 2009
@@ -27,6 +27,7 @@
import javax.annotation.Named;
import javax.annotation.NonBinding;
import javax.context.ScopeType;
+import javax.decorator.Decorates;
import javax.event.Fires;
import javax.event.Observes;
import javax.inject.DeploymentType;
@@ -45,6 +46,7 @@
import org.apache.webbeans.component.ComponentImpl;
import org.apache.webbeans.component.ObservesMethodsOwner;
import org.apache.webbeans.component.ProducerComponentImpl;
+import org.apache.webbeans.component.ProducerFieldComponent;
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
import org.apache.webbeans.deployment.DeploymentTypeManager;
@@ -340,6 +342,35 @@
}
}
+
+ /**
+ * Defines the set of {@link ProducerFieldComponent} components.
+ *
+ * @param component producer field owner component
+ *
+ * @return the set of producer field components
+ */
+ public static Set<ProducerFieldComponent<?>> defineProduerFields(AbstractComponent<?> component)
+ {
+ Set<ProducerFieldComponent<?>> producerFields = new HashSet<ProducerFieldComponent<?>>();
+ Field[] fields = component.getReturnType().getDeclaredFields();
+
+ for(Field field : fields)
+ {
+ //Producer field
+ if(AnnotationUtil.isAnnotationExist(field.getAnnotations(), Produces.class))
+ {
+ ProducerFieldComponent<?> newComponent = createProducerFieldComponent(field.getType(), field, component);
+ if (newComponent != null)
+ {
+ producerFields.add(newComponent);
+ }
+
+ }
+ }
+
+ return producerFields;
+ }
public static Set<ProducerComponentImpl<?>> defineProducerMethods(AbstractComponent<?> component)
{
@@ -417,6 +448,39 @@
return component;
}
+
+ private static <T> ProducerFieldComponent<T> createProducerFieldComponent(Class<T> returnType, Field field, AbstractComponent<?> parent)
+ {
+ ProducerFieldComponent<T> component = new ProducerFieldComponent<T>(parent, returnType);
+ component.setProducerField(field);
+
+
+ if (returnType.isPrimitive())
+ {
+ component.setNullable(false);
+ }
+
+ defineSerializable(component);
+
+ Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, field.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());
+
+ // Check if the deployment type is enabled.
+ if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
+ {
+ return null;
+ }
+
+ Annotation[] fieldAnns = field.getAnnotations();
+
+ DefinitionUtil.defineProducerMethodApiTypes(component, returnType);
+ DefinitionUtil.defineScopeType(component, fieldAnns, "WebBeans producer method : " + field.getName() + " in class " + parent.getReturnType().getName() + " must declare default @ScopeType annotation");
+ DefinitionUtil.defineBindingTypes(component, fieldAnns);
+ DefinitionUtil.defineName(component, fieldAnns,field.getName());
+
+ //WebBeansUtil.checkSteroTypeRequirements(component, fieldAnns, "WebBeans producer method : " + method.getName() + " in class : " + parent.getReturnType().getName());
+
+ return component;
+ }
public static <T> void defineDisposalMethods(AbstractComponent<T> component)
{
@@ -463,7 +527,10 @@
{
Class<T> clazz = component.getReturnType();
- WebBeansUtil.checkObservableFieldsConditions(clazz);
+ if(!WebBeansUtil.checkObservableFieldsConditions(clazz))
+ {
+ WebBeansUtil.checkObtainsFieldConditions(clazz);
+ }
Field[] fields = clazz.getDeclaredFields();
if (fields.length != 0)
@@ -472,6 +539,13 @@
{
Annotation[] anns = field.getAnnotations();
+ //Injected fields can not be @Decorates or @Produces
+ if(AnnotationUtil.isAnnotationExist(anns, Produces.class) ||
+ AnnotationUtil.isAnnotationExist(anns, Decorates.class))
+ {
+ return;
+ }
+
Annotation[] bindingAnns = AnnotationUtil.getBindingAnnotations(anns);
Annotation[] resourceAnns = AnnotationUtil.getResourceAnnotations(anns);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java Sun Feb 8 12:43:23 2009
@@ -23,6 +23,7 @@
import org.apache.webbeans.component.ComponentImpl;
import org.apache.webbeans.component.ProducerComponentImpl;
+import org.apache.webbeans.component.ProducerFieldComponent;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.container.ManagerImpl;
import org.apache.webbeans.deployment.DeploymentTypeManager;
@@ -106,6 +107,8 @@
*/
public static <T> ComponentImpl<T> define(Class<T> clazz, WebBeansType type) throws WebBeansConfigurationException
{
+ ManagerImpl manager = ManagerImpl.getManager();
+
checkSimpleWebBeanCondition(clazz);
ComponentImpl<T> component = new ComponentImpl<T>(clazz, type);
@@ -136,7 +139,10 @@
WebBeansUtil.checkSteroTypeRequirements(component, clazz.getAnnotations(), "WebBeans component class : " + clazz.getName());
Set<ProducerComponentImpl<?>> producerComponents = DefinitionUtil.defineProducerMethods(component);
- ManagerImpl.getManager().getBeans().addAll(producerComponents);
+ manager.getBeans().addAll(producerComponents);
+
+ Set<ProducerFieldComponent<?>> producerFields = DefinitionUtil.defineProduerFields(component);
+ manager.getBeans().addAll(producerFields);
DefinitionUtil.defineDisposalMethods(component);
DefinitionUtil.defineInjectedFields(component);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java Sun Feb 8 12:43:23 2009
@@ -28,7 +28,6 @@
import javax.inject.manager.Manager;
import javax.interceptor.Interceptor;
-import org.apache.webbeans.WebBeansConstants;
import org.apache.webbeans.annotation.DeployedManagerLiteral;
import org.apache.webbeans.annotation.InitializedManagerLiteral;
import org.apache.webbeans.component.ComponentImpl;
@@ -40,7 +39,6 @@
import org.apache.webbeans.deployment.StereoTypeModel;
import org.apache.webbeans.exception.WebBeansDeploymentException;
import org.apache.webbeans.logger.WebBeansLogger;
-import org.apache.webbeans.spi.ee.JNDIServiceEnterpriseImpl;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Sun Feb 8 12:43:23 2009
@@ -36,7 +36,6 @@
import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.spi.ServiceLoader;
import org.apache.webbeans.spi.TransactionService;
-import org.apache.webbeans.spi.ee.TransactionServiceJndiImpl;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
@@ -56,7 +55,6 @@
}
- @SuppressWarnings("unchecked")
public static NotificationManager getInstance()
{
NotificationManager instance = (NotificationManager) WebBeansFinder.getSingletonInstance(WebBeansFinder.SINGLETON_NOTIFICATION_MANAGER);
@@ -152,7 +150,6 @@
Set<ObserverImpl<?>> resolvedSet = new HashSet<ObserverImpl<?>>();
Set<Observer<T>> unres = new HashSet<Observer<T>>();
- @SuppressWarnings("unchecked")
Class<T> eventType = (Class<T>) event.getClass();
EventUtil.checkEventType(eventType);
@@ -173,7 +170,6 @@
Iterator<ObserverImpl<?>> it = resolvedSet.iterator();
while (it.hasNext())
{
- @SuppressWarnings("unchecked")
ObserverImpl<T> impl = (ObserverImpl<T>) it.next();
if (impl.isObserverOfBindings(bindings))
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Sun Feb 8 12:43:23 2009
@@ -20,7 +20,9 @@
import javax.context.Dependent;
import javax.event.Fires;
+import javax.inject.Instance;
import javax.inject.New;
+import javax.inject.Obtains;
import javax.inject.manager.Bean;
import javax.persistence.PersistenceContext;
@@ -37,7 +39,6 @@
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.spi.JPAService;
import org.apache.webbeans.spi.ServiceLoader;
-import org.apache.webbeans.spi.se.JPAServicePersistenceImpl;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
@@ -86,6 +87,11 @@
{
return injectForObservable(args, annotations);
}
+
+ if(isObtainsBinding(annotations))
+ {
+ return injectForObtains(type, args, annotations);
+ }
Set<Bean<T>> componentSet = InjectionResolver.getInstance().implResolveByType(type, args, annotations);
ResolutionUtil.checkResolvedBeans(componentSet, type);
@@ -151,6 +157,20 @@
return false;
}
+
+ private boolean isObtainsBinding(Annotation... annotations)
+ {
+ for (Annotation ann : annotations)
+ {
+ if (ann.annotationType().equals(Obtains.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/**
* create the instance for injecting web beans resources.
@@ -203,12 +223,20 @@
return injectForDependent(WebBeansUtil.createNewComponent(clazz));
}
- private <T> Object injectForObservable(Type[] args, Annotation... annotations)
+ private Object injectForObservable(Type[] args, Annotation... annotations)
{
Class<?> eventType = (Class<?>) args[0];
return injectForDependent(WebBeansUtil.createObservableImplicitComponent(EventImpl.class, eventType, annotations));
}
+
+ private <T> Object injectForObtains(Class<T> instanceType, Type[] args, Annotation...annotations)
+ {
+ @SuppressWarnings("unchecked")
+ Class<Instance<T>> clazz = (Class<Instance<T>>)instanceType;
+ return injectForDependent(WebBeansUtil.createInstanceComponent(clazz, args[0] , annotations));
+
+ }
private Object injectForDependent(AbstractComponent<?> component)
{
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java Sun Feb 8 12:43:23 2009
@@ -21,6 +21,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.event.Fires;
import javax.event.Observes;
@@ -29,11 +30,48 @@
import javax.inject.manager.InjectionPoint;
import org.apache.webbeans.annotation.CurrentLiteral;
+import org.apache.webbeans.inject.xml.XMLInjectionModelType;
+import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.Asserts;
public class InjectionPointFactory
{
+ public static InjectionPoint getXMLInjectionPointData(Bean<?> owner, XMLInjectionPointModel xmlInjectionModel)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(xmlInjectionModel, "xmlInjectionModel parameter can not be null");
+
+ InjectionPoint injectionPoint = null;
+
+ Set<Annotation> setAnns = xmlInjectionModel.getAnnotations();
+ Annotation[] anns = new Annotation[setAnns.size()];
+ anns = setAnns.toArray(anns);
+
+ boolean available = true;
+
+ if(xmlInjectionModel.getType().equals(XMLInjectionModelType.FIELD))
+ {
+ if(checkFieldApplicable(anns))
+ {
+ available = false;
+ }
+ }
+ else if(xmlInjectionModel.getType().equals(XMLInjectionModelType.METHOD))
+ {
+ if(checkMethodApplicable(anns))
+ {
+ available = false;
+ }
+ }
+
+ if(available)
+ {
+ injectionPoint = getGenericInjectionPoint(owner, anns, xmlInjectionModel.getInjectionGenericType(), xmlInjectionModel.getInjectionMember());
+ }
+
+ return injectionPoint;
+ }
public static InjectionPoint getFieldInjectionPointData(Bean<?> owner, Field member)
{
@@ -43,15 +81,7 @@
Annotation[] annots = null;
annots = member.getAnnotations();
-
- boolean firesOrObtainsAnnotation = false;
-
- if(AnnotationUtil.isAnnotationExist(annots, Fires.class) || AnnotationUtil.isAnnotationExist(annots, Obtains.class))
- {
- firesOrObtainsAnnotation = true;
- }
-
- if(!firesOrObtainsAnnotation)
+ if(!checkFieldApplicable(annots))
{
return getGenericInjectionPoint(owner, annots, member.getGenericType(), member);
}
@@ -61,6 +91,16 @@
}
}
+
+ private static boolean checkFieldApplicable(Annotation[] anns)
+ {
+ if(AnnotationUtil.isAnnotationExist(anns, Fires.class) || AnnotationUtil.isAnnotationExist(anns, Obtains.class))
+ {
+ return true;
+ }
+
+ return false;
+ }
private static InjectionPoint getGenericInjectionPoint(Bean<?> owner, Annotation[] annots, Type type, Member member)
{
@@ -90,7 +130,6 @@
{
int i = 0;
- boolean observesAnnotation = false;
for (Type type : types)
{
Annotation[] annot = annots[i];
@@ -100,17 +139,8 @@
annot = new Annotation[1];
annot[0] = new CurrentLiteral();
}
-
- for (Annotation observersAnnot : annot)
- {
- if (observersAnnot.annotationType().equals(Observes.class))
- {
- observesAnnotation = true;
- break;
- }
- }
-
- if (!observesAnnotation)
+
+ if (!checkMethodApplicable(annot))
{
lists.add(getGenericInjectionPoint(owner, annot, type, member));
}
@@ -121,6 +151,21 @@
return lists;
}
+
+
+ private static boolean checkMethodApplicable(Annotation[] annot)
+ {
+ for (Annotation observersAnnot : annot)
+ {
+ if (observersAnnot.annotationType().equals(Observes.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+
+ }
public static List<InjectionPoint> getConstructorInjectionPointData(Bean<?> owner, Constructor<?> member)
{
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectableConstructor.java Sun Feb 8 12:43:23 2009
@@ -25,10 +25,20 @@
import org.apache.webbeans.inject.InjectableConstructor;
import org.apache.webbeans.util.Asserts;
+/**
+ * Defines the injectable constructor.
+ * @param <T> type of the constructor
+ */
public class XMLInjectableConstructor<T> extends InjectableConstructor<T>
{
+ /**Constructor parameter injection models defined in the xml*/
private List<XMLInjectionPointModel> injectionPointModelList = new ArrayList<XMLInjectionPointModel>();
+ /**
+ * Defines new <code>XMLInjectableConstructor</code> instance.
+ * @param constructor bean constructor
+ * @param owner constructor owner beans
+ */
public XMLInjectableConstructor(Constructor<T> constructor, AbstractComponent<?> owner)
{
super(constructor, owner);
@@ -59,18 +69,6 @@
if (!EJBUtil.isEJBSessionClass(con.getDeclaringClass()))
{
instance = con.newInstance(list.toArray());
-
- // if(getInjectionOwnerComponent().getScopeType().equals(Dependent.class))
- // {
- //
- // }
- // else
- // {
- // instance = (T)
- // JavassistProxyFactory.createNewProxyInstance(con.getDeclaringClass(),
- // con.getParameterTypes(), list.toArray(),
- // getInjectionOwnerComponent());
- // }
}
}
@@ -90,10 +88,14 @@
{
return con;
}
-
+
+ /**
+ * Adds new constructor parameter injection model.
+ * @param model new injection point model for constructor parameter
+ */
public void addInjectionPointModel(XMLInjectionPointModel model)
{
Asserts.assertNotNull(model, "model parameter can not be null");
this.injectionPointModelList.add(model);
}
-}
+}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/xml/XMLInjectionPointModel.java Sun Feb 8 12:43:23 2009
@@ -14,12 +14,14 @@
package org.apache.webbeans.inject.xml;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
/**
@@ -30,9 +32,6 @@
* If injection point is a parametrized type, actual type arguments are defined
* in the XML file. See specification for further details.
* </p>
- *
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @since 1.0
*/
public class XMLInjectionPointModel
{
@@ -47,6 +46,18 @@
/** Injection point binding types */
private Set<Annotation> bindingTypes = new HashSet<Annotation>();
+
+ /**All annotations*/
+ private Set<Annotation> annotations = new HashSet<Annotation>();
+
+ /**Injection type*/
+ private Type injectionGenericType;
+
+ /**Injection Member*/
+ private Member injectionMember;
+
+ /**Type of the injection*/
+ private XMLInjectionModelType type;
/** This injection model is array */
private boolean array;
@@ -55,6 +66,7 @@
{
this.array = true;
this.injectionClassType = arrayElementType;
+ this.injectionGenericType = arrayElementType;
}
/**
@@ -66,6 +78,7 @@
public XMLInjectionPointModel(Class<?> injectionClassType, Type[] actualTypeArguments)
{
this.injectionClassType = injectionClassType;
+ this.injectionGenericType = injectionClassType;
if (actualTypeArguments != null && actualTypeArguments.length > 0)
{
@@ -127,6 +140,16 @@
{
return Collections.unmodifiableSet(this.bindingTypes);
}
+
+
+ /**
+ *
+ * @return annotations
+ */
+ public Set<Annotation> getAnnotations()
+ {
+ return Collections.unmodifiableSet(this.annotations);
+ }
/**
* @return the array
@@ -135,6 +158,56 @@
{
return array;
}
+
+ /**
+ * Add new injection point annotation
+ * @param annotation member annotation
+ */
+ public void addAnnotation(Annotation annotation)
+ {
+ Asserts.assertNotNull(annotation, "annotation parameter can not be null");
+ this.annotations.add(annotation);
+ }
+
+ /**
+ * @return the injectionType
+ */
+ public Type getInjectionGenericType()
+ {
+ return injectionGenericType;
+ }
+
+ /**
+ * @return the injectionMember
+ */
+ public Member getInjectionMember()
+ {
+ return injectionMember;
+ }
+
+ /**
+ * @param injectionMember the injectionMember to set
+ */
+ public void setInjectionMember(Member injectionMember)
+ {
+ this.injectionMember = injectionMember;
+ }
+
+ /**
+ * @return the type
+ */
+ public XMLInjectionModelType getType()
+ {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(XMLInjectionModelType type)
+ {
+ this.type = type;
+ }
/*
* (non-Javadoc)
@@ -186,4 +259,4 @@
return false;
return true;
}
-}
\ No newline at end of file
+ }
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Sun Feb 8 12:43:23 2009
@@ -1210,7 +1210,15 @@
public static boolean isFirstParametricTypeArgGeneric(ParameterizedType type)
{
Asserts.assertNotNull(type, "type parameter can not be null");
- Type arg = type.getActualTypeArguments()[0];
+
+ Type[] args = type.getActualTypeArguments();
+
+ if(args.length == 0)
+ {
+ return false;
+ }
+
+ Type arg = args[0];
if ((arg instanceof TypeVariable) || (arg instanceof WildcardType))
{
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Sun Feb 8 12:43:23 2009
@@ -36,6 +36,7 @@
import javax.context.ApplicationScoped;
import javax.context.Conversation;
import javax.context.ConversationScoped;
+import javax.context.Dependent;
import javax.context.RequestScoped;
import javax.context.ScopeType;
import javax.context.SessionScoped;
@@ -44,13 +45,17 @@
import javax.event.Fires;
import javax.event.Observes;
import javax.faces.component.UIComponent;
+import javax.inject.DefinitionException;
import javax.inject.DeploymentType;
import javax.inject.Disposes;
import javax.inject.DuplicateBindingTypeException;
+import javax.inject.IllegalProductException;
import javax.inject.InconsistentSpecializationException;
import javax.inject.Initializer;
+import javax.inject.Instance;
import javax.inject.New;
import javax.inject.NullableDependencyException;
+import javax.inject.Obtains;
import javax.inject.Produces;
import javax.inject.UnproxyableDependencyException;
import javax.inject.manager.Bean;
@@ -80,6 +85,7 @@
import org.apache.webbeans.component.Component;
import org.apache.webbeans.component.ComponentImpl;
import org.apache.webbeans.component.ConversationComponent;
+import org.apache.webbeans.component.InstanceComponentImpl;
import org.apache.webbeans.component.ManagerComponentImpl;
import org.apache.webbeans.component.NewComponentImpl;
import org.apache.webbeans.component.ObservableComponentImpl;
@@ -301,7 +307,7 @@
return false;
}
-
+
/**
* Check producer method is ok for deployment.
*
@@ -333,6 +339,33 @@
throw new WebBeansConfigurationException("Producer method : " + method.getName() + " in the class : " + parentImplClazzName + " can not be annotated with" + " @Initializer/@Destructor annotation or has a parameter annotated with @Disposes/@Observes");
}
}
+
+ /**
+ * Check producer field is ok for deployment.
+ *
+ * @param method producer method
+ * @param parentImplClazzName parent class name
+ */
+ public static void checkProducerFieldForDeployment(Field producerField, String parentImplClazzName)
+ {
+ Asserts.assertNotNull(producerField, "producerField argument can not be null");
+
+ Type returnType = producerField.getGenericType();
+ if (ClassUtil.isParametrizedType(returnType))
+ {
+ ParameterizedType pType = (ParameterizedType) returnType;
+
+ Type[] actualArguments = pType.getActualTypeArguments();
+
+ for (Type actualType : actualArguments)
+ {
+ if ((actualType instanceof TypeVariable) || (actualType instanceof WildcardType))
+ {
+ throw new WebBeansConfigurationException("Producer field : " + producerField.getName() + " in the class : " + parentImplClazzName + " can not return TypeVariable or WildcardType return type arguments.");
+ }
+ }
+ }
+ }
public static void checkProducerMethodDisposal(Method disposalMethod, String parentImplClazzName)
{
@@ -568,6 +601,20 @@
return managerComponent;
}
+
+ public static <T> InstanceComponentImpl<T> createInstanceComponent(Class<Instance<T>> clazz, Type injectedType, Annotation...obtainsBindings)
+ {
+ InstanceComponentImpl<T> instanceComponent = new InstanceComponentImpl<T>(clazz,injectedType);
+
+ instanceComponent.addApiType(clazz);
+ instanceComponent.addApiType(InstanceComponentImpl.class);
+ instanceComponent.addApiType(Object.class);
+
+ DefinitionUtil.defineBindingTypes(instanceComponent, obtainsBindings);
+ instanceComponent.setImplScopeType(new DependentScopeLiteral());
+
+ return instanceComponent;
+ }
public static ConversationComponent getConversationComponent()
{
@@ -1327,17 +1374,66 @@
}
- public static <T> void checkObservableFieldsConditions(Class<T> clazz)
+ public static <T> boolean checkObservableFieldsConditions(Class<T> clazz)
{
Asserts.nullCheckForClass(clazz);
+ boolean ok = false;
Field[] candidateFields = AnnotationUtil.getClazzFieldsWithGivenAnnotation(clazz, Fires.class);
for (Field candidateField : candidateFields)
{
+ if(!ok)
+ {
+ ok = true;
+ }
EventUtil.checkObservableFieldConditions(candidateField.getGenericType(), candidateField.getName(), clazz.getName());
}
+ return ok;
+ }
+
+ /**
+ * Check bean <code>Obtains</code> field injection conditions.
+ * @param <T> bean class type
+ * @param clazz bean class
+ */
+ public static <T> void checkObtainsFieldConditions(Class<T> clazz)
+ {
+ Asserts.assertNotNull(clazz);
+
+ Field[] candidateFields = AnnotationUtil.getClazzFieldsWithGivenAnnotation(clazz, Obtains.class);
+
+ for (Field candidateField : candidateFields)
+ {
+ Type fieldType = candidateField.getGenericType();
+ Class<?> rawType = null;
+ if(ClassUtil.isParametrizedType(fieldType))
+ {
+ ParameterizedType pt = (ParameterizedType)fieldType;
+
+ rawType = (Class<?>) pt.getRawType();
+ if(!(rawType.getClass().equals(Instance.class)))
+ {
+ throw new DefinitionException("@Obtains field with name : " + candidateField.getName() + " " +
+ "in bean class : " + clazz.getName() + " must have type javax.inject.Instance");
+ }
+ else
+ {
+ if(ClassUtil.isFirstParametricTypeArgGeneric(pt))
+ {
+ throw new DefinitionException("@Obtains field with name : " + candidateField.getName() + " " +
+ "in bean class : " + clazz.getName() + " must not have TypeVariable or WildCard generic type argument");
+ }
+ }
+ }
+ else
+ {
+ throw new DefinitionException("@Obtains field with name : " + candidateField.getName() + " " +
+ "in bean class : " + clazz.getName() + " must be defined as ParameterizedType with actual type argument");
+ }
+ }
+
}
public static <T> void checkPassivationScope(AbstractComponent<T> component, ScopeType scope)
@@ -1415,4 +1511,30 @@
}
}
+ public static void checkNullInstance(Object instance,Class<?> scopeType, String errorMessage)
+ {
+ if (instance == null)
+ {
+ if (!scopeType.equals(Dependent.class))
+ {
+ throw new IllegalProductException(errorMessage);
+ }
+ }
+
+ }
+
+ public static void checkSerializableScopeType(Class<?> scopeType, boolean isSerializable, String errorMessage)
+ {
+ // Scope type check
+ ScopeType scope = scopeType.getAnnotation(ScopeType.class);
+ if (scope.passivating())
+ {
+ if (!isSerializable)
+ {
+ throw new IllegalProductException(errorMessage);
+ }
+ }
+ }
+
+
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansResolver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansResolver.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansResolver.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansResolver.java Sun Feb 8 12:43:23 2009
@@ -25,9 +25,6 @@
/**
* Resolver for the web beans systemId's.
- *
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @since 1.0
*/
public class WebBeansResolver implements EntityResolver
{
@@ -68,7 +65,7 @@
return null;
}
- /*
+ /**
* Creates the new input source.
*/
private InputSource createInputSource(InputStream stream, String publicId, String systemId)
@@ -82,4 +79,4 @@
}
-}
+}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/WebBeansXMLConfigurator.java Sun Feb 8 12:43:23 2009
@@ -66,7 +66,9 @@
import org.apache.webbeans.exception.definition.NonexistentFieldException;
import org.apache.webbeans.exception.definition.NonexistentMethodException;
import org.apache.webbeans.exception.definition.NonexistentTypeException;
+import org.apache.webbeans.inject.impl.InjectionPointFactory;
import org.apache.webbeans.inject.xml.XMLInjectableConstructor;
+import org.apache.webbeans.inject.xml.XMLInjectionModelType;
import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
import org.apache.webbeans.intercept.InterceptorsManager;
import org.apache.webbeans.proxy.JavassistProxyFactory;
@@ -78,9 +80,6 @@
/**
* Configures the web beans from the xml declerations.
- *
- * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
- * @since 1.0
*/
@SuppressWarnings("unchecked")
public final class WebBeansXMLConfigurator
@@ -100,6 +99,9 @@
/** Annotation type manager that manages the XML defined annotations */
private XMLAnnotationTypeManager xmlAnnotTypeManager = XMLAnnotationTypeManager.getInstance();
+ /**
+ * Creates a new instance of the <code>WebBeansXMLConfigurator</code>
+ */
public WebBeansXMLConfigurator()
{
@@ -113,13 +115,15 @@
*/
public void configure(InputStream xmlStream, String fileName)
{
- Asserts.assertNotNull(xmlStream);
- Asserts.assertNotNull(fileName);
-
+ Asserts.assertNotNull(xmlStream,"xmlStream parameter can not be null!");
+ Asserts.assertNotNull(fileName,"fileName parameter can not be null!");
+
CURRENT_SCAN_FILE_NAME = fileName;
-
+
+ //Get root element of the XML document
Element webBeansRoot = XMLUtil.getRootElement(xmlStream);
-
+
+ //Start configuration
configure(webBeansRoot);
}
@@ -868,10 +872,24 @@
}
XMLInjectableConstructor<T> injectableConstructor = new XMLInjectableConstructor<T>(componentConstructor, component);
+ int i = 0;
+ Constructor<?> constructor = injectableConstructor.getConstructor();
for (Element element : constructorParameterListElement)
{
XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
injectableConstructor.addInjectionPointModel(model);
+
+ Annotation[] paramAnnos = constructor.getParameterAnnotations()[i++];
+
+ for(Annotation paramAnno : paramAnnos)
+ {
+ model.addAnnotation(paramAnno);
+ }
+
+ model.setInjectionMember(constructor);
+ model.setType(XMLInjectionModelType.CONSTRUCTOR);
+
+ component.addInjectionPoint(InjectionPointFactory.getXMLInjectionPointData(component, model));
}
component.setInjectableConstructor(injectableConstructor);
@@ -961,6 +979,16 @@
{
XMLInjectionPointModel injectionPointModel = XMLUtil.getInjectionPointModel(directChild, createConfigurationFailedMessage());
component.addFieldInjectionPoint(field, injectionPointModel);
+
+ Annotation[] annots = field.getAnnotations();
+ for(Annotation annotation : annots)
+ {
+ injectionPointModel.addAnnotation(annotation);
+ }
+
+ injectionPointModel.setInjectionMember(field);
+ injectionPointModel.setType(XMLInjectionModelType.FIELD);
+ component.addInjectionPoint(InjectionPointFactory.getXMLInjectionPointData(component, injectionPointModel));
isTypeElement = true;
isApplicable = true;
@@ -1177,6 +1205,8 @@
{
XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
component.addMethodInjectionPoint(initializeMethod, model);
+
+ component.addInjectionPoint(XMLDefinitionUtil.getXMLMethodInjectionPoint(component, model, initializeMethod));
}
}
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java Sun Feb 8 12:43:23 2009
@@ -32,6 +32,7 @@
import javax.inject.Specializes;
import javax.inject.UnsatisfiedDependencyException;
import javax.inject.manager.Bean;
+import javax.inject.manager.InjectionPoint;
import javax.inject.manager.Interceptor;
import javax.interceptor.AroundInvoke;
@@ -47,6 +48,8 @@
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.definition.NonexistentFieldException;
import org.apache.webbeans.exception.definition.NonexistentTypeException;
+import org.apache.webbeans.inject.impl.InjectionPointFactory;
+import org.apache.webbeans.inject.xml.XMLInjectionModelType;
import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
import org.apache.webbeans.intercept.InterceptorData;
import org.apache.webbeans.intercept.InterceptorUtil;
@@ -517,7 +520,7 @@
}
}
- XMLProducerComponentImpl<T> producerComponentImpl = configureProduerMethod(component, producesMethod, injectedParameters, type, arrayElement, typeElement, errorMessage);
+ XMLProducerComponentImpl<T> producerComponentImpl = configureProducerMethod(component, producesMethod, injectedParameters, type, arrayElement, typeElement, errorMessage);
configureProducerTypeLevelMetaData(configurator, producerComponentImpl, producesMethod, producerMethodElement, memberLevelMetaData, memberLevelElement, component, errorMessage);
@@ -541,7 +544,7 @@
* @return new xml defines producer method component
* @see XMLProducerComponentImpl
*/
- private static <T> XMLProducerComponentImpl<T> configureProduerMethod(AbstractComponent<?> parentComponent, Method producesMethod, List<XMLInjectionPointModel> injectedParameters, Class<T> type, Element arrayElement, Element typeElement, String errorMessage)
+ private static <T> XMLProducerComponentImpl<T> configureProducerMethod(AbstractComponent<?> parentComponent, Method producesMethod, List<XMLInjectionPointModel> injectedParameters, Class<T> type, Element arrayElement, Element typeElement, String errorMessage)
{
/* New producer webbeans component */
XMLProducerComponentImpl<T> producerComponentImpl = new XMLProducerComponentImpl<T>(parentComponent, type);
@@ -575,7 +578,8 @@
/* Configures producer method injected parameters */
for (XMLInjectionPointModel injectionPointModel : injectedParameters)
{
- producerComponentImpl.addProducerMethodInjectionPointModel(injectionPointModel);
+ producerComponentImpl.addProducerMethodInjectionPointModel(injectionPointModel);
+ producerComponentImpl.addInjectionPoint(getXMLMethodInjectionPoint(producerComponentImpl, injectionPointModel, producesMethod));
}
return producerComponentImpl;
@@ -654,6 +658,8 @@
/* Find disposal method model */
XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(typeElement, errorMessage);
+
+ component.addInjectionPoint(getXMLMethodInjectionPoint(component, model, disposalMethod));
/* Binding types for disposal method */
Set<Annotation> bindingTypes = model.getBindingTypes();
@@ -710,6 +716,8 @@
/* Find observes method model */
XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(typeElement, errorMessage);
+
+ component.addInjectionPoint(getXMLMethodInjectionPoint(component, model, observesMethod));
/* Binding types for disposal method */
Set<Annotation> bindingTypes = model.getBindingTypes();
@@ -735,4 +743,22 @@
beanObserver.addXMLInjectionObservesParameter(injectionPointParamModel);
}
}
+
+ public static InjectionPoint getXMLMethodInjectionPoint(AbstractComponent<?> component, XMLInjectionPointModel model, Method method)
+ {
+ Asserts.assertNotNull(model,"model parameter can not be null");
+ Asserts.assertNotNull(method,"method parameter can not be null");
+
+ Annotation[] annots = method.getAnnotations();
+ for(Annotation annotation : annots)
+ {
+ model.addAnnotation(annotation);
+ }
+
+ model.setInjectionMember(method);
+ model.setType(XMLInjectionModelType.METHOD);
+
+ return InjectionPointFactory.getXMLInjectionPointData(component, model);
+
+ }
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java?rev=742075&r1=742074&r2=742075&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLUtil.java Sun Feb 8 12:43:23 2009
@@ -106,7 +106,7 @@
Element element = path.getCurrent();
if (element.getNamespaceURI() == null || element.getNamespaceURI().equals(""))
{
- throw new WebBeansConfigurationException("All elements in the web-beans.xml file must have declared name space");
+ throw new WebBeansConfigurationException("All elements in the beans.xml file have to declare name space.");
}
else
{
@@ -119,7 +119,8 @@
while (itNs.hasNext())
{
- WebBeansNameSpaceContainer.getInstance().addNewPackageNameSpace(((Namespace) itNs.next()).getURI());
+ Namespace namespace = (Namespace)itNs.next();
+ WebBeansNameSpaceContainer.getInstance().addNewPackageNameSpace(namespace.getURI());
}
}
}