1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.exolab.castor.xml.schema.facets;
17
18 import java.util.Enumeration;
19
20 import org.exolab.castor.xml.schema.Facet;
21 import org.exolab.castor.xml.schema.SchemaException;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public final class MaxExclusive extends Facet {
38
39
40
41
42 private static final long serialVersionUID = 2343915377123869053L;
43
44
45
46
47
48 public MaxExclusive(final String value) {
49 super(Facet.MAX_EXCLUSIVE, value);
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public boolean overridesBase(final Facet baseFacet) {
70 final String otherName = baseFacet.getName();
71 return otherName.equals(Facet.MAX_EXCLUSIVE)
72 || otherName.equals(Facet.MAX_INCLUSIVE);
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public void checkConstraints(
88 final Enumeration localFacets, final Enumeration baseFacets)
89 throws SchemaException {
90
91 while (localFacets.hasMoreElements()) {
92 final Facet other = (Facet) localFacets.nextElement();
93 if (this == other) {
94 continue;
95 }
96 final String otherName = other.getName();
97 if (otherName.equals(Facet.MAX_INCLUSIVE)) {
98
99 throw new SchemaException(
100 "It is an error for both maxInclusive and maxExclusive "
101 + "to be specified in the same derivation step "
102 + "of a datatype definition.");
103 } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
104 && other.toBigDecimal().compareTo(this.toBigDecimal()) > 0) {
105
106 throw new SchemaException(
107 "It is an error for the value specified "
108 + "for minExclusive to be greater than the value "
109 + "specified for maxExclusive for the same datatype.");
110 }
111 }
112 if (baseFacets != null) {
113 while (baseFacets.hasMoreElements()) {
114 final Facet other = (Facet) baseFacets.nextElement();
115 final String otherName = other.getName();
116
117
118
119 if (otherName.equals(Facet.MAX_EXCLUSIVE)
120 && getOwningType().isNumericType()
121 && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
122
123 throw new SchemaException(
124 "It is an error if the following condition is true: "
125 + "maxExclusive is among the members of {facets} "
126 + "of {base type definition} and {value} is greater than "
127 + "the {value} of the parent maxExclusive.");
128 } else if (otherName.equals(Facet.MAX_INCLUSIVE)
129 && getOwningType().isNumericType()
130 && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
131
132 throw new SchemaException(
133 "It is an error if the following condition is true: "
134 + "maxInclusive is among the members of {facets} "
135 + "of {base type definition} and {value} is greater than "
136 + "the {value} of the parent maxInclusive.");
137 } else if (otherName.equals(Facet.MIN_INCLUSIVE)
138 && getOwningType().isNumericType()
139 && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
140
141 throw new SchemaException(
142 "It is an error if the following condition is true: "
143 + "minInclusive is among the members of {facets} "
144 + "of {base type definition} and {value} is less than "
145 + "or equal to the {value} of the parent minInclusive.");
146 } else if (otherName.equals(Facet.MIN_EXCLUSIVE)
147 && getOwningType().isNumericType()
148 && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
149
150 throw new SchemaException(
151 "It is an error if the following condition is true: "
152 + "minExclusive is among the members of {facets} "
153 + "of {base type definition} and {value} is less than "
154 + "or equal to the {value} of the parent minExclusive.");
155 }
156 }
157 }
158 }
159 }