View Javadoc
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  package org.exolab.castor.builder.info;
46  
47  /**
48   * A class to hold group information.
49   *
50   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
51   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
52   */
53  public final class GroupInfo {
54      /**
55       * The compositor value that indicates that all fields are required, but
56       * order is not important. <I>default</I>
57       */
58      public static final int ALL    = 0;
59      /**
60       * The compositor value that indicates that only one field may be present.
61       */
62      public static final int CHOICE = 1;
63      /**
64       * The compositor value that indicates that all fields are required and
65       * order is important.
66       */
67      public static final int SEQUENCE = 2;
68  
69      /** A flag indicating if the object described by this XML info can appear  more than once. */
70      private boolean _multivalued = false;
71      /** indicates the XML object must appear at least once. */
72      private boolean _required = false;
73      /** The compositor for this XMLInfo. */
74      private int _compositor = ALL;
75      /** The minimum occurance for this group. */
76      private int _minOccurs = 1;
77      /** The maximum occurance for this group. */
78      private int _maxOccurs = 1;
79  
80      /**
81       * Creates a new GroupInfo.
82       */
83      public GroupInfo() {
84          super();
85      } //-- GroupInfo
86  
87      /**
88       * Returns the maximum occurance for this group.
89       *
90       * @return the maximum occurance for this group.
91       */
92      public int getMaxOccurs() {
93          return _maxOccurs;
94      } //-- getMaxOccurs
95  
96      /**
97       * Returns the minimum occurance for this group.
98       *
99       * @return the minimum occurance for this group.
100      */
101     public int getMinOccurs() {
102         return _minOccurs;
103     } //-- getMinOccurs
104 
105     /**
106      * Return whether or not the object described by this XMLInfo is
107      * multi-valued (appears more than once in the XML document).
108      *
109      * @return true if this object can appear more than once.
110      */
111     public boolean isMultivalued() {
112         return _multivalued;
113     } //-- isMultivalued
114 
115     /**
116      * Return true if the XML object described by this GroupInfo must appear at
117      * least once in the XML document (or object model).
118      *
119      * @return true if the XML object must appear at least once.
120      */
121     public boolean isRequired() {
122         return _required;
123     } //-- isRequired
124 
125     /**
126      * Returns true if the compositor of this GroupInfo is a choice.
127      * @return true if the compositor of this GroupInfo is a choice.
128      */
129     public boolean isChoice() {
130         return (_compositor == CHOICE);
131     } //-- isChoice
132 
133     /**
134      * Returns true if the compositor of this GroupInfo is a sequence.
135      *
136      * @return true if the compositor of this GroupInfo is a sequence.
137      */
138     public boolean isSequence() {
139         return (_compositor == SEQUENCE);
140     } //-- isSequence
141 
142     /**
143      * Sets the compositor for the fields of this group to be "all".
144      */
145     public void setAsAll() {
146         this._compositor = ALL;
147     } //-- setAsAll
148 
149     /**
150      * Sets the compositor for the fields of this group to be a choice.
151      */
152     public void setAsChoice() {
153         this._compositor = CHOICE;
154     } //-- setAsChoice
155 
156     /**
157      * Sets the compositor for the fields of this group to be a sequence.
158      */
159     public void setAsSequence() {
160         this._compositor = SEQUENCE;
161     } //-- setAsSequence
162 
163     /**
164      * Sets the maximum occurance for this group.
165      *
166      * @param maxOccurs the maximum occurance this group must appear
167      */
168     public void setMaxOccurs(final int maxOccurs) {
169         _maxOccurs = (maxOccurs < 0) ? -1 : maxOccurs;
170     } //-- setMaxOccurs
171 
172     /**
173      * Sets the minimum occurrence for this group.
174      *
175      * @param minOccurs the minimum occurance this group must appear
176      */
177     public void setMinOccurs(final int minOccurs) {
178         _minOccurs = (minOccurs < 0) ? 1 : minOccurs;
179     } //-- setMinOccurs
180 
181     /**
182      * Sets whether the XML object can appear more than once in the XML
183      * document.
184      *
185      * @param multivalued the boolean indicating whether or not the object can
186      *        appear more than once
187      */
188     public void setMultivalued(final boolean multivalued) {
189         this._multivalued = multivalued;
190     } //-- setMultivalued
191 
192     /**
193      * Sets whether or not the XML object must appear at least once.
194      *
195      * @param required the flag indicating whether or not this XML object is
196      *        required
197      */
198     public void setRequired(final boolean required) {
199         this._required = required;
200     } //-- setRequired
201 
202 } //-- GroupInfo