KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > xs > XSDDescription


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002, 2003 The Apache Software Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl.xs;
59
60 import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
61 import com.sun.org.apache.xerces.internal.xni.QName;
62 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
63 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
64 import com.sun.org.apache.xerces.internal.xni.grammars.XMLSchemaDescription;
65
66 /*
67  * All information specific to XML Schema grammars.
68  *
69  * @author Neil Graham, IBM
70  * @author Neeraj Bajaj, SUN Microsystems.
71  *
72  * @version $Id: XSDDescription.java,v 1.9 2003/03/24 21:10:58 sandygao Exp $
73  */

74 public class XSDDescription extends XMLResourceIdentifierImpl
75                 implements XMLSchemaDescription {
76     // used to indicate what triggered the call
77
/**
78      * Indicate that this description was just initialized.
79      */

80     public final static short CONTEXT_INITIALIZE = -1;
81     /**
82      * Indicate that the current schema document is <include>d by another
83      * schema document.
84      */

85     public final static short CONTEXT_INCLUDE = 0;
86     /**
87      * Indicate that the current schema document is <redefine>d by another
88      * schema document.
89      */

90     public final static short CONTEXT_REDEFINE = 1;
91     /**
92      * Indicate that the current schema document is <import>ed by another
93      * schema document.
94      */

95     public final static short CONTEXT_IMPORT = 2;
96     /**
97      * Indicate that the current schema document is being preparsed.
98      */

99     public final static short CONTEXT_PREPARSE = 3;
100     /**
101      * Indicate that the parse of the current schema document is triggered
102      * by xsi:schemaLocation/noNamespaceSchemaLocation attribute(s) in the
103      * instance document. This value is only used if we don't defer the loading
104      * of schema documents.
105      */

106     public final static short CONTEXT_INSTANCE = 4;
107     /**
108      * Indicate that the parse of the current schema document is triggered by
109      * the occurrence of an element whose namespace is the target namespace
110      * of this schema document. This value is only used if we do defer the
111      * loading of schema documents until a component from that namespace is
112      * referenced from the instance.
113      */

114     public final static short CONTEXT_ELEMENT = 5;
115     /**
116      * Indicate that the parse of the current schema document is triggered by
117      * the occurrence of an attribute whose namespace is the target namespace
118      * of this schema document. This value is only used if we do defer the
119      * loading of schema documents until a component from that namespace is
120      * referenced from the instance.
121      */

122     public final static short CONTEXT_ATTRIBUTE = 6;
123     /**
124      * Indicate that the parse of the current schema document is triggered by
125      * the occurrence of an "xsi:type" attribute, whose value (a QName) has
126      * the target namespace of this schema document as its namespace.
127      * This value is only used if we do defer the loading of schema documents
128      * until a component from that namespace is referenced from the instance.
129      */

130     public final static short CONTEXT_XSITYPE = 7;
131
132     // REVISIT: write description of these fields
133
protected short fContextType;
134     protected String JavaDoc [] fLocationHints ;
135     protected QName fTriggeringComponent;
136     protected QName fEnclosedElementName;
137     protected XMLAttributes fAttributes;
138         
139     /**
140      * the type of the grammar (e.g., DTD or XSD);
141      *
142      * @see com.sun.org.apache.xerces.internal.xni.grammars.Grammar
143      */

144     public String JavaDoc getGrammarType() {
145         return XMLGrammarDescription.XML_SCHEMA;
146     }
147
148     /**
149      * Get the context. The returned value is one of the pre-defined
150      * CONTEXT_xxx constants.
151      *
152      * @return the value indicating the context
153      */

154     public short getContextType() {
155         return fContextType ;
156     }
157
158     /**
159      * If the context is "include" or "redefine", then return the target
160      * namespace of the enclosing schema document; otherwise, the expected
161      * target namespace of this document.
162      *
163      * @return the expected/enclosing target namespace
164      */

165     public String JavaDoc getTargetNamespace() {
166         return fNamespace;
167     }
168
169     /**
170      * For import and references from the instance document, it's possible to
171      * have multiple hints for one namespace. So this method returns an array,
172      * which contains all location hints.
173      *
174      * @return an array of all location hints associated to the expected
175      * target namespace
176      */

177     public String JavaDoc[] getLocationHints() {
178         return fLocationHints ;
179     }
180
181     /**
182      * If a call is triggered by an element/attribute/xsi:type in the instance,
183      * this call returns the name of such triggering component: the name of
184      * the element/attribute, or the value of the xsi:type.
185      *
186      * @return the name of the triggering component
187      */

188     public QName getTriggeringComponent() {
189         return fTriggeringComponent ;
190     }
191
192     /**
193      * If a call is triggered by an attribute or xsi:type, then this mehtod
194      * returns the enclosing element of such element.
195      *
196      * @return the name of the enclosing element
197      */

198     public QName getEnclosingElementName() {
199         return fEnclosedElementName ;
200     }
201     
202     /**
203      * If a call is triggered by an element/attribute/xsi:type in the instance,
204      * this call returns all attribute of such element (or enclosing element).
205      *
206      * @return all attributes of the tiggering/enclosing element
207      */

208     public XMLAttributes getAttributes() {
209         return fAttributes;
210     }
211     
212     public boolean fromInstance() {
213         return fContextType == CONTEXT_ATTRIBUTE ||
214                fContextType == CONTEXT_ELEMENT ||
215                fContextType == CONTEXT_INSTANCE ||
216                fContextType == CONTEXT_XSITYPE;
217     }
218     
219     /**
220      * Compares this grammar with the given grammar. Currently, we compare
221      * the target namespaces.
222      *
223      * @param desc The description of the grammar to be compared with
224      * @return True if they are equal, else false
225      */

226     public boolean equals(Object JavaDoc descObj) {
227         if(!(descObj instanceof XMLSchemaDescription)) return false;
228         XMLSchemaDescription desc = (XMLSchemaDescription)descObj;
229         if (fNamespace != null)
230             return fNamespace.equals(desc.getTargetNamespace());
231         else // fNamespace == null
232
return desc.getTargetNamespace() == null;
233     }
234     
235     /**
236      * Returns the hash code of this grammar
237      *
238      * @return The hash code
239      */

240     public int hashCode() {
241          return (fNamespace == null) ? 0 : fNamespace.hashCode();
242     }
243     
244     public void setContextType(short contextType){
245         fContextType = contextType ;
246     }
247
248     public void setTargetNamespace(String JavaDoc targetNamespace){
249         fNamespace = targetNamespace ;
250     }
251
252     public void setLocationHints(String JavaDoc [] locationHints){
253         int length = locationHints.length ;
254         fLocationHints = new String JavaDoc[length];
255         System.arraycopy(locationHints, 0, fLocationHints, 0, length);
256         //fLocationHints = locationHints ;
257
}
258
259     public void setTriggeringComponent(QName triggeringComponent){
260         fTriggeringComponent = triggeringComponent ;
261     }
262
263     public void setEnclosingElementName(QName enclosedElementName){
264         fEnclosedElementName = enclosedElementName ;
265     }
266
267     public void setAttributes(XMLAttributes attributes){
268         fAttributes = attributes ;
269     }
270     
271     /**
272      * resets all the fields
273      */

274     public void reset(){
275         super.clear();
276         fContextType = CONTEXT_INITIALIZE;
277         fLocationHints = null ;
278         fTriggeringComponent = null ;
279         fEnclosedElementName = null ;
280         fAttributes = null ;
281     }
282     
283     public XSDDescription makeClone() {
284         XSDDescription desc = new XSDDescription();
285         desc.fAttributes = this.fAttributes;
286         desc.fBaseSystemId = this.fBaseSystemId;
287         desc.fContextType = this.fContextType;
288         desc.fEnclosedElementName = this.fEnclosedElementName;
289         desc.fExpandedSystemId = this.fExpandedSystemId;
290         desc.fLiteralSystemId = this.fLiteralSystemId;
291         desc.fLocationHints = this.fLocationHints;
292         desc.fPublicId = this.fPublicId;
293         desc.fNamespace = this.fNamespace;
294         desc.fTriggeringComponent = this.fTriggeringComponent;
295         return desc;
296     }
297     
298 } // XSDDescription
299
Popular Tags