Skip to content

Commit

Permalink
EJB restructure tests
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@257 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 6, 2008
1 parent 6aa1f76 commit 1ba7ae8
Show file tree
Hide file tree
Showing 40 changed files with 645 additions and 510 deletions.
Expand Up @@ -39,6 +39,7 @@ public abstract class AbstractClassBeanModel<T> extends AbstractBeanModel<T, Cla
private AnnotatedClass<T> xmlAnnotatedItem;
private Set<InjectableField<?>> injectableFields;
private Set<InjectableMethod<Object>> initializerMethods;
protected boolean annotationDefined;

/**
*
Expand All @@ -50,6 +51,7 @@ public AbstractClassBeanModel(AnnotatedClass<T> annotatedItem, AnnotatedClass<T>
{
this.annotatedItem = annotatedItem;
this.xmlAnnotatedItem = xmlAnnotatedItem;
annotationDefined = annotatedItem != null ? true : false;
}

@Override
Expand Down
Expand Up @@ -5,8 +5,10 @@
import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.Interceptor;
import javax.webbeans.Specializes;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.ejb.EJB;
import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.introspector.AnnotatedClass;

Expand All @@ -30,42 +32,89 @@ protected void init(ManagerImpl container)
checkEnterpriseBeanTypeAllowed();
checkEnterpriseScopeAllowed();
checkConflictingRoles();
checkSpecialization();
}


private void checkSpecialization()
{
if (!getType().isAnnotationPresent(Specializes.class))
{
return;
}
if (annotationDefined)
{
if (!isEJB(getType().getSuperclass()))
{
throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
} else
{
if (!isEJB(getType()))
{
throw new DefinitionException("XML defined specializing EJB must have annotation defined EJB implementation");
}
}
}

private boolean isEJB(Class<? super T> clazz)
{
return clazz.isAnnotationPresent(EJB.SINGLETON_ANNOTATION)
|| clazz.isAnnotationPresent(EJB.STATEFUL_ANNOTATION)
|| clazz.isAnnotationPresent(EJB.STATELESS_ANNOTATION);
}

private void checkEnterpriseBeanTypeAllowed()
{
if (getEjbMetaData().isMessageDriven()) {
throw new DefinitionException("Message Driven Beans can't be Web Beans");
if (getEjbMetaData().isMessageDriven())
{
throw new DefinitionException(
"Message Driven Beans can't be Web Beans");
}
}

protected EjbMetaData<T> getEjbMetaData()
{
return ejbMetaData;
}

protected void checkConflictingRoles() {
if (getType().isAnnotationPresent(Interceptor.class)) {

protected void checkConflictingRoles()
{
if (getType().isAnnotationPresent(Interceptor.class))
{
throw new DefinitionException("Enterprise beans can't be interceptors");
}
if (getType().isAnnotationPresent(Decorator.class)) {
if (getType().isAnnotationPresent(Decorator.class))
{
throw new DefinitionException("Enterprise beans can't be decorators");
}
}

/**
* Check that the scope type is allowed by the stereotypes on the bean and the bean type
* @param type
* Check that the scope type is allowed by the stereotypes on the bean and
* the bean type
*
* @param type
*/
protected void checkEnterpriseScopeAllowed()
{
if (getEjbMetaData().isStateless() && !getScopeType().equals(Dependent.class))
if (getEjbMetaData().isStateless()
&& !getScopeType().equals(Dependent.class))
{
throw new DefinitionException("Scope " + getScopeType() + " is not allowed on stateless enterpise beans for " + getType() + ". Only @Dependent is allowed on stateless enterprise beans");
throw new DefinitionException("Scope " + getScopeType()
+ " is not allowed on stateless enterpise beans for "
+ getType()
+ ". Only @Dependent is allowed on stateless enterprise beans");
}
if (getEjbMetaData().isSingleton() && (!(getScopeType().equals(Dependent.class) || getScopeType().equals(ApplicationScoped.class))))
if (getEjbMetaData().isSingleton()
&& (!(getScopeType().equals(Dependent.class) || getScopeType()
.equals(ApplicationScoped.class))))
{
throw new DefinitionException("Scope " + getScopeType() + " is not allowed on singleton enterpise beans for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
throw new DefinitionException(
"Scope "
+ getScopeType()
+ " is not allowed on singleton enterpise beans for "
+ getType()
+ ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
}
}

Expand Down

This file was deleted.

0 comments on commit 1ba7ae8

Please sign in to comment.