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