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 XSByte extends AbstractDigitsFacet {
28
29
30
31 public static final String NAME = "byte";
32
33
34 public static final short TYPE = XSType.BYTE_TYPE;
35
36
37 public static final String MIN_VALUE = Byte.toString(Byte.MIN_VALUE);
38
39
40 public static final String MAX_VALUE = Byte.toString(Byte.MAX_VALUE);
41
42
43
44
45 private final boolean _asWrapper;
46
47
48 private final JType _jType;
49
50
51
52
53
54
55 public XSByte() {
56 this(false);
57 }
58
59
60
61
62
63
64 public XSByte(final boolean asWrapper) {
65 super();
66
67 _asWrapper = asWrapper;
68 if (_asWrapper) {
69 _jType = new JClass("java.lang.Byte");
70 } else {
71 _jType = JType.BYTE;
72 }
73 }
74
75
76
77
78
79
80 public String getName() {
81 return NAME;
82 }
83
84
85
86
87 public short getType() {
88 return TYPE;
89 }
90
91
92
93
94 public boolean isPrimitive() {
95 return true;
96 }
97
98
99
100
101 public boolean isDateTime() {
102 return false;
103 }
104
105
106
107
108 public JType getJType() {
109 return _jType;
110 }
111
112
113
114
115 public String newInstanceCode() {
116 return "new java.lang.Byte((byte) 0);";
117 }
118
119
120
121
122 public String createDefaultValueWithString(final String variableName) {
123 if (_asWrapper) {
124 return "new java.lang.Byte(" + variableName + ")";
125 }
126 return "new java.lang.Byte(" + variableName + ").byteValue()";
127 }
128
129
130
131
132 public String createToJavaObjectCode(final String variableName) {
133 if (_asWrapper) {
134 return variableName;
135 }
136 return "new java.lang.Byte(" + variableName + ")";
137 }
138
139
140
141
142 public String createFromJavaObjectCode(final String variableName) {
143 if (_asWrapper) {
144 return "((java.lang.Byte) " + variableName + ")";
145 }
146 return "((java.lang.Byte) " + variableName + ").byteValue()";
147 }
148
149
150
151
152
153
154 public void validationCode(final JSourceCode jsc, final String fixedValue,
155 final String validatorInstanceName) {
156 jsc.add("org.exolab.castor.xml.validators.ByteValidator typeValidator;\n"
157 + "typeValidator = new org.exolab.castor.xml.validators.ByteValidator();\n"
158 + "{0}.setValidator(typeValidator);", validatorInstanceName);
159
160 if (fixedValue != null) {
161 jsc.add("typeValidator.setFixed((byte) " + fixedValue + ");");
162 }
163
164 codePatternFacet(jsc, "typeValidator");
165 codeWhiteSpaceFacet(jsc, "typeValidator");
166
167 if (getMinExclusive() != null) {
168 jsc.add("typeValidator.setMinExclusive((byte) " + getMinExclusive() + ");");
169 } else if (getMinInclusive() != null) {
170 jsc.add("typeValidator.setMinInclusive((byte) " + getMinInclusive() + ");");
171 }
172
173 if (getMaxExclusive() != null) {
174 jsc.add("typeValidator.setMaxExclusive((byte) " + getMaxExclusive() + ");");
175 } else if (getMaxInclusive() != null) {
176 jsc.add("typeValidator.setMaxInclusive((byte) " + getMaxInclusive() + ");");
177 }
178
179 codeDigitsFacet(jsc, "typeValidator");
180 }
181
182
183 }