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 MinExclusive extends Facet {
38
39
40
41
42 private static final long serialVersionUID = 9164023814934394681L;
43
44
45
46
47
48 public MinExclusive(final String value) {
49 super(Facet.MIN_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.MIN_EXCLUSIVE)
72 || otherName.equals(Facet.MIN_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.MIN_INCLUSIVE)) {
98
99 throw new SchemaException(
100 "It is an error for both minInclusive and minExclusive "
101 + "to be specified for the same datatype.");
102 } else if (otherName.equals(Facet.MAX_INCLUSIVE)
103 && getOwningType().isNumericType()
104 && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
105
106 throw new SchemaException(
107 "It is an error for the value specified "
108 + "for minExclusive to be greater than "
109 + "or equal to the value specified for "
110 + "maxInclusive for the same datatype.");
111 }
112 }
113 if (baseFacets != null) {
114 while (baseFacets.hasMoreElements()) {
115 final Facet other = (Facet) baseFacets.nextElement();
116 final String otherName = other.getName();
117
118
119
120 if (otherName.equals(Facet.MIN_EXCLUSIVE)
121 && getOwningType().isNumericType()
122 && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
123
124 throw new SchemaException(
125 "It is an error if the following condition is true: "
126 + "minExclusive is among the members of {facets} of "
127 + "{base type definition} and {value} is less than "
128 + "the {value} of the parent minExclusive.");
129 } else if (otherName.equals(Facet.MAX_INCLUSIVE)
130 && getOwningType().isNumericType()
131 && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
132
133 throw new SchemaException(
134 "It is an error if the following condition is true: "
135 + "maxInclusive is among the members of {facets} of "
136 + "{base type definition} and {value} is greater than "
137 + "the {value} of the parent maxInclusive.");
138 } else if (otherName.equals(Facet.MIN_INCLUSIVE)
139 && getOwningType().isNumericType()
140 && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
141
142 throw new SchemaException(
143 "It is an error if the following condition is true: "
144 + "minInclusive is among the members of {facets} of "
145 + "{base type definition} and {value} is less than "
146 + "the {value} of the parent minInclusive.");
147 } else if (otherName.equals(Facet.MAX_EXCLUSIVE)
148 && getOwningType().isNumericType()
149 && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
150
151 throw new SchemaException(
152 "It is an error if the following condition is true: "
153 + "maxExclusive is among the members of {facets} of "
154 + "{base type definition} and {value} is greater than "
155 + "or equal to the {value} of the parent maxExclusive.");
156 }
157 }
158 }
159 }
160 }