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