1 17 package org.alfresco.config.element; 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.alfresco.config.ConfigElement; 26 27 33 public abstract class ConfigElementAdapter implements ConfigElement 34 { 35 protected String name; 36 protected String value; 37 protected Map <String , String > attributes; 38 protected List <ConfigElement> children; 39 40 45 public ConfigElementAdapter(String name) 46 { 47 this.name = name; 48 this.attributes = new HashMap <String , String >(); 49 this.children = new ArrayList <ConfigElement>(); 50 } 51 52 55 public String getAttribute(String name) 56 { 57 return attributes.get(name); 58 } 59 60 63 public Map <String , String > getAttributes() 64 { 65 return Collections.unmodifiableMap(this.attributes); 66 } 67 68 71 public int getAttributeCount() 72 { 73 return this.attributes.size(); 74 } 75 76 79 public List <ConfigElement> getChildren() 80 { 81 return Collections.unmodifiableList(this.children); 82 } 83 84 87 public int getChildCount() 88 { 89 return this.children.size(); 90 } 91 92 95 public ConfigElement getChild(String name) 96 { 97 ConfigElement child = null; 98 99 if (hasChildren()) 100 { 101 for (ConfigElement ce : this.children) 102 { 103 if (ce.getName().equals(name)) 104 { 105 child = ce; 106 break; 107 } 108 } 109 } 110 111 return child; 112 } 113 114 117 public String getName() 118 { 119 return this.name; 120 } 121 122 125 public String getValue() 126 { 127 return this.value; 128 } 129 130 136 public void setValue(String value) 137 { 138 this.value = value; 139 } 140 141 144 public boolean hasAttribute(String name) 145 { 146 return attributes.containsKey(name); 147 } 148 149 152 public boolean hasChildren() 153 { 154 return !children.isEmpty(); 155 } 156 157 160 public String toString() 161 { 162 StringBuilder buffer = new StringBuilder (super.toString()); 163 buffer.append(" (name=").append(this.name).append(")"); 164 return buffer.toString(); 165 } 166 167 170 public abstract ConfigElement combine(ConfigElement configElement); 171 } 172 | Popular Tags |