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/10/18 11:22:06 UTC
svn commit: r826383 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
component/ config/ decorator/ intercept/webbeans/ util/
Author: gerdogdu
Date: Sun Oct 18 09:22:04 2009
New Revision: 826383
URL: http://svn.apache.org/viewvc?rev=826383&view=rev
Log:
Update for passing JSR-330 TCK.
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.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/decorator/WebBeansDecorator.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=826383&r1=826382&r2=826383&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java Sun Oct 18 09:22:04 2009
@@ -49,11 +49,18 @@
/** Bean observable method */
private Set<Method> observableMethods = new HashSet<Method>();
- /** Injected fields of the component */
+ /** Injected fields of the bean */
private Set<Field> injectedFields = new HashSet<Field>();
- /** Injected methods of the component */
+ /** Injected methods of the bean */
private Set<Method> injectedMethods = new HashSet<Method>();
+
+ /** Injected fields of the bean */
+ private Set<Field> injectedFromSuperFields = new HashSet<Field>();
+
+ /** Injected methods of the bean */
+ private Set<Method> injectedFromSuperMethods = new HashSet<Method>();
+
/** @deprecated */
/* Removed from specification */
@@ -176,6 +183,9 @@
*/
protected void afterConstructor(T instance, CreationalContext<T> creationalContext)
{
+ injectSuperFields(instance, creationalContext);
+ injectSuperMethods(instance, creationalContext);
+
// Inject fields
injectFields(instance, creationalContext);
@@ -294,10 +304,38 @@
{
if (field.getAnnotation(Decorates.class) == null)
{
- InjectableField f = new InjectableField(field, instance, this, creationalContext);
- f.doInjection();
+ injectField(field, instance);
}
- }
+ }
+ }
+
+ public void injectSuperFields(T instance, CreationalContext<T> creationalContext)
+ {
+ Set<Field> fields = getInjectedFromSuperFields();
+ for (Field field : fields)
+ {
+ if (field.getAnnotation(Decorates.class) == null)
+ {
+ injectField(field, instance);
+ }
+ }
+ }
+
+ public void injectSuperMethods(T instance, CreationalContext<T> creationalContext)
+ {
+ Set<Method> methods = getInjectedFromSuperMethods();
+
+ for (Method method : methods)
+ {
+ injectMethod(method, instance);
+ }
+ }
+
+
+ private void injectField(Field field, Object instance)
+ {
+ InjectableField f = new InjectableField(field, instance, this, creationalContext);
+ f.doInjection();
}
/**
@@ -306,17 +344,22 @@
* @param instance bean instance
* @param creationalContext creational context instance
*/
- @SuppressWarnings("unchecked")
public void injectMethods(T instance, CreationalContext<T> creationalContext)
{
Set<Method> methods = getInjectedMethods();
for (Method method : methods)
{
- InjectableMethods m = new InjectableMethods(method, instance, this, creationalContext);
- m.doInjection();
+ injectMethod(method, instance);
}
}
+
+ @SuppressWarnings("unchecked")
+ private void injectMethod(Method method, Object instance)
+ {
+ InjectableMethods m = new InjectableMethods(method, instance, this, creationalContext);
+ m.doInjection();
+ }
/**
* {@inheritDoc}
@@ -379,6 +422,27 @@
{
this.injectedFields.add(field);
}
+
+ /**
+ * Gets injected from super fields.
+ *
+ * @return injected fields
+ */
+ public Set<Field> getInjectedFromSuperFields()
+ {
+ return this.injectedFromSuperFields;
+ }
+
+ /**
+ * Add new injected field.
+ *
+ * @param field new injected field
+ */
+ public void addInjectedFieldToSuper(Field field)
+ {
+ this.injectedFromSuperFields.add(field);
+ }
+
/**
* Gets injected methods.
@@ -401,6 +465,26 @@
}
/**
+ * Gets injected from super methods.
+ *
+ * @return injected methods
+ */
+ public Set<Method> getInjectedFromSuperMethods()
+ {
+ return this.injectedFromSuperMethods;
+ }
+
+ /**
+ * Add new injected method.
+ *
+ * @param field new injected method
+ */
+ public void addInjectedMethodToSuper(Method method)
+ {
+ this.injectedFromSuperMethods.add(method);
+ }
+
+ /**
* Sets injection target instance.
*
* @param injectionTarget injection target instance
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=826383&r1=826382&r2=826383&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java Sun Oct 18 09:22:04 2009
@@ -67,6 +67,23 @@
public void injectMethods(T instance, CreationalContext<T> creationalContext);
/**
+ * Inject fields of the bean instance.
+ *
+ * @param instance bean instance
+ * @param creationalContext creational context
+ */
+ public void injectSuperFields(T instance, CreationalContext<T> creationalContext);
+
+ /**
+ * Inject initializer methods of the bean instance.
+ *
+ * @param instance bean instance
+ * @param creationalContext creational context
+ */
+ public void injectSuperMethods(T instance, CreationalContext<T> creationalContext);
+
+
+ /**
* Calls post constrcut method.
*
* @param instance bean instance
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=826383&r1=826382&r2=826383&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 Oct 18 09:22:04 2009
@@ -21,7 +21,6 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -609,22 +608,19 @@
Class<?> clazz = component.getReturnType();
Method[] declaredMethods = clazz.getDeclaredMethods();
-
- boolean isSpecializes = false;
-
// This methods defined in the class
for (Method declaredMethod : declaredMethods)
{
- createProducerComponents(component, producerComponents, declaredMethod, clazz, isSpecializes);
+ createProducerComponents(component, producerComponents, declaredMethod, clazz);
}
-
-
+
return producerComponents;
-
}
- private static <T> void createProducerComponents(AbstractBean<T> component, Set<ProducerMethodBean<?>> producerComponents, Method declaredMethod, Class<?> clazz, boolean isSpecializes)
+ private static <T> void createProducerComponents(AbstractBean<T> component, Set<ProducerMethodBean<?>> producerComponents, Method declaredMethod, Class<?> clazz)
{
+ boolean isSpecializes = false;
+
// Producer Method
if (AnnotationUtil.hasMethodAnnotation(declaredMethod, Produces.class))
{
@@ -891,49 +887,33 @@
if (!Modifier.isStatic(mod) && !Modifier.isFinal(mod))
{
- if (!fromSuperClazz)
+ if(fromSuperClazz)
{
- component.addInjectedField(field);
-
- addFieldInjectionPointMetaData(component, field);
+ component.addInjectedFieldToSuper(field);
}
else
{
- // Check that field is already exist
- Set<Field> definedInjectedFields = component.getInjectedFields();
- boolean defined = false;
- for (Field defineInjectedField : definedInjectedFields)
- {
- if (defineInjectedField.getName().equals(field.getName()) && defineInjectedField.getType().equals(field.getType()))
- {
- defined = true;
- break;
- }
- }
-
- if(!defined)
- {
- component.addInjectedField(field);
- addFieldInjectionPointMetaData(component, field);
- }
+ component.addInjectedField(field);
}
+
+ addFieldInjectionPointMetaData(component, field);
}
}
}
}
}
- public static <T> void defineInjectedMethods(AbstractInjectionTargetBean<T> component)
+ public static <T> void defineInjectedMethods(AbstractInjectionTargetBean<T> bean)
{
- Asserts.assertNotNull(component, "component parameter can not be null");
+ Asserts.assertNotNull(bean, "bean parameter can not be null");
- Class<T> clazz = component.getReturnType();
+ Class<T> clazz = bean.getReturnType();
- // From component class definition
- defineInternalInjectedMethods(component, clazz, false);
+ // From bean class definition
+ defineInternalInjectedMethods(bean, clazz, false);
// From inheritance hierarchy
- defineInternalInjectedMethodsRecursively(component, clazz);
+ defineInternalInjectedMethodsRecursively(bean, clazz);
}
private static <T> void defineInternalInjectedMethodsRecursively(AbstractInjectionTargetBean<T> component, Class<T> clazz)
@@ -994,12 +974,12 @@
addMethodInjectionPointMetaData(component, method);
}
else
- {
- Set<Method> injectedMethods = component.getInjectedMethods();
+ {
+ Method[] beanMethods = component.getReturnType().getDeclaredMethods();
boolean defined = false;
- for (Method definedInjectedMethod : injectedMethods)
+ for (Method beanMethod : beanMethods)
{
- if (definedInjectedMethod.getName().equals(method.getName()) && Arrays.equals(definedInjectedMethod.getParameterTypes(), method.getParameterTypes()))
+ if(ClassUtil.isOverriden(beanMethod, method))
{
defined = true;
break;
@@ -1008,13 +988,11 @@
if(!defined)
{
- component.addInjectedMethod(method);
+ component.addInjectedMethodToSuper(method);
addMethodInjectionPointMetaData(component, method);
}
}
-
}
-
}
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java?rev=826383&r1=826382&r2=826383&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java Sun Oct 18 09:22:04 2009
@@ -230,27 +230,55 @@
// Set injected fields
ManagedBean<T> delegate = (ManagedBean<T>) this.wrappedBean;
- Set<Field> injectedFields = delegate.getInjectedFields();
+ Set<Field> injectedFields = delegate.getInjectedFromSuperFields();
for (Field injectedField : injectedFields)
{
boolean isDecorates = injectedField.isAnnotationPresent(Decorates.class);
if (!isDecorates)
{
- InjectableField ife = new InjectableField(injectedField, proxy, this.wrappedBean,this.creationalContext);
- ife.doInjection();
+ injectField(injectedField, proxy);
}
}
-
- Set<Method> injectedMethods = delegate.getInjectedMethods();
+
+ Set<Method> injectedMethods = delegate.getInjectedFromSuperMethods();
for (Method injectedMethod : injectedMethods)
{
- @SuppressWarnings("unchecked")
- InjectableMethods<?> ife = new InjectableMethods(injectedMethod, proxy, this.wrappedBean,this.creationalContext);
- ife.doInjection();
+ injectMethod(injectedMethod, proxy);
+ }
+
+ injectedFields = delegate.getInjectedFields();
+ for (Field injectedField : injectedFields)
+ {
+ boolean isDecorates = injectedField.isAnnotationPresent(Decorates.class);
+
+ if (!isDecorates)
+ {
+ injectField(injectedField, proxy);
+ }
}
+
+ injectedMethods = delegate.getInjectedMethods();
+ for (Method injectedMethod : injectedMethods)
+ {
+ injectMethod(injectedMethod, proxy);
+ }
+ }
+
+ private void injectField(Field field, Object instance)
+ {
+ InjectableField f = new InjectableField(field, instance, this.wrappedBean, this.creationalContext);
+ f.doInjection();
}
+ @SuppressWarnings("unchecked")
+ private void injectMethod(Method method, Object instance)
+ {
+ InjectableMethods m = new InjectableMethods(method, instance, this.wrappedBean, this.creationalContext);
+ m.doInjection();
+ }
+
+
public void destroy(T instance,CreationalContext<T> context)
{
wrappedBean.destroy(instance,context);
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java?rev=826383&r1=826382&r2=826383&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java Sun Oct 18 09:22:04 2009
@@ -269,22 +269,45 @@
// Set injected fields
ManagedBean<T> delegate = (ManagedBean<T>) this.delegateComponent;
- Set<Field> injectedFields = delegate.getInjectedFields();
+ Set<Field> injectedFields = delegate.getInjectedFromSuperFields();
for (Field injectedField : injectedFields)
{
- InjectableField ife = new InjectableField(injectedField, proxy, this.delegateComponent,creationalContext);
- ife.doInjection();
+ injectField(injectedField, proxy);
}
- Set<Method> injectedMethods = delegate.getInjectedMethods();
+ Set<Method> injectedMethods = delegate.getInjectedFromSuperMethods();
for (Method injectedMethod : injectedMethods)
{
- @SuppressWarnings("unchecked")
- InjectableMethods<?> ife = new InjectableMethods(injectedMethod, proxy, this.delegateComponent,creationalContext);
- ife.doInjection();
+ injectMethod(injectedMethod, proxy);
}
+
+ injectedFields = delegate.getInjectedFields();
+ for (Field injectedField : injectedFields)
+ {
+ injectField(injectedField, proxy);
+ }
+
+ injectedMethods = delegate.getInjectedMethods();
+ for (Method injectedMethod : injectedMethods)
+ {
+ injectMethod(injectedMethod, proxy);
+ }
}
+
+ private void injectField(Field field, Object instance)
+ {
+ InjectableField f = new InjectableField(field, instance, this.delegateComponent, this.creationalContext);
+ f.doInjection();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void injectMethod(Method method, Object instance)
+ {
+ InjectableMethods m = new InjectableMethods(method, instance, this.delegateComponent, this.creationalContext);
+ m.doInjection();
+ }
+
public void destroy(T instance,CreationalContext<T> context)
{
@@ -296,6 +319,7 @@
{
return delegateComponent.getQualifiers();
}
+
@Override
public Class<? extends Annotation> getDeploymentType()
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=826383&r1=826382&r2=826383&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 Oct 18 09:22:04 2009
@@ -1820,4 +1820,31 @@
return rawType;
}
+ public static boolean isOverriden(Method subClassMethod, Method superClassMethod)
+ {
+ if (subClassMethod.getName().equals(superClassMethod.getName()) && Arrays.equals(subClassMethod.getParameterTypes(), superClassMethod.getParameterTypes()))
+ {
+ int modifiers = superClassMethod.getModifiers();
+ if(Modifier.isPrivate(modifiers))
+ {
+ return false;
+ }
+
+ if(!Modifier.isProtected(modifiers) && !Modifier.isPublic(modifiers))
+ {
+ Class<?> superClass = superClassMethod.getDeclaringClass();
+ Class<?> subClass = subClassMethod.getDeclaringClass();
+
+ //Same package
+ if(!subClass.getPackage().getName().equals(superClass.getPackage().getName()))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
}