openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1798720 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: configurator/ portable/events/discovery/ util/
Date Wed, 14 Jun 2017 17:21:02 GMT
Author: struberg
Date: Wed Jun 14 17:21:02 2017
New Revision: 1798720

URL: http://svn.apache.org/viewvc?rev=1798720&view=rev
Log:
OWB-1186 implement observer checks

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ErrorStack.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.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/configurator/ObserverMethodConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java?rev=1798720&r1=1798719&r2=1798720&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java
Wed Jun 14 17:21:02 2017
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.event.EventContextImpl;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansDeploymentException;
 import org.apache.webbeans.exception.WebBeansException;
 
 
@@ -285,7 +285,16 @@ public class ObserverMethodConfiguratorI
         if (observedType ==  null)
         {
             String extensionName = extension != null ? "(" + extension.toString() + ") !
" : "! ";
-            WebBeansConfigurationException e = new WebBeansConfigurationException("ObserverMethod
observedType is missing "
+            WebBeansDeploymentException e = new WebBeansDeploymentException("ObserverMethod
observedType is missing "
+                + extensionName
+                + toString());
+            webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e);
+            return null;
+        }
+        if (originalObserverMethod == null && notifyWith == null)
+        {
+            String extensionName = extension != null ? "(" + extension.toString() + ") !
" : "! ";
+            WebBeansDeploymentException e = new WebBeansDeploymentException("ObserverMethod
notifyWith is missing "
                 + extensionName
                 + toString());
             webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=1798720&r1=1798719&r2=1798720&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
Wed Jun 14 17:21:02 2017
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.After
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.EventContext;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Interceptor;
@@ -45,6 +46,7 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticBean;
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticObserverMethod;
 import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.ClassUtil;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -211,6 +213,19 @@ public class AfterBeanDiscoveryImpl exte
     public void addObserverMethod(ObserverMethod<?> observerMethod)
     {
         checkState();
+
+        // spec requires that either notify(T) or notify(EventContext) is implemented
+        if (!ClassUtil.isMethodImplemented(observerMethod.getClass(), ObserverMethod.class,
"notify", Object.class) &&
+            !ClassUtil.isMethodImplemented(observerMethod.getClass(), ObserverMethod.class,
"notify", EventContext.class))
+        {
+            String extensionName = extension != null ? "(" + extension.toString() + ") !
" : "! ";
+            WebBeansConfigurationException e = new WebBeansConfigurationException("ObserverMethod
must either implement notify(T) or notify(EventContext) "
+                + extensionName
+                + observerMethod.toString());
+            webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e);
+
+        }
+
         GProcessSyntheticObserverMethod event = new GProcessSyntheticObserverMethod(webBeansContext,
null, observerMethod, extension);
         if (!event.isVetoed())
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ErrorStack.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ErrorStack.java?rev=1798720&r1=1798719&r2=1798720&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ErrorStack.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ErrorStack.java
Wed Jun 14 17:21:02 2017
@@ -76,4 +76,9 @@ public class ErrorStack
     {
         return !errorStack.isEmpty();
     }
+
+    public Iterator<? extends Throwable> iterator()
+    {
+        return errorStack.iterator();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1798720&r1=1798719&r2=1798720&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Wed Jun 14 17:21:02 2017
@@ -431,6 +431,32 @@ public final class ClassUtil
     }
 
     /**
+     * Checks, if the given {@link Class} implements the {@link Method} with the
+     * given name und parameterTypes.
+     * Returns {@code false} if the method is only a default method in the interface!
+     *
+     * @param clazz to check
+     * @param interfase the Interface which declares the method
+     * @param methodName of the method
+     * @param parameterTypes of the method
+     *
+     * @return {@code} true if the given class contains a method with the given name and
parameterTypes,
+     *         otherwise {@code false}
+     */
+    public static boolean isMethodImplemented(Class<?> clazz, Class<?> interfase,
String methodName, Class<?>... parameterTypes)
+    {
+        try
+        {
+            Method m = clazz.getMethod(methodName, parameterTypes);
+            return m != null && m.getDeclaringClass() != interfase;
+        }
+        catch (NoSuchMethodException e)
+        {
+            return false;
+        }
+    }
+
+    /**
      * Check if the method is already defined in a subclass
      * @param subclassMethods
      * @param superclassMethod

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=1798720&r1=1798719&r2=1798720&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
Wed Jun 14 17:21:02 2017
@@ -107,6 +107,7 @@ import javax.enterprise.inject.spi.BeanA
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.BeforeShutdown;
+import javax.enterprise.inject.spi.DeploymentException;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Interceptor;
@@ -1320,7 +1321,16 @@ public final class WebBeansUtil
             if(stack.hasErrors())
             {
                 stack.logErrors();
-                throw new WebBeansConfigurationException(logMessage);
+
+                // just because of some TCK and spec insanity...
+                if (stack.iterator().next() instanceof DeploymentException)
+                {
+                    throw new WebBeansDeploymentException(logMessage);
+                }
+                else
+                {
+                    throw new WebBeansConfigurationException(logMessage);
+                }
             }
         }
         finally



Mime
View raw message