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 public final class MinInclusive extends Facet {
35
36
37
38
39 private static final long serialVersionUID = 1820136879077904618L;
40
41
42
43
44
45
46 public MinInclusive(final String value) {
47 super(Facet.MIN_INCLUSIVE, value);
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public boolean overridesBase(final Facet baseFacet) {
67 final String otherName = baseFacet.getName();
68 return otherName.equals(Facet.MIN_EXCLUSIVE) || otherName.equals(Facet.MIN_INCLUSIVE);
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82 public void checkConstraints(final Enumeration localFacets, final Enumeration baseFacets)
83 throws SchemaException {
84
85 while (localFacets.hasMoreElements()) {
86 final Facet other = (Facet) localFacets.nextElement();
87 if (this == other) {
88 continue;
89 }
90 final String otherName = other.getName();
91 if (otherName.equals(Facet.MAX_EXCLUSIVE) && getOwningType().isNumericType()
92 && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
93
94 throw new SchemaException(
95 "It is an error for the value specified " + "for minInclusive to be greater than "
96 + "or equal to the value specified for " + "maxExclusive for the same datatype.");
97 }
98 }
99 if (baseFacets != null) {
100 while (baseFacets.hasMoreElements()) {
101 final Facet other = (Facet) baseFacets.nextElement();
102 final String otherName = other.getName();
103
104
105
106 if (otherName.equals(Facet.MIN_INCLUSIVE) && getOwningType().isNumericType()
107 && this.toBigDecimal().compareTo(other.toBigDecimal()) < 0) {
108
109 throw new SchemaException("It is an error if the following condition is true: "
110 + "minInclusive is among the members of {facets} of "
111 + "{base type definition} and {value} is less than "
112 + "the {value} of the parent minInclusive.");
113 } else if (otherName.equals(Facet.MAX_INCLUSIVE) && getOwningType().isNumericType()
114 && this.toBigDecimal().compareTo(other.toBigDecimal()) > 0) {
115
116 throw new SchemaException("It is an error if the following condition is true: "
117 + "maxInclusive is among the members of {facets} of "
118 + "{base type definition} and {value} is greater than "
119 + "the {value} of the parent maxInclusive.");
120 } else if (otherName.equals(Facet.MIN_EXCLUSIVE) && getOwningType().isNumericType()
121 && this.toBigDecimal().compareTo(other.toBigDecimal()) <= 0) {
122
123 throw new SchemaException("It is an error if the following condition is true: "
124 + "minExclusive is among the members of {facets} of "
125 + "{base type definition} and {value} is less than "
126 + "or equal to the {value} of the parent minExclusive.");
127 } else if (otherName.equals(Facet.MAX_EXCLUSIVE) && getOwningType().isNumericType()
128 && this.toBigDecimal().compareTo(other.toBigDecimal()) >= 0) {
129
130 throw new SchemaException("It is an error if the following condition is true: "
131 + "maxExclusive is among the members of {facets} of "
132 + "{base type definition} and {value} is greater than "
133 + "or equal to the {value} of the parent maxExclusive.");
134 }
135 }
136 }
137 }
138 }