deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-614 @Named support for ExecutableCallbackDescriptor
Date Tue, 27 May 2014 12:32:39 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master c43fed58e -> 4bc5bf309


DELTASPIKE-614 @Named support for ExecutableCallbackDescriptor


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

Branch: refs/heads/master
Commit: 4bc5bf3094994fc1cb2300a6fcca624df8b698d8
Parents: c43fed5
Author: gpetracek <gpetracek@apache.org>
Authored: Tue May 27 14:30:39 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Tue May 27 14:30:39 2014 +0200

----------------------------------------------------------------------
 .../view/metadata/CallbackDescriptor.java       | 31 ++++++++++++++++++--
 .../metadata/ExecutableCallbackDescriptor.java  | 16 +++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4bc5bf30/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/CallbackDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/CallbackDescriptor.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/CallbackDescriptor.java
index 26d62ee..5cc9695 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/CallbackDescriptor.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/CallbackDescriptor.java
@@ -20,6 +20,8 @@ package org.apache.deltaspike.core.api.config.view.metadata;
 
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 
+import javax.inject.Named;
+import java.beans.Introspector;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -80,7 +82,12 @@ public abstract class CallbackDescriptor
 
     protected Object getTargetObject(Class targetType)
     {
-        return BeanProvider.getContextualReference(targetType);
+        return BeanProvider.getContextualReference(targetType, true);
+    }
+
+    protected Object getTargetObjectByName(String beanName)
+    {
+        return BeanProvider.getContextualReference(beanName, true);
     }
 
     public boolean isBoundTo(Class<? extends Annotation> callbackType)
@@ -91,12 +98,25 @@ public abstract class CallbackDescriptor
     protected static class CallbackEntry
     {
         private List<Method> callbackMethods = new ArrayList<Method>();
-        private final Class targetBeanClass;
+        private final Class<?> targetBeanClass;
+        private final String beanName;
 
         private CallbackEntry(Class beanClass, Class<? extends Annotation> callbackMarker)
         {
             this.targetBeanClass = beanClass;
 
+            Named named = this.targetBeanClass.getAnnotation(Named.class);
+
+            if (named != null && !"".equals(named.value()))
+            {
+                this.beanName = named.value();
+            }
+            else
+            {
+                //fallback to the default (which might exist) -> TODO check meta-data
of Bean<T>
+                this.beanName = Introspector.decapitalize(targetBeanClass.getSimpleName());
+            }
+
             List<String> processedMethodNames = new ArrayList<String>();
 
             findMethodWithCallbackMarker(callbackMarker, beanClass, processedMethodNames);
@@ -150,9 +170,14 @@ public abstract class CallbackDescriptor
             return callbackMethods;
         }
 
-        public Class getTargetBeanClass()
+        public Class<?> getTargetBeanClass()
         {
             return targetBeanClass;
         }
+
+        public String getBeanName()
+        {
+            return beanName;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4bc5bf30/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/ExecutableCallbackDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/ExecutableCallbackDescriptor.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/ExecutableCallbackDescriptor.java
index 417770c..c8979f6 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/ExecutableCallbackDescriptor.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/view/metadata/ExecutableCallbackDescriptor.java
@@ -53,7 +53,21 @@ public abstract class ExecutableCallbackDescriptor<R> extends CallbackDescriptor
             {
                 try
                 {
-                    Object bean = getTargetObject(callbackEntry.getTargetBeanClass());
+                    Class<?> targetBeanClass = callbackEntry.getTargetBeanClass();
+                    Object bean = getTargetObject(targetBeanClass);
+
+                    if (bean == null)
+                    {
+                        String beanName = callbackEntry.getBeanName();
+                        bean = getTargetObjectByName(beanName);
+
+                        if (bean == null)
+                        {
+                            throw new IllegalStateException("Can't find bean by type " +
targetBeanClass +
+                                " or by name: " + beanName);
+                        }
+                    }
+
                     R result = (R) callbackMethod.invoke(bean, parameters);
 
                     if (result != null)


Mime
View raw message