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 XSUnsignedLong extends AbstractDigitsFacet {
28
29
30
31
32 private static final String JAVA_CLASS_NAME = "java.math.BigInteger";
33
34
35 public static final String NAME = "unsignedLong";
36
37
38 public static final short TYPE = XSType.UNSIGNED_LONG_TYPE;
39
40
41 private static final JType JTYPE = new JClass(JAVA_CLASS_NAME);
42
43
44 public static final String MIN_VALUE = "0";
45
46
47
48
49 public static final String MAX_VALUE = "18446744073709551615";
50
51
52
53
54 public XSUnsignedLong() {
55 super();
56 setMinInclusive(MIN_VALUE);
57 setMaxInclusive(MAX_VALUE);
58 }
59
60 public String getName() {
61 return NAME;
62 }
63
64 public short getType() {
65 return TYPE;
66 }
67
68 public boolean isPrimitive() {
69 return false;
70 }
71
72 public boolean isDateTime() {
73 return false;
74 }
75
76 public JType getJType() {
77 return JTYPE;
78 }
79
80 public String newInstanceCode() {
81 return "new java.math.BigInteger(\"0\");";
82 }
83
84 public String createToJavaObjectCode(final String variableName) {
85 return variableName;
86 }
87
88 public String createFromJavaObjectCode(final String variableName) {
89 return "((java.math.BigInteger) " + variableName + ")";
90 }
91
92 public void validationCode(final JSourceCode jsc, final String fixedValue,
93 final String validatorInstanceName) {
94 jsc.add("org.exolab.castor.xml.validators.BigIntegerValidator typeValidator;\n"
95 + "typeValidator = new org.exolab.castor.xml.validators.BigIntegerValidator();\n"
96 + "{0}.setValidator(typeValidator);", validatorInstanceName);
97
98 if (fixedValue != null) {
99 jsc.add("typeValidator.setFixed(new BigInteger(\"" + fixedValue + "\");");
100 }
101
102 codePatternFacet(jsc, "typeValidator");
103 codeWhiteSpaceFacet(jsc, "typeValidator");
104
105 if (getMinExclusive() != null) {
106 jsc.add("java.math.BigInteger min = new java.math.BigInteger(\"{0}\");\n"
107 + "typeValidator.setMinExclusive(min);", getMinExclusive());
108 } else if (getMinInclusive() != null) {
109 jsc.add("java.math.BigInteger min = new java.math.BigInteger(\"{0}\");\n"
110 + "typeValidator.setMinInclusive(min);", getMinInclusive());
111 }
112
113 if (getMaxExclusive() != null) {
114 jsc.add("java.math.BigInteger max = new java.math.BigInteger(\"{0}\");\n"
115 + "typeValidator.setMaxExclusive(max);", getMaxExclusive());
116 } else if (getMaxInclusive() != null) {
117 jsc.add("java.math.BigInteger max = new java.math.BigInteger(\"{0}\");\n"
118 + "typeValidator.setMaxInclusive(max);", getMaxInclusive());
119 }
120
121 codeDigitsFacet(jsc, "typeValidator");
122 }
123 }