View Javadoc
1 package org.apache.turbine.services.intake.xmlmodel; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import java.util.ArrayList; 58 import java.util.Iterator; 59 import java.util.List; 60 import org.xml.sax.Attributes; 61 62 /*** 63 * A Class for holding data about a grouping of inputs used in an Application. 64 * 65 * @author <a href="mailto:jmcnally@collab.net>;John McNally</a> 66 * @version $Id: XmlGroup.java,v 1.2 2001/10/09 14:14:30 henning Exp $ 67 */ 68 public class XmlGroup 69 implements java.io.Serializable 70 { 71 private List fields; 72 private List mapToObjects; 73 private String defaultMapToObject; 74 private AppData parent; 75 private String groupName; 76 private String key; 77 private String poolCapacity; 78 79 /*** 80 * Constructs a input group object 81 */ 82 public XmlGroup() 83 { 84 fields = new ArrayList(); 85 mapToObjects = new ArrayList(2); 86 } 87 88 /*** 89 * Load the input group object from an xml tag. 90 */ 91 public void loadFromXML (Attributes attrib) 92 { 93 groupName = attrib.getValue("name"); 94 key = attrib.getValue("key"); 95 poolCapacity = attrib.getValue("pool-capacity"); 96 97 String objName = attrib.getValue("mapToObject"); 98 if ( objName != null && objName.length() != 0 ) 99 { 100 defaultMapToObject = objName; 101 } 102 } 103 104 /*** 105 * Get the name that handles this group 106 */ 107 public String getName() 108 { 109 return groupName; 110 } 111 112 /*** 113 * Set the name that handles this group 114 */ 115 public void setName(String newGroupName) 116 { 117 groupName = newGroupName; 118 } 119 120 /*** 121 * Get the key used to reference this group in input (form) 122 */ 123 public String getKey() 124 { 125 return key; 126 } 127 128 /*** 129 * Set the key used to reference this group in input (form) 130 */ 131 public void setKey(String newKey) 132 { 133 key = newKey; 134 } 135 136 137 /*** 138 * The maximum number of classes specific to this group 139 * allowed at one time. 140 * 141 * @return an <code>String</code> value 142 */ 143 public String getPoolCapacity() 144 { 145 if ( poolCapacity == null ) 146 { 147 return "128"; 148 } 149 150 return poolCapacity; 151 } 152 153 /*** 154 * A utility function to create a new field 155 * from attrib and add it to this input group. 156 */ 157 public XmlField addField(Attributes attrib) 158 { 159 XmlField field = new XmlField(); 160 field.loadFromXML(attrib); 161 addField(field); 162 163 return field; 164 } 165 166 /*** 167 * Adds a new field to the fields list and set the 168 * parent group of the field to the current group 169 */ 170 public void addField(XmlField field) 171 { 172 field.setGroup(this); 173 174 // if this field has an object defined for mapping, 175 // add it to the list 176 if ( field.getMapToObject() != null ) 177 { 178 boolean isNewObject = true; 179 for ( int i=0; i<mapToObjects.size(); i++ ) 180 { 181 if ( mapToObjects.get(i).equals(field.getMapToObject()) ) 182 { 183 isNewObject = false; 184 break; 185 } 186 } 187 if ( isNewObject ) 188 { 189 mapToObjects.add(field.getMapToObject()); 190 } 191 } 192 // if a mapToProperty exists, set the object to this group's default 193 else if( field.getMapToProperty() != null 194 && !"".equals(field.getMapToProperty()) 195 && defaultMapToObject != null ) 196 { 197 field.setMapToObject(defaultMapToObject); 198 } 199 200 fields.add(field); 201 } 202 203 /*** 204 * Returns a collection of fields in this input group 205 */ 206 public List getFields() 207 { 208 return fields; 209 } 210 211 /*** 212 * Utility method to get the number of fields in this input group 213 */ 214 public int getNumFields() 215 { 216 return fields.size(); 217 } 218 219 220 /*** 221 * Returns a Specified field. 222 * @return Return a XmlField object or null if it does not exist. 223 */ 224 public XmlField getField(String name) 225 { 226 String curName; 227 228 for (Iterator iter = fields.iterator() ; iter.hasNext() ;) 229 { 230 XmlField field = (XmlField) iter.next(); 231 curName = field.getRawName(); 232 if (curName.equals(name)) 233 { 234 return field; 235 } 236 } 237 return null; 238 } 239 240 /*** 241 * Returns true if the input group contains a spesified field 242 */ 243 public boolean containsField(XmlField field) 244 { 245 return fields.contains (field); 246 } 247 248 /*** 249 * Returns true if the input group contains a specified field 250 */ 251 public boolean containsField(String name) 252 { 253 return (getField (name) != null); 254 } 255 256 public List getMapToObjects() 257 { 258 return mapToObjects; 259 } 260 261 /*** 262 * Set the parent of the group 263 */ 264 public void setAppData(AppData parent) 265 { 266 this.parent = parent; 267 if (defaultMapToObject != null ) 268 { 269 defaultMapToObject = parent.getBasePackage() + defaultMapToObject; 270 mapToObjects.add(defaultMapToObject); 271 } 272 } 273 274 /*** 275 * Get the parent of the input group 276 */ 277 public AppData getAppData() 278 { 279 return parent; 280 } 281 282 /*** 283 * A String which might be used as a variable of this class 284 */ 285 public String getVariable() 286 { 287 String firstChar = getName().substring(0,1).toLowerCase(); 288 return firstChar + getName().substring(1); 289 } 290 291 292 /*** 293 * Creates a string representation of this input group. This 294 * is an xml representation. 295 */ 296 public String toString() 297 { 298 StringBuffer result = new StringBuffer(); 299 300 result.append ("<group name=\"").append(getName()); 301 result.append(" key=\""+key+"\""); 302 result.append(">\n"); 303 304 if (fields != null) 305 { 306 for (Iterator iter = fields.iterator() ; iter.hasNext() ;) 307 { 308 result.append(iter.next()); 309 } 310 } 311 312 result.append ("</group>\n"); 313 314 return result.toString(); 315 } 316 }

This page was automatically generated by Maven