Skip to content

Commit

Permalink
WBRI-70
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@724 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Dec 24, 2008
1 parent 889bd9b commit 8cbbe8e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 77 deletions.
Expand Up @@ -24,13 +24,6 @@
import static org.jboss.webbeans.bean.BeanFactory.createProducerFieldBean;
import static org.jboss.webbeans.bean.BeanFactory.createProducerMethodBean;
import static org.jboss.webbeans.bean.BeanFactory.createSimpleBean;
import static org.jboss.webbeans.ejb.EJB.ENTERPRISE_BEAN_CLASS;
import static org.jboss.webbeans.jsf.JSF.UICOMPONENT_CLASS;
import static org.jboss.webbeans.servlet.Servlet.FILTER_CLASS;
import static org.jboss.webbeans.servlet.Servlet.HTTP_SESSION_LISTENER_CLASS;
import static org.jboss.webbeans.servlet.Servlet.SERVLET_CLASS;
import static org.jboss.webbeans.servlet.Servlet.SERVLET_CONTEXT_LISTENER_CLASS;
import static org.jboss.webbeans.servlet.Servlet.SERVLET_REQUEST_LISTENER_CLASS;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -59,14 +52,17 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.jsf.JSFApiAbstraction;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.ServletApiAbstraction;
import org.jboss.webbeans.transaction.Transaction;
import org.jboss.webbeans.util.Reflections;

Expand Down Expand Up @@ -327,18 +323,21 @@ private void registerEvent(AnnotatedItem injectionPoint, Set<AbstractBean<?, ?>>
* @param type The type to inspect
* @return True if simple Web Bean, false otherwise
*/
protected static boolean isTypeSimpleWebBean(Class<?> type)
protected boolean isTypeSimpleWebBean(Class<?> type)
{
EJBApiAbstraction ejbApiAbstraction = new EJBApiAbstraction(getResourceLoader());
JSFApiAbstraction jsfApiAbstraction = new JSFApiAbstraction(getResourceLoader());
ServletApiAbstraction servletApiAbstraction = new ServletApiAbstraction(getResourceLoader());
//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) &&
!servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(type) &&
!servletApiAbstraction.FILTER_CLASS.isAssignableFrom(type) &&
!servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(type) &&
!servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(type) &&
!servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(type) &&
!ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(type) &&
!jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(type) &&
hasSimpleWebBeanConstructor(type);
}

Expand Down
Expand Up @@ -17,24 +17,23 @@

package org.jboss.webbeans.ejb;

import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.util.ApiAbstraction;

/**
* Utility class for EJB classes etc. EJB metadata should NOT be inspected here
*
* @author Pete Muir
*/
public class EJB extends ApiAbstraction
public class EJBApiAbstraction extends ApiAbstraction
{

public static final Class<?> ENTERPRISE_BEAN_CLASS;

/**
* Static initialization block
*/
static
public EJBApiAbstraction(ResourceLoader resourceLoader)
{
super(resourceLoader);
ENTERPRISE_BEAN_CLASS = classForName("javax.ejb.EnterpriseBean");
}

public final Class<?> ENTERPRISE_BEAN_CLASS;

}
Expand Up @@ -17,6 +17,7 @@

package org.jboss.webbeans.jsf;

import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.util.ApiAbstraction;

/**
Expand All @@ -25,9 +26,17 @@
* @author Pete Muir
*
*/
public class JSF extends ApiAbstraction
public class JSFApiAbstraction extends ApiAbstraction
{


// An UI component
public static final Class<?> UICOMPONENT_CLASS = classForName("javax.faces.component.UIComponent");
public final Class<?> UICOMPONENT_CLASS;

public JSFApiAbstraction(ResourceLoader resourceLoader)
{
super(resourceLoader);
this.UICOMPONENT_CLASS = classForName("javax.faces.component.UIComponent");
}

}
14 changes: 0 additions & 14 deletions webbeans-ri/src/main/java/org/jboss/webbeans/servlet/Servlet.java

This file was deleted.

@@ -0,0 +1,26 @@
package org.jboss.webbeans.servlet;

import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.util.ApiAbstraction;

public class ServletApiAbstraction extends ApiAbstraction
{

public final Class<?> SERVLET_CLASS;
public final Class<?> FILTER_CLASS;
public final Class<?> SERVLET_CONTEXT_LISTENER_CLASS;
public final Class<?> HTTP_SESSION_LISTENER_CLASS;
public final Class<?> SERVLET_REQUEST_LISTENER_CLASS;

public ServletApiAbstraction(ResourceLoader resourceLoader)
{
super(resourceLoader);
SERVLET_CLASS = classForName("javax.servlet.Servlet");
FILTER_CLASS = classForName("javax.servlet.Filter");
SERVLET_CONTEXT_LISTENER_CLASS = classForName("javax.servlet.ServletContextListener");
HTTP_SESSION_LISTENER_CLASS = classForName("javax.servlet.http.HttpSessionListener");
SERVLET_REQUEST_LISTENER_CLASS = classForName("javax.servlet.ServletRequestListener");
}


}
Expand Up @@ -19,13 +19,18 @@

import java.lang.annotation.Annotation;

import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.resources.spi.ResourceLoadingException;

/**
* A base class for utility classes that represent annotations, classes etc
*
* @author Pete Muir
*/
public class ApiAbstraction
{

private ResourceLoader resourceLoader;

/**
* "Not found" annotation
Expand All @@ -40,6 +45,13 @@ public class ApiAbstraction
public interface Dummy
{
}



public ApiAbstraction(ResourceLoader resourceLoader)
{
this.resourceLoader = resourceLoader;
}

/**
* Initializes an annotation class
Expand All @@ -49,13 +61,13 @@ public interface Dummy
* not found
*/
@SuppressWarnings("unchecked")
protected static Class<? extends Annotation> annotationTypeForName(String name)
protected Class<? extends Annotation> annotationTypeForName(String name)
{
try
{
return (Class<? extends Annotation>) Reflections.classForName(name);
return (Class<? extends Annotation>) resourceLoader.classForName(name);
}
catch (ClassNotFoundException cnfe)
catch (ResourceLoadingException cnfe)
{
return DummyAnnotation.class;
}
Expand All @@ -69,13 +81,13 @@ protected static Class<? extends Annotation> annotationTypeForName(String name)
* found.
*/
@SuppressWarnings("unchecked")
protected static Class<?> classForName(String name)
protected Class<?> classForName(String name)
{
try
{
return (Class<? extends Annotation>) Reflections.classForName(name);
return (Class<? extends Annotation>) resourceLoader.classForName(name);
}
catch (ClassNotFoundException cnfe)
catch (ResourceLoadingException cnfe)
{
return Dummy.class;
}
Expand Down
33 changes: 0 additions & 33 deletions webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Expand Up @@ -45,39 +45,6 @@
public class Reflections
{

/**
* Creates an instance from a class name
*
* @param name The class name
* @return The instance
* @throws ClassNotFoundException If the class if not found
*/
public static Class<?> classForName(String name) throws ClassNotFoundException
{
return classForName(name, Thread.currentThread().getContextClassLoader());
}

/**
* Creates an instance from a class name
*
* @param name The class name
* @return The instance
* @throws ClassNotFoundException If the class if not found
*/
private static Class<?> classForName(String name, ClassLoader classLoader) throws ClassNotFoundException
{
try
{
return classLoader.loadClass(name);
}
catch (Exception e)
{
return Class.forName(name);
}
}



/**
* Gets the property name from a getter method
*
Expand Down

0 comments on commit 8cbbe8e

Please sign in to comment.