Skip to content

Commit

Permalink
test for correct constructor before creating the SimpleBean!
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@640 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
Gavin King authored and gavin.king@gmail.com committed Dec 21, 2008
1 parent 29920f5 commit aae5e7a
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -33,13 +33,15 @@
import static org.jboss.webbeans.servlet.Servlet.SERVLET_REQUEST_LISTENER_CLASS;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.webbeans.DefinitionException;
import javax.webbeans.Initializer;
import javax.webbeans.Observable;
import javax.webbeans.Observer;
import javax.webbeans.Observes;
Expand Down Expand Up @@ -348,7 +350,32 @@ private void registerEvent(AnnotatedItem injectionPoint, Set<AbstractBean<?, ?>>
*/
protected static boolean isTypeSimpleWebBean(Class<?> type)
{
return !type.isAnnotation() && !Reflections.isAbstract(type) && !SERVLET_CLASS.isAssignableFrom(type) && !FILTER_CLASS.isAssignableFrom(type) && !SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(type) && !HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(type) && !SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(type) && !ENTERPRISE_BEAN_CLASS.isAssignableFrom(type) && !UICOMPONENT_CLASS.isAssignableFrom(type);
//TODO: check 3.2.1 for more rules!!!!!!
return !type.isAnnotation() &&
!Reflections.isAbstract(type) &&
!SERVLET_CLASS.isAssignableFrom(type) &&
!FILTER_CLASS.isAssignableFrom(type) &&
!SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(type) &&
!HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(type) &&
!SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(type) &&
!ENTERPRISE_BEAN_CLASS.isAssignableFrom(type) &&
!UICOMPONENT_CLASS.isAssignableFrom(type) &&
hasSimpleWebBeanConstructor(type);
}

private static boolean hasSimpleWebBeanConstructor(Class<?> type) {
try {
type.getDeclaredConstructor();
return true;
}
catch (NoSuchMethodException nsme)
{
for (Constructor<?> c: type.getDeclaredConstructors())
{
if (c.isAnnotationPresent(Initializer.class)) return true;
}
return false;
}
}

}

0 comments on commit aae5e7a

Please sign in to comment.