View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.commons.schema;
21  
22  import org.apache.ws.commons.schema.constants.Constants;
23  
24  import javax.xml.namespace.QName;
25  
26  
27  /**
28   * Class for elements. Represents the World Wide Web Consortium (W3C) element element.
29   */
30  
31  public class XmlSchemaElement extends XmlSchemaParticle implements TypeReceiver {
32  
33      /**
34       * Attribute used to block a type derivation.
35       */
36      XmlSchemaDerivationMethod block;
37  
38      /**
39       * The value after an element has been compiled to post-schema infoset.
40       * This value is either from the type itself or, if not defined on the type, taken from the schema element.
41       */
42      XmlSchemaDerivationMethod blockResolved;
43      XmlSchemaObjectCollection constraints;
44  
45      /**
46       * Provides the default value of the element if its content
47       * is a simple type or the element's content is textOnly.
48       */
49      String defaultValue;
50      String fixedValue;
51  
52      /**
53       * Returns the correct common runtime library
54       * object based upon the SchemaType for the element.
55       */
56      Object elementType;
57  
58      XmlSchemaDerivationMethod finalDerivation;
59      XmlSchemaDerivationMethod finalDerivationResolved;
60  
61      /**
62       * The default value is the value of the elementFormDefault attribute for the schema element containing the attribute.
63       * The default is Unqualified.
64       */
65      XmlSchemaForm form;
66      boolean isAbstract;
67      boolean isNillable;
68      String name;
69      QName qualifiedName;
70      QName refName;
71  
72      /**
73       * Returns the type of the element.
74       * This can either be a complex type or a simple type.
75       */
76      XmlSchemaType schemaType;
77  
78      /**
79       * QName of a built-in data type defined in this schema or another
80       * schema indicated by the specified namespace.
81       */
82      QName schemaTypeName;
83  
84      /**
85       * QName of an element that can be a substitute for this element.
86       */
87      QName substitutionGroup;
88  
89      /**
90       * Creates new XmlSchemaElement
91       */
92      public XmlSchemaElement() {
93          constraints = new XmlSchemaObjectCollection();
94          isAbstract = false;
95          isNillable = false;
96          form = new XmlSchemaForm(XmlSchemaForm.NONE);
97          finalDerivation = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
98          block = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
99      }
100 
101     /**
102      * Returns a collection of constraints on the element.
103      */
104     public XmlSchemaObjectCollection getConstraints() {
105         return constraints;
106     }
107 
108     public String getDefaultValue() {
109         return defaultValue;
110     }
111 
112     public void setDefaultValue(String defaultValue) {
113         this.defaultValue = defaultValue;
114     }
115 
116     public XmlSchemaDerivationMethod getBlock() {
117         return block;
118     }
119 
120     public void setBlock(XmlSchemaDerivationMethod block) {
121         this.block = block;
122     }
123 
124     public XmlSchemaDerivationMethod getFinal() {
125         return finalDerivation;
126     }
127 
128     public void setFinal(XmlSchemaDerivationMethod finalDerivation) {
129         this.finalDerivation = finalDerivation;
130     }
131 
132     public XmlSchemaDerivationMethod getBlockResolved() {
133         return blockResolved;
134     }
135 
136     public String getFixedValue() {
137         return fixedValue;
138     }
139 
140     public void setFixedValue(String fixedValue) {
141         this.fixedValue = fixedValue;
142     }
143 
144     public Object getElementType() {
145         return elementType;
146     }
147 
148     public XmlSchemaForm getForm() {
149         return form;
150     }
151 
152     public void setForm(XmlSchemaForm form) {
153         this.form = form;
154     }
155 
156     public boolean isAbstract() {
157         return isAbstract;
158     }
159 
160     public void setAbstract(boolean isAbstract) {
161         this.isAbstract = isAbstract;
162     }
163 
164     public boolean isNillable() {
165         return isNillable;
166     }
167 
168     public void setNillable(boolean isNillable) {
169         this.isNillable = isNillable;
170     }
171 
172     public String getName() {
173         return name;
174     }
175 
176     public void setName(String name) {
177         this.name = name;
178     }
179 
180     public QName getRefName() {
181         return refName;
182     }
183 
184     public void setRefName(QName refName) {
185         this.refName = refName;
186     }
187 
188     public QName getQName() {
189         return qualifiedName;
190     }
191 
192     public void setQName(QName qualifiedName) {
193         this.qualifiedName = qualifiedName;
194     }
195 
196     public XmlSchemaType getSchemaType() {
197         return schemaType;
198     }
199 
200     public void setSchemaType(XmlSchemaType schemaType) {
201         this.schemaType = schemaType;
202     }
203 
204     public QName getSchemaTypeName() {
205         return schemaTypeName;
206     }
207 
208     public void setSchemaTypeName(QName schemaTypeName) {
209         this.schemaTypeName = schemaTypeName;
210     }
211 
212     public QName getSubstitutionGroup() {
213         return substitutionGroup;
214     }
215 
216     public void setSubstitutionGroup(QName substitutionGroup) {
217         this.substitutionGroup = substitutionGroup;
218     }
219 
220     public String toString(String prefix, int tab) {
221         String xml = new String();
222 
223         if (!prefix.equals("") && prefix.indexOf(":") == -1)
224             prefix += ":";
225 
226         for (int i = 0; i < tab; i++)
227             xml += "\t";
228 
229         xml += "<" + prefix + "element ";
230 
231         if (!name.equals(""))
232             xml += "name=\"" + name + "\" ";
233 
234         if (schemaTypeName != null)
235             xml += "type=\"" + schemaTypeName + "\"";
236 
237         if (refName != null)
238             xml += "ref=\"" + refName + "\" ";
239 
240         if (minOccurs != 1)
241             xml += "minOccurs=\"" + minOccurs + "\" ";
242 
243         if (maxOccurs != 1)
244             xml += "maxOccurs=\"" + maxOccurs + "\" ";
245         
246         if (isNillable)
247           xml += "nillable=\"" + isNillable + "\" ";
248 
249         xml += ">\n";
250 
251         if (constraints != null)
252             xml += constraints.toString(prefix, (tab + 1));
253 
254         if (schemaType != null) {
255             xml += schemaType.toString(prefix, (tab + 1));
256         }
257         for (int i = 0; i < tab; i++)
258             xml += "\t";
259 
260         xml += "</" + prefix + "element>\n";
261 
262         return xml;
263     }
264 
265     public void setType(XmlSchemaType type) {
266         this.schemaType = type;
267     }
268 }