You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ke...@apache.org on 2010/10/07 18:35:07 UTC
svn commit: r1005519 - in /openwebbeans/trunk/webbeans-impl/src/main:
java/org/apache/webbeans/config/ java/org/apache/webbeans/portable/
resources/openwebbeans/
Author: kelapure
Date: Thu Oct 7 16:35:07 2010
New Revision: 1005519
URL: http://svn.apache.org/viewvc?rev=1005519&view=rev
Log:
OWB-468 Make BeansDeployer.deployFromClassPath(ScannerService) resilient to ClassNotFoundException and NoClassDefFoundError's
https://issues.apache.org/jira/browse/OWB-468
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OWBLogConst.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
openwebbeans/trunk/webbeans-impl/src/main/resources/openwebbeans/Messages.properties
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=1005519&r1=1005518&r2=1005519&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 Thu Oct 7 16:35:07 2010
@@ -471,27 +471,39 @@ public class BeansDeployer
//Define annotation type
AnnotatedType<?> annotatedType = AnnotatedElementFactory.getInstance().newAnnotatedType(implClass);
- //Fires ProcessAnnotatedType
- ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
-
- //if veto() is called
- if(processAnnotatedEvent.isVeto())
+ if (null != annotatedType)
{
- continue;
- }
-
- //Try class is Managed Bean
- boolean isDefined = defineManagedBean((Class<Object>)implClass, (ProcessAnnotatedTypeImpl<Object>)processAnnotatedEvent);
-
- //Try class is EJB bean
- if(!isDefined && this.discoverEjb)
- {
- if(EJBWebBeansConfigurator.isSessionBean(implClass))
+ //Fires ProcessAnnotatedType
+ ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);
+
+ //if veto() is called
+ if(processAnnotatedEvent.isVeto())
{
- logger.debug("Found Enterprise Bean with class name : [{0}]", implClass.getName());
- defineEnterpriseWebBean((Class<Object>)implClass, (ProcessAnnotatedTypeImpl<Object>)processAnnotatedEvent);
+ continue;
}
- }
+
+ //Try class is Managed Bean
+ boolean isDefined = defineManagedBean((Class<Object>)implClass, (ProcessAnnotatedTypeImpl<Object>)processAnnotatedEvent);
+
+ //Try class is EJB bean
+ if(!isDefined && this.discoverEjb)
+ {
+ if(EJBWebBeansConfigurator.isSessionBean(implClass))
+ {
+ logger.debug("Found Enterprise Bean with class name : [{0}]", implClass.getName());
+ defineEnterpriseWebBean((Class<Object>)implClass, (ProcessAnnotatedTypeImpl<Object>)processAnnotatedEvent);
+ }
+ }
+ }
+ else
+ {
+ if (logger.wblWillLogDebug())
+ {
+ logger.debug("Error creating managed bean "+ implClass);
+ }
+
+ }
+
}
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OWBLogConst.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OWBLogConst.java?rev=1005519&r1=1005518&r2=1005519&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OWBLogConst.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OWBLogConst.java Thu Oct 7 16:35:07 2010
@@ -95,6 +95,7 @@ public class OWBLogConst
public final static String ERROR_0024 = "ERROR_0024"; // Unable to get resource with class \: [{0}] in \: [{1}] with name \: [{2}].
public final static String ERROR_0025 = "ERROR_0025"; // Unable to inject field \: [{0}]
public final static String ERROR_0026 = "ERROR_0026"; // An error occured while injecting dependencies of bean \: [{0}]
+ public final static String ERROR_0027 = "ERROR_0027"; // Unable to create AnnotatedType for class \: [{0}]. Exception cause \: [{1}].
public final static String FATAL_0001 = "FATAL_0001"; // Exception thrown while destroying bean instance : {0}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java?rev=1005519&r1=1005518&r2=1005519&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java Thu Oct 7 16:35:07 2010
@@ -29,9 +29,11 @@ import javax.enterprise.inject.spi.Annot
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.util.Asserts;
import org.apache.webbeans.util.SecurityUtil;
-import org.apache.webbeans.config.WebBeansFinder;
/**
* Factory for {@link javax.enterprise.inject.spi.Annotated} elements.
@@ -41,8 +43,11 @@ import org.apache.webbeans.config.WebBea
public final class AnnotatedElementFactory
{
+ // Logger instance
+ private final WebBeansLogger logger = WebBeansLogger.getLogger(AnnotatedElementFactory.class);
+
public static AnnotatedElementFactory getInstance()
- {
+ {
AnnotatedElementFactory aef = (AnnotatedElementFactory) WebBeansFinder.getSingletonInstance(AnnotatedElementFactory.class.getName());
return aef;
}
@@ -88,33 +93,62 @@ public final class AnnotatedElementFacto
}
else
{
- annotatedType = new AnnotatedTypeImpl<X>(annotatedClass);
-
- Field[] fields = SecurityUtil.doPrivilegedGetDeclaredFields(annotatedClass);
- Method[] methods = SecurityUtil.doPrivilegedGetDeclaredMethods(annotatedClass);
- Constructor<X>[] ctxs = (Constructor<X>[])SecurityUtil.doPrivilegedGetDeclaredConstructors(annotatedClass);
- for(Field f : fields)
- {
- AnnotatedField<X> af = new AnnotatedFieldImpl<X>(f, annotatedType);
- annotatedType.addAnnotatedField(af);
- }
-
- for(Method m : methods)
- {
- AnnotatedMethod<X> am = new AnnotatedMethodImpl<X>(m,annotatedType);
- annotatedType.addAnnotatedMethod(am);
- }
-
- for(Constructor<X> ct : ctxs)
- {
- AnnotatedConstructor<X> ac = new AnnotatedConstructorImpl<X>(ct,annotatedType);
- annotatedType.addAnnotatedConstructor(ac);
- }
-
- AnnotatedTypeImpl<X> oldType = (AnnotatedTypeImpl<X>)annotatedTypeCache.putIfAbsent(annotatedClass, annotatedType);
- if(oldType != null)
+ try
{
- annotatedType = oldType;
+ annotatedType = new AnnotatedTypeImpl<X>(annotatedClass);
+
+ Field[] fields = SecurityUtil.doPrivilegedGetDeclaredFields(annotatedClass);
+ Method[] methods = SecurityUtil.doPrivilegedGetDeclaredMethods(annotatedClass);
+ Constructor<X>[] ctxs = (Constructor<X>[])SecurityUtil.doPrivilegedGetDeclaredConstructors(annotatedClass);
+ for(Field f : fields)
+ {
+ AnnotatedField<X> af = new AnnotatedFieldImpl<X>(f, annotatedType);
+ annotatedType.addAnnotatedField(af);
+ }
+
+ for(Method m : methods)
+ {
+ AnnotatedMethod<X> am = new AnnotatedMethodImpl<X>(m,annotatedType);
+ annotatedType.addAnnotatedMethod(am);
+ }
+
+ for(Constructor<X> ct : ctxs)
+ {
+ AnnotatedConstructor<X> ac = new AnnotatedConstructorImpl<X>(ct,annotatedType);
+ annotatedType.addAnnotatedConstructor(ac);
+ }
+
+ AnnotatedTypeImpl<X> oldType = (AnnotatedTypeImpl<X>)annotatedTypeCache.putIfAbsent(annotatedClass, annotatedType);
+ if(oldType != null)
+ {
+ annotatedType = oldType;
+ }
+
+ }
+ catch (Exception e)
+ {
+ if (e instanceof ClassNotFoundException)
+ {
+ if (logger.wblWillLogError())
+ {
+ logger.error(OWBLogConst.ERROR_0027, e, annotatedClass.getName(), e.getCause());
+ }
+
+ annotatedType = null;
+ }
+ else
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ catch (NoClassDefFoundError ncdfe)
+ {
+ if (logger.wblWillLogError())
+ {
+ logger.error(OWBLogConst.ERROR_0027, ncdfe, annotatedClass.getName(), ncdfe.getCause());
+ }
+
+ annotatedType = null;
}
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/openwebbeans/Messages.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/openwebbeans/Messages.properties?rev=1005519&r1=1005518&r2=1005519&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/openwebbeans/Messages.properties (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/openwebbeans/Messages.properties Thu Oct 7 16:35:07 2010
@@ -84,7 +84,7 @@ ERROR_0023 = An error occured while inje
ERROR_0024 = Unable to get resource with class [{0}] in [{1}] with name [{2}].
ERROR_0025 = Unable to inject field \: [{0}]
ERROR_0026 = An error occured while injecting dependencies of bean \: [{0}]
-
+ERROR_0027 = Unable to create AnnotatedType for class \: [{0}]. Exception cause \: [{1}]
#fatal messages:
FATAL_0001 = Exception thrown while destroying bean instance \: [{0}]