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