Coverage Report - pt.digitalis.dif.dem.objects.parameters.types.StringParameter
 
Classes in this File Line Coverage Branch Coverage Complexity
StringParameter
0%
0/19
0%
0/10
2,625
StringParameter$1
0%
0/3
N/A
2,625
 
 1  0
 /**
 2  
  * 2007, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
 3  
  * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
 4  
  */
 5  
 package pt.digitalis.dif.dem.objects.parameters.types;
 6  
 
 7  
 import java.math.BigDecimal;
 8  
 import java.text.ParseException;
 9  
 import java.util.ArrayList;
 10  
 import java.util.Date;
 11  
 import java.util.List;
 12  
 
 13  
 import pt.digitalis.dif.controller.interfaces.IDIFContext;
 14  
 import pt.digitalis.dif.dem.interfaces.IStageInstance;
 15  
 import pt.digitalis.dif.dem.objects.parameters.errors.ParameterErrorList;
 16  
 import pt.digitalis.dif.exception.objects.ParameterException;
 17  
 import pt.digitalis.utils.common.DateUtils;
 18  
 
 19  
 /**
 20  
  * /** This class will define a numeric Parameter.
 21  
  * <p>
 22  
  * It will hold information relative to the Parameter value, ID key and validation constraints.
 23  
  * 
 24  
  * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
 25  
  * @author Rodrigo Gon�alves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
 26  
  * @created Nov 23, 2007
 27  
  */
 28  0
 public class StringParameter extends AbstractParameter<String> {
 29  
 
 30  
     /** The list of supported classes to define in the concrete implementations */
 31  
     @SuppressWarnings("serial")
 32  0
     final static private List<String> supportedClasses = new ArrayList<String>() {
 33  
 
 34  
         {
 35  0
             add(String.class.getCanonicalName());
 36  
         }
 37  
     };
 38  
 
 39  
     /**
 40  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getSupportedClasses()
 41  
      */
 42  
     public List<String> getSupportedClasses()
 43  
     {
 44  0
         return supportedClasses;
 45  
     }
 46  
 
 47  
     /**
 48  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getValueAsBigDecimal(pt.digitalis.dif.controller.interfaces.IDIFContext)
 49  
      */
 50  
     public BigDecimal getValueAsBigDecimal(IDIFContext context) throws ParameterException
 51  
     {
 52  
         try
 53  
         {
 54  0
             return new BigDecimal(getValue(context).toString());
 55  
 
 56  
         }
 57  0
         catch (Exception e)
 58  
         {
 59  0
             throw new ParameterException("Error parsing value", e, this);
 60  
         }
 61  
     }
 62  
 
 63  
     /**
 64  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getValueAsBoolean(IDIFContext)
 65  
      */
 66  
     public boolean getValueAsBoolean(IDIFContext context) throws ParameterException
 67  
     {
 68  0
         String value = getValue(context);
 69  
 
 70  0
         return (value == null ? false : Boolean.getBoolean(value));
 71  
     }
 72  
 
 73  
     /**
 74  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getValueAsDate(IDIFContext)
 75  
      */
 76  
     public Date getValueAsDate(IDIFContext context) throws ParameterException
 77  
     {
 78  
         try
 79  
         {
 80  0
             return DateUtils.stringToDate(getValue(context));
 81  
         }
 82  0
         catch (ParseException e)
 83  
         {
 84  0
             throw new ParameterException("Error parsing value", e, this);
 85  
         }
 86  
     }
 87  
 
 88  
     /**
 89  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getValueAsDouble(IDIFContext)
 90  
      */
 91  
     public Double getValueAsDouble(IDIFContext context) throws ParameterException
 92  
     {
 93  
         try
 94  
         {
 95  0
             return Double.parseDouble(getValue(context).toString());
 96  
 
 97  
         }
 98  0
         catch (Exception e)
 99  
         {
 100  0
             throw new ParameterException("Error parsing value", e, this);
 101  
         }
 102  
     }
 103  
 
 104  
     /**
 105  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#getValueAsLong(IDIFContext)
 106  
      */
 107  
     public Long getValueAsLong(IDIFContext context) throws ParameterException
 108  
     {
 109  
         try
 110  
         {
 111  0
             return Long.parseLong(getValue(context).toString());
 112  
 
 113  
         }
 114  0
         catch (Exception e)
 115  
         {
 116  0
             throw new ParameterException("Error parsing value", e, this);
 117  
         }
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#isNumeric()
 122  
      */
 123  
     public boolean isNumeric()
 124  
     {
 125  0
         return false;
 126  
     }
 127  
 
 128  
     /**
 129  
      * @see pt.digitalis.dif.dem.objects.parameters.IParameter#setValueFromString(java.lang.String,
 130  
      *      pt.digitalis.dif.dem.interfaces.IStageInstance, boolean)
 131  
      */
 132  
     public ParameterErrorList setValueFromString(String value, IStageInstance stageInstance,
 133  
             boolean initializationInProgress)
 134  
     {
 135  0
         return setValue(value, stageInstance, initializationInProgress);
 136  
     }
 137  
 }