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 XSGDay extends AbstractRangeFacet {
28
29
30
31 public static final String NAME = "gDay";
32
33
34 public static final short TYPE = XSType.GDAY_TYPE;
35
36
37 private static final JType JTYPE = new JClass("org.exolab.castor.types.GDay");
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 " + getJType().getName() + "();";
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 "(" + getJType().getName() + ") " + 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 if (fixedValue != null) {
109 jsc.add("try {\n" + " typeValidator.setFixed({0});\n"
110 + "} catch (java.text.ParseException pe) {\n"
111 + " System.out.println(\"ParseException\" + pe);\n" + "}", fixedValue);
112 }
113
114 codePatternFacet(jsc, "typeValidator");
115 codeWhiteSpaceFacet(jsc, "typeValidator");
116
117 if (hasMinimum() || hasMaximum()) {
118 jsc.add("try {");
119
120
121 if (getMinInclusive() != null) {
122 jsc.add(" org.exolab.castor.types.GDay min;\n"
123 + " min = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n"
124 + " typeValidator.setMinInclusive(min);", getMinInclusive());
125 } else if (getMinExclusive() != null) {
126 jsc.add(" org.exolab.castor.types.GDay min;\n"
127 + " min = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n"
128 + " typeValidator.setMinExclusive(min);", getMinExclusive());
129 }
130
131
132 if (getMaxInclusive() != null) {
133 jsc.add(" org.exolab.castor.types.GDay max;\n"
134 + " max = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n"
135 + " typeValidator.setMaxInclusive(max);", getMaxInclusive());
136 } else if (getMaxExclusive() != null) {
137 jsc.add(" org.exolab.castor.types.GDay max;\n"
138 + " max = org.exolab.castor.types.GDay.parseGDay(\"{0}\");\n"
139 + " typeValidator.setMaxExclusive(max);", getMaxExclusive());
140 }
141
142 jsc.add("} catch (java.text.ParseException pe) {\n"
143 + " System.out.println(\"ParseException\" + pe);\n" + "}", "");
144 }
145 }
146
147
148 }