1 16 17 package org.springframework.beans.factory.support; 18 19 import java.util.Properties ; 20 21 import org.springframework.beans.BeanMetadataElement; 22 import org.springframework.beans.Mergeable; 23 24 32 public class ManagedProperties extends Properties implements Mergeable, BeanMetadataElement { 33 34 private Object source; 35 36 private boolean mergeEnabled; 37 38 39 43 public void setSource(Object source) { 44 this.source = source; 45 } 46 47 public Object getSource() { 48 return this.source; 49 } 50 51 55 public void setMergeEnabled(boolean mergeEnabled) { 56 this.mergeEnabled = mergeEnabled; 57 } 58 59 public boolean isMergeEnabled() { 60 return this.mergeEnabled; 61 } 62 63 64 public Object merge(Object parent) { 65 if (!this.mergeEnabled) { 66 throw new IllegalStateException ("Not allowed to merge when the 'mergeEnabled' property is set to 'false'"); 67 } 68 if (parent == null) { 69 return this; 70 } 71 if (!(parent instanceof Properties )) { 72 throw new IllegalArgumentException ("Cannot merge with object of type [" + parent.getClass() + "]"); 73 } 74 Properties merged = new ManagedProperties(); 75 merged.putAll((Properties ) parent); 76 merged.putAll(this); 77 return merged; 78 } 79 80 } 81 | Popular Tags |