Coverage report

  %line %branch
org.apache.turbine.services.intake.xmlmodel.XmlGroup
0% 
0% 

 1  
 package org.apache.turbine.services.intake.xmlmodel;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2004 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 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.commons.lang.StringUtils;
 26  
 
 27  
 import org.xml.sax.Attributes;
 28  
 
 29  
 /**
 30  
  * A Class for holding data about a grouping of inputs used in an Application.
 31  
  *
 32  
  * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
 33  
  * @version $Id: XmlGroup.java,v 1.5.2.2 2004/05/20 03:06:49 seade Exp $
 34  
  */
 35  
 public class XmlGroup
 36  
         implements Serializable
 37  
 {
 38  
     private List fields;
 39  
     private List mapToObjects;
 40  
     private String defaultMapToObject;
 41  
     private AppData parent;
 42  
     private String groupName;
 43  
     private String key;
 44  
     private String poolCapacity;
 45  
 
 46  
     /**
 47  
      * Constructs a input group object
 48  
      */
 49  
     public XmlGroup()
 50  0
     {
 51  0
         fields = new ArrayList();
 52  0
         mapToObjects = new ArrayList(2);
 53  0
     }
 54  
 
 55  
     /**
 56  
      * Load the input group object from an xml tag.
 57  
      */
 58  
     public void loadFromXML(Attributes attrib)
 59  
     {
 60  0
         groupName = attrib.getValue("name");
 61  0
         key = attrib.getValue("key");
 62  0
         poolCapacity = attrib.getValue("pool-capacity");
 63  
 
 64  0
         String objName = attrib.getValue("mapToObject");
 65  0
         if (StringUtils.isNotEmpty(objName))
 66  
         {
 67  0
             defaultMapToObject = objName;
 68  
         }
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Get the name that handles this group
 73  
      */
 74  
     public String getName()
 75  
     {
 76  0
         return groupName;
 77  
     }
 78  
 
 79  
     /**
 80  
      * Set the name that handles this group
 81  
      */
 82  
     public void setName(String newGroupName)
 83  
     {
 84  0
         groupName = newGroupName;
 85  0
     }
 86  
 
 87  
     /**
 88  
      * Get the key used to reference this group in input (form)
 89  
      */
 90  
     public String getKey()
 91  
     {
 92  0
         return key;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Set the key used to reference this group in input (form)
 97  
      */
 98  
     public void setKey(String newKey)
 99  
     {
 100  0
         key = newKey;
 101  0
     }
 102  
 
 103  
     /**
 104  
      * The maximum number of classes specific to this group
 105  
      * allowed at one time.
 106  
      *
 107  
      * @return an <code>String</code> value
 108  
      */
 109  
     public String getPoolCapacity()
 110  
     {
 111  0
         if (poolCapacity == null)
 112  
         {
 113  0
             return "128";
 114  
         }
 115  
 
 116  0
         return poolCapacity;
 117  
     }
 118  
 
 119  
     /**
 120  
      * A utility function to create a new field
 121  
      * from attrib and add it to this input group.
 122  
      */
 123  
     public XmlField addField(Attributes attrib)
 124  
     {
 125  0
         XmlField field = new XmlField();
 126  0
         field.loadFromXML(attrib);
 127  0
         addField(field);
 128  
 
 129  0
         return field;
 130  
     }
 131  
 
 132  
     /**
 133  
      * Adds a new field to the fields list and set the
 134  
      * parent group of the field to the current group
 135  
      */
 136  
     public void addField(XmlField field)
 137  
     {
 138  0
         field.setGroup(this);
 139  
 
 140  
         // if this field has an object defined for mapping,
 141  
         // add it to the list
 142  0
         if (field.getMapToObject() != null)
 143  
         {
 144  0
             boolean isNewObject = true;
 145  0
             for (int i = 0; i < mapToObjects.size(); i++)
 146  
             {
 147  0
                 if (mapToObjects.get(i).equals(field.getMapToObject()))
 148  
                 {
 149  0
                     isNewObject = false;
 150  0
                     break;
 151  
                 }
 152  
             }
 153  0
             if (isNewObject)
 154  
             {
 155  0
                 mapToObjects.add(field.getMapToObject());
 156  
             }
 157  
         }
 158  
         // if a mapToProperty exists, set the object to this group's default
 159  0
         else if (field.getMapToProperty() != null
 160  
                 && !"".equals(field.getMapToProperty())
 161  
                 && defaultMapToObject != null)
 162  
         {
 163  0
             field.setMapToObject(defaultMapToObject);
 164  
         }
 165  
 
 166  0
         fields.add(field);
 167  0
     }
 168  
 
 169  
     /**
 170  
      * Returns a collection of fields in this input group
 171  
      */
 172  
     public List getFields()
 173  
     {
 174  0
         return fields;
 175  
     }
 176  
 
 177  
     /**
 178  
      * Utility method to get the number of fields in this input group
 179  
      */
 180  
     public int getNumFields()
 181  
     {
 182  0
         return fields.size();
 183  
     }
 184  
 
 185  
     /**
 186  
      * Returns a Specified field.
 187  
      * @return Return a XmlField object or null if it does not exist.
 188  
      */
 189  
     public XmlField getField(String name)
 190  
     {
 191  
         String curName;
 192  
 
 193  0
         for (Iterator iter = fields.iterator(); iter.hasNext();)
 194  
         {
 195  0
             XmlField field = (XmlField) iter.next();
 196  0
             curName = field.getRawName();
 197  0
             if (curName.equals(name))
 198  
             {
 199  0
                 return field;
 200  
             }
 201  
         }
 202  0
         return null;
 203  
     }
 204  
 
 205  
     /**
 206  
      * Returns true if the input group contains a spesified field
 207  
      */
 208  
     public boolean containsField(XmlField field)
 209  
     {
 210  0
         return fields.contains(field);
 211  
     }
 212  
 
 213  
     /**
 214  
      * Returns true if the input group contains a specified field
 215  
      */
 216  
     public boolean containsField(String name)
 217  
     {
 218  0
         return (getField(name) != null);
 219  
     }
 220  
 
 221  
     public List getMapToObjects()
 222  
     {
 223  0
         return mapToObjects;
 224  
     }
 225  
 
 226  
     /**
 227  
      * Set the parent of the group
 228  
      */
 229  
     public void setAppData(AppData parent)
 230  
     {
 231  0
         this.parent = parent;
 232  0
         if (defaultMapToObject != null)
 233  
         {
 234  0
             defaultMapToObject = parent.getBasePackage() + defaultMapToObject;
 235  0
             mapToObjects.add(defaultMapToObject);
 236  
         }
 237  0
     }
 238  
 
 239  
     /**
 240  
      * Get the parent of the input group
 241  
      */
 242  
     public AppData getAppData()
 243  
     {
 244  0
         return parent;
 245  
     }
 246  
 
 247  
     /**
 248  
      * A String which might be used as a variable of this class
 249  
      */
 250  
     public String getVariable()
 251  
     {
 252  0
         String firstChar = getName().substring(0, 1).toLowerCase();
 253  0
         return firstChar + getName().substring(1);
 254  
     }
 255  
 
 256  
     /**
 257  
      * Creates a string representation of this input group. This
 258  
      * is an xml representation.
 259  
      */
 260  
     public String toString()
 261  
     {
 262  0
         StringBuffer result = new StringBuffer();
 263  
 
 264  0
         result.append("<group name=\"").append(getName());
 265  0
         result.append(" key=\"" + key + "\"");
 266  0
         result.append(">\n");
 267  
 
 268  0
         if (fields != null)
 269  
         {
 270  0
             for (Iterator iter = fields.iterator(); iter.hasNext();)
 271  
             {
 272  0
                 result.append(iter.next());
 273  
             }
 274  
         }
 275  
 
 276  0
         result.append("</group>\n");
 277  
 
 278  0
         return result.toString();
 279  
     }
 280  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.