Skip to content

Commit

Permalink
Remove XML stuff, there is a new way of doing it, other tidy ups
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@438 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Dec 7, 2008
1 parent 9965c10 commit cda2347
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 600 deletions.
Expand Up @@ -52,7 +52,6 @@
import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.ejb.DefaultEnterpriseBeanLookup;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.exceptions.NameResolutionLocation;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
Expand Down Expand Up @@ -474,7 +473,7 @@ public Object getInstanceByName(String name)
}
else if (beans.size() > 1)
{
throw new AmbiguousDependencyException(new NameResolutionLocation(name) + "Resolved multiple Web Beans");
throw new AmbiguousDependencyException("Resolved multiple Web Beans with " + name);
}
else
{
Expand Down
182 changes: 47 additions & 135 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -146,42 +146,23 @@ protected void initApiTypes()
protected void initBindingTypes()
{
this.bindingTypes = new HashSet<Annotation>();
if (isDefinedInXml())
boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
this.bindingTypes.addAll(getAnnotatedItem().getMetaAnnotations(BindingType.class));
if (specialization)
{
boolean xmlSpecialization = false;
Set<Annotation> xmlBindingTypes = null;
this.bindingTypes.addAll(xmlBindingTypes);
if (xmlSpecialization)
{
this.bindingTypes.addAll(bindingTypes);
log.trace("Using binding types " + this.bindingTypes + " specified in XML and specialized type");
}
else
{
log.trace("Using binding types " + this.bindingTypes + " specified in XML");
}
return;
this.bindingTypes.addAll(getSpecializedType().getBindingTypes());
log.trace("Using binding types " + bindingTypes + " specified by annotations and specialized supertype");
}
else if (!mergedStereotypes.isDeclaredInXml())
else if (bindingTypes.size() == 0)
{
boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
this.bindingTypes.addAll(getAnnotatedItem().getMetaAnnotations(BindingType.class));
if (specialization)
{
this.bindingTypes.addAll(getSpecializedType().getBindingTypes());
log.trace("Using binding types " + bindingTypes + " specified by annotations and specialized supertype");
}
else if (bindingTypes.size() == 0)
{
log.trace("Adding default @Current binding type");
this.bindingTypes.add(new CurrentAnnotationLiteral());
}
else
{
log.trace("Using binding types " + bindingTypes + " specified by annotations");
}
return;
log.trace("Adding default @Current binding type");
this.bindingTypes.add(new CurrentAnnotationLiteral());
}
else
{
log.trace("Using binding types " + bindingTypes + " specified by annotations");
}
return;
}

/**
Expand All @@ -190,42 +171,24 @@ else if (bindingTypes.size() == 0)
@SuppressWarnings("null")
protected void initDeploymentType()
{
if (isDefinedInXml())
{
Set<Annotation> xmlDeploymentTypes = null;
if (xmlDeploymentTypes.size() > 1)
{
throw new DefinitionException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
}
Set<Annotation> deploymentTypes = getAnnotatedItem().getMetaAnnotations(DeploymentType.class);

if (xmlDeploymentTypes.size() == 1)
{
this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType();
log.trace("Deployment type " + deploymentType + " specified in XML");
return;
}
if (deploymentTypes.size() > 1)
{
throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
}
else
if (deploymentTypes.size() == 1)
{
Set<Annotation> deploymentTypes = getAnnotatedItem().getMetaAnnotations(DeploymentType.class);

if (deploymentTypes.size() > 1)
{
throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
}
if (deploymentTypes.size() == 1)
{
this.deploymentType = deploymentTypes.iterator().next().annotationType();
log.trace("Deployment type " + deploymentType + " specified by annotation");
return;
}
this.deploymentType = deploymentTypes.iterator().next().annotationType();
log.trace("Deployment type " + deploymentType + " specified by annotation");
return;
}

if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
{
this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
log.trace("Deployment type " + deploymentType + " specified by stereotype");
return;
}
if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
{
this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
log.trace("Deployment type " + deploymentType + " specified by stereotype");
return;
}

this.deploymentType = getDefaultDeploymentType();
Expand Down Expand Up @@ -256,54 +219,31 @@ protected void initInjectionPoints()
protected void initName()
{
boolean beanNameDefaulted = false;
if (isDefinedInXml())
boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
if (getAnnotatedItem().isAnnotationPresent(Named.class))
{
boolean xmlSpecialization = false;
if (xmlSpecialization)
if (specialization)
{
throw new DefinitionException("Name specified for specialized bean (declared in XML)");
throw new DefinitionException("Name specified for specialized bean");
}
String xmlName = "";
if ("".equals(xmlName))
String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
if ("".equals(javaName))
{
log.trace("Using default name (specified in XML)");
log.trace("Using default name (specified by annotations)");
beanNameDefaulted = true;
}
else
{
log.trace("Using name " + xmlName + " specified in XML");
this.name = xmlName;
log.trace("Using name " + javaName + " specified by annotations");
this.name = javaName;
return;
}
}
else
else if (specialization)
{
boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
if (getAnnotatedItem().isAnnotationPresent(Named.class))
{
if (specialization)
{
throw new DefinitionException("Name specified for specialized bean");
}
String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
if ("".equals(javaName))
{
log.trace("Using default name (specified by annotations)");
beanNameDefaulted = true;
}
else
{
log.trace("Using name " + javaName + " specified by annotations");
this.name = javaName;
return;
}
}
else if (specialization)
{
this.name = getSpecializedType().getName();
log.trace("Using supertype name");
return;
}
this.name = getSpecializedType().getName();
log.trace("Using supertype name");
return;
}

if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
Expand All @@ -327,34 +267,16 @@ protected void initPrimitive()
@SuppressWarnings("null")
protected void initScopeType()
{
if (isDefinedInXml())
if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() > 1)
{
Set<Class<? extends Annotation>> scopeTypes = null;
if (scopeTypes.size() > 1)
{
throw new DefinitionException("At most one scope may be specified in XML");
}

if (scopeTypes.size() == 1)
{
this.scopeType = scopeTypes.iterator().next();
log.trace("Scope " + scopeType + " specified in XML");
return;
}
throw new DefinitionException("At most one scope may be specified");
}
else
{
if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() > 1)
{
throw new DefinitionException("At most one scope may be specified");
}

if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() == 1)
{
this.scopeType = getAnnotatedItem().getMetaAnnotations(ScopeType.class).iterator().next().annotationType();
log.trace("Scope " + scopeType + " specified by annotation");
return;
}
if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() == 1)
{
this.scopeType = getAnnotatedItem().getMetaAnnotations(ScopeType.class).iterator().next().annotationType();
log.trace("Scope " + scopeType + " specified by annotation");
return;
}

if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
Expand Down Expand Up @@ -579,16 +501,6 @@ public boolean isAssignableFrom(AnnotatedItem<?, ?> annotatedItem)
return this.getAnnotatedItem().isAssignableFrom(annotatedItem);
}

/**
* Indicates if bean was defined in XML
*
* @return True if defined in XML, false if defined with annotations
*/
protected boolean isDefinedInXml()
{
return false;
}

/**
* Inicates if bean is nullable
*
Expand Down
Expand Up @@ -88,15 +88,8 @@ protected void init()
*/
protected void initType()
{
if (isDefinedInXml())
{
log.trace("Bean type specified in Java");
}
else
{
log.trace("Bean type specified in Java");
this.type = getAnnotatedItem().getType();
}
log.trace("Bean type specified in Java");
this.type = getAnnotatedItem().getType();
}

/**
Expand Down Expand Up @@ -154,39 +147,32 @@ protected void initInjectionPoints()
*/
protected void initInitializerMethods()
{
if (isDefinedInXml())
initializerMethods = new HashSet<AnnotatedMethod<Object>>();
for (AnnotatedMethod<Object> annotatedMethod : annotatedItem.getAnnotatedMethods(Initializer.class))
{

}
else
{
initializerMethods = new HashSet<AnnotatedMethod<Object>>();
for (AnnotatedMethod<Object> annotatedMethod : annotatedItem.getAnnotatedMethods(Initializer.class))
if (annotatedMethod.isStatic())
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be static");
}
else if (annotatedMethod.getAnnotation(Produces.class) != null)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Produces");
}
else if (annotatedMethod.getAnnotation(Destructor.class) != null)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Destructor");
}
else if (annotatedMethod.getAnnotatedParameters(Disposes.class).size() > 0)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot have parameters annotated @Disposes");
}
else if (annotatedMethod.getAnnotatedParameters(Observes.class).size() > 0)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Observes");
}
else
{
if (annotatedMethod.isStatic())
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be static");
}
else if (annotatedMethod.getAnnotation(Produces.class) != null)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Produces");
}
else if (annotatedMethod.getAnnotation(Destructor.class) != null)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Destructor");
}
else if (annotatedMethod.getAnnotatedParameters(Disposes.class).size() > 0)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot have parameters annotated @Disposes");
}
else if (annotatedMethod.getAnnotatedParameters(Observes.class).size() > 0)
{
throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Observes");
}
else
{
initializerMethods.add(annotatedMethod);
}
initializerMethods.add(annotatedMethod);
}
}
}
Expand Down
Expand Up @@ -50,8 +50,6 @@
public class EnterpriseBean<T> extends AbstractClassBean<T>
{

private String location;

private EjbMetaData<T> ejbMetaData;

/**
Expand Down Expand Up @@ -138,19 +136,9 @@ private void checkSpecialization()
{
return;
}
if (!isDefinedInXml())
{
if (!MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
}
else
if (!MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
if (MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
throw new DefinitionException("XML defined specializing EJB must have annotation defined EJB implementation");
}
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
}

Expand Down Expand Up @@ -280,20 +268,6 @@ protected void injectBoundFields(Manager manager, T instance)
}
}

/**
* Gets the debugging location info
*
* @return The location string
*/
public String getLocation()
{
if (location == null)
{
location = "type: Enterprise Bean; declaring class: " + getType() + ";";
}
return location;
}

/**
* Returns the specializes type of the bean
*
Expand Down

0 comments on commit cda2347

Please sign in to comment.