camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject [5/6] camel git commit: Shorter forms for CDI qualifier literals
Date Tue, 19 Apr 2016 12:58:57 GMT
Shorter forms for CDI qualifier literals


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3e0795ca
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3e0795ca
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3e0795ca

Branch: refs/heads/master
Commit: 3e0795ca29afd7b255db42ff08de72e7bd461f7a
Parents: 7a2a58c
Author: Antonin Stefanutti <antonin@stefanutti.fr>
Authored: Mon Apr 18 15:44:24 2016 +0200
Committer: Antonin Stefanutti <antonin@stefanutti.fr>
Committed: Tue Apr 19 14:49:35 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/cdi/AnyLiteral.java   |  2 +-
 .../apache/camel/cdi/CamelContextProducer.java  |  9 +++++---
 .../camel/cdi/CdiCamelBeanPostProcessor.java    |  3 ++-
 .../org/apache/camel/cdi/CdiCamelExtension.java | 23 +++++++++++---------
 .../org/apache/camel/cdi/CdiCamelFactory.java   |  6 +++--
 .../org/apache/camel/cdi/CdiCamelRegistry.java  |  7 ++++--
 .../java/org/apache/camel/cdi/CdiSpiHelper.java |  7 ++++--
 .../org/apache/camel/cdi/DefaultLiteral.java    |  2 +-
 .../java/org/apache/camel/cdi/Excluded.java     |  2 +-
 .../main/java/org/apache/camel/cdi/Main.java    |  4 +++-
 10 files changed, 41 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
index decff53..7bc11d8 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
@@ -22,7 +22,7 @@ import javax.enterprise.util.AnnotationLiteral;
 @Vetoed
 final class AnyLiteral extends AnnotationLiteral<Any> implements Any {
 
-    static final Any INSTANCE = new AnyLiteral();
+    static final Any ANY = new AnyLiteral();
 
     private static final long serialVersionUID = 1L;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
index 1d8c99c..03602da 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
@@ -16,7 +16,7 @@
  */
 package org.apache.camel.cdi;
 
-import java.beans.Introspector;
+import  java.beans.Introspector;
 import java.lang.annotation.Annotation;
 import java.util.Set;
 import javax.enterprise.context.spi.CreationalContext;
@@ -37,6 +37,9 @@ import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.cdi.AnyLiteral.ANY;
+import static org.apache.camel.cdi.DefaultLiteral.DEFAULT;
+
 final class CamelContextProducer<T extends CamelContext> extends DelegateProducer<T>
{
 
     private final Logger logger = LoggerFactory.getLogger(getClass());
@@ -75,9 +78,9 @@ final class CamelContextProducer<T extends CamelContext> extends DelegateProduce
 
         // Add event notifier if at least one observer is present
         Set<Annotation> qualifiers = CdiSpiHelper.excludeElementOfTypes(CdiSpiHelper.getQualifiers(annotated,
manager), Named.class);
-        qualifiers.add(AnyLiteral.INSTANCE);
+        qualifiers.add(ANY);
         if (qualifiers.size() == 1) {
-            qualifiers.add(DefaultLiteral.INSTANCE);
+            qualifiers.add(DEFAULT);
         }
         qualifiers.retainAll(extension.getObserverEvents());
         if (!qualifiers.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
index f8411e4..8ca6092 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
@@ -33,6 +33,7 @@ import org.apache.camel.impl.DefaultCamelBeanPostProcessor;
 import org.apache.camel.util.ReflectionHelper;
 
 import static org.apache.camel.cdi.BeanManagerHelper.getReferenceByType;
+import static org.apache.camel.cdi.DefaultLiteral.DEFAULT;
 
 @Vetoed
 final class CdiCamelBeanPostProcessor extends DefaultCamelBeanPostProcessor {
@@ -113,7 +114,7 @@ final class CdiCamelBeanPostProcessor extends DefaultCamelBeanPostProcessor
{
     private CamelContext getOrLookupCamelContext(String contextName) {
         // TODO: proper support for custom context qualifiers
         return getReferenceByType(manager, CamelContext.class,
-            contextName.isEmpty() ? DefaultLiteral.INSTANCE : ContextName.Literal.of(contextName))
+            contextName.isEmpty() ? DEFAULT : ContextName.Literal.of(contextName))
             .orElseThrow(() -> new UnsatisfiedResolutionException("No Camel context with
name [" + contextName + "] is deployed!"));
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
index 19e3eba..ea4a0c1 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelExtension.java
@@ -69,7 +69,10 @@ import org.apache.camel.model.RouteContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.cdi.AnyLiteral.ANY;
 import static org.apache.camel.cdi.CdiSpiHelper.hasAnnotation;
+import static org.apache.camel.cdi.DefaultLiteral.DEFAULT;
+import static org.apache.camel.cdi.Excluded.EXCLUDED;
 
 public class CdiCamelExtension implements Extension {
 
@@ -181,7 +184,7 @@ public class CdiCamelExtension implements Extension {
                 producerQualifiers.put(am.getJavaMember(), qualifiers);
                 Set<Annotation> annotations = new HashSet<>(am.getAnnotations());
                 annotations.removeAll(qualifiers);
-                annotations.add(Excluded.INSTANCE);
+                annotations.add(EXCLUDED);
                 methods.add(new AnnotatedMethodDelegate<>(am, annotations));
             }
         }
@@ -193,7 +196,7 @@ public class CdiCamelExtension implements Extension {
         Type type = pom.getObserverMethod().getObservedType();
         // Camel events are raw types
         if (type instanceof Class && Class.class.cast(type).getPackage().equals(AbstractExchangeEvent.class.getPackage()))
{
-            eventQualifiers.addAll(pom.getObserverMethod().getObservedQualifiers().isEmpty()
? Collections.singleton(AnyLiteral.INSTANCE) : pom.getObserverMethod().getObservedQualifiers());
+            eventQualifiers.addAll(pom.getObserverMethod().getObservedQualifiers().isEmpty()
? Collections.singleton(ANY) : pom.getObserverMethod().getObservedQualifiers());
         }
     }
 
@@ -220,14 +223,14 @@ public class CdiCamelExtension implements Extension {
         contextNames.removeAll(contextQualifiers);
         if (contextQualifiers.isEmpty() && contextNames.isEmpty()) {
             // Add a @Default Camel context bean if any
-            abd.addBean(camelContextBean(manager, AnyLiteral.INSTANCE, DefaultLiteral.INSTANCE));
+            abd.addBean(camelContextBean(manager, ANY, DEFAULT));
         } else if (contextQualifiers.isEmpty() && contextNames.size() == 1) {
             // Add a @ContextName and @Default Camel context bean if only one
-            abd.addBean(camelContextBean(manager, AnyLiteral.INSTANCE, DefaultLiteral.INSTANCE,
contextNames.iterator().next()));
+            abd.addBean(camelContextBean(manager, ANY, DEFAULT, contextNames.iterator().next()));
         } else {
             // Add missing @ContextName Camel context beans
             for (ContextName name : contextNames) {
-                abd.addBean(camelContextBean(manager, AnyLiteral.INSTANCE, name));
+                abd.addBean(camelContextBean(manager, ANY, name));
             }
         }
 
@@ -267,7 +270,7 @@ public class CdiCamelExtension implements Extension {
 
     private void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, BeanManager
manager) {
         Collection<CamelContext> contexts = new ArrayList<>();
-        for (Bean<?> context : manager.getBeans(CamelContext.class, AnyLiteral.INSTANCE))
{
+        for (Bean<?> context : manager.getBeans(CamelContext.class, ANY)) {
             contexts.add(BeanManagerHelper.getReference(manager, CamelContext.class, context));
         }
 
@@ -281,9 +284,9 @@ public class CdiCamelExtension implements Extension {
 
         // Add routes to Camel contexts
         boolean deploymentException = false;
-        Set<Bean<?>> routes = new HashSet<>(manager.getBeans(RoutesBuilder.class,
AnyLiteral.INSTANCE));
-        routes.addAll(manager.getBeans(RouteContainer.class, AnyLiteral.INSTANCE));
-        for (Bean<?> context : manager.getBeans(CamelContext.class, AnyLiteral.INSTANCE))
{
+        Set<Bean<?>> routes = new HashSet<>(manager.getBeans(RoutesBuilder.class,
ANY));
+        routes.addAll(manager.getBeans(RouteContainer.class, ANY));
+        for (Bean<?> context : manager.getBeans(CamelContext.class, ANY)) {
             for (Bean<?> route : routes) {
                 Set<Annotation> qualifiers = new HashSet<>(context.getQualifiers());
                 qualifiers.retainAll(route.getQualifiers());
@@ -300,7 +303,7 @@ public class CdiCamelExtension implements Extension {
         // Trigger eager beans instantiation
         for (AnnotatedType<?> type : eagerBeans) {
             // Calling toString is necessary to force the initialization of normal-scoped
beans
-            BeanManagerHelper.getReferencesByType(manager, type.getJavaClass(), AnyLiteral.INSTANCE).toString();
+            BeanManagerHelper.getReferencesByType(manager, type.getJavaClass(), ANY).toString();
         }
 
         // Start Camel contexts

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelFactory.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelFactory.java
index 965da41..86fee57 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelFactory.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelFactory.java
@@ -44,6 +44,8 @@ import org.apache.camel.ProducerTemplate;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.component.mock.MockEndpoint;
 
+import static org.apache.camel.cdi.DefaultLiteral.DEFAULT;
+
 final class CdiCamelFactory {
 
     @Produces
@@ -194,8 +196,8 @@ final class CdiCamelFactory {
     private static <T extends CamelContext> T selectContext(InjectionPoint ip, Instance<T>
instance, CdiCamelExtension extension) {
         Collection<Annotation> qualifiers = new HashSet<>(ip.getQualifiers());
         qualifiers.retainAll(extension.getContextQualifiers());
-        if (qualifiers.isEmpty() && !instance.select(DefaultLiteral.INSTANCE).isUnsatisfied())
{
-            return instance.select(DefaultLiteral.INSTANCE).get();
+        if (qualifiers.isEmpty() && !instance.select(DEFAULT).isUnsatisfied()) {
+            return instance.select(DEFAULT).get();
         }
         return instance.select(qualifiers.toArray(new Annotation[qualifiers.size()])).get();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelRegistry.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelRegistry.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelRegistry.java
index 6c68b7e..1c49122 100755
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelRegistry.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelRegistry.java
@@ -19,6 +19,7 @@ package org.apache.camel.cdi;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 
@@ -28,6 +29,8 @@ import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.cdi.AnyLiteral.ANY;
+
 /**
  * The {@link Registry} used by Camel to perform lookup into the CDI {@link BeanManager}.
  */
@@ -68,7 +71,7 @@ final class CdiCamelRegistry implements Registry {
         ObjectHelper.notNull(type, "type");
         logger.trace("Looking up named beans of type [{}]", type);
         Map<String, T> references = new HashMap<>();
-        for (Bean<?> bean : manager.getBeans(type, AnyLiteral.INSTANCE)) {
+        for (Bean<?> bean : manager.getBeans(type, ANY)) {
             if (bean.getName() != null) {
                 references.put(bean.getName(), BeanManagerHelper.getReference(manager, type,
bean));
             }
@@ -80,7 +83,7 @@ final class CdiCamelRegistry implements Registry {
     public <T> Set<T> findByType(Class<T> type) {
         ObjectHelper.notNull(type, "type");
         logger.trace("Looking up beans of type [{}]", type);
-        return BeanManagerHelper.getReferencesByType(manager, type, AnyLiteral.INSTANCE);
+        return BeanManagerHelper.getReferencesByType(manager, type, ANY);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
index 8a7c8c5..e1e6f62 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiSpiHelper.java
@@ -36,6 +36,9 @@ import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.camel.util.ObjectHelper;
 
+import static org.apache.camel.cdi.AnyLiteral.ANY;
+import static org.apache.camel.cdi.DefaultLiteral.DEFAULT;
+
 @Vetoed
 final class CdiSpiHelper {
 
@@ -139,9 +142,9 @@ final class CdiSpiHelper {
             }
         }
         if (qualifiers.isEmpty()) {
-            qualifiers.add(DefaultLiteral.INSTANCE);
+            qualifiers.add(DEFAULT);
         }
-        qualifiers.add(AnyLiteral.INSTANCE);
+        qualifiers.add(ANY);
         return qualifiers;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/DefaultLiteral.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/DefaultLiteral.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/DefaultLiteral.java
index c78d6c0..b88120d 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/DefaultLiteral.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/DefaultLiteral.java
@@ -22,7 +22,7 @@ import javax.enterprise.util.AnnotationLiteral;
 @Vetoed
 final class DefaultLiteral extends AnnotationLiteral<Default> implements Default {
 
-    static final Default INSTANCE = new DefaultLiteral();
+    static final Default DEFAULT = new DefaultLiteral();
 
     private static final long serialVersionUID = 1L;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/Excluded.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Excluded.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Excluded.java
index 0956c95..3debbcf 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Excluded.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Excluded.java
@@ -33,7 +33,7 @@ import javax.inject.Qualifier;
 @Target(value = { TYPE, METHOD, PARAMETER, FIELD })
 @interface Excluded {
 
-    Excluded INSTANCE = new ExcludedLiteral();
+    Excluded EXCLUDED = new ExcludedLiteral();
 
     @Vetoed
     final class ExcludedLiteral extends AnnotationLiteral<Excluded> implements Excluded
{

http://git-wip-us.apache.org/repos/asf/camel/blob/3e0795ca/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
index ebdae5b..380573b 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/Main.java
@@ -31,6 +31,8 @@ import org.apache.deltaspike.cdise.api.CdiContainerLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.cdi.AnyLiteral.ANY;
+
 /**
  * Camel CDI boot integration. Allows Camel and CDI to be booted up on the command line as
a JVM process.
  * See http://camel.apache.org/camel-boot.html.
@@ -81,7 +83,7 @@ public class Main extends MainSupport {
     protected Map<String, CamelContext> getCamelContextMap() {
         BeanManager manager = cdiContainer.getBeanManager();
         Map<String, CamelContext> answer = new HashMap<>();
-        for (Bean<?> bean : manager.getBeans(CamelContext.class, AnyLiteral.INSTANCE))
{
+        for (Bean<?> bean : manager.getBeans(CamelContext.class, ANY)) {
             CamelContext context = (CamelContext) manager.getReference(bean, CamelContext.class,
manager.createCreationalContext(bean));
             answer.put(context.getName(), context);
         }


Mime
View raw message