Coverage report

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

 1  
 package org.apache.turbine.services.intake.xmlmodel;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 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.IOException;
 20  
 import java.io.ObjectInputStream;
 21  
 import java.io.ObjectOutputStream;
 22  
 import java.io.Serializable;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.HashMap;
 26  
 import java.util.Iterator;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 import org.apache.commons.lang.StringUtils;
 31  
 
 32  
 import org.xml.sax.Attributes;
 33  
 
 34  
 /**
 35  
  * A Class for holding data about a property used in an Application.
 36  
  *
 37  
  * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
 38  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 39  
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
 40  
  * @version $Id: XmlField.java 278822 2005-09-05 19:53:05Z henning $
 41  
  */
 42  
 public class XmlField
 43  
         implements Serializable
 44  
 {
 45  
     /** Serial Version UID */
 46  
     private static final long serialVersionUID = 6403078189106766569L;
 47  
 
 48  
     private String name;
 49  
     private String key;
 50  
     private String type;
 51  
     private String displayName;
 52  
     private String multiValued;
 53  
     private XmlGroup parent;
 54  
     private List rules;
 55  
     private Map ruleMap;
 56  
     private String ifRequiredMessage;
 57  
     private String mapToObject;
 58  
     private String mapToProperty;
 59  
     private String validator;
 60  
     private String defaultValue;
 61  
     private String emptyValue;
 62  
     private String displaySize;
 63  
 
 64  
     /**
 65  
      * Default Constructor
 66  
      */
 67  
     public XmlField()
 68  0
     {
 69  0
         rules = new ArrayList();
 70  0
         ruleMap = new HashMap();
 71  0
     }
 72  
 
 73  
     /**
 74  
      * Creates a new column and set the name
 75  
      */
 76  
     public XmlField(String name)
 77  0
     {
 78  0
         this.name = name;
 79  0
         rules = new ArrayList();
 80  0
         ruleMap = new HashMap();
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Imports a column from an XML specification
 85  
      */
 86  
     public void loadFromXML(Attributes attrib)
 87  
     {
 88  0
         setName(attrib.getValue("name"));
 89  0
         setKey(attrib.getValue("key"));
 90  0
         setType(attrib.getValue("type"));
 91  0
         setDisplayName(attrib.getValue("displayName"));
 92  0
         setDisplaySize(attrib.getValue("displaySize"));
 93  0
         setMultiValued(attrib.getValue("multiValued"));
 94  
 
 95  0
         String mapObj = attrib.getValue("mapToObject");
 96  0
         if (mapObj != null && mapObj.length() != 0)
 97  
         {
 98  0
             setMapToObject(mapObj);
 99  
         }
 100  
 
 101  0
         setMapToProperty(attrib.getValue("mapToProperty"));
 102  0
         setValidator(attrib.getValue("validator"));
 103  0
         setDefaultValue(attrib.getValue("defaultValue"));
 104  0
         setEmptyValue(attrib.getValue("emptyValue"));
 105  0
     }
 106  
 
 107  
     /**
 108  
      * Get the name of the property
 109  
      */
 110  
     public String getRawName()
 111  
     {
 112  0
         return name;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Get the name of the property
 117  
      */
 118  
     public String getName()
 119  
     {
 120  0
         return StringUtils.replace(name, "_", "");
 121  
     }
 122  
 
 123  
     /**
 124  
      * Set the name of the property
 125  
      */
 126  
     public void setName(String newName)
 127  
     {
 128  0
         name = newName;
 129  0
     }
 130  
 
 131  
     /**
 132  
      * Get the display name of the property
 133  
      */
 134  
     public String getDisplayName()
 135  
     {
 136  0
         return displayName;
 137  
     }
 138  
 
 139  
     /**
 140  
      * Set the display name of the property
 141  
      */
 142  
     public void setDisplayName(String newDisplayName)
 143  
     {
 144  0
         displayName = newDisplayName;
 145  0
     }
 146  
 
 147  
     /**
 148  
      * Sets the display size of the field.
 149  
      */
 150  
     private void setDisplaySize(String size)
 151  
     {
 152  0
         this.displaySize = size;
 153  0
     }
 154  
 
 155  
     /**
 156  
      * Gets the display size of the field.  This is
 157  
      * useful for constructing the HTML input tag.
 158  
      */
 159  
     public String getDisplaySize()
 160  
     {
 161  0
         return this.displaySize;
 162  
     }
 163  
 
 164  
     /**
 165  
      * Set the parameter key of the property
 166  
      */
 167  
     public void setKey(String newKey)
 168  
     {
 169  0
         key = newKey;
 170  0
     }
 171  
 
 172  
     /**
 173  
      * Get the parameter key of the property
 174  
      */
 175  
     public String getKey()
 176  
     {
 177  0
         return key;
 178  
     }
 179  
 
 180  
     /**
 181  
      * Set the type of the property
 182  
      */
 183  
     public void setType(String newType)
 184  
     {
 185  0
         type = newType;
 186  0
     }
 187  
 
 188  
     /**
 189  
      * Get the type of the property
 190  
      */
 191  
     public String getType()
 192  
     {
 193  0
         return type;
 194  
     }
 195  
 
 196  
     /**
 197  
      * Set whether this class can have multiple values
 198  
      */
 199  
     public void setMultiValued(String newMultiValued)
 200  
     {
 201  0
         multiValued = newMultiValued;
 202  0
     }
 203  
 
 204  
     /**
 205  
      * can this field have several values?
 206  
      */
 207  
     public boolean isMultiValued()
 208  
     {
 209  0
         if (multiValued != null && multiValued.equals("true"))
 210  
         {
 211  0
             return true;
 212  
         }
 213  0
         return false;
 214  
     }
 215  
 
 216  
     /**
 217  
      * Set the name of the object that takes this input
 218  
      *
 219  
      * @param objectName name of the class.
 220  
      */
 221  
     public void setMapToObject(String objectName)
 222  
     {
 223  0
         mapToObject = objectName;
 224  0
     }
 225  
 
 226  
     /**
 227  
      * Get the name of the object that takes this input
 228  
      */
 229  
     public String getMapToObject()
 230  
     {
 231  0
         return mapToObject;
 232  
     }
 233  
 
 234  
     /**
 235  
      * Set the property method that takes this input
 236  
      *
 237  
      * @param prop Name of the property to which the field will be mapped.
 238  
      */
 239  
     public void setMapToProperty(String prop)
 240  
     {
 241  0
         mapToProperty = prop;
 242  0
     }
 243  
 
 244  
     /**
 245  
      * Get the property method that takes this input
 246  
      */
 247  
     public String getMapToProperty()
 248  
     {
 249  0
         if (mapToProperty == null)
 250  
         {
 251  0
             return getName();
 252  
         }
 253  
         else
 254  
         {
 255  0
             return mapToProperty;
 256  
         }
 257  
     }
 258  
 
 259  
     /**
 260  
      * Set the class name of the validator
 261  
      */
 262  
     public void setValidator(String prop)
 263  
     {
 264  0
         validator = prop;
 265  0
     }
 266  
 
 267  
     /**
 268  
      * Get the className of the validator
 269  
      */
 270  
     public String getValidator()
 271  
     {
 272  0
         return validator;
 273  
     }
 274  
 
 275  
     /**
 276  
      * Set the default Value.
 277  
      *
 278  
      * @param prop The parameter to use as default value.
 279  
      */
 280  
     public void setDefaultValue(String prop)
 281  
     {
 282  0
         defaultValue = prop;
 283  0
     }
 284  
 
 285  
     /**
 286  
      * Get the default Value.
 287  
      *
 288  
      * @return The default value for this field.
 289  
      */
 290  
     public String getDefaultValue()
 291  
     {
 292  0
         return defaultValue;
 293  
     }
 294  
 
 295  
     /**
 296  
      * Set the empty Value.
 297  
      *
 298  
      * @param prop The parameter to use as empty value.
 299  
      */
 300  
     public void setEmptyValue(String prop)
 301  
     {
 302  0
         emptyValue = prop;
 303  0
     }
 304  
 
 305  
     /**
 306  
      * Get the empty Value.
 307  
      *
 308  
      * @return The empty value for this field.
 309  
      */
 310  
     public String getEmptyValue()
 311  
     {
 312  0
         return emptyValue;
 313  
     }
 314  
 
 315  
     /**
 316  
      * The name of the field making sure the first letter is lowercase.
 317  
      *
 318  
      * @return a <code>String</code> value
 319  
      * @deprecated No replacement
 320  
      */
 321  
     public String getVariable()
 322  
     {
 323  0
         String firstChar = getName().substring(0, 1).toLowerCase();
 324  0
         return firstChar + getName().substring(1);
 325  
     }
 326  
 
 327  
     /**
 328  
      * Set the parent XmlGroup of the property
 329  
      */
 330  
     public void setGroup(XmlGroup parent)
 331  
     {
 332  0
         this.parent = parent;
 333  0
         if (mapToObject != null && mapToObject.length() != 0)
 334  
         {
 335  0
             mapToObject = parent.getAppData().getBasePackage() + mapToObject;
 336  
         }
 337  0
     }
 338  
 
 339  
     /**
 340  
      * Get the parent XmlGroup of the property
 341  
      */
 342  
     public XmlGroup getGroup()
 343  
     {
 344  0
         return parent;
 345  
     }
 346  
 
 347  
     /**
 348  
      * Get the value of ifRequiredMessage.
 349  
      *
 350  
      * @return value of ifRequiredMessage.
 351  
      */
 352  
     public String getIfRequiredMessage()
 353  
     {
 354  0
         return ifRequiredMessage;
 355  
     }
 356  
 
 357  
     /**
 358  
      * Set the value of ifRequiredMessage.
 359  
      *
 360  
      * @param v  Value to assign to ifRequiredMessage.
 361  
      */
 362  
     public void setIfRequiredMessage(String v)
 363  
     {
 364  0
         this.ifRequiredMessage = v;
 365  0
     }
 366  
 
 367  
     /**
 368  
      * A utility function to create a new input parameter
 369  
      * from attrib and add it to this property.
 370  
      */
 371  
     public Rule addRule(Attributes attrib)
 372  
     {
 373  0
         Rule rule = new Rule();
 374  0
         rule.loadFromXML(attrib);
 375  0
         addRule(rule);
 376  
 
 377  0
         return rule;
 378  
     }
 379  
 
 380  
     /**
 381  
      * Adds a new rule to the parameter Map and set the
 382  
      * parent property of the Rule to this property
 383  
      */
 384  
     public void addRule(Rule rule)
 385  
     {
 386  0
         rule.setField(this);
 387  0
         rules.add(rule);
 388  0
         ruleMap.put(rule.getName(), rule);
 389  0
     }
 390  
 
 391  
     /**
 392  
      * The collection of rules for this field.
 393  
      *
 394  
      * @return a <code>List</code> value
 395  
      */
 396  
     public List getRules()
 397  
     {
 398  0
         return rules;
 399  
     }
 400  
 
 401  
     /**
 402  
      * The collection of rules for this field keyed by
 403  
      * parameter name.
 404  
      *
 405  
      * @return a <code>Map</code> value
 406  
      */
 407  
     public Map getRuleMap()
 408  
     {
 409  0
         return ruleMap;
 410  
     }
 411  
 
 412  
     /**
 413  
      * String representation of the column. This
 414  
      * is an xml representation.
 415  
      */
 416  
     public String toString()
 417  
     {
 418  0
         StringBuffer result = new StringBuffer();
 419  0
         result.append(" <field name=\"" + name + "\"");
 420  0
         result.append(" key=\"" + key + "\"");
 421  0
         result.append(" type=\"" + type + "\"");
 422  
 
 423  0
         if (displayName != null)
 424  
         {
 425  0
             result.append(" displayName=\"" + displayName + "\"");
 426  
         }
 427  0
         if (mapToObject != null)
 428  
         {
 429  0
             result.append(" mapToObject=\"" + mapToObject + "\"");
 430  
         }
 431  0
         if (mapToProperty != null)
 432  
         {
 433  0
             result.append(" mapToProperty=\"" + mapToProperty + "\"");
 434  
         }
 435  0
         if (validator != null)
 436  
         {
 437  0
             result.append(" validator=\"" + validator + "\"");
 438  
         }
 439  0
         if (defaultValue != null)
 440  
         {
 441  0
             result.append(" defaultValue=\"" + defaultValue + "\"");
 442  
         }
 443  
 
 444  0
         if (emptyValue != null)
 445  
         {
 446  0
             result.append(" emptyValue=\"" + emptyValue + "\"");
 447  
         }
 448  
 
 449  0
         if (rules.size() == 0)
 450  
         {
 451  0
             result.append(" />\n");
 452  
         }
 453  
         else
 454  
         {
 455  0
             result.append(">\n");
 456  0
             for (Iterator i = rules.iterator(); i.hasNext();)
 457  
             {
 458  0
                 result.append(i.next());
 459  
             }
 460  0
             result.append("</field>\n");
 461  
         }
 462  
 
 463  0
         return result.toString();
 464  
     }
 465  
 
 466  
     // this methods are called during serialization
 467  
     private void writeObject(ObjectOutputStream stream)
 468  
             throws IOException
 469  
     {
 470  0
         stream.defaultWriteObject();
 471  0
     }
 472  
 
 473  
     private void readObject(ObjectInputStream stream)
 474  
             throws IOException, ClassNotFoundException
 475  
     {
 476  0
         stream.defaultReadObject();
 477  0
     }
 478  
 }

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