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