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 2000 (C) Intalio Inc. All Rights Reserved.
32 *
33 * $Id$
34 */
35
36 package org.exolab.castor.xml.schema.reader;
37
38 import org.exolab.castor.xml.schema.*;
39 import org.exolab.castor.xml.schema.simpletypes.UrType;
40
41 import java.util.Enumeration;
42
43 /**
44 * A simple class used when unmarshalling simpleTypes
45 *
46 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
47 * @version $Revision$ $Date: 2004-10-01 07:25:46 -0600 (Fri, 01 Oct 2004) $
48 **/
49 public class SimpleTypeDefinition {
50
51
52 private String _name = null;
53 private String _id = null;
54 private String _final = null;
55 private Schema _schema = null;
56 private SimpleType _baseType = null;
57 private String _baseTypeName = null;
58 private Annotation _annotation = null;
59 private FacetList _facets = null;
60
61 public SimpleTypeDefinition(Schema schema, String name, String id) {
62 super();
63 this._schema = schema;
64 this._name = name;
65 this._id = id;
66
67 _facets = new FacetList();
68
69 } // -- SimpleTypeDefinition
70
71 /**
72 * Adds the given Facet to the list of Facets for this SimpleTypeDefinition
73 *
74 * @param facet the Facet to add
75 **/
76 public void addFacet(Facet facet) {
77 _facets.add(facet);
78 } // -- addFacet
79
80 /**
81 * Copies the name, facets and annotations of this SimpleTypeDefinition into the given SimpleType.
82 *
83 * @param simpleType the SimpleType to copy into.
84 **/
85 void copyInto(SimpleType simpleType) {
86
87 // -- set name
88 simpleType.setName(_name);
89
90 // -- set Schema
91 simpleType.setSchema(_schema);
92
93 // -- @id
94 simpleType.setId(_id);
95
96 // -- @final
97 simpleType.setFinal(_final);
98
99 // -- copy Facets
100 Enumeration<Facet> enumeration = _facets.enumerate();
101 while (enumeration.hasMoreElements())
102 simpleType.addFacet(enumeration.nextElement());
103
104 if (_annotation != null)
105 simpleType.addAnnotation(_annotation);
106 } // -- copyInto
107
108 /**
109 * Creates the SimpleType instance which represents this SimpleTypeDefinition
110 *
111 * @return the new SimpleType instance.
112 **/
113 public SimpleType createSimpleType() {
114 SimpleType simpleType = null;
115
116 if (_baseType != null)
117 simpleType = _schema.createSimpleType(_name, _baseType);
118 else if (_baseTypeName != null)
119 simpleType = _schema.createSimpleType(_name, _baseTypeName, "restriction");
120 else {
121 simpleType = new UrType();
122 }
123
124
125 // -- @id
126 simpleType.setId(_id);
127
128 // -- @final
129 simpleType.setFinal(_final);
130
131 // -- copy Facets
132 Enumeration<Facet> enumeration = _facets.enumerate();
133 while (enumeration.hasMoreElements())
134 simpleType.addFacet(enumeration.nextElement());
135
136 if (_annotation != null)
137 simpleType.addAnnotation(_annotation);
138
139 return simpleType;
140
141 } // -- createSimpleType
142
143 /**
144 * Returns the Schema for this SimpleTypeDefinition
145 *
146 * @return the Schema for this SimpleTypeDefinition
147 **/
148 Schema getSchema() {
149 return _schema;
150 } // -- getSchema
151
152 /**
153 * Sets the annotation for this SimpleTypeDefinition
154 *
155 * @param annotation the Annotation for this SimpleTypeDefinition
156 **/
157 void setAnnotation(Annotation annotation) {
158 _annotation = annotation;
159 } // -- setAnnotation
160
161 /**
162 * Sets the base type for this SimpleTypeDefinition. This method is mutually exclusive with
163 * #setBaseTypeName
164 *
165 * @param baseType the base type for this SimpleTypeDefinition
166 **/
167 public void setBaseType(SimpleType baseType) {
168 _baseType = baseType;
169 _baseTypeName = null;
170 } // -- setBaseType
171
172 /**
173 * Sets the base type for this SimpleTypeDefinition. This method is mutually exclusive with
174 * #setBaseType
175 *
176 * @param baseTypeName the base type for this SimpleTypeDefinition
177 **/
178 void setBaseTypeName(String baseTypeName) {
179 _baseTypeName = baseTypeName;
180 _baseType = null;
181 } // -- setBaseTypeName
182
183 /**
184 * Sets the value of the 'final' property, indicating which types of derivation are not allowed. A
185 * null value will indicate all types of derivation (list, restriction, union) are allowed.
186 *
187 * @param finalValue the value of the final property.
188 **/
189 public void setFinal(String finalValue) {
190 _final = finalValue;
191 }
192
193 Object getBaseType() {
194 return _baseType;
195 }
196
197 } // -- SimpleTypeDefinition
198
199