KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > schema > Type


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.schema;
24
25 import org.xquark.schema.validation.ContentIterator;
26 import org.xquark.schema.validation.ValidationContextProvider;
27 import org.xquark.schema.validation.ValidationInfo;
28
29 /**
30  * Abstract class for SimpleType and ComplexType.
31  *
32  * <p>This is the implementation of the common propertoes of Simple Type
33  * and Complex Type. The following properties are defined :</p>
34  * <p> 1. base type defintion : a simple type or a complex type defintion.
35  * if a type is an instance of Simple Type, this base type must be a simple type</p>
36  * <p> 2. abstract : a boolean, only a complex type can be abstract </p>
37  *
38  * <p>See XML Schema Part 1: Structures 3.4, 3.14
39  * W3C Recommendation 2 May 2001</p>
40  *
41  * @see org.xquark.xml.schema.SchemaComponent
42  * @see org.xquark.xml.schema.SimpleType
43  * @see org.xquark.xml.schema.ComplexType
44  */

45 public abstract class Type extends SchemaComponent {
46 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
47 private static final String JavaDoc RCSName = "$Name: $";
48   
49   private Type baseType;
50   private int fin = 0;
51   
52   /**
53    * Create a new Type.
54    *
55    * @param schema The schema which contains this type.
56    * @param name The type name, optional, a NCName as defined by [XML-Namespace].
57    * @param baseType The base type definition, either a simple type definition or
58    * a complex type definition. if a type is an instance of Simple Type,
59    * this base type must be a simple type.
60    */

61   protected Type(Schema schema, String JavaDoc name, Type baseType) {
62     super(schema, name);
63     this.baseType = baseType;
64   }
65
66   public void accept(SchemaVisitor visitor) throws SchemaException {
67     visitor.visit(this);
68   }
69
70   /**
71    * Return the type's base type definition, if any
72    *
73    * @return The base type definition, or null if there is none.
74    */

75   public Type getBaseType() {
76     return baseType;
77   }
78    
79   /**
80    * This is a final type, which can't have substitions.
81    *
82    * @return The type final definition, a subset of {extension, restriction}..
83    */

84   public int getFinal() {
85     return fin;
86   }
87
88   public boolean isAbstract() {
89     return false;
90   }
91
92   public int getBlock() {
93     return 0;
94   }
95   
96   public int getDerivationMethod() {
97     return RESTRICTION;
98   }
99
100   public boolean isDerivedFrom(Type ancestor) {
101     if (ancestor == this) return true;
102     if (baseType == null) return false;
103     else return baseType.isDerivedFrom(ancestor);
104   }
105
106   /**
107    * @return null if valid, a string containing the error code otherwise
108    */

109
110   public String JavaDoc checkTypeDerivationOK(Type ancestor, int exclusions, boolean useBlock) {
111     return null;
112   }
113
114   public abstract int getContentType();
115
116   public abstract SimpleType getValueType();
117
118   public ElementDeclaration getElementDeclaration(String JavaDoc namespace, String JavaDoc name) {
119     return null;
120   }
121
122   public java.util.Collection JavaDoc getElementDeclarations() {
123     return null;
124   }
125   
126   public AttributeDeclaration getAttributeDeclaration(String JavaDoc namespace, String JavaDoc name) {
127     return null;
128   }
129   
130   public java.util.Collection JavaDoc getAttributeDeclarations() {
131     return null;
132   }
133   
134   public Wildcard getAttributeWildcard() {
135     return null;
136   }
137
138   public ContentIterator contentIterator() {
139     return null;
140   }
141
142   public ContentIterator childIterator() {
143     return null;
144   }
145
146   public String JavaDoc normalizedValue(String JavaDoc value) {
147     return value;
148   }
149  
150   public StringBuffer JavaDoc normalizedValue(StringBuffer JavaDoc value) {
151     return value;
152   }
153
154   public StringBuffer JavaDoc normalizedValue(StringBuffer JavaDoc value, StringBuffer JavaDoc out) {
155     if (out == value) return value;
156     if (out == null) out = new StringBuffer JavaDoc();
157     out.append(value.toString());
158     return out;
159   }
160   
161   public String JavaDoc toXMLString(Object JavaDoc value, ValidationContextProvider context) {
162     return value.toString();
163   }
164
165   public String JavaDoc toXMLString(Object JavaDoc value) {
166     return toXMLString(value, null);
167   }
168
169   public abstract ValidationInfo validate(String JavaDoc value, boolean normalize, ValidationContextProvider context)
170     throws SchemaException;
171     
172   public abstract ValidationInfo validate(StringBuffer JavaDoc value, boolean normalize, ValidationContextProvider context)
173     throws SchemaException;
174     
175   public Object JavaDoc convert(String JavaDoc value, boolean normalize, ValidationContextProvider context)
176     throws SchemaException
177   {
178     return value;
179   }
180    
181   public Object JavaDoc convert(StringBuffer JavaDoc value, boolean normalize, ValidationContextProvider context)
182     throws SchemaException
183   {
184     return value;
185   }
186     
187   public ValidationInfo validate(String JavaDoc value) throws SchemaException {
188     return validate(value, true, null);
189   }
190     
191   public ValidationInfo validate(StringBuffer JavaDoc value) throws SchemaException {
192     return validate(value, true, null);
193   }
194     
195   public Object JavaDoc convert(String JavaDoc value) throws SchemaException {
196     return convert(value, true, null);
197   }
198    
199   public Object JavaDoc convert(StringBuffer JavaDoc value) throws SchemaException {
200     return convert(value, true, null);
201   }
202     
203   public String JavaDoc validateDefault(String JavaDoc value, ValidationContextProvider context) throws SchemaException {
204     return value;
205   }
206   
207   public String JavaDoc toCanonicalForm(String JavaDoc value, ValidationContextProvider context) throws SchemaException {
208     return value;
209   }
210   
211   public String JavaDoc toCanonicalForm(String JavaDoc value) throws SchemaException {
212     return toCanonicalForm(value, null);
213   }
214   
215   public void setBaseType(Type type) {
216     baseType = type;
217   }
218
219   public void setFinal(int fin) {
220     this.fin = fin;
221   }
222   
223   // TYPING STUFF
224
public boolean isSimpleType() { return false; }
225   
226 }
227
228
229
230
231
232
233
234
235
236
237
238
Popular Tags