Skip to content

Commit

Permalink
Switch to using Class<? extends Annotation> from Class<Annotation> an…
Browse files Browse the repository at this point in the history
…d enable some Bean methods

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@128 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Oct 23, 2008
1 parent 193c435 commit 3f48b2d
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 277 deletions.
26 changes: 26 additions & 0 deletions webbeans-api/src/main/java/javax/webbeans/DeploymentException.java
@@ -0,0 +1,26 @@
package javax.webbeans;

public class DeploymentException extends RuntimeException
{

public DeploymentException()
{
super();
}

public DeploymentException(String arg0, Throwable arg1)
{
super(arg0, arg1);
}

public DeploymentException(String arg0)
{
super(arg0);
}

public DeploymentException(Throwable arg0)
{
super(arg0);
}

}
23 changes: 11 additions & 12 deletions webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
Expand Up @@ -16,20 +16,20 @@ public class BeanImpl<T> extends Bean<T>

private static Logger log = LoggerUtil.getLogger(LOGGER_NAME);

private AbstractComponentModel<T, ?> componentMetaModel;
private AbstractComponentModel<T, ?> model;

private ManagerImpl manager;

public BeanImpl(AbstractComponentModel<T, ?> componentMetaModel, ManagerImpl manager)
public BeanImpl(AbstractComponentModel<T, ?> model, ManagerImpl manager)
{
super(manager);
this.componentMetaModel = componentMetaModel;
this.model = model;
}

@Override
public T create()
{
return componentMetaModel.getConstructor().invoke(manager);
return model.getConstructor().invoke(manager);
}

@Override
Expand All @@ -42,32 +42,31 @@ public void destroy(T instance)
@Override
public Set<Annotation> getBindingTypes()
{
return componentMetaModel.getBindingTypes();
return model.getBindingTypes();
}

@Override
public Class<Annotation> getDeploymentType()
public Class<? extends Annotation> getDeploymentType()
{
return null; // componentMetaModel.getDeploymentType();
return model.getDeploymentType();
}

@Override
public String getName()
{
return componentMetaModel.getName();
return model.getName();
}

@Override
public Class<Annotation> getScopeType()
public Class<? extends Annotation> getScopeType()
{
return null; //componentMetaModel.getScopeType();
return model.getScopeType();
}

@Override
public Set<Class<?>> getTypes()
{
// TODO Auto-generated method stub
return null;
return model.getApiTypes();
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -8,6 +8,8 @@
import java.util.Map;
import java.util.Set;

import javax.webbeans.DeploymentException;
import javax.webbeans.Production;
import javax.webbeans.Standard;
import javax.webbeans.TypeLiteral;
import javax.webbeans.manager.Bean;
Expand All @@ -18,16 +20,14 @@
import javax.webbeans.manager.Manager;
import javax.webbeans.Observer;

import org.jboss.webbeans.bindings.ProductionAnnotationLiteral;
import org.jboss.webbeans.bindings.StandardAnnotationLiteral;
import org.jboss.webbeans.ejb.EjbManager;
import org.jboss.webbeans.event.EventBus;
import org.jboss.webbeans.injectable.SimpleInjectable;

public class ManagerImpl implements Manager
{

private List<Annotation> enabledDeploymentTypes;
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private ModelManager modelManager;
private EjbManager ejbLookupManager;
private EventBus eventBus;
Expand All @@ -37,7 +37,7 @@ public class ManagerImpl implements Manager

private Set<Bean<?>> beans;

public ManagerImpl(List<Annotation> enabledDeploymentTypes)
public ManagerImpl(List<Class<? extends Annotation>> enabledDeploymentTypes)
{
initEnabledDeploymentTypes(enabledDeploymentTypes);
this.modelManager = new ModelManager();
Expand All @@ -48,20 +48,20 @@ public ManagerImpl(List<Annotation> enabledDeploymentTypes)
}

private void initEnabledDeploymentTypes(
List<Annotation> enabledDeploymentTypes)
List<Class<? extends Annotation>> enabledDeploymentTypes)
{
this.enabledDeploymentTypes = new ArrayList<Annotation>();
this.enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
if (enabledDeploymentTypes == null)
{
this.enabledDeploymentTypes.add(0, new StandardAnnotationLiteral());
this.enabledDeploymentTypes.add(1, new ProductionAnnotationLiteral());
this.enabledDeploymentTypes.add(0, Standard.class);
this.enabledDeploymentTypes.add(1, Production.class);
} else
{
this.enabledDeploymentTypes.addAll(enabledDeploymentTypes);
if (!this.enabledDeploymentTypes.get(0).annotationType().equals(
if (!this.enabledDeploymentTypes.get(0).equals(
Standard.class))
{
throw new RuntimeException(
throw new DeploymentException(
"@Standard must be the lowest precedence deployment type");
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public <T> Set<Observer<T>> resolveObservers(T event, Annotation... bindings)
return (Set<Observer<T>>) eventBus.getObservers(event, bindings);
}

public List<Annotation> getEnabledDeploymentTypes()
public List<Class<? extends Annotation>> getEnabledDeploymentTypes()
{
return enabledDeploymentTypes;
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void addInjectionPoint(Injectable<?, ?> injectable)

public void registerInjectionPoint(Injectable<?, ?> injectable)
{
resolvedInjectionPoints.put(injectable, injectable.getPossibleTargets(manager.getBeans()));
resolvedInjectionPoints.put(injectable, injectable.getPossibleBeans(manager.getBeans()));
}

public void registerInjectionPoints()
Expand Down
Expand Up @@ -56,10 +56,10 @@ public AnnotatedItem<T, S> getAnnotatedItem()
return annotatedItem;
}

public Set<Bean<?>> getPossibleTargets(Set<Bean<?>> possibleBeans)
public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> beans)
{
Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
for (Bean<?> bean : possibleBeans)
for (Bean<?> bean : beans)
{
if (bean.getTypes().contains(getType()))
{
Expand Down
Expand Up @@ -24,9 +24,9 @@ public Set<Annotation> getBindingTypes()
}

@Override
public Set<Bean<?>> getPossibleTargets(Set<Bean<?>> possibleBeans)
public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> possibleBeans)
{
return delegate.getPossibleTargets(possibleBeans);
return delegate.getPossibleBeans(possibleBeans);
}

@Override
Expand Down
Expand Up @@ -24,9 +24,9 @@ public Set<Annotation> getBindingTypes()
}

@Override
public Set<Bean<?>> getPossibleTargets(Set<Bean<?>> possibleBeans)
public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> possibleBeans)
{
return delegate.getPossibleTargets(possibleBeans);
return delegate.getPossibleBeans(possibleBeans);
}

@Override
Expand Down
Expand Up @@ -32,7 +32,7 @@ public abstract class AbstractClassComponentModel<T> extends AbstractComponentMo
*
* @param annotatedItem Annotations read from java classes
* @param xmlAnnotatedItem Annotations read from XML
* @param container
* @param manager
*/
@SuppressWarnings("unchecked")
public AbstractClassComponentModel(AnnotatedType<T> annotatedItem, AnnotatedType xmlAnnotatedItem)
Expand Down Expand Up @@ -135,12 +135,12 @@ protected void checkScopeAllowed()
log.finest("Checking if " + getScopeType() + " is allowed for " + type);
if (getMergedStereotypes().getSupportedScopes().size() > 0)
{
if (!getMergedStereotypes().getSupportedScopes().contains(getScopeType().annotationType()))
if (!getMergedStereotypes().getSupportedScopes().contains(getScopeType()))
{
throw new RuntimeException("Scope " + getScopeType() + " is not an allowed by the stereotype for " + type);
}
}
if (isDeclaredFinal(type) && !getScopeType().annotationType().equals(Dependent.class))
if (isDeclaredFinal(type) && !getScopeType().equals(Dependent.class))
{
throw new RuntimeException("Scope " + getScopeType() + " is not allowed as the class is declared final or has methods declared final for " + type + ". Only @Dependent is allowed for final components");
}
Expand Down
Expand Up @@ -8,14 +8,14 @@
import java.util.logging.Logger;

import javax.webbeans.BindingType;
import javax.webbeans.Dependent;
import javax.webbeans.DeploymentType;
import javax.webbeans.Named;
import javax.webbeans.Production;
import javax.webbeans.ScopeType;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
import org.jboss.webbeans.bindings.DependentAnnotationLiteral;
import org.jboss.webbeans.bindings.ProductionAnnotationLiteral;
import org.jboss.webbeans.injectable.ComponentConstructor;
import org.jboss.webbeans.injectable.Injectable;
import org.jboss.webbeans.injectable.InjectableMethod;
Expand All @@ -32,12 +32,12 @@ public abstract class AbstractComponentModel<T, E>

private Set<Annotation> bindingTypes;
protected String name;
protected Annotation scopeType;
protected Class<? extends Annotation> scopeType;
private MergedStereotypesModel<T, E> mergedStereotypes;
protected Annotation deploymentType;
protected Class<? extends Annotation> deploymentType;
protected Class<T> type;
protected InjectableMethod<?> removeMethod;
private Set<Class> apiTypes;
private Set<Class<?>> apiTypes;
protected Set<Injectable<?, ?>> injectionPoints;

protected void init(ManagerImpl container)
Expand Down Expand Up @@ -72,9 +72,9 @@ protected void initApiTypes()
apiTypes = getTypeHierachy(getType());
}

protected Set<Class> getTypeHierachy(Class clazz)
protected Set<Class<?>> getTypeHierachy(Class<?> clazz)
{
Set<Class> classes = new HashSet<Class>();
Set<Class<?>> classes = new HashSet<Class<?>>();
if (!(clazz == null || clazz == Object.class))
{
classes.add(clazz);
Expand Down Expand Up @@ -132,7 +132,7 @@ protected void initScopeType()

if (xmlScopes.size() == 1)
{
this.scopeType = xmlScopes.iterator().next();
this.scopeType = xmlScopes.iterator().next().annotationType();
log.finest("Scope " + scopeType + " specified in XML");
return;
}
Expand All @@ -145,22 +145,22 @@ protected void initScopeType()

if (scopes.size() == 1)
{
this.scopeType = scopes.iterator().next();
this.scopeType = scopes.iterator().next().annotationType();
log.finest("Scope " + scopeType + " specified b annotation");
return;
}

if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
{
this.scopeType = getMergedStereotypes().getPossibleScopeTypes().iterator().next();
this.scopeType = getMergedStereotypes().getPossibleScopeTypes().iterator().next().annotationType();
log.finest("Scope " + scopeType + " specified by stereotype");
return;
}
else if (getMergedStereotypes().getPossibleScopeTypes().size() > 1)
{
throw new RuntimeException("All stereotypes must specify the same scope OR a scope must be specified on the component");
}
this.scopeType = new DependentAnnotationLiteral();
this.scopeType = Dependent.class;
log.finest("Using default @Dependent scope");
}

Expand Down Expand Up @@ -215,7 +215,7 @@ protected void initDeploymentType(ManagerImpl container)

if (xmlDeploymentTypes.size() == 1)
{
this.deploymentType = xmlDeploymentTypes.iterator().next();
this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType();
log.finest("Deployment type " + deploymentType + " specified in XML");
return;
}
Expand All @@ -229,7 +229,7 @@ protected void initDeploymentType(ManagerImpl container)
}
if (deploymentTypes.size() == 1)
{
this.deploymentType = deploymentTypes.iterator().next();
this.deploymentType = deploymentTypes.iterator().next().annotationType();
log.finest("Deployment type " + deploymentType + " specified by annotation");
return;
}
Expand All @@ -243,7 +243,7 @@ protected void initDeploymentType(ManagerImpl container)

if (getXmlAnnotatedItem().getDelegate() != null)
{
this.deploymentType = new ProductionAnnotationLiteral();
this.deploymentType = Production.class;
log.finest("Using default @Production deployment type");
return;
}
Expand All @@ -257,11 +257,11 @@ protected void checkDeploymentType()
}
}

public static Annotation getDeploymentType(List<Annotation> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
public static Class<? extends Annotation> getDeploymentType(List<Class<? extends Annotation>> enabledDeploymentTypes, Map<Class<? extends Annotation>, Annotation> possibleDeploymentTypes)
{
for (int i = (enabledDeploymentTypes.size() - 1); i > 0; i--)
{
if (possibleDeploymentTypes.containsKey((enabledDeploymentTypes.get(i).annotationType())))
if (possibleDeploymentTypes.containsKey((enabledDeploymentTypes.get(i))))
{
return enabledDeploymentTypes.get(i);
}
Expand All @@ -281,7 +281,7 @@ public Set<Annotation> getBindingTypes()
return bindingTypes;
}

public Annotation getScopeType()
public Class<? extends Annotation> getScopeType()
{
return scopeType;
}
Expand All @@ -291,7 +291,7 @@ public Class<T> getType()
return type;
}

public Set<Class> getApiTypes()
public Set<Class<?>> getApiTypes()
{
return apiTypes;
}
Expand All @@ -304,7 +304,7 @@ public Set<Class> getApiTypes()
*/
public abstract String getLocation();

public Annotation getDeploymentType()
public Class<? extends Annotation> getDeploymentType()
{
return deploymentType;
}
Expand Down
Expand Up @@ -39,11 +39,11 @@ protected EjbMetaData<T> getEjbMetaData()
*/
protected void checkEnterpriseScopeAllowed()
{
if (getEjbMetaData().isStateless() && !getScopeType().annotationType().equals(Dependent.class))
if (getEjbMetaData().isStateless() && !getScopeType().equals(Dependent.class))
{
throw new RuntimeException("Scope " + getScopeType() + " is not allowed on stateless enterpise bean components for " + getType() + ". Only @Dependent is allowed on stateless enterprise bean components");
}
if (getEjbMetaData().isSingleton() && (!getScopeType().annotationType().equals(Dependent.class) || !getScopeType().annotationType().equals(ApplicationScoped.class)))
if (getEjbMetaData().isSingleton() && (!getScopeType().equals(Dependent.class) || !getScopeType().equals(ApplicationScoped.class)))
{
throw new RuntimeException("Scope " + getScopeType() + " is not allowed on singleton enterpise bean components for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise bean components");
}
Expand Down

0 comments on commit 3f48b2d

Please sign in to comment.