Skip to content

Commit

Permalink
Look over ejb remove method tests ->
Browse files Browse the repository at this point in the history
changes in ejb remove method validation

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@290 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 11, 2008
1 parent dec6cac commit 3128840
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 165 deletions.
Expand Up @@ -2,8 +2,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import javax.webbeans.ApplicationScoped;
import javax.webbeans.Decorator;
Expand All @@ -24,7 +22,6 @@
import org.jboss.webbeans.introspector.impl.InjectableField;
import org.jboss.webbeans.introspector.impl.InjectableMethod;
import org.jboss.webbeans.introspector.impl.InjectableParameter;
import org.jboss.webbeans.util.Reflections;

public class EnterpriseBean<T> extends AbstractClassBean<T>
{
Expand Down Expand Up @@ -130,12 +127,41 @@ private void checkSpecialization()
// TODO logging
protected void initRemoveMethod()
{
if (!getEjbMetaData().isStateful())
{
// Nothing to do for stateless enterprise beans;
return;
}

// >1 @Destructor
if (getEjbMetaData().getDestructorMethods().size() > 1)
{
throw new DefinitionException("Multiple @Destructor methods not allowed");
}


// <1 (0) @Destructors
if (getEjbMetaData().getNoArgsRemoveMethod() != null)
{
if (getEjbMetaData().getRemoveMethods().size() > 1)
{
throw new DefinitionException("Multiple @Remove methods but no @Destructor found");
}
super.removeMethod = checkRemoveMethod(getEjbMetaData().getNoArgsRemoveMethod());
return;
}

if (!getScopeType().equals(Dependent.class))
{
throw new DefinitionException("Only @Dependent scoped enterprise beans can be without remove methods");
}

/*
if (getEjbMetaData().isStateful())
{
if (getEjbMetaData().getRemoveMethods().size() == 1)
{
// super.removeMethod = new InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
super.removeMethod = checkRemoveMethod(getEjbMetaData().getRemoveMethods().get(0));
super.removeMethod = checkRemoveMethod(getEjbMetaData().getRemoveMethods().iterator().next());
}
else if (getEjbMetaData().getRemoveMethods().size() > 1)
{
Expand All @@ -149,7 +175,7 @@ else if (getEjbMetaData().getRemoveMethods().size() > 1)
}
if (possibleRemoveMethods.size() == 1)
{
super.removeMethod = checkRemoveMethod(possibleRemoveMethods.get(0));
super.removeMethod = checkRemoveMethod(possibleRemoveMethods.iterator().next());
}
else if (possibleRemoveMethods.size() == 2)
{
Expand All @@ -160,6 +186,7 @@ else if (possibleRemoveMethods.size() == 2)
if (!firstMethod.equals(secondMethod)) {
throw new DefinitionException("Multiple remove methods are annotated @Remove/@Destructor for " + getType());
}
super.removeMethod = checkRemoveMethod(possibleRemoveMethods.iterator().next());
}
else if (possibleRemoveMethods.size() > 2)
{
Expand All @@ -183,6 +210,7 @@ else if (getEjbMetaData().getRemoveMethods().isEmpty() && !getScopeType().equals
throw new DefinitionException("Only stateful enterprise beans can have methods annotated @Destructor; " + getType() + " is not a stateful enterprise bean");
}
}
*/
}


Expand Down
30 changes: 27 additions & 3 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.webbeans.DefinitionException;
import javax.webbeans.Destructor;

import org.jboss.webbeans.util.Reflections;
Expand All @@ -30,7 +31,9 @@ public enum EjbType
}

private EjbType ejbType;
private List<Method> removeMethods;
private List<Method> removeMethods = new ArrayList<Method>();
private List<Method> destructorMethods = new ArrayList<Method>();
private Method noArgsRemoveMethod;

// TODO Populate this from web.xml
private String ejbLinkJndiName;
Expand All @@ -51,18 +54,24 @@ public EjbMetaData(Class<? extends T> type)
if (type.isAnnotationPresent(STATELESS_ANNOTATION))
{
this.ejbType = STATELESS;
// TODO Has to be done here? If they are not parsed, they can't be detected later on (EnterpriseBean remove method init)
if (!Reflections.getMethods(type, Destructor.class).isEmpty()) {
throw new DefinitionException("Stateless enterprise beans cannot have @Destructor methods");
}
}
else if (type.isAnnotationPresent(STATEFUL_ANNOTATION))
{
this.ejbType = STATEFUL;
this.removeMethods = new ArrayList<Method>();
for (Method removeMethod : Reflections.getMethods(type, REMOVE_ANNOTATION))
{
removeMethods.add(removeMethod);
if (removeMethod.getParameterTypes().length == 0) {
noArgsRemoveMethod = removeMethod;
}
}
for (Method destructorMethod : Reflections.getMethods(type, Destructor.class))
{
removeMethods.add(destructorMethod);
destructorMethods.add(destructorMethod);
}
}
else if (type.isAnnotationPresent(MESSAGE_DRIVEN_ANNOTATION))
Expand Down Expand Up @@ -119,5 +128,20 @@ public Class<? extends T> getType()
{
return type;
}

public List<Method> getDestructorMethods()
{
return destructorMethods;
}

public Method getNoArgsRemoveMethod()
{
return noArgsRemoveMethod;
}

public void setNoArgsRemoveMethod(Method noArgsRemoveMethod)
{
this.noArgsRemoveMethod = noArgsRemoveMethod;
}

}
Expand Up @@ -14,7 +14,7 @@ public void testStateless()
{
EjbMetaData<Lion> lion = new EjbMetaData<Lion>(Lion.class);
assert lion.isStateless();
assert lion.getRemoveMethods() == null;
assert lion.getRemoveMethods().isEmpty();
}

@Test
Expand All @@ -30,7 +30,7 @@ public void testMessageDriven()
{
EjbMetaData<Leopard> leopard = new EjbMetaData<Leopard>(Leopard.class);
assert leopard.isMessageDriven();
assert leopard.getRemoveMethods() == null;
assert leopard.getRemoveMethods().isEmpty();
}

}
Expand Up @@ -12,14 +12,12 @@ public class EnterpriseBeanLifecycleTest extends AbstractTest
@Test(groups="removeMethod") @SpecAssertion(section="3.2.3")
public void testInjectonOfParametersIntoRemoveMethod()
{
// TODO Placeholder
assert false;
}

@Test(groups="specialization") @SpecAssertion(section="3.2.4")
public void testSpecializedBeanAlwaysUsed()
{
// TODO Placeholder
assert false;
}

Expand Down

0 comments on commit 3128840

Please sign in to comment.