incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1066610 - /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/MetaContainer.java
Date Wed, 02 Feb 2011 20:24:15 GMT
Author: mbenson
Date: Wed Feb  2 20:24:15 2011
New Revision: 1066610

URL: http://svn.apache.org/viewvc?rev=1066610&view=rev
Log:
Extract merged MetaBean creation as well as actual merge logic to overridable methods

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

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/MetaContainer.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/MetaContainer.java?rev=1066610&r1=1066609&r2=1066610&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/MetaContainer.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/MetaContainer.java
Wed Feb  2 20:24:15 2011
@@ -113,10 +113,11 @@ public abstract class MetaContainer<K> {
      * @return MetaBean
      */
     public MetaBean getMergedElement(K id) {
-        MetaBean result = createMetaBean();
-        copy(result, prototype);
-        if (id != null) {
-            copy(result, elements.get(id));
+        MetaBean result = createMergeBean();
+        if (id == null) {
+            merge(result, prototype);
+        } else {
+            merge(result, prototype, elements.get(id));
         }
         return result;
     }
@@ -131,6 +132,28 @@ public abstract class MetaContainer<K> {
     }
 
     /**
+     * Create a {@link MetaBean} instance for merging.
+     * 
+     * @return MetaBean
+     */
+    protected MetaBean createMergeBean() {
+        return new MetaBean();
+    }
+
+    /**
+     * Merge MetaBeans. Provides a hook for subclasses to see the sources.
+     * 
+     * @param target
+     * @param sources
+     *            in order of increasing specificity
+     */
+    protected void merge(MetaBean target, MetaBean... sources) {
+        for (MetaBean source : sources) {
+            copy(target, source);
+        }
+    }
+
+    /**
      * Get the element type of a container of type <code>type</code>.
      * 
      * @param type



Mime
View raw message