1 | 0 | |
2 | |
|
3 | |
|
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 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class StringParameter extends AbstractParameter<String> { |
29 | |
|
30 | |
|
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 | |
|
41 | |
|
42 | |
public List<String> getSupportedClasses() |
43 | |
{ |
44 | 0 | return supportedClasses; |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
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 | |
|
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 | |
|
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 | |
|
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 | |
|
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 | |
|
122 | |
|
123 | |
public boolean isNumeric() |
124 | |
{ |
125 | 0 | return false; |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public ParameterErrorList setValueFromString(String value, IStageInstance stageInstance, |
133 | |
boolean initializationInProgress) |
134 | |
{ |
135 | 0 | return setValue(value, stageInstance, initializationInProgress); |
136 | |
} |
137 | |
} |