[weld-commits] Weld SVN: r6860 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/interceptors and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Fri Jul 30 15:10:02 EDT 2010


Author: marius.bogoevici
Date: 2010-07-30 15:10:01 -0400 (Fri, 30 Jul 2010)
New Revision: 6860

Added:
   core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBinding.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBindingTest.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/NaiveClass.java
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java
   core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MetaAnnotationStore.java
Log:
WELD-563: throw a DefinitionException if the InterceptorBinding has the wrong Target. initial take on unwrapping the ComputationException

Modified: core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java	2010-07-29 22:21:09 UTC (rev 6859)
+++ core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java	2010-07-30 19:10:01 UTC (rev 6860)
@@ -57,6 +57,7 @@
       super(type, transformer);
       if (isValid())
       {
+         checkTargetType();
          initNonBindingTypes();
          initInterceptionBindingTypes();
          checkArrayAndAnnotationValuedMembers();
@@ -86,27 +87,29 @@
       inheritedInterceptionBindingTypes = getAnnotatedAnnotation().getMetaAnnotations(InterceptorBinding.class);
    }
 
-   @Override
-   protected void initValid()
+   private void checkTargetType()
    {
-      super.initValid();
       if (!getAnnotatedAnnotation().isAnnotationPresent(Target.class))
       {
          this.valid = false;
-         log.debug(MISSING_TARGET, getAnnotatedAnnotation());
+         throw new DefinitionException(MISSING_TARGET, getAnnotatedAnnotation());
       }
       else
       {
-         ElementType[] targetElementTypes = getAnnotatedAnnotation().getAnnotation(Target.class).value();
-         if (!Arrays2.unorderedEquals(targetElementTypes, ElementType.TYPE, ElementType.METHOD)
-               && !Arrays2.unorderedEquals(targetElementTypes, ElementType.TYPE))
+         if (!isValidTargetType())
          {
             this.valid = false;
-            log.debug(MISSING_TARGET_TYPE_METHOD_OR_TARGET_TYPE, getAnnotatedAnnotation());
+            throw new DefinitionException(MISSING_TARGET_TYPE_METHOD_OR_TARGET_TYPE, getAnnotatedAnnotation());
          }
       }
    }
 
+   private boolean isValidTargetType()
+   {
+      return Arrays2.unorderedEquals(getAnnotatedAnnotation().getAnnotation(Target.class).value(), ElementType.TYPE, ElementType.METHOD)
+            || Arrays2.unorderedEquals(getAnnotatedAnnotation().getAnnotation(Target.class).value(), ElementType.TYPE);
+   }
+
    private void checkMetaAnnotations()
    {
       if (Arrays2.containsAll(getAnnotatedAnnotation().getAnnotation(Target.class).value(), ElementType.METHOD))
@@ -116,8 +119,7 @@
             if (!Arrays2.containsAll(inheritedBinding.annotationType().getAnnotation(Target.class).value(), ElementType.METHOD))
             {
                this.valid = false;
-               log.debug(TARGET_TYPE_METHOD_INHERITS_FROM_TARGET_TYPE, 
-                     getAnnotatedAnnotation(), inheritedBinding);
+               log.debug(TARGET_TYPE_METHOD_INHERITS_FROM_TARGET_TYPE, getAnnotatedAnnotation(), inheritedBinding);
             }
          }
       }

Modified: core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MetaAnnotationStore.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MetaAnnotationStore.java	2010-07-29 22:21:09 UTC (rev 6859)
+++ core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MetaAnnotationStore.java	2010-07-30 19:10:01 UTC (rev 6860)
@@ -19,12 +19,15 @@
 import java.lang.annotation.Annotation;
 import java.util.concurrent.ConcurrentMap;
 
+import com.google.common.base.Function;
+import com.google.common.collect.ComputationException;
+import com.google.common.collect.MapMaker;
 import org.jboss.weld.bootstrap.api.Service;
+import org.jboss.weld.exceptions.DefinitionException;
+import org.jboss.weld.exceptions.DeploymentException;
+import org.jboss.weld.exceptions.WeldException;
 import org.jboss.weld.resources.ClassTransformer;
 
-import com.google.common.base.Function;
-import com.google.common.collect.MapMaker;
-
 /**
  * Metadata singleton for holding EJB metadata, scope models etc.
  * 
@@ -202,6 +205,22 @@
 
    public <T extends Annotation> InterceptorBindingModel<T> getInterceptorBindingModel(final Class<T> interceptorBinding)
    {
-      return (InterceptorBindingModel<T>) interceptorBindings.get(interceptorBinding);
+      // Unwrap Definition/Deployment exceptions wrapped in a ComputationException
+      // TODO: generalize this and move to a higher level (MBG)
+      try
+      {
+         return (InterceptorBindingModel<T>) interceptorBindings.get(interceptorBinding);
+      }
+      catch (ComputationException e)
+      {
+         if (e.getCause() instanceof DeploymentException || e.getCause() instanceof DefinitionException)
+         {
+            throw (WeldException)e.getCause();
+         }
+         else
+         {
+            throw e;
+         }
+      }
    }
 }

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBinding.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBinding.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBinding.java	2010-07-30 19:10:01 UTC (rev 6860)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.tests.interceptors.interceptorBinding;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at InterceptorBinding
+ at Retention(RUNTIME)
+ at Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR})
+ at Documented
+public @interface BadInterceptorBinding
+{
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBindingTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBindingTest.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/BadInterceptorBindingTest.java	2010-07-30 19:10:01 UTC (rev 6860)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.tests.interceptors.interceptorBinding;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
+import org.jboss.weld.exceptions.DefinitionException;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at Artifact
+ at ExpectedDeploymentException(DefinitionException.class)
+public class BadInterceptorBindingTest extends AbstractWeldTest
+{
+
+   @Test
+   public void testBadInterceptorBinding()
+   {
+
+   }
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/NaiveClass.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/NaiveClass.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/interceptors/interceptorBinding/NaiveClass.java	2010-07-30 19:10:01 UTC (rev 6860)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.weld.tests.interceptors.interceptorBinding;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at BadInterceptorBinding
+public class NaiveClass
+{
+   public void doSomething()
+   {
+   }
+}



More information about the weld-commits mailing list