~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/xs/XSDDescription.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
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.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.xs;
 
19
 
 
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;
 
25
 
 
26
/**
 
27
 * All information specific to XML Schema grammars.
 
28
 *
 
29
 * @xerces.internal 
 
30
 *
 
31
 * @author Neil Graham, IBM
 
32
 * @author Neeraj Bajaj, SUN Microsystems.
 
33
 *
 
34
 * @version $Id: XSDDescription.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
 
35
 */
 
36
public class XSDDescription extends XMLResourceIdentifierImpl 
 
37
                implements XMLSchemaDescription {
 
38
    // used to indicate what triggered the call
 
39
    /**
 
40
     * Indicate that this description was just initialized. 
 
41
     */
 
42
    public final static short CONTEXT_INITIALIZE = -1;
 
43
    /**
 
44
     * Indicate that the current schema document is <include>d by another
 
45
     * schema document.
 
46
     */
 
47
    public final static short CONTEXT_INCLUDE   = 0;
 
48
    /**
 
49
     * Indicate that the current schema document is <redefine>d by another
 
50
     * schema document.
 
51
     */
 
52
    public final static short CONTEXT_REDEFINE  = 1;
 
53
    /**
 
54
     * Indicate that the current schema document is <import>ed by another
 
55
     * schema document.
 
56
     */
 
57
    public final static short CONTEXT_IMPORT    = 2;
 
58
    /**
 
59
     * Indicate that the current schema document is being preparsed.
 
60
     */
 
61
    public final static short CONTEXT_PREPARSE  = 3;
 
62
    /**
 
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.
 
67
     */
 
68
    public final static short CONTEXT_INSTANCE  = 4;
 
69
    /**
 
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.
 
75
     */
 
76
    public final static short CONTEXT_ELEMENT   = 5;
 
77
    /**
 
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.
 
83
     */
 
84
    public final static short CONTEXT_ATTRIBUTE = 6;
 
85
    /**
 
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.
 
91
     */
 
92
    public final static short CONTEXT_XSITYPE   = 7;
 
93
 
 
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;
 
100
        
 
101
    /**
 
102
     * the type of the grammar (e.g., DTD or XSD);
 
103
     *  
 
104
     * @see org.apache.xerces.xni.grammars.Grammar
 
105
     */
 
106
    public String getGrammarType() {
 
107
        return XMLGrammarDescription.XML_SCHEMA;
 
108
    }
 
109
 
 
110
    /**
 
111
     * Get the context. The returned value is one of the pre-defined
 
112
     * CONTEXT_xxx constants.
 
113
     * 
 
114
     * @return  the value indicating the context
 
115
     */
 
116
    public short getContextType() {
 
117
        return fContextType ;
 
118
    }
 
119
 
 
120
    /**
 
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.
 
124
     * 
 
125
     * @return  the expected/enclosing target namespace
 
126
     */
 
127
    public String getTargetNamespace() {
 
128
        return fNamespace;
 
129
    }
 
130
 
 
131
    /**
 
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.
 
135
     * 
 
136
     * @return  an array of all location hints associated to the expected
 
137
     *          target namespace
 
138
     */          
 
139
    public String[] getLocationHints() {
 
140
        return fLocationHints ;
 
141
    }
 
142
 
 
143
    /**
 
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.
 
147
     * 
 
148
     * @return  the name of the triggering component
 
149
     */
 
150
    public QName getTriggeringComponent() {
 
151
        return fTriggeringComponent ;
 
152
    }
 
153
 
 
154
    /**
 
155
     * If a call is triggered by an attribute or xsi:type, then this mehtod
 
156
     * returns the enclosing element of such element.
 
157
     * 
 
158
     * @return  the name of the enclosing element
 
159
     */
 
160
    public QName getEnclosingElementName() {
 
161
        return fEnclosedElementName ;
 
162
    }
 
163
    
 
164
    /**
 
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).
 
167
     * 
 
168
     * @return  all attributes of the tiggering/enclosing element
 
169
     */
 
170
    public XMLAttributes getAttributes() {
 
171
        return fAttributes;
 
172
    }
 
173
    
 
174
    public boolean fromInstance() {
 
175
        return fContextType == CONTEXT_ATTRIBUTE ||
 
176
               fContextType == CONTEXT_ELEMENT ||
 
177
               fContextType == CONTEXT_INSTANCE ||
 
178
               fContextType == CONTEXT_XSITYPE;
 
179
    }
 
180
    
 
181
    /**
 
182
     * Compares this grammar with the given grammar. Currently, we compare 
 
183
     * the target namespaces.
 
184
     * 
 
185
     * @param descObj The description of the grammar to be compared with
 
186
     * @return        True if they are equal, else false
 
187
     */
 
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;
 
195
    }
 
196
    
 
197
    /**
 
198
     * Returns the hash code of this grammar
 
199
     * 
 
200
     * @return The hash code
 
201
     */
 
202
    public int hashCode() {
 
203
         return (fNamespace == null) ? 0 : fNamespace.hashCode();
 
204
    }
 
205
    
 
206
    public void setContextType(short contextType){
 
207
        fContextType = contextType ;
 
208
    }
 
209
 
 
210
    public void setTargetNamespace(String targetNamespace){
 
211
        fNamespace = targetNamespace ;
 
212
    }
 
213
 
 
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 ;
 
219
    }
 
220
 
 
221
    public void setTriggeringComponent(QName triggeringComponent){
 
222
        fTriggeringComponent = triggeringComponent ;
 
223
    }
 
224
 
 
225
    public void setEnclosingElementName(QName enclosedElementName){
 
226
        fEnclosedElementName = enclosedElementName ;
 
227
    }
 
228
 
 
229
    public void setAttributes(XMLAttributes attributes){
 
230
        fAttributes = attributes ;    
 
231
    }
 
232
    
 
233
    /**
 
234
     *  resets all the fields
 
235
     */
 
236
    public void reset(){
 
237
        super.clear();
 
238
        fContextType = CONTEXT_INITIALIZE;
 
239
        fLocationHints  = null ;
 
240
        fTriggeringComponent = null ;
 
241
        fEnclosedElementName = null ;
 
242
        fAttributes = null ;    
 
243
    }
 
244
    
 
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;
 
257
        return desc;
 
258
    }
 
259
    
 
260
} // XSDDescription