1 23 24 package org.apache.slide.util.conf; 25 26 import java.util.*; 27 28 38 public class ConfigurationElement extends AbstractConfiguration { 39 40 private Element content; 41 private Vector children; 42 43 public ConfigurationElement(Element content) { 44 this.content = content; 45 children = new Vector(); 46 try { 47 for (Enumeration e = content.getChildren(); e.hasMoreElements();) { 48 children.addElement(new ConfigurationElement((Element) e.nextElement())); 49 } 50 } catch (ConfigurationException e) { 51 } 52 } 53 54 public String getName() { 55 return content.getName(); 56 } 57 58 public String getValue() { 59 return content.getData(); 60 } 61 62 public String getAttribute(String name) 63 throws ConfigurationException { 64 String attribute = content.getAttributeValue(name); 65 if (attribute == null) { 66 throw new ConfigurationException("No attribute named \"" + name + "\" is " + 67 "associated with the configuration element \"" + this.getName() + "\"", 68 this); 69 } 70 return attribute; 71 } 72 73 public Configuration getConfiguration(String name) 74 throws ConfigurationException { 75 76 int index = name.indexOf('.'); 77 if (index == -1) { 78 for (Enumeration e = children.elements(); e.hasMoreElements();) { 79 Configuration c = (Configuration) e.nextElement(); 80 if (c.getName().equals(name)) { 81 return c; 82 } 83 } 84 } else { 85 return getConfiguration(name.substring(0, index)).getConfiguration(name.substring(index + 1)); 86 } 87 throw new ConfigurationException("No Configuration named \"" + name + "\" is " + 88 "associated with the configuration element \"" + this.getName() + "\"", this); 89 } 90 91 public Enumeration getConfigurations(String name) 92 throws ConfigurationException { 93 94 int index = name.indexOf('.'); 95 if (index == -1) { 96 Vector v = new Vector(); 97 for (Enumeration e = children.elements(); e.hasMoreElements();) { 98 Configuration c = (Configuration) e.nextElement(); 99 if (c.getName().equals(name)) { 100 v.addElement(c); 101 } 102 } 103 return v.elements(); 104 } else { 105 return getConfiguration(name.substring(0, index)).getConfigurations(name.substring(index + 1)); 106 } 107 } 108 } 109 | Popular Tags |