1 /**
2 * Redistribution and use of this software and associated documentation ("Software"), with or
3 * without modification, are permitted provided that the following conditions are met:
4 *
5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions
6 * must also contain a copy of this document.
7 *
8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials provided with
10 * the distribution.
11 *
12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software
13 * without prior written permission of Intalio, Inc. For written permission, please contact
14 * info@exolab.org.
15 *
16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in
17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of
18 * Intalio, Inc.
19 *
20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/).
21 *
22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
32 *
33 * $Id$
34 */
35
36 package org.exolab.castor.xml.schema;
37
38
39 /**
40 * An abstract class that represents an XML Schema Particle This is not an entirely true
41 * representation of how XML Schema depicts a "particle" since this representation of a particle
42 * does not hold the "term" component (element, all, choice, sequence, group, any) but rather the
43 * "term" extends this class.
44 *
45 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
46 **/
47 public abstract class Particle extends Annotated {
48
49 /**
50 * The maximum occurance
51 **/
52 private int _maxOccurs = 1;
53
54 /**
55 * Indicates whether maxOccurs has been set.
56 */
57 private boolean _maxOccursSet = false;
58
59 /**
60 * The minimum occurance
61 **/
62 private int _minOccurs = 1;
63
64 /**
65 * Indicates whether minOccurs has been set.
66 */
67 private boolean _minOccursSet = false;
68
69 /**
70 * A constant to represent an UNBOUNDED particle
71 */
72 public static int UNBOUNDED = -1;
73
74 /**
75 * Default Constructor, uses a default minimum occurance of 1, and a default unbounded maximum
76 * occurance
77 **/
78 protected Particle() {
79 super();
80 } // -- Particle
81
82 /**
83 * Returns the maximum number of occurances that this CMParticle may appear
84 *
85 * @return the maximum number of occurances that this CMParticle may appear. A non positive (n <
86 * 1) value indicates that the value is unspecified (ie. unbounded).
87 **/
88 public final int getMaxOccurs() {
89 return _maxOccurs;
90 } // -- getMaxOccurs
91
92 /**
93 * Returns the minimum number of occurances that this CMParticle must appear
94 *
95 * @return the minimum number of occurances that this CMParticle must appear A negative (n < 0)
96 * value indicates that the value is unspecified.
97 **/
98 public final int getMinOccurs() {
99 return _minOccurs;
100 } // -- getMinOccurs
101
102 /**
103 * Sets the maximum number of occurances that this CMParticle must appear within it's parent
104 * context
105 *
106 * @param maxOccurs the maximum number of occurances that this CMParticle may appear within it's
107 * parent context (-1 for unbounded)
108 **/
109 public final void setMaxOccurs(int maxOccurs) {
110 _maxOccurs = maxOccurs;
111 _maxOccursSet = true;
112 } // -- setMaxOccurs
113
114 /**
115 * Sets the minimum number of occurances that this CMParticle must appear within it's parent
116 * context
117 *
118 * @param minOccurs the number of occurances that this CMParticle must appeae within it's parent
119 * context
120 **/
121 public final void setMinOccurs(int minOccurs) {
122 _minOccurs = minOccurs;
123 _minOccursSet = true;
124 } // -- setMinOccurs
125
126 /**
127 * @return true if this Particle is emptiable
128 */
129 public boolean isEmptiable() {
130 if (getMinOccurs() == 0) {
131 return true;
132 }
133 return false;
134 }
135
136 /**
137 * Indicates whetehr maxOccurs has been set.
138 *
139 * @return True if maxOccurs has been set.
140 */
141 protected final boolean isMaxOccursSet() {
142 return _maxOccursSet;
143 }
144
145 /**
146 * Indicates whether minOccurs has been set.
147 *
148 * @return True if minOccurs has been set.
149 */
150 protected final boolean isMinOccursSet() {
151 return _minOccursSet;
152 }
153
154 } // -- CMParticle