1 | 0 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
package pt.digitalis.dif.dem.objects.parameters.types; |
6 | |
|
7 | |
import java.math.BigDecimal; |
8 | |
import java.util.ArrayList; |
9 | |
import java.util.Date; |
10 | |
import java.util.List; |
11 | |
|
12 | |
import pt.digitalis.dif.controller.interfaces.IDIFContext; |
13 | |
import pt.digitalis.dif.dem.interfaces.IStageInstance; |
14 | |
import pt.digitalis.dif.dem.objects.parameters.errors.ParameterErrorList; |
15 | |
import pt.digitalis.dif.exception.objects.ParameterException; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | public class BooleanParameter extends AbstractParameter<Boolean> { |
27 | |
|
28 | |
|
29 | |
@SuppressWarnings("serial") |
30 | 0 | final static private List<String> supportedClasses = new ArrayList<String>() { |
31 | |
|
32 | |
{ |
33 | 0 | add(Boolean.class.getCanonicalName()); |
34 | |
} |
35 | |
}; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public List<String> getSupportedClasses() |
41 | |
{ |
42 | 0 | return supportedClasses; |
43 | |
} |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
@Override |
49 | |
public Boolean getValue(IDIFContext context) throws ParameterException |
50 | |
{ |
51 | 0 | Boolean temp = super.getValue(context); |
52 | |
|
53 | 0 | if (temp == null) |
54 | 0 | return false; |
55 | |
else |
56 | 0 | return temp; |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public BigDecimal getValueAsBigDecimal(IDIFContext context) throws ParameterException |
63 | |
{ |
64 | 0 | return (getValue(context) ? BigDecimal.valueOf(1L) : BigDecimal.valueOf(0L)); |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public boolean getValueAsBoolean(IDIFContext context) throws ParameterException |
71 | |
{ |
72 | 0 | Boolean value = getValue(context); |
73 | |
|
74 | 0 | if (value == null) |
75 | 0 | return false; |
76 | |
else |
77 | 0 | return value.booleanValue(); |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public Date getValueAsDate(IDIFContext context) |
84 | |
{ |
85 | 0 | return null; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public Double getValueAsDouble(IDIFContext context) throws ParameterException |
92 | |
{ |
93 | 0 | return (getValue(context) ? 1D : 0D); |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public Long getValueAsLong(IDIFContext context) throws ParameterException |
100 | |
{ |
101 | 0 | return (getValue(context) ? 1L : 0L); |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@Override |
108 | |
public String getValueAsString(IDIFContext context) throws ParameterException |
109 | |
{ |
110 | 0 | return Boolean.toString(getValueAsBoolean(context)); |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public boolean isNumeric() |
117 | |
{ |
118 | 0 | return false; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public ParameterErrorList setValueFromString(String value, IStageInstance stageInstance, |
126 | |
boolean initializationInProgress) |
127 | |
{ |
128 | 0 | if (value == null || "".equals(value)) |
129 | 0 | return setValue(null, stageInstance); |
130 | |
else |
131 | |
{ |
132 | 0 | value = value.toLowerCase(); |
133 | 0 | value = value.replace("on", "true"); |
134 | 0 | value = value.replace("off", "false"); |
135 | 0 | value = value.replace("yes", "true"); |
136 | 0 | value = value.replace("no", "false"); |
137 | |
|
138 | 0 | return setValue(Boolean.parseBoolean(value), stageInstance, initializationInProgress); |
139 | |
} |
140 | |
} |
141 | |
} |