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