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/07/19 19:00:31 UTC
svn commit: r795576 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
component/ decorator/ inject/ util/
Author: gerdogdu
Date: Sun Jul 19 17:00:31 2009
New Revision: 795576
URL: http://svn.apache.org/viewvc?rev=795576&view=rev
Log:
Small corrections.
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/decorator/DecoratorUtil.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/inject/AbstractInjectable.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.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=795576&r1=795575&r2=795576&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 Jul 19 17:00:31 2009
@@ -84,12 +84,22 @@
{
T instance = null;
+ //If injection target is set by Exntesion Observer, use it
if (isInjectionTargetSet())
{
+ //Create instance
instance = getInjectionTarget().produce(creationalContext);
+
+ //Injection Operation
+ getInjectionTarget().inject(instance, creationalContext);
+
+ //Call @PostConstrcut
+ postConstruct(instance);
}
+ //Default operations
else
{
+ //Default creation phases
instance = createDefaultInstance(creationalContext);
}
@@ -144,7 +154,7 @@
}
/**
- * Called before constructor
+ * Called before constructor.
*/
protected void beforeConstructor()
{
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorUtil.java?rev=795576&r1=795575&r2=795576&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DecoratorUtil.java Sun Jul 19 17:00:31 2009
@@ -34,15 +34,27 @@
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.ClassUtil;
+/**
+ * Decorator related utility class.
+ *
+ * @version $Rev$ $Date$
+ *
+ */
public final class DecoratorUtil
{
- private static WebBeansLogger logger = WebBeansLogger.getLogger(DecoratorUtil.class);
+ //Logger instance
+ private static final WebBeansLogger logger = WebBeansLogger.getLogger(DecoratorUtil.class);
+ //Non-instantiate
private DecoratorUtil()
{
-
+ //Empty
}
+ /**
+ * Check decorator conditions.
+ * @param decoratorClazz decorator class
+ */
public static void checkDecoratorConditions(Class<?> decoratorClazz)
{
Set<Type> decoratorSet = new HashSet<Type>();
@@ -85,7 +97,7 @@
boolean found = false;
for (Field field : fields)
{
- if (AnnotationUtil.isAnnotationExist(field.getAnnotations(), Decorates.class))
+ if (AnnotationUtil.isAnnotationExist(field.getDeclaredAnnotations(), Decorates.class))
{
if (found)
{
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=795576&r1=795575&r2=795576&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 Jul 19 17:00:31 2009
@@ -36,6 +36,15 @@
import org.apache.webbeans.util.AnnotationUtil;
import org.apache.webbeans.util.ClassUtil;
+/**
+ * Defines decorators. It wraps the bean instance related
+ * with decorator class. Actually, each decorator is an instance
+ * of the {@link ManagedBean}.
+ *
+ * @version $Rev$ $Date$
+ *
+ * @param <T> decorator type info
+ */
public class WebBeansDecorator<T> implements Decorator<T>
{
private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansDecorator.class);
@@ -52,15 +61,20 @@
/** Delegate field binding types */
protected Set<Annotation> delegateBindingTypes = new HashSet<Annotation>();
- /** Delegated component */
- private AbstractBean<T> delegateComponent;
+ /** Wrapped bean*/
+ private AbstractBean<T> wrappedBean;
+ /**Creational context*/
private CreationalContext<Object> creationalContext;
- public WebBeansDecorator(AbstractBean<T> delegateComponent)
+ /**
+ * Creates a new decorator bean instance with the given wrapped bean.
+ * @param delegateComponent delegate bean instance
+ */
+ public WebBeansDecorator(AbstractBean<T> wrappedBean)
{
- this.delegateComponent = delegateComponent;
- this.clazz = delegateComponent.getReturnType();
+ this.wrappedBean = wrappedBean;
+ this.clazz = wrappedBean.getReturnType();
init();
}
@@ -221,7 +235,7 @@
public void setInjections(Object proxy)
{
// Set injected fields
- ManagedBean<T> delegate = (ManagedBean<T>) this.delegateComponent;
+ ManagedBean<T> delegate = (ManagedBean<T>) this.wrappedBean;
Set<Field> injectedFields = delegate.getInjectedFields();
for (Field injectedField : injectedFields)
@@ -230,7 +244,7 @@
if (!isDecorates)
{
- InjectableField ife = new InjectableField(injectedField, proxy, this.delegateComponent,this.creationalContext);
+ InjectableField ife = new InjectableField(injectedField, proxy, this.wrappedBean,this.creationalContext);
ife.doInjection();
}
}
@@ -239,56 +253,56 @@
for (Method injectedMethod : injectedMethods)
{
@SuppressWarnings("unchecked")
- InjectableMethods<?> ife = new InjectableMethods(injectedMethod, proxy, this.delegateComponent,this.creationalContext);
+ InjectableMethods<?> ife = new InjectableMethods(injectedMethod, proxy, this.wrappedBean,this.creationalContext);
ife.doInjection();
}
}
public void destroy(T instance,CreationalContext<T> context)
{
- delegateComponent.destroy(instance,context);
+ wrappedBean.destroy(instance,context);
}
@Override
public Set<Annotation> getBindings()
{
- return delegateComponent.getBindings();
+ return wrappedBean.getBindings();
}
@Override
public Class<? extends Annotation> getDeploymentType()
{
- return delegateComponent.getDeploymentType();
+ return wrappedBean.getDeploymentType();
}
@Override
public String getName()
{
- return delegateComponent.getName();
+ return wrappedBean.getName();
}
@Override
public Class<? extends Annotation> getScopeType()
{
- return delegateComponent.getScopeType();
+ return wrappedBean.getScopeType();
}
public Set<Type> getTypes()
{
- return delegateComponent.getTypes();
+ return wrappedBean.getTypes();
}
@Override
public boolean isNullable()
{
- return delegateComponent.isNullable();
+ return wrappedBean.isNullable();
}
@Override
public boolean isSerializable()
{
- return delegateComponent.isSerializable();
+ return wrappedBean.isSerializable();
}
/**
@@ -296,12 +310,12 @@
*/
public AbstractBean<T> getDelegateComponent()
{
- return delegateComponent;
+ return wrappedBean;
}
public Set<InjectionPoint> getInjectionPoints()
{
- return delegateComponent.getInjectionPoints();
+ return wrappedBean.getInjectionPoints();
}
/**
@@ -352,18 +366,18 @@
@Override
public Class<?> getBeanClass()
{
- return this.delegateComponent.getBeanClass();
+ return this.wrappedBean.getBeanClass();
}
@Override
public Set<Class<? extends Annotation>> getStereotypes()
{
- return this.delegateComponent.getStereotypes();
+ return this.wrappedBean.getStereotypes();
}
@Override
public Set<Type> getDecoratedTypes() {
- return this.delegateComponent.getTypes();
+ return this.wrappedBean.getTypes();
}
@Override
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=795576&r1=795575&r2=795576&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 Jul 19 17:00:31 2009
@@ -66,10 +66,8 @@
}
/**
- * Gets the injected bean instance in its scoped context.
- *
- * @param injectionPoint injection point definition
- *
+ * Gets the injected bean instance in its scoped context.
+ * @param injectionPoint injection point definition
* @return current bean instance in the resolved bean scope
*/
public <T> Object inject(InjectionPoint injectionPoint)
@@ -89,25 +87,20 @@
return injectResource(injectionPoint.getType(),injectionAnnotations);
}
- //Get injection point Bean component
+ //Get injection point Bean to look for @Dependent
Bean<?> component = InjectionResolver.getInstance().getInjectionPointBean(injectionPoint);
+ //Managed @Dependence instances
if (component.getScopeType().equals(Dependent.class))
{
- if(WebBeansUtil.isManagedBean(this.injectionOwnerComponent))
+ if(WebBeansUtil.isManagedBean(this.injectionOwnerComponent) ||
+ WebBeansUtil.isEnterpriseBean(this.injectionOwnerComponent))
{
return injectForDependent(component,injectionPoint);
}
-
- else
- {
- return injectForComponent(injectionPoint);
- }
- }
- else
- {
- return injectForComponent(injectionPoint);
}
+
+ return injectForComponent(injectionPoint);
}
/**
@@ -161,21 +154,37 @@
return null;
}
- private Object injectForDependent(Bean<?> component, InjectionPoint injectionPoint)
+ /**
+ * Return dependent scoped injection point bean instance.
+ * @param bean injected depedent scoped bean
+ * @param injectionPoint injection point
+ * @return injection point instance
+ */
+ private Object injectForDependent(Bean<?> bean, InjectionPoint injectionPoint)
{
Object object = null;
- object = this.injectionOwnerComponent.getDependent(component,injectionPoint);
+ object = this.injectionOwnerComponent.getDependent(bean,injectionPoint);
return object;
}
- private <T> Object injectForComponent(InjectionPoint injectionPoint)
+ /**
+ * Returns injection point instance.
+ * @param injectionPoint injection point
+ * @return injection point instance
+ */
+ private Object injectForComponent(InjectionPoint injectionPoint)
{
Object object = BeanManagerImpl.getManager().getInstanceToInject(injectionPoint,this.creationalContext);
return object;
}
+ /**
+ * Returns injection points related with given member type of the bean.
+ * @param member java member
+ * @return injection points related with given member type
+ */
protected List<InjectionPoint> getInjectedPoints(Member member)
{
List<InjectionPoint> injectedFields = this.injectionOwnerComponent.getInjectionPoint(member);
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=795576&r1=795575&r2=795576&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 Jul 19 17:00:31 2009
@@ -1882,6 +1882,23 @@
return false;
}
+ /**
+ * Returns true if bean is an enterprise bean, false otherwise.
+ * @param bean bean instance
+ * @return true if bean is an enterprise bean
+ */
+ public static boolean isEnterpriseBean(AbstractBean<?> bean)
+ {
+ Asserts.assertNotNull(bean,"Bean is null");
+
+ if(bean.getWebBeansType().equals(WebBeansType.ENTERPRISE))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
public static void addInjectedImplicitEventComponent(InjectionPoint injectionPoint)
{
Type type = injectionPoint.getType();