1 package org.apache.turbine.services.intake.xmlmodel; 2 3 18 19 import java.io.Serializable ; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.apache.turbine.services.intake.IntakeException; 26 27 import org.xml.sax.Attributes ; 28 29 36 public class AppData 37 implements Serializable 38 { 39 40 private List inputs; 41 42 43 private String basePackage; 44 45 46 private String groupPrefix; 47 48 51 public AppData() 52 { 53 inputs = new ArrayList (); 54 } 55 56 59 public void loadFromXML(Attributes attrib) 60 { 61 String basePkg = attrib.getValue("basePackage"); 62 if (basePkg == null) 63 { 64 setBasePackage(""); 65 } 66 else 67 { 68 if (basePkg.charAt(basePkg.length() - 1) != '.') 69 { 70 setBasePackage(basePkg + '.'); 71 } 72 else 73 { 74 setBasePackage(basePkg); 75 } 76 } 77 78 setGroupPrefix(attrib.getValue("groupPrefix")); 79 } 80 81 89 public List getGroups() 90 { 91 return inputs; 92 } 93 94 102 public XmlGroup getGroup(String groupName) 103 throws IntakeException 104 { 105 if (groupName == null) 106 { 107 throw new IntakeException( 108 "Intake AppData.getGroup(groupName) is null"); 109 } 110 111 String groupPrefix = getGroupPrefix(); 112 113 for (Iterator it = inputs.iterator(); it.hasNext();) 114 { 115 XmlGroup group = (XmlGroup) it.next(); 116 117 if (group.getName().equals(groupName)) 118 { 119 return group; 120 } 121 if (groupPrefix != null) 122 { 123 StringBuffer qualifiedGroupName = new StringBuffer (); 124 125 qualifiedGroupName.append(groupPrefix) 126 .append(':') 127 .append(group.getName()); 128 129 if (qualifiedGroupName.toString().equals(groupName)) 130 { 131 return group; 132 } 133 } 134 } 135 return null; 136 } 137 138 142 public XmlGroup addGroup(Attributes attrib) 143 { 144 XmlGroup input = new XmlGroup(); 145 input.loadFromXML(attrib); 146 addGroup(input); 147 return input; 148 } 149 150 154 public void addGroup(XmlGroup input) 155 { 156 input.setAppData(this); 157 inputs.add(input); 158 } 159 160 166 public String getBasePackage() 167 { 168 return basePackage; 169 } 170 171 177 public void setBasePackage(String v) 178 { 179 this.basePackage = v; 180 } 181 182 188 public String getGroupPrefix() 189 { 190 return groupPrefix; 191 } 192 193 199 public void setGroupPrefix(String groupPrefix) 200 { 201 this.groupPrefix = groupPrefix; 202 } 203 204 208 public String toString() 209 { 210 StringBuffer result = new StringBuffer (); 211 212 result.append("<input-data>\n"); 213 for (Iterator iter = inputs.iterator(); iter.hasNext();) 214 { 215 result.append(iter.next()); 216 } 217 result.append("</input-data>"); 218 return result.toString(); 219 } 220 } 221 | Popular Tags |