deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [2/2] git commit: DELTASPIKE-654 veto converters and validators without injection-points or normal-scope
Date Mon, 30 Jun 2014 13:00:27 GMT
DELTASPIKE-654 veto converters and validators without injection-points or normal-scope


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

Branch: refs/heads/master
Commit: 0584be0cf1d55fafcf09163e28d0923aab095b1b
Parents: a411ec7
Author: gpetracek <gpetracek@apache.org>
Authored: Mon Jun 30 14:51:30 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Mon Jun 30 14:54:25 2014 +0200

----------------------------------------------------------------------
 .../ConverterAndValidatorProxyExtension.java    | 22 +++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/0584be0c/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/proxy/ConverterAndValidatorProxyExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/proxy/ConverterAndValidatorProxyExtension.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/proxy/ConverterAndValidatorProxyExtension.java
index dff508f..7c6f58a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/proxy/ConverterAndValidatorProxyExtension.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/proxy/ConverterAndValidatorProxyExtension.java
@@ -34,6 +34,7 @@ import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.faces.convert.Converter;
 import javax.faces.validator.Validator;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -55,7 +56,7 @@ public class ConverterAndValidatorProxyExtension implements Extension, Deactivat
 
     @SuppressWarnings("UnusedDeclaration")
     public <X> void findConverterAndValidatorsWhichNeedProxiesForDependencyInjectionSupport(
-        @Observes ProcessAnnotatedType<X> pat)
+        @Observes ProcessAnnotatedType<X> pat, BeanManager beanManager)
     {
         if (!this.isActivated)
         {
@@ -69,6 +70,14 @@ public class ConverterAndValidatorProxyExtension implements Extension,
Deactivat
             return;
         }
 
+        Bean<X> bean = new BeanBuilder<X>(beanManager).readFromType(pat.getAnnotatedType()).create();
+        //veto normal converters/validators -> they will get excluded from the special
handling later on
+        if (!hasInjectionPoints(bean) && !hasNormalScopeAnnotation(bean, beanManager))
+        {
+            pat.veto();
+            return;
+        }
+
         //converters/validators without properties for tags, will be handled by the corresponding
manual wrapper
         if (!hasPublicProperty(beanClass))
         {
@@ -96,6 +105,17 @@ public class ConverterAndValidatorProxyExtension implements Extension,
Deactivat
         }
     }
 
+    protected <X> boolean hasInjectionPoints(Bean<X> bean)
+    {
+        return !bean.getInjectionPoints().isEmpty();
+    }
+
+    protected <X> boolean hasNormalScopeAnnotation(Bean<X> bean, BeanManager
beanManager)
+    {
+        Class<? extends Annotation> scopeAnnotationClass = bean.getScope();
+        return  scopeAnnotationClass != null && beanManager.isNormalScope(scopeAnnotationClass);
+    }
+
     protected <X> boolean hasPublicProperty(Class<X> beanClass)
     {
         for (Method currentMethod : beanClass.getMethods())


Mime
View raw message