Skip to content

Commit

Permalink
WELD-78 (first of many)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 11, 2010
1 parent 0aa86a5 commit 8f5fd02
Show file tree
Hide file tree
Showing 38 changed files with 253 additions and 295 deletions.
144 changes: 50 additions & 94 deletions impl/src/main/java/org/jboss/weld/bean/AbstractBean.java
Expand Up @@ -69,45 +69,20 @@
public abstract class AbstractBean<T, S> extends RIBean<T>
{

private boolean proxyable;

// Logger
private static final LocLogger log = loggerFactory().getLogger(BEAN);
// The binding types
protected Set<Annotation> bindings;
// The name
protected Set<Annotation> qualifiers;
protected String name;
// The scope type
protected Class<? extends Annotation> scopeType;
// The merged stereotypes
protected Class<? extends Annotation> scope;
private MergedStereotypes<T, S> mergedStereotypes;
// Is it a policy, either defined by stereotypes or directly?
protected boolean alternative;
// The type
protected Class<T> type;
// The API types
protected Set<Type> types;
// The injection points
private Set<WeldInjectionPoint<?, ?>> injectionPoints;
private Set<WeldInjectionPoint<?, ?>> delegateInjectionPoints;

// The @New injection points
private Set<WeldInjectionPoint<?, ?>> newInjectionPoints;

// If the type a primitive?
private boolean primitive;
// The Bean manager
protected BeanManagerImpl manager;

protected BeanManagerImpl beanManager;
private boolean initialized;



protected boolean isInitialized()
{
return initialized;
}

/**
* Constructor
*
Expand All @@ -116,7 +91,7 @@ protected boolean isInitialized()
public AbstractBean(String idSuffix, BeanManagerImpl manager)
{
super(idSuffix, manager);
this.manager = manager;
this.beanManager = manager;
this.injectionPoints = new HashSet<WeldInjectionPoint<?, ?>>();
this.delegateInjectionPoints = new HashSet<WeldInjectionPoint<?,?>>();
this.newInjectionPoints = new HashSet<WeldInjectionPoint<?,?>>();
Expand All @@ -134,18 +109,16 @@ public void initialize(BeanDeployerEnvironment environment)
specialize(environment);
postSpecialize();
}
initDefaultBindings();
initPrimitive();
initDefaultQualifiers();
log.trace(CREATING_BEAN, getType());
initName();
initScopeType();
initProxyable();
initScope();
checkDelegateInjectionPoints();
}

protected void initStereotypes()
{
mergedStereotypes = new MergedStereotypes<T, S>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager);
mergedStereotypes = new MergedStereotypes<T, S>(getWeldAnnotated().getMetaAnnotations(Stereotype.class), beanManager);
}

protected void checkDelegateInjectionPoints()
Expand Down Expand Up @@ -182,18 +155,15 @@ protected void addInjectionPoints(Iterable<? extends WeldInjectionPoint<?, ?>> i
return delegateInjectionPoints;
}

/**
* Initializes the API types
*/
protected void initTypes()
{
if (getAnnotatedItem().isAnnotationPresent(Typed.class))
if (getWeldAnnotated().isAnnotationPresent(Typed.class))
{
this.types = getTypedTypes(Reflections.buildTypeMap(getAnnotatedItem().getTypeClosure()), getAnnotatedItem().getJavaClass(), getAnnotatedItem().getAnnotation(Typed.class));
this.types = getTypedTypes(Reflections.buildTypeMap(getWeldAnnotated().getTypeClosure()), getWeldAnnotated().getJavaClass(), getWeldAnnotated().getAnnotation(Typed.class));
}
else
{
this.types = new HashSet<Type>(getAnnotatedItem().getTypeClosure());
this.types = new HashSet<Type>(getWeldAnnotated().getTypeClosure());
if (getType().isInterface())
{
this.types.add(Object.class);
Expand All @@ -219,38 +189,35 @@ protected static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<
return types;
}

/**
* Initializes the binding types
*/
protected void initBindings()
protected void initQualifiers()
{
this.bindings = new HashSet<Annotation>();
this.bindings.addAll(getAnnotatedItem().getMetaAnnotations(Qualifier.class));
initDefaultBindings();
log.trace(QUALIFIERS_USED, bindings, this);
this.qualifiers = new HashSet<Annotation>();
this.qualifiers.addAll(getWeldAnnotated().getMetaAnnotations(Qualifier.class));
initDefaultQualifiers();
log.trace(QUALIFIERS_USED, qualifiers, this);
}

protected void initDefaultBindings()
protected void initDefaultQualifiers()
{
if (bindings.size() == 0)
if (qualifiers.size() == 0)
{
log.trace(USING_DEFAULT_QUALIFIER, this);
this.bindings.add(DefaultLiteral.INSTANCE);
this.qualifiers.add(DefaultLiteral.INSTANCE);
}
if (bindings.size() == 1)
if (qualifiers.size() == 1)
{
if (bindings.iterator().next().annotationType().equals(Named.class))
if (qualifiers.iterator().next().annotationType().equals(Named.class))
{
log.trace(USING_DEFAULT_QUALIFIER, this);
this.bindings.add(DefaultLiteral.INSTANCE);
this.qualifiers.add(DefaultLiteral.INSTANCE);
}
}
this.bindings.add(AnyLiteral.INSTANCE);
this.qualifiers.add(AnyLiteral.INSTANCE);
}

protected void initAlternative()
{
this.alternative = Beans.isAlternative(getAnnotatedItem(), getMergedStereotypes());
this.alternative = Beans.isAlternative(getWeldAnnotated(), getMergedStereotypes());
}

/**
Expand All @@ -259,9 +226,9 @@ protected void initAlternative()
protected void initName()
{
boolean beanNameDefaulted = false;
if (getAnnotatedItem().isAnnotationPresent(Named.class))
if (getWeldAnnotated().isAnnotationPresent(Named.class))
{
String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
String javaName = getWeldAnnotated().getAnnotation(Named.class).value();
if ("".equals(javaName))
{
beanNameDefaulted = true;
Expand All @@ -282,36 +249,20 @@ protected void initName()
}
}

protected void initProxyable()
{
proxyable = getAnnotatedItem().isProxyable();
}
protected abstract void initScope();

/**
* Initializes the primitive flag
*/
protected void initPrimitive()
protected boolean initScopeFromStereotype()
{
this.primitive = Reflections.isPrimitive(getType());
}

/**
* Initializes the scope type
*/
protected abstract void initScopeType();

protected boolean initScopeTypeFromStereotype()
{
Set<Annotation> possibleScopeTypes = getMergedStereotypes().getPossibleScopeTypes();
if (possibleScopeTypes.size() == 1)
Set<Annotation> possibleScopes = getMergedStereotypes().getPossibleScopes();
if (possibleScopes.size() == 1)
{
this.scopeType = possibleScopeTypes.iterator().next().annotationType();
log.trace(USING_SCOPE_FROM_STEREOTYPE, scopeType, this, getMergedStereotypes());
this.scope = possibleScopes.iterator().next().annotationType();
log.trace(USING_SCOPE_FROM_STEREOTYPE, scope, this, getMergedStereotypes());
return true;
}
else if (possibleScopeTypes.size() > 1)
else if (possibleScopes.size() > 1)
{
throw new DefinitionException(MULTIPLE_SCOPES_FOUND_FROM_STEREOTYPES, getAnnotatedItem());
throw new DefinitionException(MULTIPLE_SCOPES_FOUND_FROM_STEREOTYPES, getWeldAnnotated());
}
else
{
Expand All @@ -321,16 +272,16 @@ else if (possibleScopeTypes.size() > 1)

protected void postSpecialize()
{
if (getAnnotatedItem().isAnnotationPresent(Named.class) && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
if (getWeldAnnotated().isAnnotationPresent(Named.class) && getSpecializedBean().getWeldAnnotated().isAnnotationPresent(Named.class))
{
throw new DefinitionException(NAME_NOT_ALLOWED_ON_SPECIALIZATION, getAnnotatedItem());
throw new DefinitionException(NAME_NOT_ALLOWED_ON_SPECIALIZATION, getWeldAnnotated());
}
this.bindings.addAll(getSpecializedBean().getQualifiers());
if (isSpecializing() && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
this.qualifiers.addAll(getSpecializedBean().getQualifiers());
if (isSpecializing() && getSpecializedBean().getWeldAnnotated().isAnnotationPresent(Named.class))
{
this.name = getSpecializedBean().getName();
}
manager.getSpecializedBeans().put(getSpecializedBean(), this);
beanManager.getSpecializedBeans().put(getSpecializedBean(), this);
}

protected void preSpecialize(BeanDeployerEnvironment environment)
Expand All @@ -348,7 +299,7 @@ protected void specialize(BeanDeployerEnvironment environment)
*
* @return The annotated item
*/
public abstract WeldAnnotated<T, S> getAnnotatedItem();
public abstract WeldAnnotated<T, S> getWeldAnnotated();

/**
* Gets the binding types
Expand All @@ -359,7 +310,7 @@ protected void specialize(BeanDeployerEnvironment environment)
*/
public Set<Annotation> getQualifiers()
{
return bindings;
return qualifiers;
}

/**
Expand All @@ -373,7 +324,7 @@ public Set<Annotation> getQualifiers()
public abstract AbstractBean<?, ?> getSpecializedBean();

@Override
public Set<WeldInjectionPoint<?, ?>> getAnnotatedInjectionPoints()
public Set<WeldInjectionPoint<?, ?>> getWeldInjectionPoints()
{
return injectionPoints;
}
Expand Down Expand Up @@ -414,7 +365,7 @@ public String getName()
*/
public Class<? extends Annotation> getScope()
{
return scopeType;
return scope;
}

/**
Expand Down Expand Up @@ -460,13 +411,13 @@ public boolean isNullable()
@Override
public boolean isPrimitive()
{
return primitive;
return getWeldAnnotated().isPrimitive();
}

@Override
public boolean isProxyable()
{
return proxyable;
return getWeldAnnotated().isProxyable();
}

@Override
Expand All @@ -488,12 +439,17 @@ public boolean isAlternative()
@Override
public boolean isSpecializing()
{
return getAnnotatedItem().isAnnotationPresent(Specializes.class);
return getWeldAnnotated().isAnnotationPresent(Specializes.class);
}

public Set<Class<? extends Annotation>> getStereotypes()
{
return mergedStereotypes.getStereotypes();
}

protected boolean isInitialized()
{
return initialized;
}

}

0 comments on commit 8f5fd02

Please sign in to comment.