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 2001 (C) Intalio, Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  
46  package org.exolab.castor.xml.schema;
47  
48  /**
49   * Represents an enumerated type which consists of two values:
50   * "qualified" and "unqualified". This is used for the "form"
51   * property on attribute and element defintions as well as
52   * the attributeFormDefault and elementFormDefault proprties on 
53   * the Schema itself.
54   *
55   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
56   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
57  **/
58  public class Form {
59      
60      /**
61       * The String value for the qualified Form
62      **/
63      public static final String QUALIFIED_VALUE   = "qualified";
64      
65      /**
66       * The String value for the unqualified Form
67      **/
68      public static final String UNQUALIFIED_VALUE = "unqualified";
69      
70      
71      /**
72       * The Qualified Form Object
73      **/
74      public static final Form Qualified   = new Form(QUALIFIED_VALUE);
75  
76      /**
77       * The Qualified Form Object
78      **/
79      public static final Form Unqualified = new Form(UNQUALIFIED_VALUE);
80      
81      /**
82       * The value of this Form
83      **/
84      private String _value = UNQUALIFIED_VALUE;
85      
86      /**
87       * Creates a new Form
88       *
89       * @param value the value of the Form
90      **/
91      private Form(String value) {
92          _value = value;
93      } //-- Form
94      
95      /**
96       * Returns the String value of this Form.
97       *
98       * @return the String value of this Form.
99      **/
100     public String getValue() {
101         return _value;
102     } //-- getValue
103     
104     /**
105      * Returns true if this Form is the qualified Form.
106      *
107      * @return true if this Form is the qualified Form.
108     **/
109     public boolean isQualified() {
110         return (this == Qualified);
111     } //-- isQualified
112 
113     /**
114      * Returns true if this Form is the unqualified Form.
115      *
116      * @return true if this Form is the unqualified Form.
117     **/
118     public boolean isUnqualified() {
119         return (this == Unqualified);
120     } //-- isUnqualified
121     
122     /**
123      * Returns the String value of this Form.
124      *
125      * @return the String value of this Form.
126     **/
127     public String toString() {
128         return _value;
129     } //-- toString
130     
131     /**
132      * Returns the Form corresponding to the given value.
133      *
134      * @param formValue the value of the Form to return.
135      * @return the Form corresponding to the given value.
136      * @exception IllegalArgumentException when the given value
137      * is not valid.
138     **/
139     public static Form valueOf(String formValue) {
140         if (QUALIFIED_VALUE.equals(formValue)) {
141             return Form.Qualified;
142         }
143         else if (UNQUALIFIED_VALUE.equals(formValue)) {
144             return Form.Unqualified;
145         }
146         else {
147             String err = formValue + " is not a valid Form value.";
148             throw new IllegalArgumentException(err);
149         }
150     } //-- valueOf
151     
152 } //-- Form