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-2003 (C) Intalio, Inc. All Rights Reserved.
32   *
33   * $Id$
34   */
35  
36  package org.exolab.castor.xml.schema;
37  
38  /**
39   * An XML Schema ContentType
40   *
41   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
42   * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $
43   */
44  public class ContentType implements java.io.Serializable {
45    /** SerialVersionUID */
46    private static final long serialVersionUID = -2985958570376322773L;
47  
48    public static final short ELEMENT_ONLY = 0;
49    public static final short MIXED = 1;
50    public static final short EMPTY = 2;
51    public static final short ANY = 3;
52    public static final short SIMPLE = 4;
53  
54    // -- This is currently replaced by SIMPLE, leaving
55    // -- for now for the dtd package
56    public static final short TEXT_ONLY = 5;
57  
58    public static final ContentType elemOnly = new ContentType(ELEMENT_ONLY);
59  
60    public static final ContentType mixed = new ContentType(MIXED);
61  
62    public static final ContentType empty = new ContentType(EMPTY);
63  
64    public static final ContentType any = new ContentType(ANY);
65  
66  
67  
68    // need to keep it for the dtd package
69    public static final ContentType textOnly = new ContentType(TEXT_ONLY);
70  
71  
72    /* Private Members */
73  
74    private static final String[] _names =
75        {"elementOnly", "mixed", "empty", "any", "simple", "textOnly"};
76  
77    private short _type = ELEMENT_ONLY;
78  
79  
80    /**
81     * Creates a new ContentType.
82     */
83    protected ContentType(short type) {
84      _type = type;
85    } // -- ContentType
86  
87    /**
88     * Returns the type of this ContentType
89     *
90     * @return the type of this ContentType
91     */
92    public short getType() {
93      return _type;
94    } // -- getType
95  
96    /**
97     * Returns the String representation of this ContentType
98     *
99     * @return the String representation of this ContentType
100    */
101   public String toString() {
102     return _names[_type];
103   } // -- toString
104 
105   /**
106    * Creates a new ContentType based on the given String
107    * 
108    * @param contentType the type of the ContentType to create. <BR />
109    * 
110    *        <PRE>
111    * The valid values are as follows:
112    *  elemOnly, textOnly, mixed, empty, any, simple
113    *        </PRE>
114    * 
115    * @exception IllegalArgumentException when the given type is not one of the possible valid values
116    */
117   public static ContentType valueOf(String contentType) throws IllegalArgumentException {
118     if (contentType.equals(_names[ELEMENT_ONLY]))
119       return elemOnly;
120     else if (contentType.equals(_names[MIXED]))
121       return mixed;
122     else if (contentType.equals(_names[EMPTY]))
123       return empty;
124     else if (contentType.equals(_names[ANY]))
125       return any;
126     else if (contentType.equals(_names[SIMPLE])) {
127       return new SimpleContent();
128     } else if (contentType.equals(_names[TEXT_ONLY]))
129       return textOnly;
130     else {
131       String err = contentType;
132       err += " is not a valid ContentType";
133       throw new IllegalArgumentException(err);
134     }
135   } // -- valueOf
136 
137 } // -- ContentType