Author: gpetracek
Date: Tue May 21 21:08:16 2013
New Revision: 1484957
URL: http://svn.apache.org/r1484957
Log:
OWB-774 cleanup of deployment checks (first step)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1484957&r1=1484956&r2=1484957&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Tue May 21 21:08:16 2013
@@ -46,6 +46,7 @@ import org.apache.webbeans.event.Observe
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.WebBeansDeploymentException;
import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.exception.inject.DefinitionException;
import
org.apache.webbeans.exception.inject.InconsistentSpecializationException;
import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.portable.AnnotatedElementFactory;
@@ -594,18 +595,38 @@ public class BeansDeployer
return;
}
+ Class beanClass =
processAnnotatedEvent.getAnnotatedType().getJavaClass();
+
// EJBs can be defined so test them really before going for a
ManagedBean
if (discoverEjb && EJBWebBeansConfigurator.isSessionBean(implClass,
webBeansContext))
{
logger.log(Level.FINE, "Found Enterprise Bean with class name :
[{0}]", implClass.getName());
defineEnterpriseWebBean((Class<Object>) implClass,
(ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
}
- else
+ else if((ClassUtil.isConcrete(beanClass) ||
WebBeansUtil.isDecorator(processAnnotatedEvent.getAnnotatedType())) &&
+ isValidManagedBean(beanClass))
{
- defineManagedBean((Class<Object>) implClass,
(ProcessAnnotatedTypeImpl<Object>) processAnnotatedEvent);
+ defineManagedBean(processAnnotatedEvent);
}
}
-
+
+ private boolean isValidManagedBean(Class beanClass)
+ {
+ try
+ {
+ webBeansContext.getWebBeansUtil().checkManagedBean(beanClass);
+ }
+ catch (DefinitionException e)
+ {
+ logger.info("skipped deployment of: " + beanClass.getName() + "
reason: " + e.getMessage());
+ logger.log(Level.FINER, "skipped deployment of: " +
beanClass.getName() + " details: ", e);
+ return false;
+ }
+ //we are not allowed to catch possible exceptions thrown by the
following method
+ webBeansContext.getWebBeansUtil().checkManagedBeanCondition(beanClass);
+ return true;
+ }
+
/**
* Discovers and deploys alternatives, interceptors and decorators from
XML.
*
@@ -796,10 +817,8 @@ public class BeansDeployer
/**
* Defines and configures managed bean.
* @param <T> type info
- * @param clazz bean class
- * @return true if given class is configured as a managed bean
*/
- protected <T> boolean defineManagedBean(Class<T> clazz,
ProcessAnnotatedTypeImpl<T> processAnnotatedEvent)
+ protected <T> void defineManagedBean(ProcessAnnotatedTypeImpl<T>
processAnnotatedEvent)
{
//Bean manager
BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
@@ -809,12 +828,13 @@ public class BeansDeployer
//Fires ProcessInjectionTarget event for Java EE components instances
//That supports injections but not managed beans
- ProcessInjectionTargetImpl<T> processInjectionTargetEvent = null;
-
if(webBeansContext.getWebBeansUtil().supportsJavaEeComponentInjections(clazz))
+ ProcessInjectionTargetImpl<T> processInjectionTargetEvent;
+ Class beanClass =
processAnnotatedEvent.getAnnotatedType().getJavaClass();
+
if(webBeansContext.getWebBeansUtil().supportsJavaEeComponentInjections(beanClass))
{
//Fires ProcessInjectionTarget
processInjectionTargetEvent =
-
webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEventForJavaEeComponents(clazz);
+
webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEventForJavaEeComponents(beanClass);
webBeansContext.getWebBeansUtil().inspectErrorStack(
"There are errors that are added by ProcessInjectionTarget
event observers. Look at logs for further details");
@@ -822,24 +842,18 @@ public class BeansDeployer
if(processInjectionTargetEvent.isSet())
{
//Adding injection target
- manager.putProducerForJavaEeComponent(clazz,
processInjectionTargetEvent.getInjectionTarget());
+ manager.putProducerForJavaEeComponent(beanClass,
processInjectionTargetEvent.getInjectionTarget());
}
//Checks that not contains @Inject InjectionPoint
-
webBeansContext.getAnnotationManager().checkInjectionPointForInjectInjectionPoint(clazz);
+
webBeansContext.getAnnotationManager().checkInjectionPointForInjectInjectionPoint(beanClass);
}
-
- //Check for whether this class is candidate for Managed Bean
- if (webBeansContext.getWebBeansUtil().isManagedBean(clazz))
+
{
- //Check conditions
- webBeansContext.getWebBeansUtil().checkManagedBeanCondition(clazz);
-
BeanAttributesImpl<T> beanAttributes =
BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(annotatedType).build();
ManagedBeanBuilder<T, ManagedBean<T>> managedBeanCreator = new
ManagedBeanBuilder<T, ManagedBean<T>>(webBeansContext, annotatedType,
beanAttributes);
- InjectionTargetBean<T> bean;
if(WebBeansUtil.isDecorator(annotatedType))
{
if (logger.isLoggable(Level.FINE))
@@ -852,11 +866,6 @@ public class BeansDeployer
dbb.defineDecoratorRules();
DecoratorBean<T> decorator = dbb.getBean();
webBeansContext.getDecoratorsManager().addDecorator(decorator);
- bean = decorator;
- }
- else
- {
- bean = null;
}
}
else if(WebBeansUtil.isCdiInterceptor(annotatedType))
@@ -872,22 +881,16 @@ public class BeansDeployer
ibb.defineCdiInterceptorRules();
CdiInterceptorBean<T> interceptor = ibb.getBean();
webBeansContext.getInterceptorsManager().addCdiInterceptor(interceptor);
- bean = interceptor;
- }
- else
- {
- bean = null;
}
}
else
{
-
- bean = managedBeanCreator.getBean();
+ InjectionTargetBean<T> bean = managedBeanCreator.getBean();
if
(webBeansContext.getDecoratorsManager().containsCustomDecoratorClass(annotatedType.getJavaClass())
||
webBeansContext.getInterceptorsManager().containsCustomInterceptorClass(annotatedType.getJavaClass()))
{
- return false;
+ return; //TODO discuss this case (it was ignored before)
}
if (logger.isLoggable(Level.FINE))
@@ -979,14 +982,7 @@ public class BeansDeployer
}
}
}
- return true;
- }
- else
- {
- //Not a managed bean
- return false;
}
-
}
/**
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=1484957&r1=1484956&r2=1484957&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
Tue May 21 21:08:16 2013
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
import org.apache.webbeans.config.OWBLogConst;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.inject.DefinitionException;
import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
@@ -100,9 +101,9 @@ public class PluginLoader
public static void throwsException(Exception e) throws
WebBeansConfigurationException
{
- if(e instanceof WebBeansConfigurationException)
+ if(e instanceof DefinitionException)
{
- throw (WebBeansConfigurationException)e;
+ throw (DefinitionException)e;
}
else
{
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1484957&r1=1484956&r2=1484957&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Tue May 21 21:08:16 2013
@@ -262,29 +262,9 @@ public final class WebBeansUtil
* Returns true if this class can be candidate for simple web bean, false
otherwise.
*
* @param clazz implementation class
- * @return true if this class can be candidate for simple web bean
* @throws WebBeansConfigurationException if any configuration exception
occurs
*/
- public boolean isManagedBean(Class<?> clazz) throws
WebBeansConfigurationException
- {
- try
- {
- isManagedBeanClass(clazz);
-
- }
- catch (WebBeansConfigurationException e)
- {
- return false;
- }
-
- return true;
- }
-
- /**
- * Return <code>true</code> if the given class is ok for manage bean
conditions,
- * <code>false</code> otherwise.
- */
- public void isManagedBeanClass(Class<?> clazz)
+ public void checkManagedBean(Class<?> clazz)
{
Asserts.nullCheckForClass(clazz, "Class is null");
@@ -296,12 +276,6 @@ public final class WebBeansUtil
+ clazz.getName() + " can
not be non-static inner class");
}
- if (!ClassUtil.isConcrete(clazz) &&
!AnnotationUtil.hasClassAnnotation(clazz, Decorator.class))
- {
- throw new WebBeansConfigurationException("Bean implementation
class : " + clazz.getName()
- + " have to be concrete
if not defines as @Decorator");
- }
-
if (!isConstructorOk(clazz))
{
throw new WebBeansConfigurationException("Bean implementation
class : " + clazz.getName()
@@ -344,8 +318,6 @@ public final class WebBeansUtil
public void checkManagedBeanCondition(Class<?> clazz) throws
WebBeansConfigurationException
{
- int modifier = clazz.getModifiers();
-
if (AnnotationUtil.hasClassAnnotation(clazz, Decorator.class) &&
AnnotationUtil.hasClassAnnotation(clazz, javax.interceptor.Interceptor.class))
{
throw new WebBeansConfigurationException("ManagedBean
implementation class : " + clazz.getName()
@@ -356,11 +328,6 @@ public final class WebBeansUtil
{
webBeansContext.getInterceptorUtil().checkSimpleWebBeansInterceptorConditions(clazz);
}
-
- if (Modifier.isInterface(modifier))
- {
- throw new WebBeansConfigurationException("ManagedBean
implementation class : " + clazz.getName() + " may not _defined as interface");
- }
}
/**