1 16 17 package org.springframework.beans.factory.support; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.springframework.beans.BeanMetadataElement; 23 import org.springframework.beans.Mergeable; 24 25 34 public class ManagedList extends ArrayList implements Mergeable, BeanMetadataElement { 35 36 private Object source; 37 38 private boolean mergeEnabled; 39 40 41 public ManagedList() { 42 } 43 44 public ManagedList(int initialCapacity) { 45 super(initialCapacity); 46 } 47 48 49 53 public void setSource(Object source) { 54 this.source = source; 55 } 56 57 public Object getSource() { 58 return this.source; 59 } 60 61 65 public void setMergeEnabled(boolean mergeEnabled) { 66 this.mergeEnabled = mergeEnabled; 67 } 68 69 public boolean isMergeEnabled() { 70 return this.mergeEnabled; 71 } 72 73 public Object merge(Object parent) { 74 if (!this.mergeEnabled) { 75 throw new IllegalStateException ("Not allowed to merge when the 'mergeEnabled' property is set to 'false'"); 76 } 77 if (parent == null) { 78 return this; 79 } 80 if (!(parent instanceof List )) { 81 throw new IllegalArgumentException ("Cannot merge with object of type [" + parent.getClass() + "]"); 82 } 83 List merged = new ManagedList(); 84 merged.addAll((List ) parent); 85 merged.addAll(this); 86 return merged; 87 } 88 89 } 90 | Popular Tags |