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 javax.xml.namespace.QName;
23  
24  import org.apache.ws.commons.schema.constants.Constants;
25  
26  /**
27   * Class for complex types. Defines a complex type that determines the
28   * set of attributes and content of an element. Represents the World Wide
29   * Web Consortium (W3C) complexType element.
30   */
31  
32  public class XmlSchemaComplexType extends XmlSchemaType {
33      XmlSchemaAnyAttribute anyAttribute, attributeWildcard;
34      XmlSchemaObjectCollection attributes;
35      XmlSchemaObjectTable attributeUses;
36      XmlSchemaDerivationMethod block, blockResolved;
37      XmlSchemaContentModel contentModel;
38      XmlSchemaContentType contentType;
39      XmlSchemaParticle particleType, particle;
40      boolean isAbstract, isMixed;
41  
42      /**
43       * Creates new XmlSchemaComplexType
44       */
45      public XmlSchemaComplexType(XmlSchema schema) {
46          super(schema);
47          attributes = new XmlSchemaObjectCollection();
48          block = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
49          isAbstract = false;
50          isMixed = false;
51      }
52  
53      public XmlSchemaAnyAttribute getAnyAttribute() {
54          return anyAttribute;
55      }
56  
57      public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
58          this.anyAttribute = anyAttribute;
59      }
60  
61      public XmlSchemaObjectCollection getAttributes() {
62          return attributes;
63      }
64  
65      public XmlSchemaObjectTable getAttributeUses() {
66          return attributeUses;
67      }
68  
69      public XmlSchemaAnyAttribute getAttributeWildcard() {
70          return attributeWildcard;
71      }
72  
73      public XmlSchemaDerivationMethod getBlock() {
74          return block;
75      }
76  
77      public void setBlock(XmlSchemaDerivationMethod block) {
78          this.block = block;
79      }
80  
81      public XmlSchemaDerivationMethod getBlockResolved() {
82          return blockResolved;
83      }
84  
85      public XmlSchemaContentModel getContentModel() {
86          return contentModel;
87      }
88  
89      public void setContentModel(XmlSchemaContentModel contentModel) {
90          this.contentModel = contentModel;
91      }
92  
93      public XmlSchemaContentType getContentType() {
94          return contentType;
95      }
96  
97      public void setContentType(XmlSchemaContentType contentType) {
98          this.contentType = contentType;
99      }
100 
101     public XmlSchemaParticle getContentTypeParticle() {
102         return particleType;
103     }
104 
105     public boolean isAbstract() {
106         return isAbstract;
107     }
108 
109     public void setAbstract(boolean b) {
110         isAbstract = b;
111     }
112 
113     public boolean isMixed() {
114         return isMixed;
115     }
116 
117     public void setMixed(boolean b) {
118         isMixed = b;
119     }
120 
121     public XmlSchemaParticle getParticle() {
122         return particle;
123     }
124 
125     public void setParticle(XmlSchemaParticle particle) {
126         this.particle = particle;
127     }
128 
129     public String toString(String prefix, int tab) {
130         String xml = new String();
131 
132         for (int i = 0; i < tab; i++)
133             xml += "\t";
134 
135         if (!prefix.equals("") && prefix.indexOf(":") == -1)
136             prefix += ":";
137 
138         String typeName = name != null ? name : "";
139 
140         xml += "<" + prefix + "complexType name=\"" + typeName + "\">\n";
141 
142         if (particle != null)
143             xml += particle.toString(prefix, (tab + 1));
144 
145         if (contentModel != null)
146             xml += contentModel.toString(prefix, (tab + 1));
147 
148         for (int i = 0; i < attributes.getCount(); i++) {
149             xml += attributes.getItem(i).toString(prefix, (tab + 1));
150         }
151 
152         for (int i = 0; i < tab; i++)
153             xml += "\t";
154 
155         xml += "</" + prefix + "complexType>\n";
156         return xml;
157     }
158 
159     /**
160      * Return the QName of the base schema type, if any, as defined in the content model.
161      */
162 	public QName getBaseSchemaTypeName() {
163 		XmlSchemaContentModel model = getContentModel();
164 		if (model == null) {
165 			return null;
166 		}
167 		XmlSchemaContent content = model.getContent();
168 		if (content == null) {
169 			return null;
170 		}
171 
172 		if (!(content instanceof XmlSchemaComplexContentExtension)) {
173 			return null;
174 		}
175 
176 		XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension) content;
177 		return ext.getBaseTypeName();
178 	}
179 
180 
181 }