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 XSDateTime extends AbstractRangeFacet {
28
29
30
31 public static final String NAME = "dateTime";
32
33
34 public static final short TYPE = XSType.DATETIME_TYPE;
35
36
37 private static final JType JTYPE = new JClass("java.util.Date");
38
39
40
41
42
43
44 public String getName() {
45 return NAME;
46 }
47
48
49
50
51 public short getType() {
52 return TYPE;
53 }
54
55
56
57
58 public boolean isPrimitive() {
59 return false;
60 }
61
62
63
64
65 public boolean isDateTime() {
66 return true;
67 }
68
69
70
71
72 public JType getJType() {
73 return JTYPE;
74 }
75
76
77
78
79 public String newInstanceCode() {
80 return "new java.util.Date();";
81 }
82
83
84
85
86 public String createToJavaObjectCode(final String variableName) {
87 return variableName;
88 }
89
90
91
92
93 public String createFromJavaObjectCode(final String variableName) {
94 return "(java.util.Date) " + variableName;
95 }
96
97
98
99
100
101
102 public void validationCode(final JSourceCode jsc, final String fixedValue,
103 final String validatorInstanceName) {
104 jsc.add("org.exolab.castor.xml.validators.DateTimeValidator typeValidator;\n"
105 + "typeValidator = new org.exolab.castor.xml.validators.DateTimeValidator();\n"
106 + "{0}.setValidator(typeValidator);", validatorInstanceName);
107
108
109
110
111
112
113
114
115
116
117
118
119 codePatternFacet(jsc, "typeValidator");
120 codeWhiteSpaceFacet(jsc, "typeValidator");
121
122 if (hasMinimum() || hasMaximum()) {
123 jsc.add("try {");
124
125
126 if (getMinInclusive() != null) {
127 jsc.add(" org.exolab.castor.types.DateTime min;\n"
128 + " min = new org.exolab.castor.types.DateTime(\"{0}\");\n"
129 + " typeValidator.setMinInclusive(min);", getMinInclusive());
130 } else if (getMinExclusive() != null) {
131 jsc.add(" org.exolab.castor.types.DateTime min;\n"
132 + " min = new org.exolab.castor.types.DateTime(\"{0}\");\n"
133 + " typeValidator.setMinExclusive(min);", getMinExclusive());
134 }
135
136
137 if (getMaxInclusive() != null) {
138 jsc.add(" org.exolab.castor.types.DateTime max;\n"
139 + " max = new org.exolab.castor.types.DateTime(\"{0}\");\n"
140 + " typeValidator.setMaxInclusive(max);", getMaxInclusive());
141 } else if (getMaxExclusive() != null) {
142 jsc.add(" org.exolab.castor.types.DateTime max;\n"
143 + " max = new org.exolab.castor.types.DateTime(\"{0}\");\n"
144 + " typeValidator.setMaxExclusive(max);", getMaxExclusive());
145 }
146
147 jsc.add("} catch (java.text.ParseException pe) {\n"
148 + " System.out.println(\"ParseException\" + pe);\n" + "}", "");
149 }
150 }
151
152
153 }