1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.exolab.castor.builder.types;
15
16 import org.exolab.javasource.JClass;
17 import org.exolab.javasource.JSourceCode;
18 import org.exolab.javasource.JType;
19
20
21
22
23
24
25
26
27 public final class XSDecimal extends AbstractDigitsFacet {
28
29
30
31 public static final String NAME = "decimal";
32
33
34 public static final short TYPE = XSType.DECIMAL_TYPE;
35
36
37 private static final JType JTYPE = new JClass("java.math.BigDecimal");
38
39
40
41
42
43
44 public XSDecimal() {
45 super(false);
46 }
47
48
49
50
51
52
53 public String getName() {
54 return NAME;
55 }
56
57
58
59
60 public short getType() {
61 return TYPE;
62 }
63
64
65
66
67 public boolean isPrimitive() {
68 return false;
69 }
70
71
72
73
74 public boolean isDateTime() {
75 return false;
76 }
77
78
79
80
81 public JType getJType() {
82 return JTYPE;
83 }
84
85
86
87
88 public String newInstanceCode() {
89 return "new java.math.BigDecimal(0);";
90 }
91
92
93
94
95 public String createToJavaObjectCode(final String variableName) {
96 return variableName;
97 }
98
99
100
101
102 public String createFromJavaObjectCode(final String variableName) {
103 return "(java.math.BigDecimal) " + variableName;
104 }
105
106
107
108
109
110
111 public void validationCode(final JSourceCode jsc, final String fixedValue,
112 final String validatorInstanceName) {
113 jsc.add("org.exolab.castor.xml.validators.DecimalValidator typeValidator;\n"
114 + "typeValidator = new org.exolab.castor.xml.validators.DecimalValidator();\n"
115 + "{0}.setValidator(typeValidator);", validatorInstanceName);
116
117 if (fixedValue != null) {
118 jsc.add("typeValidator.setFixed(" + fixedValue + ");");
119 }
120
121 codePatternFacet(jsc, "typeValidator");
122 codeWhiteSpaceFacet(jsc, "typeValidator");
123
124 if (getMinExclusive() != null) {
125 jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"{0}\");\n"
126 + "typeValidator.setMinExclusive(min);", getMinExclusive());
127 } else if (getMinInclusive() != null) {
128 jsc.add("java.math.BigDecimal min = new java.math.BigDecimal(\"{0}\");\n"
129 + "typeValidator.setMinInclusive(min);", getMinInclusive());
130 }
131
132 if (getMaxExclusive() != null) {
133 jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"{0}\");\n"
134 + "typeValidator.setMaxExclusive(max);", getMaxExclusive());
135 } else if (getMaxInclusive() != null) {
136 jsc.add("java.math.BigDecimal max = new java.math.BigDecimal(\"{0}\");\n"
137 + "typeValidator.setMaxInclusive(max);", getMaxInclusive());
138 }
139
140 codeDigitsFacet(jsc, "typeValidator");
141 }
142
143
144 }