incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1000301 - /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java
Date Thu, 23 Sep 2010 03:49:54 GMT
Author: mbenson
Date: Thu Sep 23 03:49:53 2010
New Revision: 1000301

URL: http://svn.apache.org/viewvc?rev=1000301&view=rev
Log:
copy non-dynamic features between metas

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java?rev=1000301&r1=1000300&r2=1000301&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModel.java
Thu Sep 23 03:49:53 2010
@@ -19,10 +19,13 @@ package org.apache.bval.jsr303.dynamic;
 import static org.apache.bval.jsr303.dynamic.DynamicModel.Features.*;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import org.apache.bval.jsr303.ConstraintValidation;
 import org.apache.bval.model.FeaturesCapable;
@@ -50,6 +53,20 @@ public class DynamicModel {
 
         /** meta-container key */
         public static final String META_CONTAINER = "metaContainer";
+
+    }
+
+    private static final SortedSet<String> FEATURE_KEYS;
+    static {
+        TreeSet<String> featureKeys = new TreeSet<String>();
+        for (Field f : Features.class.getDeclaredFields()) {
+            try {
+                featureKeys.add((String) f.get(null));
+            } catch (Exception e) {
+                // dunno, shouldn't happen
+            }
+        }
+        FEATURE_KEYS = Collections.unmodifiableSortedSet(featureKeys);
     }
 
     private DynamicModel() {
@@ -70,6 +87,7 @@ public class DynamicModel {
         for (MetaProperty property : source.getProperties()) {
             copy(getRequiredProperty(target, property.getName()), property);
         }
+        copyFeatures(target, source);
         copyConstraints(target, source);
     }
 
@@ -126,6 +144,7 @@ public class DynamicModel {
      * @param source
      */
     public static void copy(MetaProperty target, MetaProperty source) {
+        copyFeatures(target, source);
         copyConstraints(target, source);
 
         if (KeyedAccess.getJavaElementType(source.getType()) != null
@@ -187,7 +206,8 @@ public class DynamicModel {
         }
         targetConstraints = getRequiredDynamicConstraints(target);
 
-        // treat the target's preexisting ConstraintValidations like early arrivals to the
dynamic constraints: 
+        // treat the target's preexisting ConstraintValidations like early
+        // arrivals to the dynamic constraints:
         ArrayList<Validation> ignoredValidations = new ArrayList<Validation>();
         for (Validation v : target.getValidations()) {
             if (v instanceof ConstraintValidation<?>) {
@@ -225,4 +245,18 @@ public class DynamicModel {
         return result;
     }
 
+    /**
+     * Copy features that are not members of {@link DynamicModel.Features}
+     * 
+     * @param target
+     * @param source
+     */
+    public static void copyFeatures(FeaturesCapable target, FeaturesCapable source) {
+        for (Map.Entry<String, Object> e : source.getFeatures().entrySet()) {
+            if (FEATURE_KEYS.contains(e.getKey())) {
+                continue;
+            }
+            target.putFeature(e.getKey(), e.getValue());
+        }
+    }
 }



Mime
View raw message