2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.impl.xs;
20
import org.apache.xerces.util.XMLResourceIdentifierImpl;
21
import org.apache.xerces.xni.QName;
22
import org.apache.xerces.xni.XMLAttributes;
23
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
24
import org.apache.xerces.xni.grammars.XMLSchemaDescription;
27
* All information specific to XML Schema grammars.
31
* @author Neil Graham, IBM
32
* @author Neeraj Bajaj, SUN Microsystems.
34
* @version $Id: XSDDescription.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
36
public class XSDDescription extends XMLResourceIdentifierImpl
37
implements XMLSchemaDescription {
38
// used to indicate what triggered the call
40
* Indicate that this description was just initialized.
42
public final static short CONTEXT_INITIALIZE = -1;
44
* Indicate that the current schema document is <include>d by another
47
public final static short CONTEXT_INCLUDE = 0;
49
* Indicate that the current schema document is <redefine>d by another
52
public final static short CONTEXT_REDEFINE = 1;
54
* Indicate that the current schema document is <import>ed by another
57
public final static short CONTEXT_IMPORT = 2;
59
* Indicate that the current schema document is being preparsed.
61
public final static short CONTEXT_PREPARSE = 3;
63
* Indicate that the parse of the current schema document is triggered
64
* by xsi:schemaLocation/noNamespaceSchemaLocation attribute(s) in the
65
* instance document. This value is only used if we don't defer the loading
66
* of schema documents.
68
public final static short CONTEXT_INSTANCE = 4;
70
* Indicate that the parse of the current schema document is triggered by
71
* the occurrence of an element whose namespace is the target namespace
72
* of this schema document. This value is only used if we do defer the
73
* loading of schema documents until a component from that namespace is
74
* referenced from the instance.
76
public final static short CONTEXT_ELEMENT = 5;
78
* Indicate that the parse of the current schema document is triggered by
79
* the occurrence of an attribute whose namespace is the target namespace
80
* of this schema document. This value is only used if we do defer the
81
* loading of schema documents until a component from that namespace is
82
* referenced from the instance.
84
public final static short CONTEXT_ATTRIBUTE = 6;
86
* Indicate that the parse of the current schema document is triggered by
87
* the occurrence of an "xsi:type" attribute, whose value (a QName) has
88
* the target namespace of this schema document as its namespace.
89
* This value is only used if we do defer the loading of schema documents
90
* until a component from that namespace is referenced from the instance.
92
public final static short CONTEXT_XSITYPE = 7;
94
// REVISIT: write description of these fields
95
protected short fContextType;
96
protected String [] fLocationHints ;
97
protected QName fTriggeringComponent;
98
protected QName fEnclosedElementName;
99
protected XMLAttributes fAttributes;
102
* the type of the grammar (e.g., DTD or XSD);
104
* @see org.apache.xerces.xni.grammars.Grammar
106
public String getGrammarType() {
107
return XMLGrammarDescription.XML_SCHEMA;
111
* Get the context. The returned value is one of the pre-defined
112
* CONTEXT_xxx constants.
114
* @return the value indicating the context
116
public short getContextType() {
117
return fContextType ;
121
* If the context is "include" or "redefine", then return the target
122
* namespace of the enclosing schema document; otherwise, the expected
123
* target namespace of this document.
125
* @return the expected/enclosing target namespace
127
public String getTargetNamespace() {
132
* For import and references from the instance document, it's possible to
133
* have multiple hints for one namespace. So this method returns an array,
134
* which contains all location hints.
136
* @return an array of all location hints associated to the expected
139
public String[] getLocationHints() {
140
return fLocationHints ;
144
* If a call is triggered by an element/attribute/xsi:type in the instance,
145
* this call returns the name of such triggering component: the name of
146
* the element/attribute, or the value of the xsi:type.
148
* @return the name of the triggering component
150
public QName getTriggeringComponent() {
151
return fTriggeringComponent ;
155
* If a call is triggered by an attribute or xsi:type, then this mehtod
156
* returns the enclosing element of such element.
158
* @return the name of the enclosing element
160
public QName getEnclosingElementName() {
161
return fEnclosedElementName ;
165
* If a call is triggered by an element/attribute/xsi:type in the instance,
166
* this call returns all attribute of such element (or enclosing element).
168
* @return all attributes of the tiggering/enclosing element
170
public XMLAttributes getAttributes() {
174
public boolean fromInstance() {
175
return fContextType == CONTEXT_ATTRIBUTE ||
176
fContextType == CONTEXT_ELEMENT ||
177
fContextType == CONTEXT_INSTANCE ||
178
fContextType == CONTEXT_XSITYPE;
182
* Compares this grammar with the given grammar. Currently, we compare
183
* the target namespaces.
185
* @param descObj The description of the grammar to be compared with
186
* @return True if they are equal, else false
188
public boolean equals(Object descObj) {
189
if(!(descObj instanceof XMLSchemaDescription)) return false;
190
XMLSchemaDescription desc = (XMLSchemaDescription)descObj;
191
if (fNamespace != null)
192
return fNamespace.equals(desc.getTargetNamespace());
193
else // fNamespace == null
194
return desc.getTargetNamespace() == null;
198
* Returns the hash code of this grammar
200
* @return The hash code
202
public int hashCode() {
203
return (fNamespace == null) ? 0 : fNamespace.hashCode();
206
public void setContextType(short contextType){
207
fContextType = contextType ;
210
public void setTargetNamespace(String targetNamespace){
211
fNamespace = targetNamespace ;
214
public void setLocationHints(String [] locationHints){
215
int length = locationHints.length ;
216
fLocationHints = new String[length];
217
System.arraycopy(locationHints, 0, fLocationHints, 0, length);
218
//fLocationHints = locationHints ;
221
public void setTriggeringComponent(QName triggeringComponent){
222
fTriggeringComponent = triggeringComponent ;
225
public void setEnclosingElementName(QName enclosedElementName){
226
fEnclosedElementName = enclosedElementName ;
229
public void setAttributes(XMLAttributes attributes){
230
fAttributes = attributes ;
234
* resets all the fields
238
fContextType = CONTEXT_INITIALIZE;
239
fLocationHints = null ;
240
fTriggeringComponent = null ;
241
fEnclosedElementName = null ;
245
public XSDDescription makeClone() {
246
XSDDescription desc = new XSDDescription();
247
desc.fAttributes = this.fAttributes;
248
desc.fBaseSystemId = this.fBaseSystemId;
249
desc.fContextType = this.fContextType;
250
desc.fEnclosedElementName = this.fEnclosedElementName;
251
desc.fExpandedSystemId = this.fExpandedSystemId;
252
desc.fLiteralSystemId = this.fLiteralSystemId;
253
desc.fLocationHints = this.fLocationHints;
254
desc.fPublicId = this.fPublicId;
255
desc.fNamespace = this.fNamespace;
256
desc.fTriggeringComponent = this.fTriggeringComponent;