1 package org.apache.fulcrum.intake.xmlmodel; 2 3 56 57 import java.io.Serializable ; 58 import java.util.ArrayList ; 59 import java.util.Iterator ; 60 import java.util.List ; 61 import org.xml.sax.Attributes ; 62 63 69 public class XmlGroup 70 implements Serializable 71 { 72 private List fields; 73 private List mapToObjects; 74 private String defaultMapToObject; 75 private AppData parent; 76 private String groupName; 77 private String key; 78 private String poolCapacity; 79 80 83 public XmlGroup() 84 { 85 fields = new ArrayList (); 86 mapToObjects = new ArrayList (2); 87 } 88 89 92 public void loadFromXML (Attributes attrib) 93 { 94 groupName = attrib.getValue("name"); 95 key = attrib.getValue("key"); 96 poolCapacity = attrib.getValue("pool-capacity"); 97 98 String objName = attrib.getValue("mapToObject"); 99 if ( objName != null && objName.length() != 0 ) 100 { 101 defaultMapToObject = objName; 102 } 103 } 104 105 108 public String getName() 109 { 110 return groupName; 111 } 112 113 116 public void setName(String newGroupName) 117 { 118 groupName = newGroupName; 119 } 120 121 124 public String getKey() 125 { 126 return key; 127 } 128 129 132 public void setKey(String newKey) 133 { 134 key = newKey; 135 } 136 137 138 144 public String getPoolCapacity() 145 { 146 if ( poolCapacity == null ) 147 { 148 return "128"; 149 } 150 151 return poolCapacity; 152 } 153 154 158 public XmlField addField(Attributes attrib) 159 { 160 XmlField field = new XmlField(); 161 field.loadFromXML(attrib); 162 addField(field); 163 164 return field; 165 } 166 167 171 public void addField(XmlField field) 172 { 173 field.setGroup(this); 174 175 if ( field.getMapToObject() != null ) 178 { 179 boolean isNewObject = true; 180 for ( int i=0; i<mapToObjects.size(); i++ ) 181 { 182 if ( mapToObjects.get(i).equals(field.getMapToObject()) ) 183 { 184 isNewObject = false; 185 break; 186 } 187 } 188 if ( isNewObject ) 189 { 190 mapToObjects.add(field.getMapToObject()); 191 } 192 } 193 else if( field.getMapToProperty() != null 195 && !"".equals(field.getMapToProperty()) 196 && defaultMapToObject != null ) 197 { 198 field.setMapToObject(defaultMapToObject); 199 } 200 201 fields.add(field); 202 } 203 204 207 public List getFields() 208 { 209 return fields; 210 } 211 212 215 public int getNumFields() 216 { 217 return fields.size(); 218 } 219 220 221 225 public XmlField getField(String name) 226 { 227 String curName; 228 229 for (Iterator iter = fields.iterator() ; iter.hasNext() ;) 230 { 231 XmlField field = (XmlField) iter.next(); 232 curName = field.getRawName(); 233 if (curName.equals(name)) 234 { 235 return field; 236 } 237 } 238 return null; 239 } 240 241 244 public boolean containsField(XmlField field) 245 { 246 return fields.contains (field); 247 } 248 249 252 public boolean containsField(String name) 253 { 254 return (getField (name) != null); 255 } 256 257 public List getMapToObjects() 258 { 259 return mapToObjects; 260 } 261 262 265 public void setAppData(AppData parent) 266 { 267 this.parent = parent; 268 if (defaultMapToObject != null ) 269 { 270 defaultMapToObject = parent.getBasePackage() + defaultMapToObject; 271 mapToObjects.add(defaultMapToObject); 272 } 273 } 274 275 278 public AppData getAppData() 279 { 280 return parent; 281 } 282 283 286 public String getVariable() 287 { 288 String firstChar = getName().substring(0,1).toLowerCase(); 289 return firstChar + getName().substring(1); 290 } 291 292 293 297 public String toString() 298 { 299 StringBuffer result = new StringBuffer (); 300 301 result.append ("<group name=\"").append(getName()); 302 result.append(" key=\""+key+"\""); 303 result.append(">\n"); 304 305 if (fields != null) 306 { 307 for (Iterator iter = fields.iterator() ; iter.hasNext() ;) 308 { 309 result.append(iter.next()); 310 } 311 } 312 313 result.append ("</group>\n"); 314 315 return result.toString(); 316 } 317 } 318 | Popular Tags |