1 package org.sapia.regis.util; 2 3 import java.io.Serializable ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 import java.util.Properties ; 7 8 public class CompositeProperties extends Properties 9 implements Serializable { 10 11 static final long serialVersionUID = 1L; 12 13 private List _children = new ArrayList (); 14 15 public CompositeProperties(){} 16 17 public CompositeProperties(Properties ancestor){ 18 super(ancestor); 19 } 20 21 public Properties addChild(Properties child){ 22 _children.add(0, child); 23 return this; 24 } 25 26 public Properties addAncestor(Properties ancestor){ 27 _children.add(ancestor); 28 return this; 29 } 30 31 public String getProperty(String name){ 32 for(int i = 0; i < _children.size(); i++){ 33 Properties child = (Properties )_children.get(i); 34 String value = child.getProperty(name); 35 if(value != null) return value; 36 } 37 return super.getProperty(name); 38 } 39 40 public String getProperty(String name, String defaultVal){ 41 for(int i = 0; i < _children.size(); i++){ 42 Properties child = (Properties )_children.get(i); 43 String value = child.getProperty(name); 44 if(value != null) return value; 45 } 46 return super.getProperty(name, defaultVal); 47 } 48 49 } 50 | Popular Tags |