1 23 24 package org.apache.slide.util.conf; 25 26 import java.util.Enumeration ; 27 import java.util.Hashtable ; 28 import java.util.Vector ; 29 import java.util.NoSuchElementException ; 30 31 39 public class ConfigurationImpl extends AbstractConfiguration { 40 41 42 private Hashtable attributes=new Hashtable (); 43 44 private Hashtable children=new Hashtable (); 45 46 private String name=null; 47 48 private String value=null; 49 50 53 protected ConfigurationImpl() { 54 super(); 55 } 56 57 60 protected ConfigurationImpl(String name) { 61 super(); 62 this.name=name; 63 } 64 65 68 protected ConfigurationImpl(String name, String source, int line) { 69 super(source,line); 70 this.name=name; 71 } 72 73 76 public String getName() { 77 return(this.name); 78 } 79 80 85 public String getValue() 86 throws ConfigurationException { 87 if (this.value!=null) return(this.value); 88 throw new ConfigurationException("No value is associated with the "+ 89 "configuration element \""+this.getName()+"\"", this); 90 } 91 92 98 public String getAttribute(String name) 99 throws ConfigurationException { 100 String value=(String )this.attributes.get(name); 101 if (value!=null) return(value); 102 throw new ConfigurationException("No attribute named \""+name+"\" is "+ 103 "associated with the configuration element \""+this.getName()+"\"", 104 this); 105 } 106 107 115 public Configuration getConfiguration(String name) { 116 Vector v=(Vector )this.children.get(name); 117 if ((v!=null) && (v.size()>0)) return((Configuration)v.firstElement()); 118 return(null); 119 } 120 121 129 public Enumeration getConfigurations(String name) { 130 Vector v=(Vector )this.children.get(name); 131 if (v==null) return(new EmptyEnumerationImpl()); 132 else return(v.elements()); 133 } 134 135 138 protected void appendValueData(String value) { 139 if (this.value==null) this.value=value; 140 else this.value=this.value+value; 141 } 142 143 147 protected String addAttribute(String name, String value) { 148 return((String )this.attributes.put(name,value)); 149 } 150 151 154 public void addConfiguration(Configuration conf) { 155 String name=conf.getName(); 156 Vector v=(Vector )this.children.get(name); 157 if (v==null) { 158 v=new Vector (); 159 this.children.put(name,v); 160 } 161 v.addElement(conf); 162 } 163 164 165 private class EmptyEnumerationImpl implements Enumeration { 166 167 public boolean hasMoreElements() { 168 return(false); 169 } 170 171 172 public Object nextElement() { 173 throw new NoSuchElementException (); 174 } 175 } 176 } 177 | Popular Tags |