[webbeans-commits] Webbeans SVN: r3716 - in ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean: builder and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Sep 21 17:45:58 EDT 2009
Author: kabir.khan at jboss.com
Date: 2009-09-21 17:45:58 -0400 (Mon, 21 Sep 2009)
New Revision: 3716
Modified:
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java
Log:
Encapsulate builder better, and make beans more immutable
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -206,7 +206,7 @@
{
Set<FieldInjectionPoint<?, ?>> injectableFields = new HashSet<FieldInjectionPoint<?, ?>>(Beans.getFieldInjectionPoints(this, annotatedItem));
addInjectionPoints(injectableFields);
- return injectableFields;
+ return Collections.unmodifiableSet(injectableFields);
}
/**
@@ -216,7 +216,7 @@
{
Set<MethodInjectionPoint<?, ?>> initializerMethods = Beans.getInitializerMethods(this, getAnnotatedItem());
addInjectionPoints(Beans.getParameterInjectionPoints(this, initializerMethods));
- return initializerMethods;
+ return Collections.unmodifiableSet(initializerMethods);
}
/**
@@ -255,7 +255,7 @@
*/
public Set<? extends MethodInjectionPoint<?, ?>> getInitializerMethods()
{
- return Collections.unmodifiableSet(initializerMethods);
+ return initializerMethods;
}
/**
@@ -263,7 +263,7 @@
*/
public Set<FieldInjectionPoint<?, ?>> getInjectableFields()
{
- return Collections.unmodifiableSet(injectableFields);
+ return injectableFields;
}
// TODO maybe a better way to expose this?
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -21,6 +21,7 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -45,11 +46,11 @@
public class DecoratorImpl<T> extends ManagedBean<T> implements Decorator<T>
{
- private WBInjectionPoint<?, ?> delegateInjectionPoint;
- private final Set<Annotation> delegateBindings = new HashSet<Annotation>();
- private Type delegateType;
- private Set<Type> delegateTypes;
- private Set<Type> decoratedTypes;
+ private final WBInjectionPoint<?, ?> delegateInjectionPoint;
+ private final Set<Annotation> delegateBindings;
+ private final Type delegateType;
+ private final Set<Type> delegateTypes;
+ private final Set<Type> decoratedTypes;
/**
* Creates a decorator bean
@@ -95,23 +96,25 @@
postConstruct, preDestroy, specializedBean);
checkDelegateInjectionPoints();
- initDelegateInjectionPoint();
- initDecoratedTypes();
- initDelegateBindings();
- initDelegateType();
+ delegateInjectionPoint = initDelegateInjectionPoint();
+ decoratedTypes = Collections.unmodifiableSet(initDecoratedTypes());
+ delegateBindings = Collections.unmodifiableSet(initDelegateBindings());
+ delegateType = this.delegateInjectionPoint.getBaseType();
+ delegateTypes = Collections.unmodifiableSet(initDelegateTypes());
checkDelegateType();
}
- protected void initDecoratedTypes()
+ protected Set<Type> initDecoratedTypes()
{
- this.decoratedTypes = new HashSet<Type>();
- this.decoratedTypes.addAll(getAnnotatedItem().getInterfaceOnlyFlattenedTypeHierarchy());
- this.decoratedTypes.remove(Serializable.class);
+ Set<Type> types = new HashSet<Type>();
+ types.addAll(getAnnotatedItem().getInterfaceOnlyFlattenedTypeHierarchy());
+ types.remove(Serializable.class);
+ return types;
}
- protected void initDelegateInjectionPoint()
+ protected WBInjectionPoint<?, ?> initDelegateInjectionPoint()
{
- this.delegateInjectionPoint = getDelegateInjectionPoints().iterator().next();
+ return getDelegateInjectionPoints().iterator().next();
}
@Override
@@ -134,16 +137,16 @@
}
}
- protected void initDelegateBindings()
+ protected Set<Annotation> initDelegateBindings()
{
- this.delegateBindings.addAll(this.delegateInjectionPoint.getQualifiers());
+ return this.delegateInjectionPoint.getQualifiers();
}
- protected void initDelegateType()
+ protected Set<Type> initDelegateTypes()
{
- this.delegateType = this.delegateInjectionPoint.getBaseType();
- this.delegateTypes = new HashSet<Type>();
- delegateTypes.add(delegateType);
+ Set<Type> types = new HashSet<Type>();
+ types.add(delegateType);
+ return types;
}
protected void checkDelegateType()
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -61,13 +61,13 @@
private final Log log = Logging.getLog(AbstractBeanBuilder.class);
// The binding types
- protected Set<Annotation> bindings;
+ private Set<Annotation> bindings;
// The name
- protected String name;
+ private String name;
// The scope type
- protected Class<? extends Annotation> scopeType;
+ private Class<? extends Annotation> scopeType;
// The merged stereotypes
private MergedStereotypes<T, E> mergedStereotypes;
@@ -79,13 +79,13 @@
protected Class<T> type;
// The API types
- protected Set<Type> types;
+ private Set<Type> types;
// If the type a primitive?
private boolean primitive;
// The Web Beans manager
- protected BeanManagerImpl manager;
+ private BeanManagerImpl manager;
private boolean serializable;
@@ -142,6 +142,11 @@
{
types = getAnnotatedItem().getTypeClosure();
}
+
+ void setTypes(Set<Type> types)
+ {
+ this.types = types;
+ }
/**
* Initializes the binding types
@@ -154,6 +159,11 @@
log.trace("Using binding types " + bindings + " specified by annotations");
}
+ void setBindings(Set<Annotation> bindings)
+ {
+ this.bindings = bindings;
+ }
+
void initDefaultBindings()
{
if (bindings.size() == 0)
@@ -335,6 +345,11 @@
{
return scopeType;
}
+
+ void setScope(Class<? extends Annotation> scopeType)
+ {
+ this.scopeType = scopeType;
+ }
/**
* Gets the type of the bean
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -241,8 +241,8 @@
{
if (getAnnotatedItem().isAnnotationPresent(scopeTypes.iterator().next().annotationType()))
{
- this.scopeType = scopeTypes.iterator().next().annotationType();
- log.trace("Scope " + scopeType + " specified by annotation");
+ setScope(scopeTypes.iterator().next().annotationType());
+ log.trace("Scope " + getScope() + " specified by annotation");
}
break;
}
@@ -252,14 +252,14 @@
}
}
- if (this.scopeType == null)
+ if (getScope() == null)
{
initScopeTypeFromStereotype();
}
- if (this.scopeType == null)
+ if (this.getScope() == null)
{
- this.scopeType = Dependent.class;
+ setScope(Dependent.class);
log.trace("Using default @Dependent scope");
}
}
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -94,14 +94,14 @@
types = new HashSet<Type>();
types.add(getType());
types.add(Object.class);
- super.types = types;
+ setTypes(types);
}
else if (getType().isInterface())
{
Set<Type> types = new HashSet<Type>();
types.add(Object.class);
types.addAll(getAnnotatedItem().getTypeClosure());
- super.types = types;
+ setTypes(types);
}
else
{
@@ -189,12 +189,12 @@
}
else if (instance != null)
{
- boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating();
+ boolean passivating = getManager().getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating();
if (passivating && !Reflections.isSerializable(instance.getClass()))
{
throw new IllegalProductException("Producers cannot declare passivating scope and return a non-serializable class");
}
- InjectionPoint injectionPoint = manager.getCurrentInjectionPoint();
+ InjectionPoint injectionPoint = getManager().getCurrentInjectionPoint();
if (injectionPoint == null)
{
return;
@@ -240,16 +240,16 @@
}
if (scopeAnnotations.size() == 1)
{
- this.scopeType = scopeAnnotations.iterator().next().annotationType();
- log.trace("Scope " + scopeType + " specified by annotation");
+ setScope(scopeAnnotations.iterator().next().annotationType());
+ log.trace("Scope " + getScope() + " specified by annotation");
return;
}
initScopeTypeFromStereotype();
- if (this.scopeType == null)
+ if (getScope() == null)
{
- this.scopeType = Dependent.class;
+ setScope(Dependent.class);
log.trace("Using default @Dependent scope");
}
}
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -77,7 +77,7 @@
return creationalContextImpl.getIncompleteInstance(getDeclaringBean());
}
}
- return manager.getReference(getDeclaringBean(), Object.class, creationalContext);
+ return getManager().getReference(getDeclaringBean(), Object.class, creationalContext);
}
}
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -144,13 +144,13 @@
{
DecoratorImpl<T> bean = DecoratorImpl.of(getAnnotatedItem(),
getManager(),
- name,
+ getName(),
getMergedStereotypes(),
getScope(),
null,
isAlternative(),
isProxyable(),
- bindings,
+ getQualifiers(),
getSuperclasses(),
getPostConstruct(),
getPreDestroy(),
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -91,8 +91,9 @@
void initBindings()
{
// At least 1 parameter exists, already checked in constructor
- this.bindings = new HashSet<Annotation>();
- this.bindings.addAll(disposalMethod.getWBParameters().get(0).getQualifiers());
+ HashSet<Annotation> bindings = new HashSet<Annotation>();
+ bindings.addAll(disposalMethod.getWBParameters().get(0).getQualifiers());
+ setBindings(bindings);
initDefaultBindings();
}
@@ -106,7 +107,7 @@
types = new HashSet<Type>();
types.addAll(disposalMethod.getAnnotatedWBParameters(Disposes.class).get(0).getTypeClosure());
types.add(Object.class);
- super.types = types;
+ setTypes(types);
}
@Override
@@ -122,12 +123,6 @@
}
@Override
- Set<Type> getTypes()
- {
- return types;
- }
-
- @Override
public String toString()
{
return disposalMethod.toString();
@@ -240,16 +235,16 @@
DisposalMethod<T> createBean()
{
- DisposalMethod<T> bean = DisposalMethod.of(manager,
- name,
+ DisposalMethod<T> bean = DisposalMethod.of(getManager(),
+ getName(),
disposalMethod,
getDeclaringBean(),
- type,
- types,
+ getType(),
+ getTypes(),
getMergedStereotypes(),
isAlternative(),
isProxyable(),
- bindings);
+ getQualifiers());
bean.initialize();
registerSpecializedBean(bean);
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -104,7 +104,7 @@
{
throw new DefinitionException("Managed bean " + type + " must be @Dependent");
}
- boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).isPassivating();
+ boolean passivating = getManager().getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating();
if (passivating && !Reflections.isSerializable(getBeanClass()))
{
throw new DefinitionException("Simple bean declaring a passivating scope must have a serializable implementation class " + toString());
@@ -221,13 +221,13 @@
ManagedBean<T> bean = ManagedBean.of(
getAnnotatedItem(),
getManager(),
- name,
+ getName(),
getMergedStereotypes(),
getScope(),
getDecorators(),
isAlternative(),
isProxyable(),
- bindings,
+ getQualifiers(),
getSuperclasses(),
getProxyClassForDecorators(),
getPostConstruct(),
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -122,13 +122,13 @@
NewManagedBean<T> bean = NewManagedBean.of(
getAnnotatedItem(),
getManager(),
- name,
+ getName(),
getMergedStereotypes(),
getScope(),
getDecorators(),
isAlternative(),
isAlternative(),
- bindings,
+ getQualifiers(),
getSuperclasses(),
getProxyClassForDecorators(),
getPostConstruct(),
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -130,14 +130,14 @@
{
NewSessionBean<T> bean = NewSessionBean.of(getEjbDescriptor(),
getManager(),
- name,
- types,
+ getName(),
+ getTypes(),
getMergedStereotypes(),
getScope(),
getDecorators(),
isAlternative(),
isProxyable(),
- bindings,
+ getQualifiers(),
getSuperclasses(),
getProxyClassForDecorators(),
getPostConstruct(),
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -163,44 +163,44 @@
{
bean = PersistenceContextProducerField.of(field,
getDeclaringBean(),
- manager,
- name,
- type,
- types,
- getMergedStereotypes(), //Should be empty?
+ getManager(),
+ getName(),
+ getType(),
+ getTypes(),
+ getMergedStereotypes(),
getScope(),
isAlternative(),
isProxyable(),
- bindings);
+ getQualifiers());
}
else if (isEEResourceProducerField(field))
{
bean = EEResourceProducerField.of(field,
getDeclaringBean(),
- manager,
- name,
- type,
- types,
- getMergedStereotypes(), //Should be empty?
+ getManager(),
+ getName(),
+ getType(),
+ getTypes(),
+ getMergedStereotypes(),
getScope(),
isAlternative(),
isProxyable(),
- bindings);
+ getQualifiers());
}
else
{
bean = ProducerField.of(field,
getDeclaringBean(),
- manager,
- name,
- type,
- types,
- getMergedStereotypes(), //Should be empty?
+ getManager(),
+ getName(),
+ getType(),
+ getTypes(),
+ getMergedStereotypes(),
getScope(),
isAlternative(),
isProxyable(),
- bindings);
+ getQualifiers());
}
bean.initialize();
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -248,15 +248,15 @@
{
ProducerMethod<T> bean = ProducerMethod.of(method,
getDeclaringBean(),
- manager,
- name,
- type,
- types,
+ getManager(),
+ getName(),
+ getType(),
+ getTypes(),
getMergedStereotypes(),
- scopeType,
+ getScope(),
isAlternative(),
isProxyable(),
- bindings,
+ getQualifiers(),
disposalMethodBean,
specializedBean);
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java 2009-09-21 21:13:38 UTC (rev 3715)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java 2009-09-21 21:45:58 UTC (rev 3716)
@@ -119,7 +119,7 @@
{
types.add(businessInterfaceDescriptor.getInterface());
}
- super.types = types;
+ setTypes(types);
}
void initProxyClass()
@@ -312,14 +312,14 @@
{
SessionBean<T> bean = SessionBean.of(getEjbDescriptor(),
getManager(),
- name,
- types,
+ getName(),
+ getTypes(),
getMergedStereotypes(),
getScope(),
getDecorators(),
isAlternative(),
isProxyable(),
- bindings,
+ getQualifiers(),
getSuperclasses(),
getProxyClassForDecorators(),
getPostConstruct(),
More information about the weld-commits
mailing list