deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-719 fixed handling of multiple stereotype view-metadata instances
Date Thu, 18 Sep 2014 20:00:13 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master f041be252 -> 5a22110b7


DELTASPIKE-719 fixed handling of multiple stereotype view-metadata instances


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

Branch: refs/heads/master
Commit: 5a22110b71dba7f36f68303e41d41563e9bf37f2
Parents: f041be2
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Sep 18 21:50:52 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Sep 18 21:57:16 2014 +0200

----------------------------------------------------------------------
 .../config/view/DefaultConfigNodeConverter.java | 31 +++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5a22110b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultConfigNodeConverter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultConfigNodeConverter.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultConfigNodeConverter.java
index 798b5ca..6655699 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultConfigNodeConverter.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/config/view/DefaultConfigNodeConverter.java
@@ -34,6 +34,7 @@ import org.apache.deltaspike.jsf.api.config.view.Folder;
 import org.apache.deltaspike.jsf.api.config.view.View;
 import org.apache.deltaspike.jsf.impl.util.ViewConfigUtils;
 
+import javax.enterprise.inject.Stereotype;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -89,6 +90,7 @@ public class DefaultConfigNodeConverter implements ConfigNodeConverter
     {
         //TODO add qualifier support
         List<Annotation> nodeViewMetaData = new ArrayList<Annotation>();
+        List<Annotation> viewMetaDataFromStereotype = new ArrayList<Annotation>();
 
         for (Annotation annotation : metaData)
         {
@@ -96,13 +98,34 @@ public class DefaultConfigNodeConverter implements ConfigNodeConverter
             {
                 nodeViewMetaData.add(annotation);
             }
+
+            //TODO move to stereotype-util, improve it and merge it with DefaultViewConfigInheritanceStrategy
+            if (annotation.annotationType().isAnnotationPresent(Stereotype.class))
+            {
+                for (Annotation metaAnnotation : annotation.annotationType().getAnnotations())
+                {
+                    if (metaAnnotation.annotationType().isAnnotationPresent(ViewMetaData.class))
+                    {
+                        viewMetaDataFromStereotype.add(metaAnnotation);
+                    }
+                }
+            }
         }
 
-        if (inheritedMetaData == null || inheritedMetaData.isEmpty())
+        //merge meta-data of same level
+        List<Annotation> result = mergeAnnotationInstances(viewMetaDataFromStereotype,
nodeViewMetaData);
+
+        if (inheritedMetaData != null && !inheritedMetaData.isEmpty())
         {
-            return nodeViewMetaData;
+            //merge meta-data with levels above
+            result = mergeAnnotationInstances(inheritedMetaData, result);
         }
 
+        return result;
+    }
+
+    private List<Annotation> mergeAnnotationInstances(List<Annotation> inheritedMetaData,
List<Annotation> nodeMetaData)
+    {
         List<Annotation> mergedResult = new ArrayList<Annotation>();
 
         for (Annotation inheritedAnnotation : inheritedMetaData)
@@ -127,7 +150,7 @@ public class DefaultConfigNodeConverter implements ConfigNodeConverter
             }
             else
             {
-                Annotation currentNodeMetaData = findInResult(nodeViewMetaData, inheritedAnnotation);
+                Annotation currentNodeMetaData = findInResult(nodeMetaData, inheritedAnnotation);
                 if (currentNodeMetaData == null)
                 {
                     Annotation mergedMetaData = findInResult(mergedResult, inheritedAnnotation);
@@ -151,7 +174,7 @@ public class DefaultConfigNodeConverter implements ConfigNodeConverter
         }
 
         //add all annotations at the beginning which weren't used for the merge
-        mergedResult.addAll(0, nodeViewMetaData);
+        mergedResult.addAll(0, nodeMetaData);
         return mergedResult;
     }
 


Mime
View raw message