deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject deltaspike git commit: DELTASPIKE-879 use @Priority for global-alternatives
Date Thu, 23 Apr 2015 09:56:24 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 0752f78aa -> 5a9d6262d


DELTASPIKE-879 use @Priority for global-alternatives

 (in case of cdi 1.1+)


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/5a9d6262
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/5a9d6262
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/5a9d6262

Branch: refs/heads/master
Commit: 5a9d6262d3118ee482fb350f127ea59beda88783
Parents: 0752f78
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Apr 23 11:47:52 2015 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Apr 23 11:51:20 2015 +0200

----------------------------------------------------------------------
 .../exclude/extension/ExcludeExtension.java     | 30 +++++++++-
 .../interceptor/GlobalInterceptorExtension.java | 19 +------
 .../core/impl/util/AnnotationInstanceUtils.java | 60 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5a9d6262/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
index d819f13..3aa3ede 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exclude/extension/ExcludeExtension.java
@@ -19,7 +19,9 @@
 package org.apache.deltaspike.core.impl.exclude.extension;
 
 import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.core.api.config.base.CoreBaseConfig;
 import org.apache.deltaspike.core.api.exclude.Exclude;
+import org.apache.deltaspike.core.impl.util.AnnotationInstanceUtils;
 import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
 import org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter;
 import org.apache.deltaspike.core.impl.exclude.GlobalAlternative;
@@ -77,6 +79,7 @@ public class ExcludeExtension implements Extension, Deactivatable
      * VALUE=Implementation class name
      */
     private Map<String, String> globalAlternatives = new HashMap<String, String>();
+    private Annotation priorityAnnotationInstance;
 
 
     @SuppressWarnings("UnusedDeclaration")
@@ -112,6 +115,12 @@ public class ExcludeExtension implements Extension, Deactivatable
             {
                 isGlobalAlternativeActivated = false;
             }
+
+            if (isGlobalAlternativeActivated)
+            {
+                int priorityValue = CoreBaseConfig.Interceptor.PRIORITY.getValue();
+                priorityAnnotationInstance = AnnotationInstanceUtils.getPriorityAnnotationInstance(priorityValue);
+            }
         }
     }
 
@@ -272,10 +281,16 @@ public class ExcludeExtension implements Extension, Deactivatable
                 continue;
             }
 
+            if (!doQualifiersMatch(qualifiersOfCurrentBean, qualifiersOfConfiguredBean))
+            {
+                continue;
+            }
+
             //current bean is annotated with @Alternative and of the same type as the configured
bean
             if (isAlternativeBeanImplementation && alternativeBeanClass.equals(currentBean))
             {
-                if (doQualifiersMatch(qualifiersOfCurrentBean, qualifiersOfConfiguredBean))
+                //cdi 1.0
+                if (priorityAnnotationInstance == null)
                 {
                     AnnotatedTypeBuilder<Object> annotatedTypeBuilder
                         = new AnnotatedTypeBuilder<Object>().readFromType(processAnnotatedType.getAnnotatedType());
@@ -284,10 +299,21 @@ public class ExcludeExtension implements Extension, Deactivatable
                     processAnnotatedType.setAnnotatedType(annotatedTypeBuilder.create());
                     return;
                 }
+                //cdi 1.1+
+                else
+                {
+                    AnnotatedTypeBuilder<Object> annotatedTypeBuilder
+                        = new AnnotatedTypeBuilder<Object>().readFromType(processAnnotatedType.getAnnotatedType());
+
+                    annotatedTypeBuilder.addToClass(priorityAnnotationInstance);
+                    processAnnotatedType.setAnnotatedType(annotatedTypeBuilder.create());
+                    return;
+                }
             }
             else //current bean is the original implementation
             {
-                if (doQualifiersMatch(qualifiersOfCurrentBean, qualifiersOfConfiguredBean))
+                //cdi 1.0 (no change needed with cdi 1.1+)
+                if (priorityAnnotationInstance == null)
                 {
                     //veto this original implementation because the alternative will be added
                     processAnnotatedType.veto();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5a9d6262/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/GlobalInterceptorExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/GlobalInterceptorExtension.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/GlobalInterceptorExtension.java
index ddf1cf0..7531e49 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/GlobalInterceptorExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/GlobalInterceptorExtension.java
@@ -19,10 +19,9 @@
 package org.apache.deltaspike.core.impl.interceptor;
 
 import org.apache.deltaspike.core.api.config.base.CoreBaseConfig;
+import org.apache.deltaspike.core.impl.util.AnnotationInstanceUtils;
 import org.apache.deltaspike.core.spi.activation.Deactivatable;
 import org.apache.deltaspike.core.util.ClassDeactivationUtils;
-import org.apache.deltaspike.core.util.ClassUtils;
-import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.BeanManager;
@@ -31,8 +30,6 @@ import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.interceptor.Interceptor;
 import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.logging.Logger;
 
 //promotes deltaspike interceptors to global interceptors in case of cdi 1.1+
@@ -50,18 +47,8 @@ public class GlobalInterceptorExtension implements Deactivatable, Extension
             return;
         }
 
-        Class<? extends Annotation> priorityAnnotationClass =
-            ClassUtils.tryToLoadClassForName("javax.annotation.Priority");
-
-        //check for @Priority and CDI v1.1+
-        if (priorityAnnotationClass != null &&
-            ClassUtils.tryToLoadClassForName("javax.enterprise.inject.spi.AfterTypeDiscovery")
!= null)
-        {
-            Map<String, Object> defaultValueMap = new HashMap<String, Object>();
-            int priorityValue = CoreBaseConfig.Interceptor.PRIORITY.getValue();
-            defaultValueMap.put("value", priorityValue);
-            priorityAnnotationInstance = AnnotationInstanceProvider.of(priorityAnnotationClass,
defaultValueMap);
-        }
+        int priorityValue = CoreBaseConfig.Interceptor.PRIORITY.getValue();
+        priorityAnnotationInstance = AnnotationInstanceUtils.getPriorityAnnotationInstance(priorityValue);
     }
 
     protected void promoteInterceptors(@Observes ProcessAnnotatedType pat, BeanManager beanManager)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5a9d6262/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/AnnotationInstanceUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/AnnotationInstanceUtils.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/AnnotationInstanceUtils.java
new file mode 100644
index 0000000..9c19215
--- /dev/null
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/util/AnnotationInstanceUtils.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.core.impl.util;
+
+import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
+
+import javax.enterprise.inject.Typed;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+@Typed()
+public abstract class AnnotationInstanceUtils
+{
+    private AnnotationInstanceUtils()
+    {
+        // prevent instantiation
+    }
+
+    /**
+     * @return a new instance of {@link javax.annotation.Priority} with the given value
+     *         if the annotation-class is available in a cdi 1.1+ based environment, null
otherwise
+     */
+    public static Annotation getPriorityAnnotationInstance(int priorityValue)
+    {
+        Annotation priorityAnnotationInstance = null;
+
+        Class<? extends Annotation> priorityAnnotationClass =
+            ClassUtils.tryToLoadClassForName("javax.annotation.Priority");
+
+        //check for @Priority and CDI v1.1+
+        if (priorityAnnotationClass != null &&
+            ClassUtils.tryToLoadClassForName("javax.enterprise.inject.spi.AfterTypeDiscovery")
!= null)
+        {
+            Map<String, Object> defaultValueMap = new HashMap<String, Object>();
+            defaultValueMap.put("value", priorityValue);
+            priorityAnnotationInstance = AnnotationInstanceProvider.of(priorityAnnotationClass,
defaultValueMap);
+        }
+
+        return priorityAnnotationInstance;
+    }
+}


Mime
View raw message