author | joehw |
Wed, 04 Oct 2017 10:54:18 -0700 | |
changeset 47312 | d4f959806fe9 |
parent 47216 | 71c04702a3d5 |
child 47359 | e1a6c0168741 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
42247
diff
changeset
|
2 |
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. |
47312 | 3 |
* @LastModified: Sep 2017 |
12005 | 4 |
*/ |
5 |
/* |
|
33349 | 6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
7 |
* contributor license agreements. See the NOTICE file distributed with |
|
8 |
* this work for additional information regarding copyright ownership. |
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
10 |
* (the "License"); you may not use this file except in compliance with |
|
11 |
* the License. You may obtain a copy of the License at |
|
12005 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xerces.internal.impl.xs.traversers; |
|
23 |
||
24 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
25 |
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; |
|
26 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
27 |
import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory; |
|
28 |
import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; |
|
30 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaNamespaceSupport; |
|
31 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; |
|
32 |
import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException; |
|
33 |
import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader; |
|
34 |
import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl; |
|
35 |
import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl; |
|
36 |
import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl; |
|
37 |
import com.sun.org.apache.xerces.internal.impl.xs.XSDDescription; |
|
38 |
import com.sun.org.apache.xerces.internal.impl.xs.XSDeclarationPool; |
|
39 |
import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl; |
|
40 |
import com.sun.org.apache.xerces.internal.impl.xs.XSGrammarBucket; |
|
41 |
import com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl; |
|
42 |
import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; |
|
43 |
import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl; |
|
44 |
import com.sun.org.apache.xerces.internal.impl.xs.XSNotationDecl; |
|
45 |
import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; |
|
46 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint; |
|
47 |
import com.sun.org.apache.xerces.internal.impl.xs.opti.ElementImpl; |
|
48 |
import com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser; |
|
49 |
import com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig; |
|
50 |
import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator; |
|
51 |
import com.sun.org.apache.xerces.internal.impl.xs.util.XSInputSource; |
|
52 |
import com.sun.org.apache.xerces.internal.parsers.SAXParser; |
|
53 |
import com.sun.org.apache.xerces.internal.parsers.XML11Configuration; |
|
54 |
import com.sun.org.apache.xerces.internal.util.DOMInputSource; |
|
55 |
import com.sun.org.apache.xerces.internal.util.DOMUtil; |
|
56 |
import com.sun.org.apache.xerces.internal.util.DefaultErrorHandler; |
|
57 |
import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper; |
|
58 |
import com.sun.org.apache.xerces.internal.util.SAXInputSource; |
|
59 |
import com.sun.org.apache.xerces.internal.util.StAXInputSource; |
|
60 |
import com.sun.org.apache.xerces.internal.util.StAXLocationWrapper; |
|
61 |
import com.sun.org.apache.xerces.internal.util.SymbolHash; |
|
62 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
33349 | 63 |
import com.sun.org.apache.xerces.internal.util.URI.MalformedURIException; |
12005 | 64 |
import com.sun.org.apache.xerces.internal.util.XMLSymbols; |
33349 | 65 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
66 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
12005 | 67 |
import com.sun.org.apache.xerces.internal.xni.QName; |
68 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
69 |
import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; |
|
70 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; |
|
71 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
|
72 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLSchemaDescription; |
|
73 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
74 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
75 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; |
|
76 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; |
|
77 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
78 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException; |
|
79 |
import com.sun.org.apache.xerces.internal.xs.StringList; |
|
80 |
import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration; |
|
81 |
import com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinition; |
|
82 |
import com.sun.org.apache.xerces.internal.xs.XSAttributeUse; |
|
83 |
import com.sun.org.apache.xerces.internal.xs.XSConstants; |
|
84 |
import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration; |
|
85 |
import com.sun.org.apache.xerces.internal.xs.XSModelGroup; |
|
86 |
import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition; |
|
87 |
import com.sun.org.apache.xerces.internal.xs.XSNamedMap; |
|
88 |
import com.sun.org.apache.xerces.internal.xs.XSObject; |
|
89 |
import com.sun.org.apache.xerces.internal.xs.XSObjectList; |
|
90 |
import com.sun.org.apache.xerces.internal.xs.XSParticle; |
|
91 |
import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; |
|
92 |
import com.sun.org.apache.xerces.internal.xs.XSTerm; |
|
93 |
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; |
|
94 |
import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList; |
|
33349 | 95 |
import java.io.IOException; |
96 |
import java.io.StringReader; |
|
97 |
import java.util.ArrayList; |
|
98 |
import java.util.Collections; |
|
99 |
import java.util.HashMap; |
|
100 |
import java.util.Locale; |
|
101 |
import java.util.Map; |
|
102 |
import java.util.Stack; |
|
103 |
import java.util.Vector; |
|
17534 | 104 |
import javax.xml.XMLConstants; |
39907 | 105 |
import javax.xml.catalog.CatalogFeatures; |
33349 | 106 |
import javax.xml.stream.XMLEventReader; |
107 |
import javax.xml.stream.XMLStreamException; |
|
108 |
import javax.xml.stream.XMLStreamReader; |
|
39907 | 109 |
import jdk.xml.internal.JdkXmlUtils; |
47312 | 110 |
import jdk.xml.internal.SecuritySupport; |
12005 | 111 |
import org.w3c.dom.Document; |
112 |
import org.w3c.dom.Element; |
|
113 |
import org.w3c.dom.Node; |
|
114 |
import org.xml.sax.InputSource; |
|
115 |
import org.xml.sax.SAXException; |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
116 |
import org.xml.sax.SAXNotRecognizedException; |
12005 | 117 |
import org.xml.sax.SAXParseException; |
118 |
import org.xml.sax.XMLReader; |
|
119 |
import org.xml.sax.helpers.XMLReaderFactory; |
|
120 |
||
121 |
/** |
|
122 |
* The purpose of this class is to co-ordinate the construction of a |
|
123 |
* grammar object corresponding to a schema. To do this, it must be |
|
124 |
* prepared to parse several schema documents (for instance if the |
|
125 |
* schema document originally referred to contains <include> or |
|
126 |
* <redefined> information items). If any of the schemas imports a |
|
127 |
* schema, other grammars may be constructed as a side-effect. |
|
128 |
* |
|
129 |
* @xerces.internal |
|
130 |
* |
|
131 |
* @author Neil Graham, IBM |
|
132 |
* @author Pavani Mukthipudi, Sun Microsystems |
|
133 |
* |
|
134 |
*/ |
|
45853
bfa06be36a17
8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents:
42247
diff
changeset
|
135 |
@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory |
12005 | 136 |
public class XSDHandler { |
137 |
||
138 |
/** Feature identifier: validation. */ |
|
139 |
protected static final String VALIDATION = |
|
140 |
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; |
|
141 |
||
142 |
/** feature identifier: XML Schema validation */ |
|
143 |
protected static final String XMLSCHEMA_VALIDATION = |
|
144 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; |
|
145 |
||
146 |
/** Feature identifier: allow java encodings */ |
|
147 |
protected static final String ALLOW_JAVA_ENCODINGS = |
|
148 |
Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; |
|
149 |
||
150 |
/** Feature identifier: continue after fatal error */ |
|
151 |
protected static final String CONTINUE_AFTER_FATAL_ERROR = |
|
152 |
Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; |
|
153 |
||
154 |
/** Feature identifier: allow java encodings */ |
|
155 |
protected static final String STANDARD_URI_CONFORMANT_FEATURE = |
|
156 |
Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE; |
|
157 |
||
158 |
/** Feature: disallow doctype*/ |
|
159 |
protected static final String DISALLOW_DOCTYPE = |
|
160 |
Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; |
|
161 |
||
162 |
/** Feature: generate synthetic annotations */ |
|
163 |
protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = |
|
164 |
Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE; |
|
165 |
||
166 |
/** Feature identifier: validate annotations. */ |
|
167 |
protected static final String VALIDATE_ANNOTATIONS = |
|
168 |
Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE; |
|
169 |
||
170 |
/** Feature identifier: honour all schemaLocations */ |
|
171 |
protected static final String HONOUR_ALL_SCHEMALOCATIONS = |
|
172 |
Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE; |
|
173 |
||
174 |
/** Feature identifier: namespace growth */ |
|
175 |
protected static final String NAMESPACE_GROWTH = |
|
176 |
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE; |
|
177 |
||
178 |
/** Feature identifier: tolerate duplicates */ |
|
179 |
protected static final String TOLERATE_DUPLICATES = |
|
180 |
Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE; |
|
181 |
||
182 |
/** Feature identifier: namespace prefixes. */ |
|
183 |
private static final String NAMESPACE_PREFIXES = |
|
184 |
Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACE_PREFIXES_FEATURE; |
|
185 |
||
186 |
/** Feature identifier: string interning. */ |
|
187 |
protected static final String STRING_INTERNING = |
|
188 |
Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE; |
|
189 |
||
190 |
/** Property identifier: error handler. */ |
|
191 |
protected static final String ERROR_HANDLER = |
|
192 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; |
|
193 |
||
194 |
/** Property identifier: JAXP schema source. */ |
|
195 |
protected static final String JAXP_SCHEMA_SOURCE = |
|
196 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; |
|
197 |
||
198 |
/** Property identifier: entity resolver. */ |
|
199 |
public static final String ENTITY_RESOLVER = |
|
200 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
201 |
|
12005 | 202 |
/** Property identifier: entity manager. */ |
203 |
protected static final String ENTITY_MANAGER = |
|
204 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
205 |
||
206 |
/** Property identifier: error reporter. */ |
|
207 |
public static final String ERROR_REPORTER = |
|
208 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
209 |
||
210 |
/** Property identifier: grammar pool. */ |
|
211 |
public static final String XMLGRAMMAR_POOL = |
|
212 |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
213 |
||
214 |
/** Property identifier: symbol table. */ |
|
215 |
public static final String SYMBOL_TABLE = |
|
216 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
217 |
||
218 |
/** Property identifier: security manager. */ |
|
219 |
protected static final String SECURITY_MANAGER = |
|
220 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; |
|
221 |
||
222 |
/** Property identifier: locale. */ |
|
223 |
protected static final String LOCALE = |
|
224 |
Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; |
|
225 |
||
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
226 |
/** Property identifier: Security property manager. */ |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
227 |
private static final String XML_SECURITY_PROPERTY_MANAGER = |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
228 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
17534 | 229 |
|
12005 | 230 |
protected static final boolean DEBUG_NODE_POOL = false; |
231 |
||
232 |
// Data |
|
233 |
||
234 |
// different sorts of declarations; should make lookup and |
|
235 |
// traverser calling more efficient/less bulky. |
|
236 |
final static int ATTRIBUTE_TYPE = 1; |
|
237 |
final static int ATTRIBUTEGROUP_TYPE = 2; |
|
238 |
final static int ELEMENT_TYPE = 3; |
|
239 |
final static int GROUP_TYPE = 4; |
|
240 |
final static int IDENTITYCONSTRAINT_TYPE = 5; |
|
241 |
final static int NOTATION_TYPE = 6; |
|
242 |
final static int TYPEDECL_TYPE = 7; |
|
243 |
||
244 |
// this string gets appended to redefined names; it's purpose is to be |
|
245 |
// as unlikely as possible to cause collisions. |
|
246 |
public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi"; |
|
247 |
||
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
248 |
//protected data that can be accessible by any traverser |
12005 | 249 |
|
250 |
protected XSDeclarationPool fDeclPool = null; |
|
251 |
||
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
252 |
// the Security manager in effect. |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
253 |
protected XMLSecurityManager fSecurityManager = null; |
12005 | 254 |
|
17534 | 255 |
private String fAccessExternalSchema; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
256 |
private String fAccessExternalDTD; |
17534 | 257 |
|
12005 | 258 |
// These tables correspond to the symbol spaces defined in the |
259 |
// spec. |
|
260 |
// They are keyed with a QName (that is, String("URI,localpart) and |
|
261 |
// their values are nodes corresponding to the given name's decl. |
|
262 |
// By asking the node for its ownerDocument and looking in |
|
263 |
// XSDocumentInfoRegistry we can easily get the corresponding |
|
264 |
// XSDocumentInfo object. |
|
265 |
private boolean registryEmpty = true; |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
266 |
private Map<String, Element> fUnparsedAttributeRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
267 |
private Map<String, Element> fUnparsedAttributeGroupRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
268 |
private Map<String, Element> fUnparsedElementRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
269 |
private Map<String, Element> fUnparsedGroupRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
270 |
private Map<String, Element> fUnparsedIdentityConstraintRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
271 |
private Map<String, Element> fUnparsedNotationRegistry = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
272 |
private Map<String, Element> fUnparsedTypeRegistry = new HashMap<>(); |
33349 | 273 |
// Compensation for the above maps to locate XSDocumentInfo, |
12005 | 274 |
// Since we may take Schema Element directly, so can not get the |
33349 | 275 |
// corresponding XSDocumentInfo object just using above maps. |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
276 |
private Map<String, XSDocumentInfo> fUnparsedAttributeRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
277 |
private Map<String, XSDocumentInfo> fUnparsedAttributeGroupRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
278 |
private Map<String, XSDocumentInfo> fUnparsedElementRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
279 |
private Map<String, XSDocumentInfo> fUnparsedGroupRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
280 |
private Map<String, XSDocumentInfo> fUnparsedIdentityConstraintRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
281 |
private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub = new HashMap<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
282 |
private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub = new HashMap<>(); |
12005 | 283 |
|
284 |
// Stores XSDocumentInfo (keyed by component name), to check for duplicate |
|
285 |
// components declared within the same xsd document |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
286 |
@SuppressWarnings("unchecked") |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
287 |
private Map<String, XSDocumentInfo> fUnparsedRegistriesExt[] = new HashMap[] { |
12005 | 288 |
null, |
289 |
null, // ATTRIBUTE_TYPE |
|
290 |
null, // ATTRIBUTEGROUP_TYPE |
|
291 |
null, // ELEMENT_TYPE |
|
292 |
null, // GROUP_TYPE |
|
293 |
null, // IDENTITYCONSTRAINT_TYPE |
|
294 |
null, // NOTATION_TYPE |
|
295 |
null, // TYPEDECL_TYPE |
|
296 |
}; |
|
297 |
||
33349 | 298 |
// this map is keyed on by XSDocumentInfo objects. Its values |
12005 | 299 |
// are Vectors containing the XSDocumentInfo objects <include>d, |
300 |
// <import>ed or <redefine>d by the key XSDocumentInfo. |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
301 |
private Map<XSDocumentInfo, Vector<XSDocumentInfo>> fDependencyMap = new HashMap<>(); |
12005 | 302 |
|
33349 | 303 |
// this map is keyed on by a target namespace. Its values |
12005 | 304 |
// are Vectors containing namespaces imported by schema documents |
305 |
// with the key target namespace. |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
306 |
// if an imported schema has absent namespace, the value "null" is stored. |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
307 |
private Map<String, Vector> fImportMap = new HashMap<> (); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
308 |
|
12005 | 309 |
// all namespaces that imports other namespaces |
310 |
// if the importing schema has absent namespace, empty string is stored. |
|
33349 | 311 |
// (because the key of a map can't be null.) |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
312 |
private Vector<String> fAllTNSs = new Vector<>(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
313 |
|
12005 | 314 |
// stores instance document mappings between namespaces and schema hints |
33349 | 315 |
private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null; |
12005 | 316 |
|
317 |
// Records which nodes are hidden when the input is a DOMInputSource. |
|
33349 | 318 |
Map<Node, String> fHiddenNodes = null; |
12005 | 319 |
|
320 |
// convenience methods |
|
321 |
private String null2EmptyString(String ns) { |
|
322 |
return ns == null ? XMLSymbols.EMPTY_STRING : ns; |
|
323 |
} |
|
324 |
private String emptyString2Null(String ns) { |
|
325 |
return ns == XMLSymbols.EMPTY_STRING ? null : ns; |
|
326 |
} |
|
327 |
// use Schema Element to lookup the SystemId. |
|
328 |
private String doc2SystemId(Element ele) { |
|
329 |
String documentURI = null; |
|
330 |
/** |
|
331 |
* REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas |
|
332 |
*/ |
|
333 |
if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){ |
|
334 |
documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI(); |
|
335 |
} |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
336 |
return documentURI != null ? documentURI : fDoc2SystemId.get(ele); |
12005 | 337 |
} |
338 |
||
339 |
// This vector stores strings which are combinations of the |
|
340 |
// publicId and systemId of the inputSource corresponding to a |
|
341 |
// schema document. This combination is used so that the user's |
|
342 |
// EntityResolver can provide a consistent way of identifying a |
|
343 |
// schema document that is included in multiple other schemas. |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
344 |
private Map<XSDKey, Element> fTraversed = new HashMap<>(); |
12005 | 345 |
|
33349 | 346 |
// this map contains a mapping from Schema Element to its systemId |
12005 | 347 |
// this is useful to resolve a uri relative to the referring document |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
348 |
private Map<Element, String> fDoc2SystemId = new HashMap<>(); |
12005 | 349 |
|
350 |
// the primary XSDocumentInfo we were called to parse |
|
351 |
private XSDocumentInfo fRoot = null; |
|
352 |
||
33349 | 353 |
// This map's job is to act as a link between the Schema Element and its |
12005 | 354 |
// XSDocumentInfo object. |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
355 |
private Map<Element, XSDocumentInfo> fDoc2XSDocumentMap = new HashMap<>(); |
12005 | 356 |
|
357 |
// map between <redefine> elements and the XSDocumentInfo |
|
358 |
// objects that correspond to the documents being redefined. |
|
359 |
private Map fRedefine2XSDMap = null; |
|
360 |
||
361 |
// map between <redefine> elements and the namespace support |
|
362 |
private Map fRedefine2NSSupport = null; |
|
363 |
||
364 |
// these objects store a mapping between the names of redefining |
|
365 |
// groups/attributeGroups and the groups/AttributeGroups which |
|
366 |
// they redefine by restriction (implicitly). It is up to the |
|
367 |
// Group and AttributeGroup traversers to check these restrictions for |
|
368 |
// validity. |
|
369 |
private Map fRedefinedRestrictedAttributeGroupRegistry = new HashMap(); |
|
370 |
private Map fRedefinedRestrictedGroupRegistry = new HashMap(); |
|
371 |
||
372 |
// a variable storing whether the last schema document |
|
373 |
// processed (by getSchema) was a duplicate. |
|
374 |
private boolean fLastSchemaWasDuplicate; |
|
375 |
||
376 |
// validate annotations feature |
|
377 |
private boolean fValidateAnnotations = false; |
|
378 |
||
379 |
//handle multiple import feature |
|
380 |
private boolean fHonourAllSchemaLocations = false; |
|
381 |
||
382 |
//handle namespace growth feature |
|
383 |
boolean fNamespaceGrowth = false; |
|
384 |
||
385 |
// handle tolerate duplicates feature |
|
386 |
boolean fTolerateDuplicates = false; |
|
387 |
||
388 |
// the XMLErrorReporter |
|
389 |
private XMLErrorReporter fErrorReporter; |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
390 |
|
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
391 |
// the XMLErrorHandler |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
392 |
private XMLErrorHandler fErrorHandler; |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
393 |
|
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
394 |
// the Locale |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
395 |
private Locale fLocale; |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
396 |
|
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
397 |
// the XMLEntityManager |
39907 | 398 |
private XMLEntityManager fEntityManager; |
12005 | 399 |
|
400 |
// the XSAttributeChecker |
|
401 |
private XSAttributeChecker fAttributeChecker; |
|
402 |
||
403 |
// the symbol table |
|
404 |
private SymbolTable fSymbolTable; |
|
405 |
||
406 |
// the GrammarResolver |
|
407 |
private XSGrammarBucket fGrammarBucket; |
|
408 |
||
409 |
// the Grammar description |
|
410 |
private XSDDescription fSchemaGrammarDescription; |
|
411 |
||
412 |
// the Grammar Pool |
|
413 |
private XMLGrammarPool fGrammarPool; |
|
414 |
||
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
415 |
// the security property manager |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
416 |
private XMLSecurityPropertyManager fSecurityPropertyMgr = null; |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
417 |
|
39907 | 418 |
/** indicate whether Catalog should be used for resolving external resources */ |
419 |
private boolean fUseCatalog = true; |
|
420 |
private String fCatalogFile; |
|
421 |
private String fDefer; |
|
422 |
private String fPrefer; |
|
423 |
private String fResolve; |
|
424 |
||
12005 | 425 |
//************ Traversers ********** |
426 |
XSDAttributeGroupTraverser fAttributeGroupTraverser; |
|
427 |
XSDAttributeTraverser fAttributeTraverser; |
|
428 |
XSDComplexTypeTraverser fComplexTypeTraverser; |
|
429 |
XSDElementTraverser fElementTraverser; |
|
430 |
XSDGroupTraverser fGroupTraverser; |
|
431 |
XSDKeyrefTraverser fKeyrefTraverser; |
|
432 |
XSDNotationTraverser fNotationTraverser; |
|
433 |
XSDSimpleTypeTraverser fSimpleTypeTraverser; |
|
434 |
XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser; |
|
435 |
XSDWildcardTraverser fWildCardTraverser; |
|
436 |
||
437 |
SchemaDVFactory fDVFactory; |
|
438 |
SchemaDOMParser fSchemaParser; |
|
439 |
SchemaContentHandler fXSContentHandler; |
|
440 |
StAXSchemaParser fStAXSchemaParser; |
|
441 |
XML11Configuration fAnnotationValidator; |
|
442 |
XSAnnotationGrammarPool fGrammarBucketAdapter; |
|
443 |
||
444 |
// these data members are needed for the deferred traversal |
|
445 |
// of local elements. |
|
446 |
||
447 |
// the initial size of the array to store deferred local elements |
|
448 |
private static final int INIT_STACK_SIZE = 30; |
|
449 |
// the incremental size of the array to store deferred local elements |
|
450 |
private static final int INC_STACK_SIZE = 10; |
|
451 |
// current position of the array (# of deferred local elements) |
|
452 |
private int fLocalElemStackPos = 0; |
|
453 |
||
454 |
private XSParticleDecl[] fParticle = new XSParticleDecl[INIT_STACK_SIZE]; |
|
455 |
private Element[] fLocalElementDecl = new Element[INIT_STACK_SIZE]; |
|
456 |
private XSDocumentInfo[] fLocalElementDecl_schema = new XSDocumentInfo[INIT_STACK_SIZE]; //JACK |
|
457 |
private int[] fAllContext = new int[INIT_STACK_SIZE]; |
|
458 |
private XSObject[] fParent = new XSObject[INIT_STACK_SIZE]; |
|
459 |
private String [][] fLocalElemNamespaceContext = new String [INIT_STACK_SIZE][1]; |
|
460 |
||
461 |
// these data members are needed for the deferred traversal |
|
462 |
// of keyrefs. |
|
463 |
||
464 |
// the initial size of the array to store deferred keyrefs |
|
465 |
private static final int INIT_KEYREF_STACK = 2; |
|
466 |
// the incremental size of the array to store deferred keyrefs |
|
467 |
private static final int INC_KEYREF_STACK_AMOUNT = 2; |
|
468 |
// current position of the array (# of deferred keyrefs) |
|
469 |
private int fKeyrefStackPos = 0; |
|
470 |
||
471 |
private Element [] fKeyrefs = new Element[INIT_KEYREF_STACK]; |
|
472 |
private XSDocumentInfo [] fKeyrefsMapXSDocumentInfo = new XSDocumentInfo[INIT_KEYREF_STACK]; |
|
473 |
private XSElementDecl [] fKeyrefElems = new XSElementDecl [INIT_KEYREF_STACK]; |
|
474 |
private String [][] fKeyrefNamespaceContext = new String[INIT_KEYREF_STACK][1]; |
|
475 |
||
476 |
// global decls: map from decl name to decl object |
|
33349 | 477 |
SymbolHash fGlobalAttrDecls = new SymbolHash(12); |
478 |
SymbolHash fGlobalAttrGrpDecls = new SymbolHash(5); |
|
479 |
SymbolHash fGlobalElemDecls = new SymbolHash(25); |
|
480 |
SymbolHash fGlobalGroupDecls = new SymbolHash(5); |
|
481 |
SymbolHash fGlobalNotationDecls = new SymbolHash(1); |
|
482 |
SymbolHash fGlobalIDConstraintDecls = new SymbolHash(3); |
|
483 |
SymbolHash fGlobalTypeDecls = new SymbolHash(25); |
|
12005 | 484 |
|
485 |
// Constructors |
|
486 |
public XSDHandler(){ |
|
33349 | 487 |
fHiddenNodes = new HashMap<>(); |
12005 | 488 |
fSchemaParser = new SchemaDOMParser(new SchemaParsingConfig()); |
489 |
} |
|
490 |
||
491 |
// it should be possible to use the same XSDHandler to parse |
|
492 |
// multiple schema documents; this will allow one to be |
|
493 |
// constructed. |
|
494 |
public XSDHandler (XSGrammarBucket gBucket) { |
|
495 |
this(); |
|
496 |
fGrammarBucket = gBucket; |
|
497 |
||
498 |
// Note: don't use SchemaConfiguration internally |
|
499 |
// we will get stack overflaw because |
|
500 |
// XMLSchemaValidator will be instantiating XSDHandler... |
|
501 |
fSchemaGrammarDescription = new XSDDescription(); |
|
502 |
} // end constructor |
|
503 |
||
504 |
/** |
|
505 |
* This method initiates the parse of a schema. It will likely be |
|
506 |
* called from the Validator and it will make the |
|
507 |
* resulting grammar available; it returns a reference to this object just |
|
508 |
* in case. A reset(XMLComponentManager) must be called before this methods is called. |
|
509 |
* @param is |
|
510 |
* @param desc |
|
511 |
* @param locationPairs |
|
512 |
* @return the SchemaGrammar |
|
513 |
* @throws IOException |
|
514 |
*/ |
|
515 |
public SchemaGrammar parseSchema(XMLInputSource is, XSDDescription desc, |
|
33349 | 516 |
Map<String, XMLSchemaLoader.LocationArray> locationPairs) |
12005 | 517 |
throws IOException { |
518 |
fLocationPairs = locationPairs; |
|
519 |
fSchemaParser.resetNodePool(); |
|
520 |
SchemaGrammar grammar = null; |
|
521 |
String schemaNamespace = null; |
|
522 |
short referType = desc.getContextType(); |
|
523 |
||
524 |
// if loading using JAXP schemaSource property, or using grammar caching loadGrammar |
|
525 |
// the desc.targetNamespace is always null. |
|
526 |
// Therefore we should not attempt to find out if |
|
527 |
// the schema is already in the bucket, since in the case we have |
|
528 |
// no namespace schema in the bucket, findGrammar will always return the |
|
529 |
// no namespace schema. |
|
530 |
if (referType != XSDDescription.CONTEXT_PREPARSE){ |
|
531 |
// first try to find it in the bucket/pool, return if one is found |
|
532 |
if (fHonourAllSchemaLocations && referType == XSDDescription.CONTEXT_IMPORT && isExistingGrammar(desc, fNamespaceGrowth)) { |
|
533 |
grammar = fGrammarBucket.getGrammar(desc.getTargetNamespace()); |
|
534 |
} |
|
535 |
else { |
|
536 |
grammar = findGrammar(desc, fNamespaceGrowth); |
|
537 |
} |
|
538 |
if (grammar != null) { |
|
539 |
if (!fNamespaceGrowth) { |
|
540 |
return grammar; |
|
541 |
} |
|
542 |
else { |
|
543 |
try { |
|
544 |
if (grammar.getDocumentLocations().contains(XMLEntityManager.expandSystemId(is.getSystemId(), is.getBaseSystemId(), false))) { |
|
545 |
return grammar; |
|
546 |
} |
|
547 |
} |
|
548 |
catch (MalformedURIException e) { |
|
549 |
//REVISIT: return the grammar? |
|
550 |
} |
|
551 |
} |
|
552 |
} |
|
553 |
||
554 |
schemaNamespace = desc.getTargetNamespace(); |
|
555 |
// handle empty string URI as null |
|
556 |
if (schemaNamespace != null) { |
|
557 |
schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
// before parsing a schema, need to clear registries associated with |
|
562 |
// parsing schemas |
|
563 |
prepareForParse(); |
|
564 |
||
565 |
Element schemaRoot = null; |
|
566 |
// first phase: construct trees. |
|
567 |
if (is instanceof DOMInputSource) { |
|
568 |
schemaRoot = getSchemaDocument(schemaNamespace, (DOMInputSource) is, |
|
569 |
referType == XSDDescription.CONTEXT_PREPARSE, |
|
570 |
referType, null); |
|
571 |
} // DOMInputSource |
|
572 |
else if (is instanceof SAXInputSource) { |
|
573 |
schemaRoot = getSchemaDocument(schemaNamespace, (SAXInputSource) is, |
|
574 |
referType == XSDDescription.CONTEXT_PREPARSE, |
|
575 |
referType, null); |
|
576 |
} // SAXInputSource |
|
577 |
else if (is instanceof StAXInputSource) { |
|
578 |
schemaRoot = getSchemaDocument(schemaNamespace, (StAXInputSource) is, |
|
579 |
referType == XSDDescription.CONTEXT_PREPARSE, |
|
580 |
referType, null); |
|
581 |
} // StAXInputSource |
|
582 |
else if (is instanceof XSInputSource) { |
|
583 |
schemaRoot = getSchemaDocument((XSInputSource) is, desc); |
|
584 |
} // XSInputSource |
|
585 |
else { |
|
586 |
schemaRoot = getSchemaDocument(schemaNamespace, is, |
|
587 |
referType == XSDDescription.CONTEXT_PREPARSE, |
|
588 |
referType, null); |
|
589 |
||
590 |
} //is instanceof XMLInputSource |
|
591 |
||
592 |
if (schemaRoot == null) { |
|
593 |
// something went wrong right off the hop |
|
594 |
if (is instanceof XSInputSource) { |
|
595 |
return fGrammarBucket.getGrammar(desc.getTargetNamespace()); |
|
596 |
} |
|
597 |
return grammar; |
|
598 |
} |
|
599 |
||
600 |
if (referType == XSDDescription.CONTEXT_PREPARSE) { |
|
601 |
Element schemaElem = schemaRoot; |
|
602 |
schemaNamespace = DOMUtil.getAttrValue(schemaElem, SchemaSymbols.ATT_TARGETNAMESPACE); |
|
603 |
if(schemaNamespace != null && schemaNamespace.length() > 0) { |
|
604 |
// Since now we've discovered a namespace, we need to update xsd key |
|
605 |
// and store this schema in traversed schemas bucket |
|
606 |
schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); |
|
607 |
desc.setTargetNamespace(schemaNamespace); |
|
608 |
} |
|
609 |
else { |
|
610 |
schemaNamespace = null; |
|
611 |
} |
|
612 |
grammar = findGrammar(desc, fNamespaceGrowth); |
|
613 |
String schemaId = XMLEntityManager.expandSystemId(is.getSystemId(), is.getBaseSystemId(), false); |
|
614 |
if (grammar != null) { |
|
615 |
// When namespace growth is enabled and a null location is provided we cannot tell |
|
616 |
// whether we've loaded this schema document before so we must assume that we haven't. |
|
617 |
if (!fNamespaceGrowth || (schemaId != null && grammar.getDocumentLocations().contains(schemaId))) { |
|
618 |
return grammar; |
|
619 |
} |
|
620 |
} |
|
621 |
||
622 |
XSDKey key = new XSDKey(schemaId, referType, schemaNamespace); |
|
623 |
fTraversed.put(key, schemaRoot); |
|
624 |
if (schemaId != null) { |
|
625 |
fDoc2SystemId.put(schemaRoot, schemaId); |
|
626 |
} |
|
627 |
} |
|
628 |
||
629 |
// before constructing trees and traversing a schema, need to reset |
|
630 |
// all traversers and clear all registries |
|
631 |
prepareForTraverse(); |
|
632 |
||
633 |
fRoot = constructTrees(schemaRoot, is.getSystemId(), desc, grammar != null); |
|
634 |
if (fRoot == null) { |
|
635 |
return null; |
|
636 |
} |
|
637 |
||
638 |
// second phase: fill global registries. |
|
639 |
buildGlobalNameRegistries(); |
|
640 |
||
641 |
// third phase: call traversers |
|
642 |
ArrayList annotationInfo = fValidateAnnotations ? new ArrayList() : null; |
|
643 |
traverseSchemas(annotationInfo); |
|
644 |
||
645 |
// fourth phase: handle local element decls |
|
646 |
traverseLocalElements(); |
|
647 |
||
648 |
// fifth phase: handle Keyrefs |
|
649 |
resolveKeyRefs(); |
|
650 |
||
651 |
// sixth phase: validate attribute of non-schema namespaces |
|
652 |
// REVISIT: skip this for now. we really don't want to do it. |
|
653 |
//fAttributeChecker.checkNonSchemaAttributes(fGrammarBucket); |
|
654 |
||
655 |
// seventh phase: store imported grammars |
|
656 |
// for all grammars with <import>s |
|
657 |
for (int i = fAllTNSs.size() - 1; i >= 0; i--) { |
|
658 |
// get its target namespace |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
659 |
String tns = fAllTNSs.elementAt(i); |
12005 | 660 |
// get all namespaces it imports |
661 |
Vector ins = (Vector)fImportMap.get(tns); |
|
662 |
// get the grammar |
|
663 |
SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns)); |
|
664 |
if (sg == null) |
|
665 |
continue; |
|
666 |
SchemaGrammar isg; |
|
667 |
// for imported namespace |
|
668 |
int count = 0; |
|
669 |
for (int j = 0; j < ins.size(); j++) { |
|
670 |
// get imported grammar |
|
671 |
isg = fGrammarBucket.getGrammar((String)ins.elementAt(j)); |
|
672 |
// reuse the same vector |
|
673 |
if (isg != null) |
|
674 |
ins.setElementAt(isg, count++); |
|
675 |
} |
|
676 |
ins.setSize(count); |
|
677 |
// set the imported grammars |
|
678 |
sg.setImportedGrammars(ins); |
|
679 |
} |
|
680 |
||
681 |
/** validate annotations **/ |
|
682 |
if (fValidateAnnotations && annotationInfo.size() > 0) { |
|
683 |
validateAnnotations(annotationInfo); |
|
684 |
} |
|
685 |
||
686 |
// and return. |
|
687 |
return fGrammarBucket.getGrammar(fRoot.fTargetNamespace); |
|
688 |
} // end parseSchema |
|
689 |
||
690 |
private void validateAnnotations(ArrayList annotationInfo) { |
|
691 |
if (fAnnotationValidator == null) { |
|
692 |
createAnnotationValidator(); |
|
693 |
} |
|
694 |
final int size = annotationInfo.size(); |
|
39080
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
36146
diff
changeset
|
695 |
final XMLInputSource src = new XMLInputSource(null, null, null, false); |
12005 | 696 |
fGrammarBucketAdapter.refreshGrammars(fGrammarBucket); |
697 |
for (int i = 0; i < size; i += 2) { |
|
698 |
src.setSystemId((String) annotationInfo.get(i)); |
|
699 |
XSAnnotationInfo annotation = (XSAnnotationInfo) annotationInfo.get(i+1); |
|
700 |
while (annotation != null) { |
|
701 |
src.setCharacterStream(new StringReader(annotation.fAnnotation)); |
|
702 |
try { |
|
703 |
fAnnotationValidator.parse(src); |
|
704 |
} |
|
705 |
catch (IOException exc) {} |
|
706 |
annotation = annotation.next; |
|
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
||
711 |
private void createAnnotationValidator() { |
|
712 |
fAnnotationValidator = new XML11Configuration(); |
|
713 |
fGrammarBucketAdapter = new XSAnnotationGrammarPool(); |
|
714 |
fAnnotationValidator.setFeature(VALIDATION, true); |
|
715 |
fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true); |
|
716 |
fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
717 |
/** set security manager and XML Security Property Manager **/ |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
718 |
fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true)); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
719 |
fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
12005 | 720 |
/** Set error handler. **/ |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
721 |
fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); |
12005 | 722 |
/** Set locale. **/ |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
723 |
fAnnotationValidator.setProperty(LOCALE, fLocale); |
39907 | 724 |
|
725 |
// Passing on the Catalog settings |
|
726 |
fAnnotationValidator.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); |
|
727 |
fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_FILES, fCatalogFile); |
|
728 |
fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_DEFER, fDefer); |
|
729 |
fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_PREFER, fPrefer); |
|
730 |
fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_RESOLVE, fResolve); |
|
12005 | 731 |
} |
732 |
||
733 |
/** |
|
734 |
* Pull the grammar out of the bucket simply using |
|
735 |
* its TNS as a key |
|
736 |
*/ |
|
737 |
SchemaGrammar getGrammar(String tns) { |
|
738 |
return fGrammarBucket.getGrammar(tns); |
|
739 |
} |
|
740 |
||
741 |
/** |
|
742 |
* First try to find a grammar in the bucket, if failed, consult the |
|
743 |
* grammar pool. If a grammar is found in the pool, then add it (and all |
|
744 |
* imported ones) into the bucket. |
|
745 |
*/ |
|
746 |
protected SchemaGrammar findGrammar(XSDDescription desc, boolean ignoreConflict) { |
|
747 |
SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); |
|
748 |
if (sg == null) { |
|
749 |
if (fGrammarPool != null) { |
|
750 |
sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc); |
|
751 |
if (sg != null) { |
|
752 |
// put this grammar into the bucket, along with grammars |
|
753 |
// imported by it (directly or indirectly) |
|
754 |
if (!fGrammarBucket.putGrammar(sg, true, ignoreConflict)) { |
|
755 |
// REVISIT: a conflict between new grammar(s) and grammars |
|
756 |
// in the bucket. What to do? A warning? An exception? |
|
757 |
reportSchemaWarning("GrammarConflict", null, null); |
|
758 |
sg = null; |
|
759 |
} |
|
760 |
} |
|
761 |
} |
|
762 |
} |
|
763 |
return sg; |
|
764 |
} |
|
765 |
||
766 |
// may wish to have setter methods for ErrorHandler, |
|
767 |
// EntityResolver... |
|
768 |
||
769 |
private static final String[][] NS_ERROR_CODES = { |
|
770 |
{"src-include.2.1", "src-include.2.1"}, |
|
771 |
{"src-redefine.3.1", "src-redefine.3.1"}, |
|
772 |
{"src-import.3.1", "src-import.3.2"}, |
|
773 |
null, |
|
774 |
{"TargetNamespace.1", "TargetNamespace.2"}, |
|
775 |
{"TargetNamespace.1", "TargetNamespace.2"}, |
|
776 |
{"TargetNamespace.1", "TargetNamespace.2"}, |
|
777 |
{"TargetNamespace.1", "TargetNamespace.2"} |
|
778 |
}; |
|
779 |
||
780 |
private static final String[] ELE_ERROR_CODES = { |
|
781 |
"src-include.1", "src-redefine.2", "src-import.2", "schema_reference.4", |
|
782 |
"schema_reference.4", "schema_reference.4", "schema_reference.4", "schema_reference.4" |
|
783 |
}; |
|
784 |
||
785 |
// This method does several things: |
|
786 |
// It constructs an instance of an XSDocumentInfo object using the |
|
787 |
// schemaRoot node. Then, for each <include>, |
|
788 |
// <redefine>, and <import> children, it attempts to resolve the |
|
789 |
// requested schema document, initiates a DOM parse, and calls |
|
790 |
// itself recursively on that document's root. It also records in |
|
791 |
// the DependencyMap object what XSDocumentInfo objects its XSDocumentInfo |
|
792 |
// depends on. |
|
793 |
// It also makes sure the targetNamespace of the schema it was |
|
794 |
// called to parse is correct. |
|
795 |
protected XSDocumentInfo constructTrees(Element schemaRoot, String locationHint, XSDDescription desc, boolean nsCollision) { |
|
796 |
if (schemaRoot == null) return null; |
|
797 |
String callerTNS = desc.getTargetNamespace(); |
|
798 |
short referType = desc.getContextType(); |
|
799 |
||
800 |
XSDocumentInfo currSchemaInfo = null; |
|
801 |
try { |
|
802 |
// note that attributes are freed at end of traverseSchemas() |
|
803 |
currSchemaInfo = new XSDocumentInfo(schemaRoot, fAttributeChecker, fSymbolTable); |
|
804 |
} catch (XMLSchemaException se) { |
|
805 |
reportSchemaError(ELE_ERROR_CODES[referType], |
|
806 |
new Object[]{locationHint}, |
|
807 |
schemaRoot); |
|
808 |
return null; |
|
809 |
} |
|
810 |
// targetNamespace="" is not valid, issue a warning, and ignore it |
|
811 |
if (currSchemaInfo.fTargetNamespace != null && |
|
812 |
currSchemaInfo.fTargetNamespace.length() == 0) { |
|
813 |
reportSchemaWarning("EmptyTargetNamespace", |
|
814 |
new Object[]{locationHint}, |
|
815 |
schemaRoot); |
|
816 |
currSchemaInfo.fTargetNamespace = null; |
|
817 |
} |
|
818 |
||
819 |
if (callerTNS != null) { |
|
820 |
// the second index to the NS_ERROR_CODES array |
|
821 |
// if the caller/expected NS is not absent, we use the first column |
|
822 |
int secondIdx = 0; |
|
823 |
// for include and redefine |
|
824 |
if (referType == XSDDescription.CONTEXT_INCLUDE || |
|
825 |
referType == XSDDescription.CONTEXT_REDEFINE) { |
|
826 |
// if the referred document has no targetNamespace, |
|
827 |
// it's a chameleon schema |
|
828 |
if (currSchemaInfo.fTargetNamespace == null) { |
|
829 |
currSchemaInfo.fTargetNamespace = callerTNS; |
|
830 |
currSchemaInfo.fIsChameleonSchema = true; |
|
831 |
} |
|
832 |
// if the referred document has a target namespace differing |
|
833 |
// from the caller, it's an error |
|
834 |
else if (callerTNS != currSchemaInfo.fTargetNamespace) { |
|
835 |
reportSchemaError(NS_ERROR_CODES[referType][secondIdx], |
|
836 |
new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, |
|
837 |
schemaRoot); |
|
838 |
return null; |
|
839 |
} |
|
840 |
} |
|
841 |
// for instance and import, the two NS's must be the same |
|
842 |
else if (referType != XSDDescription.CONTEXT_PREPARSE && callerTNS != currSchemaInfo.fTargetNamespace) { |
|
843 |
reportSchemaError(NS_ERROR_CODES[referType][secondIdx], |
|
844 |
new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, |
|
845 |
schemaRoot); |
|
846 |
return null; |
|
847 |
} |
|
848 |
} |
|
849 |
// now there is no caller/expected NS, it's an error for the referred |
|
850 |
// document to have a target namespace, unless we are preparsing a schema |
|
851 |
else if (currSchemaInfo.fTargetNamespace != null) { |
|
852 |
// set the target namespace of the description |
|
853 |
if (referType == XSDDescription.CONTEXT_PREPARSE) { |
|
854 |
desc.setTargetNamespace(currSchemaInfo.fTargetNamespace); |
|
855 |
callerTNS = currSchemaInfo.fTargetNamespace; |
|
856 |
} |
|
857 |
else { |
|
858 |
// the second index to the NS_ERROR_CODES array |
|
859 |
// if the caller/expected NS is absent, we use the second column |
|
860 |
int secondIdx = 1; |
|
861 |
reportSchemaError(NS_ERROR_CODES[referType][secondIdx], |
|
862 |
new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, |
|
863 |
schemaRoot); |
|
864 |
return null; |
|
865 |
} |
|
866 |
} |
|
867 |
// the other cases (callerTNS == currSchemaInfo.fTargetNamespce == null) |
|
868 |
// are valid |
|
869 |
||
870 |
// a schema document can always access it's own target namespace |
|
871 |
currSchemaInfo.addAllowedNS(currSchemaInfo.fTargetNamespace); |
|
872 |
||
873 |
SchemaGrammar sg = null; |
|
874 |
||
875 |
// we have a namespace collision |
|
876 |
if (nsCollision) { |
|
877 |
SchemaGrammar sg2 = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace); |
|
878 |
if (sg2.isImmutable()) { |
|
879 |
sg = new SchemaGrammar(sg2); |
|
880 |
fGrammarBucket.putGrammar(sg); |
|
881 |
// update all the grammars in the bucket to point to the new grammar. |
|
882 |
updateImportListWith(sg); |
|
883 |
} |
|
884 |
else { |
|
885 |
sg = sg2; |
|
886 |
} |
|
887 |
||
888 |
// update import list of the new grammar |
|
889 |
updateImportListFor(sg); |
|
890 |
} |
|
891 |
else if (referType == XSDDescription.CONTEXT_INCLUDE || |
|
892 |
referType == XSDDescription.CONTEXT_REDEFINE) { |
|
893 |
sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace); |
|
894 |
} |
|
895 |
else if(fHonourAllSchemaLocations && referType == XSDDescription.CONTEXT_IMPORT) { |
|
896 |
sg = findGrammar(desc, false); |
|
897 |
if(sg == null) { |
|
898 |
sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable); |
|
899 |
fGrammarBucket.putGrammar(sg); |
|
900 |
} |
|
901 |
} |
|
902 |
else { |
|
903 |
sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable); |
|
904 |
fGrammarBucket.putGrammar(sg); |
|
905 |
} |
|
906 |
||
907 |
// store the document and its location |
|
908 |
// REVISIT: don't expose the DOM tree |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
909 |
sg.addDocument(null, fDoc2SystemId.get(currSchemaInfo.fSchemaElement)); |
12005 | 910 |
|
911 |
fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
912 |
Vector<XSDocumentInfo> dependencies = new Vector<>(); |
12005 | 913 |
Element rootNode = schemaRoot; |
914 |
||
915 |
Element newSchemaRoot = null; |
|
916 |
for (Element child = DOMUtil.getFirstChildElement(rootNode); |
|
917 |
child != null; |
|
918 |
child = DOMUtil.getNextSiblingElement(child)) { |
|
919 |
String schemaNamespace=null; |
|
920 |
String schemaHint=null; |
|
921 |
String localName = DOMUtil.getLocalName(child); |
|
922 |
||
923 |
short refType = -1; |
|
924 |
boolean importCollision = false; |
|
925 |
||
926 |
if (localName.equals(SchemaSymbols.ELT_ANNOTATION)) |
|
927 |
continue; |
|
928 |
else if (localName.equals(SchemaSymbols.ELT_IMPORT)) { |
|
929 |
refType = XSDDescription.CONTEXT_IMPORT; |
|
930 |
// have to handle some validation here too! |
|
931 |
// call XSAttributeChecker to fill in attrs |
|
932 |
Object[] importAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); |
|
933 |
schemaHint = (String)importAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; |
|
934 |
schemaNamespace = (String)importAttrs[XSAttributeChecker.ATTIDX_NAMESPACE]; |
|
935 |
if (schemaNamespace != null) |
|
936 |
schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); |
|
937 |
||
938 |
// check contents and process optional annotations |
|
939 |
Element importChild = DOMUtil.getFirstChildElement(child); |
|
940 |
if(importChild != null ) { |
|
941 |
String importComponentType = DOMUtil.getLocalName(importChild); |
|
942 |
if (importComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
943 |
// promoting annotations to parent component |
|
944 |
sg.addAnnotation( |
|
945 |
fElementTraverser.traverseAnnotationDecl(importChild, importAttrs, true, currSchemaInfo)); |
|
946 |
} else { |
|
947 |
reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", importComponentType}, child); |
|
948 |
} |
|
949 |
if(DOMUtil.getNextSiblingElement(importChild) != null) { |
|
950 |
reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(importChild))}, child); |
|
951 |
} |
|
952 |
} |
|
953 |
else { |
|
954 |
String text = DOMUtil.getSyntheticAnnotation(child); |
|
955 |
if (text != null) { |
|
956 |
sg.addAnnotation(fElementTraverser.traverseSyntheticAnnotation(child, text, importAttrs, true, currSchemaInfo)); |
|
957 |
} |
|
958 |
} |
|
959 |
fAttributeChecker.returnAttrArray(importAttrs, currSchemaInfo); |
|
960 |
||
961 |
// a document can't import another document with the same namespace |
|
962 |
if (schemaNamespace == currSchemaInfo.fTargetNamespace) { |
|
963 |
reportSchemaError(schemaNamespace != null ? |
|
964 |
"src-import.1.1" : "src-import.1.2", new Object [] {schemaNamespace}, child); |
|
965 |
continue; |
|
966 |
} |
|
967 |
||
968 |
// if this namespace has not been imported by this document, |
|
969 |
// then import if multiple imports support is enabled. |
|
970 |
if(currSchemaInfo.isAllowedNS(schemaNamespace)) { |
|
971 |
if(!fHonourAllSchemaLocations && !fNamespaceGrowth) |
|
972 |
continue; |
|
973 |
} |
|
974 |
else { |
|
975 |
currSchemaInfo.addAllowedNS(schemaNamespace); |
|
976 |
} |
|
977 |
// also record the fact that one namespace imports another one |
|
978 |
// convert null to "" |
|
979 |
String tns = null2EmptyString(currSchemaInfo.fTargetNamespace); |
|
980 |
// get all namespaces imported by this one |
|
981 |
Vector ins = (Vector)fImportMap.get(tns); |
|
982 |
// if no namespace was imported, create new Vector |
|
983 |
if (ins == null) { |
|
984 |
// record that this one imports other(s) |
|
985 |
fAllTNSs.addElement(tns); |
|
986 |
ins = new Vector(); |
|
987 |
fImportMap.put(tns, ins); |
|
988 |
ins.addElement(schemaNamespace); |
|
989 |
} |
|
990 |
else if (!ins.contains(schemaNamespace)){ |
|
991 |
ins.addElement(schemaNamespace); |
|
992 |
} |
|
993 |
||
994 |
fSchemaGrammarDescription.reset(); |
|
995 |
fSchemaGrammarDescription.setContextType(XSDDescription.CONTEXT_IMPORT); |
|
996 |
fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot)); |
|
997 |
fSchemaGrammarDescription.setLiteralSystemId(schemaHint); |
|
998 |
fSchemaGrammarDescription.setLocationHints(new String[]{schemaHint}); |
|
999 |
fSchemaGrammarDescription.setTargetNamespace(schemaNamespace); |
|
1000 |
||
1001 |
// if a grammar with the same namespace and location exists (or being |
|
1002 |
// built), ignore this one (don't traverse it). |
|
1003 |
SchemaGrammar isg = findGrammar(fSchemaGrammarDescription, fNamespaceGrowth); |
|
1004 |
if (isg != null) { |
|
1005 |
if (fNamespaceGrowth) { |
|
1006 |
try { |
|
1007 |
if (isg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(schemaHint, fSchemaGrammarDescription.getBaseSystemId(), false))) { |
|
1008 |
continue; |
|
1009 |
} |
|
1010 |
else { |
|
1011 |
importCollision = true; |
|
1012 |
} |
|
1013 |
} |
|
1014 |
catch (MalformedURIException e) { |
|
1015 |
} |
|
1016 |
} |
|
1017 |
else if (!fHonourAllSchemaLocations || isExistingGrammar(fSchemaGrammarDescription, false)) { |
|
1018 |
continue; |
|
1019 |
} |
|
1020 |
} |
|
1021 |
//if ((!fHonourAllSchemaLocations && findGrammar(fSchemaGrammarDescription) != null) || isExistingGrammar(fSchemaGrammarDescription)) |
|
1022 |
// continue; |
|
1023 |
||
1024 |
// If "findGrammar" returns a grammar, then this is not the |
|
1025 |
// the first time we see a location for a given namespace. |
|
33349 | 1026 |
// Don't consult the location pair map in this case, |
12005 | 1027 |
// otherwise the location will be ignored because it'll get |
1028 |
// resolved to the same location as the first hint. |
|
1029 |
newSchemaRoot = resolveSchema(fSchemaGrammarDescription, false, child, isg == null); |
|
1030 |
} |
|
1031 |
else if ((localName.equals(SchemaSymbols.ELT_INCLUDE)) || |
|
1032 |
(localName.equals(SchemaSymbols.ELT_REDEFINE))) { |
|
1033 |
// validation for redefine/include will be the same here; just |
|
1034 |
// make sure TNS is right (don't care about redef contents |
|
1035 |
// yet). |
|
1036 |
Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); |
|
1037 |
schemaHint = (String)includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; |
|
1038 |
// store the namespace decls of the redefine element |
|
1039 |
if (localName.equals(SchemaSymbols.ELT_REDEFINE)) { |
|
1040 |
if (fRedefine2NSSupport == null) fRedefine2NSSupport = new HashMap(); |
|
1041 |
fRedefine2NSSupport.put(child, new SchemaNamespaceSupport(currSchemaInfo.fNamespaceSupport)); |
|
1042 |
} |
|
1043 |
||
1044 |
// check annotations. Must do this here to avoid having to |
|
1045 |
// re-parse attributes later |
|
1046 |
if(localName.equals(SchemaSymbols.ELT_INCLUDE)) { |
|
1047 |
Element includeChild = DOMUtil.getFirstChildElement(child); |
|
1048 |
if(includeChild != null ) { |
|
1049 |
String includeComponentType = DOMUtil.getLocalName(includeChild); |
|
1050 |
if (includeComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
1051 |
// promoting annotations to parent component |
|
1052 |
sg.addAnnotation( |
|
1053 |
fElementTraverser.traverseAnnotationDecl(includeChild, includeAttrs, true, currSchemaInfo)); |
|
1054 |
} else { |
|
1055 |
reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", includeComponentType}, child); |
|
1056 |
} |
|
1057 |
if(DOMUtil.getNextSiblingElement(includeChild) != null) { |
|
1058 |
reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(includeChild))}, child); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
else { |
|
1062 |
String text = DOMUtil.getSyntheticAnnotation(child); |
|
1063 |
if (text != null) { |
|
1064 |
sg.addAnnotation(fElementTraverser.traverseSyntheticAnnotation(child, text, includeAttrs, true, currSchemaInfo)); |
|
1065 |
} |
|
1066 |
} |
|
1067 |
} |
|
1068 |
else { |
|
1069 |
for (Element redefinedChild = DOMUtil.getFirstChildElement(child); |
|
1070 |
redefinedChild != null; |
|
1071 |
redefinedChild = DOMUtil.getNextSiblingElement(redefinedChild)) { |
|
1072 |
String redefinedComponentType = DOMUtil.getLocalName(redefinedChild); |
|
1073 |
if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
1074 |
// promoting annotations to parent component |
|
1075 |
sg.addAnnotation( |
|
1076 |
fElementTraverser.traverseAnnotationDecl(redefinedChild, includeAttrs, true, currSchemaInfo)); |
|
1077 |
DOMUtil.setHidden(redefinedChild, fHiddenNodes); |
|
1078 |
} |
|
1079 |
else { |
|
1080 |
String text = DOMUtil.getSyntheticAnnotation(child); |
|
1081 |
if (text != null) { |
|
1082 |
sg.addAnnotation(fElementTraverser.traverseSyntheticAnnotation(child, text, includeAttrs, true, currSchemaInfo)); |
|
1083 |
} |
|
1084 |
} |
|
1085 |
// catch all other content errors later |
|
1086 |
} |
|
1087 |
} |
|
1088 |
fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo); |
|
1089 |
// schemaLocation is required on <include> and <redefine> |
|
1090 |
if (schemaHint == null) { |
|
1091 |
reportSchemaError("s4s-att-must-appear", new Object [] { |
|
1092 |
"<include> or <redefine>", "schemaLocation"}, |
|
1093 |
child); |
|
1094 |
} |
|
1095 |
// pass the systemId of the current document as the base systemId |
|
1096 |
boolean mustResolve = false; |
|
1097 |
refType = XSDDescription.CONTEXT_INCLUDE; |
|
1098 |
if(localName.equals(SchemaSymbols.ELT_REDEFINE)) { |
|
1099 |
mustResolve = nonAnnotationContent(child); |
|
1100 |
refType = XSDDescription.CONTEXT_REDEFINE; |
|
1101 |
} |
|
1102 |
fSchemaGrammarDescription.reset(); |
|
1103 |
fSchemaGrammarDescription.setContextType(refType); |
|
1104 |
fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot)); |
|
1105 |
fSchemaGrammarDescription.setLocationHints(new String[]{schemaHint}); |
|
1106 |
fSchemaGrammarDescription.setTargetNamespace(callerTNS); |
|
1107 |
||
1108 |
boolean alreadyTraversed = false; |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1109 |
XMLInputSource schemaSource = |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1110 |
resolveSchemaSource(fSchemaGrammarDescription, mustResolve, child, true); |
12005 | 1111 |
if (fNamespaceGrowth && refType == XSDDescription.CONTEXT_INCLUDE) { |
1112 |
try { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1113 |
final String schemaId = XMLEntityManager.expandSystemId( |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1114 |
schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); |
12005 | 1115 |
alreadyTraversed = sg.getDocumentLocations().contains(schemaId); |
1116 |
} |
|
1117 |
catch(MalformedURIException e) { |
|
1118 |
||
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
if (!alreadyTraversed) { |
|
1123 |
newSchemaRoot = resolveSchema(schemaSource, fSchemaGrammarDescription, mustResolve, child); |
|
1124 |
schemaNamespace = currSchemaInfo.fTargetNamespace; |
|
1125 |
} |
|
1126 |
else { |
|
1127 |
fLastSchemaWasDuplicate = true; |
|
1128 |
} |
|
1129 |
} |
|
1130 |
else { |
|
1131 |
// no more possibility of schema references in well-formed |
|
1132 |
// schema... |
|
1133 |
break; |
|
1134 |
} |
|
1135 |
||
1136 |
// If the schema is duplicate, we needn't call constructTrees() again. |
|
1137 |
// To handle mutual <include>s |
|
1138 |
XSDocumentInfo newSchemaInfo = null; |
|
1139 |
if (fLastSchemaWasDuplicate) { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1140 |
newSchemaInfo = newSchemaRoot == null ? null : fDoc2XSDocumentMap.get(newSchemaRoot); |
12005 | 1141 |
} |
1142 |
else { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1143 |
newSchemaInfo = constructTrees(newSchemaRoot, schemaHint, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
1144 |
fSchemaGrammarDescription, importCollision); |
12005 | 1145 |
} |
1146 |
||
1147 |
if (localName.equals(SchemaSymbols.ELT_REDEFINE) && |
|
1148 |
newSchemaInfo != null) { |
|
1149 |
// must record which schema we're redefining so that we can |
|
1150 |
// rename the right things later! |
|
1151 |
if (fRedefine2XSDMap == null) fRedefine2XSDMap = new HashMap(); |
|
1152 |
fRedefine2XSDMap.put(child, newSchemaInfo); |
|
1153 |
} |
|
1154 |
if (newSchemaRoot != null) { |
|
1155 |
if (newSchemaInfo != null) |
|
1156 |
dependencies.addElement(newSchemaInfo); |
|
1157 |
newSchemaRoot = null; |
|
1158 |
} |
|
1159 |
} |
|
1160 |
||
1161 |
fDependencyMap.put(currSchemaInfo, dependencies); |
|
1162 |
return currSchemaInfo; |
|
1163 |
} // end constructTrees |
|
1164 |
||
1165 |
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) { |
|
1166 |
SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); |
|
1167 |
if (sg == null) { |
|
1168 |
return findGrammar(desc, ignoreConflict) != null; |
|
1169 |
} |
|
1170 |
else if (sg.isImmutable()) { |
|
1171 |
return true; |
|
1172 |
} |
|
1173 |
else { |
|
1174 |
try { |
|
1175 |
return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false)); |
|
1176 |
} |
|
1177 |
catch (MalformedURIException e) { |
|
1178 |
return false; |
|
1179 |
} |
|
1180 |
} |
|
1181 |
} |
|
1182 |
||
1183 |
/** |
|
1184 |
* Namespace growth |
|
1185 |
* |
|
1186 |
* Go through the import list of a given grammar and for each imported |
|
1187 |
* grammar, check to see if the grammar bucket has a newer version. |
|
1188 |
* If a new instance is found, we update the import list with the |
|
1189 |
* newer version. |
|
1190 |
*/ |
|
1191 |
private void updateImportListFor(SchemaGrammar grammar) { |
|
1192 |
Vector importedGrammars = grammar.getImportedGrammars(); |
|
1193 |
if (importedGrammars != null) { |
|
1194 |
for (int i=0; i<importedGrammars.size(); i++) { |
|
1195 |
SchemaGrammar isg1 = (SchemaGrammar) importedGrammars.elementAt(i); |
|
1196 |
SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace()); |
|
1197 |
if (isg2 != null && isg1 != isg2) { |
|
1198 |
importedGrammars.set(i, isg2); |
|
1199 |
} |
|
1200 |
} |
|
1201 |
} |
|
1202 |
} |
|
1203 |
||
1204 |
/** |
|
1205 |
* Namespace growth |
|
1206 |
* |
|
1207 |
* Go throuth the grammar bucket, and for each grammar in the bucket |
|
1208 |
* check the import list. If there exists a grammar in import list |
|
1209 |
* that has the same namespace as newGrammar, but a different instance, |
|
1210 |
* then update the import list and replace the old grammar instance with |
|
1211 |
* the new one |
|
1212 |
*/ |
|
1213 |
private void updateImportListWith(SchemaGrammar newGrammar) { |
|
1214 |
SchemaGrammar[] schemaGrammars = fGrammarBucket.getGrammars(); |
|
1215 |
for (int i = 0; i < schemaGrammars.length; ++i) { |
|
1216 |
SchemaGrammar sg = schemaGrammars[i]; |
|
1217 |
if (sg != newGrammar) { |
|
1218 |
Vector importedGrammars = sg.getImportedGrammars(); |
|
1219 |
if (importedGrammars != null) { |
|
1220 |
for (int j=0; j<importedGrammars.size(); j++) { |
|
1221 |
SchemaGrammar isg = (SchemaGrammar) importedGrammars.elementAt(j); |
|
1222 |
if (null2EmptyString(isg.getTargetNamespace()).equals(null2EmptyString(newGrammar.getTargetNamespace()))) { |
|
1223 |
if (isg != newGrammar) { |
|
1224 |
importedGrammars.set(j, newGrammar); |
|
1225 |
} |
|
1226 |
break; |
|
1227 |
} |
|
1228 |
} |
|
1229 |
} |
|
1230 |
} |
|
1231 |
} |
|
1232 |
} |
|
1233 |
||
1234 |
// This method builds registries for all globally-referenceable |
|
1235 |
// names. A registry will be built for each symbol space defined |
|
1236 |
// by the spec. It is also this method's job to rename redefined |
|
1237 |
// components, and to record which components redefine others (so |
|
1238 |
// that implicit redefinitions of groups and attributeGroups can be handled). |
|
1239 |
protected void buildGlobalNameRegistries() { |
|
1240 |
||
1241 |
registryEmpty = false; |
|
1242 |
// Starting with fRoot, we examine each child of the schema |
|
1243 |
// element. Skipping all imports and includes, we record the names |
|
1244 |
// of all other global components (and children of <redefine>). We |
|
1245 |
// also put <redefine> names in a registry that we look through in |
|
1246 |
// case something needs renaming. Once we're done with a schema we |
|
1247 |
// set its Document node to hidden so that we don't try to traverse |
|
1248 |
// it again; then we look to its Dependency map entry. We keep a |
|
1249 |
// stack of schemas that we haven't yet finished processing; this |
|
1250 |
// is a depth-first traversal. |
|
1251 |
||
1252 |
Stack schemasToProcess = new Stack(); |
|
1253 |
schemasToProcess.push(fRoot); |
|
1254 |
||
1255 |
while (!schemasToProcess.empty()) { |
|
1256 |
XSDocumentInfo currSchemaDoc = |
|
1257 |
(XSDocumentInfo)schemasToProcess.pop(); |
|
1258 |
Element currDoc = currSchemaDoc.fSchemaElement; |
|
1259 |
if(DOMUtil.isHidden(currDoc, fHiddenNodes)){ |
|
1260 |
// must have processed this already! |
|
1261 |
continue; |
|
1262 |
} |
|
1263 |
||
1264 |
Element currRoot = currDoc; |
|
1265 |
// process this schema's global decls |
|
1266 |
boolean dependenciesCanOccur = true; |
|
1267 |
for (Element globalComp = |
|
1268 |
DOMUtil.getFirstChildElement(currRoot); |
|
1269 |
globalComp != null; |
|
1270 |
globalComp = DOMUtil.getNextSiblingElement(globalComp)) { |
|
1271 |
// this loop makes sure the <schema> element ordering is |
|
1272 |
// also valid. |
|
1273 |
if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
1274 |
//skip it; traverse it later |
|
1275 |
continue; |
|
1276 |
} |
|
1277 |
else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_INCLUDE) || |
|
1278 |
DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_IMPORT)) { |
|
1279 |
if (!dependenciesCanOccur) { |
|
1280 |
reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp); |
|
1281 |
} |
|
1282 |
DOMUtil.setHidden(globalComp, fHiddenNodes); |
|
1283 |
} |
|
1284 |
else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) { |
|
1285 |
if (!dependenciesCanOccur) { |
|
1286 |
reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp); |
|
1287 |
} |
|
1288 |
for (Element redefineComp = DOMUtil.getFirstChildElement(globalComp); |
|
1289 |
redefineComp != null; |
|
1290 |
redefineComp = DOMUtil.getNextSiblingElement(redefineComp)) { |
|
1291 |
String lName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME); |
|
1292 |
if (lName.length() == 0) // an error we'll catch later |
|
1293 |
continue; |
|
1294 |
String qName = currSchemaDoc.fTargetNamespace == null ? |
|
1295 |
","+lName: |
|
1296 |
currSchemaDoc.fTargetNamespace +","+lName; |
|
1297 |
String componentType = DOMUtil.getLocalName(redefineComp); |
|
1298 |
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { |
|
1299 |
checkForDuplicateNames(qName, ATTRIBUTEGROUP_TYPE, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, redefineComp, currSchemaDoc); |
|
1300 |
// the check will have changed our name; |
|
1301 |
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER; |
|
1302 |
// and all we need to do is error-check+rename our kkids: |
|
1303 |
renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_ATTRIBUTEGROUP, |
|
1304 |
lName, targetLName); |
|
1305 |
} |
|
1306 |
else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) || |
|
1307 |
(componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) { |
|
1308 |
checkForDuplicateNames(qName, TYPEDECL_TYPE, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, redefineComp, currSchemaDoc); |
|
1309 |
// the check will have changed our name; |
|
1310 |
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME) + REDEF_IDENTIFIER; |
|
1311 |
// and all we need to do is error-check+rename our kkids: |
|
1312 |
if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { |
|
1313 |
renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_COMPLEXTYPE, |
|
1314 |
lName, targetLName); |
|
1315 |
} |
|
1316 |
else { // must be simpleType |
|
1317 |
renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_SIMPLETYPE, |
|
1318 |
lName, targetLName); |
|
1319 |
} |
|
1320 |
} |
|
1321 |
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { |
|
1322 |
checkForDuplicateNames(qName, GROUP_TYPE, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, redefineComp, currSchemaDoc); |
|
1323 |
// the check will have changed our name; |
|
1324 |
String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER; |
|
1325 |
// and all we need to do is error-check+rename our kids: |
|
1326 |
renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_GROUP, |
|
1327 |
lName, targetLName); |
|
1328 |
} |
|
1329 |
} // end march through <redefine> children |
|
1330 |
// and now set as traversed |
|
1331 |
//DOMUtil.setHidden(globalComp); |
|
1332 |
} |
|
1333 |
else { |
|
1334 |
dependenciesCanOccur = false; |
|
1335 |
String lName = DOMUtil.getAttrValue(globalComp, SchemaSymbols.ATT_NAME); |
|
1336 |
if (lName.length() == 0) // an error we'll catch later |
|
1337 |
continue; |
|
1338 |
String qName = currSchemaDoc.fTargetNamespace == null? |
|
1339 |
","+lName: |
|
1340 |
currSchemaDoc.fTargetNamespace +","+lName; |
|
1341 |
String componentType = DOMUtil.getLocalName(globalComp); |
|
1342 |
||
1343 |
if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) { |
|
1344 |
checkForDuplicateNames(qName, ATTRIBUTE_TYPE, fUnparsedAttributeRegistry, fUnparsedAttributeRegistrySub, globalComp, currSchemaDoc); |
|
1345 |
} |
|
1346 |
else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { |
|
1347 |
checkForDuplicateNames(qName, ATTRIBUTEGROUP_TYPE, fUnparsedAttributeGroupRegistry, fUnparsedAttributeGroupRegistrySub, globalComp, currSchemaDoc); |
|
1348 |
} |
|
1349 |
else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) || |
|
1350 |
(componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) { |
|
1351 |
checkForDuplicateNames(qName, TYPEDECL_TYPE, fUnparsedTypeRegistry, fUnparsedTypeRegistrySub, globalComp, currSchemaDoc); |
|
1352 |
} |
|
1353 |
else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) { |
|
1354 |
checkForDuplicateNames(qName, ELEMENT_TYPE, fUnparsedElementRegistry, fUnparsedElementRegistrySub, globalComp, currSchemaDoc); |
|
1355 |
} |
|
1356 |
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { |
|
1357 |
checkForDuplicateNames(qName, GROUP_TYPE, fUnparsedGroupRegistry, fUnparsedGroupRegistrySub, globalComp, currSchemaDoc); |
|
1358 |
} |
|
1359 |
else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) { |
|
1360 |
checkForDuplicateNames(qName, NOTATION_TYPE, fUnparsedNotationRegistry, fUnparsedNotationRegistrySub, globalComp, currSchemaDoc); |
|
1361 |
} |
|
1362 |
} |
|
1363 |
} // end for |
|
1364 |
||
1365 |
// now we're done with this one! |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
1366 |
DOMUtil.setHidden(currDoc, fHiddenNodes); |
12005 | 1367 |
// now add the schemas this guy depends on |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
1368 |
Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc); |
12005 | 1369 |
for (int i = 0; i < currSchemaDepends.size(); i++) { |
1370 |
schemasToProcess.push(currSchemaDepends.elementAt(i)); |
|
1371 |
} |
|
1372 |
} // while |
|
1373 |
||
1374 |
} // end buildGlobalNameRegistries |
|
1375 |
||
1376 |
// Beginning at the first schema processing was requested for |
|
1377 |
// (fRoot), this method |
|
1378 |
// examines each child (global schema information item) of each |
|
1379 |
// schema document (and of each <redefine> element) |
|
1380 |
// corresponding to an XSDocumentInfo object. If the |
|
1381 |
// readOnly field on that node has not been set, it calls an |
|
1382 |
// appropriate traverser to traverse it. Once all global decls in |
|
1383 |
// an XSDocumentInfo object have been traversed, it marks that object |
|
1384 |
// as traversed (or hidden) in order to avoid infinite loops. It completes |
|
1385 |
// when it has visited all XSDocumentInfo objects in the |
|
1386 |
// DependencyMap and marked them as traversed. |
|
1387 |
protected void traverseSchemas(ArrayList annotationInfo) { |
|
1388 |
// the process here is very similar to that in |
|
1389 |
// buildGlobalRegistries, except we can't set our schemas as |
|
1390 |
// hidden for a second time; so make them all visible again |
|
1391 |
// first! |
|
1392 |
setSchemasVisible(fRoot); |
|
1393 |
Stack schemasToProcess = new Stack(); |
|
1394 |
schemasToProcess.push(fRoot); |
|
1395 |
while (!schemasToProcess.empty()) { |
|
1396 |
XSDocumentInfo currSchemaDoc = |
|
1397 |
(XSDocumentInfo)schemasToProcess.pop(); |
|
1398 |
Element currDoc = currSchemaDoc.fSchemaElement; |
|
1399 |
||
1400 |
SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace); |
|
1401 |
||
1402 |
if(DOMUtil.isHidden(currDoc, fHiddenNodes)) { |
|
1403 |
// must have processed this already! |
|
1404 |
continue; |
|
1405 |
} |
|
1406 |
Element currRoot = currDoc; |
|
1407 |
boolean sawAnnotation = false; |
|
1408 |
// traverse this schema's global decls |
|
1409 |
for (Element globalComp = |
|
1410 |
DOMUtil.getFirstVisibleChildElement(currRoot, fHiddenNodes); |
|
1411 |
globalComp != null; |
|
1412 |
globalComp = DOMUtil.getNextVisibleSiblingElement(globalComp, fHiddenNodes)) { |
|
1413 |
DOMUtil.setHidden(globalComp, fHiddenNodes); |
|
1414 |
String componentType = DOMUtil.getLocalName(globalComp); |
|
1415 |
// includes and imports will not show up here! |
|
1416 |
if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) { |
|
1417 |
// use the namespace decls for the redefine, instead of for the parent <schema> |
|
1418 |
currSchemaDoc.backupNSSupport((fRedefine2NSSupport!=null)?(SchemaNamespaceSupport)fRedefine2NSSupport.get(globalComp):null); |
|
1419 |
for (Element redefinedComp = DOMUtil.getFirstVisibleChildElement(globalComp, fHiddenNodes); |
|
1420 |
redefinedComp != null; |
|
1421 |
redefinedComp = DOMUtil.getNextVisibleSiblingElement(redefinedComp, fHiddenNodes)) { |
|
1422 |
String redefinedComponentType = DOMUtil.getLocalName(redefinedComp); |
|
1423 |
DOMUtil.setHidden(redefinedComp, fHiddenNodes); |
|
1424 |
if (redefinedComponentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { |
|
1425 |
fAttributeGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); |
|
1426 |
} |
|
1427 |
else if (redefinedComponentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { |
|
1428 |
fComplexTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); |
|
1429 |
} |
|
1430 |
else if (redefinedComponentType.equals(SchemaSymbols.ELT_GROUP)) { |
|
1431 |
fGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); |
|
1432 |
} |
|
1433 |
else if (redefinedComponentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { |
|
1434 |
fSimpleTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); |
|
1435 |
} |
|
1436 |
// annotations will have been processed already; this is now |
|
1437 |
// unnecessary |
|
1438 |
//else if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
1439 |
// fElementTraverser.traverseAnnotationDecl(redefinedComp, null, true, currSchemaDoc); |
|
1440 |
//} |
|
1441 |
else { |
|
1442 |
reportSchemaError("s4s-elt-must-match.1", new Object [] {DOMUtil.getLocalName(globalComp), "(annotation | (simpleType | complexType | group | attributeGroup))*", redefinedComponentType}, redefinedComp); |
|
1443 |
} |
|
1444 |
} // end march through <redefine> children |
|
1445 |
currSchemaDoc.restoreNSSupport(); |
|
1446 |
} |
|
1447 |
else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) { |
|
1448 |
fAttributeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1449 |
} |
|
1450 |
else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { |
|
1451 |
fAttributeGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1452 |
} |
|
1453 |
else if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { |
|
1454 |
fComplexTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1455 |
} |
|
1456 |
else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) { |
|
1457 |
fElementTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1458 |
} |
|
1459 |
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { |
|
1460 |
fGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1461 |
} |
|
1462 |
else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) { |
|
1463 |
fNotationTraverser.traverse(globalComp, currSchemaDoc, currSG); |
|
1464 |
} |
|
1465 |
else if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { |
|
1466 |
fSimpleTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); |
|
1467 |
} |
|
1468 |
else if (componentType.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
1469 |
currSG.addAnnotation(fElementTraverser.traverseAnnotationDecl(globalComp, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc)); |
|
1470 |
sawAnnotation = true; |
|
1471 |
} |
|
1472 |
else { |
|
1473 |
reportSchemaError("s4s-elt-invalid-content.1", new Object [] {SchemaSymbols.ELT_SCHEMA, DOMUtil.getLocalName(globalComp)}, globalComp); |
|
1474 |
} |
|
1475 |
} // end for |
|
1476 |
||
1477 |
if (!sawAnnotation) { |
|
1478 |
String text = DOMUtil.getSyntheticAnnotation(currRoot); |
|
1479 |
if (text != null) { |
|
1480 |
currSG.addAnnotation(fElementTraverser.traverseSyntheticAnnotation(currRoot, text, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc)); |
|
1481 |
} |
|
1482 |
} |
|
1483 |
||
1484 |
/** Collect annotation information for validation. **/ |
|
1485 |
if (annotationInfo != null) { |
|
1486 |
XSAnnotationInfo info = currSchemaDoc.getAnnotations(); |
|
1487 |
/** Only add annotations to the list if there were any in this document. **/ |
|
1488 |
if (info != null) { |
|
1489 |
annotationInfo.add(doc2SystemId(currDoc)); |
|
1490 |
annotationInfo.add(info); |
|
1491 |
} |
|
1492 |
} |
|
1493 |
// now we're done with this one! |
|
1494 |
currSchemaDoc.returnSchemaAttrs(); |
|
1495 |
DOMUtil.setHidden(currDoc, fHiddenNodes); |
|
1496 |
||
1497 |
// now add the schemas this guy depends on |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
1498 |
Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc); |
12005 | 1499 |
for (int i = 0; i < currSchemaDepends.size(); i++) { |
1500 |
schemasToProcess.push(currSchemaDepends.elementAt(i)); |
|
1501 |
} |
|
1502 |
} // while |
|
1503 |
} // end traverseSchemas |
|
1504 |
||
1505 |
// store whether we have reported an error about that no grammar |
|
1506 |
// is found for the given namespace uri |
|
1507 |
private Vector fReportedTNS = null; |
|
1508 |
// check whether we need to report an error against the given uri. |
|
1509 |
// if we have reported an error, then we don't need to report again; |
|
1510 |
// otherwise we reported the error, and remember this fact. |
|
1511 |
private final boolean needReportTNSError(String uri) { |
|
1512 |
if (fReportedTNS == null) |
|
1513 |
fReportedTNS = new Vector(); |
|
1514 |
else if (fReportedTNS.contains(uri)) |
|
1515 |
return false; |
|
1516 |
fReportedTNS.addElement(uri); |
|
1517 |
return true; |
|
1518 |
} |
|
1519 |
||
1520 |
private static final String[] COMP_TYPE = { |
|
1521 |
null, // index 0 |
|
1522 |
"attribute declaration", |
|
1523 |
"attribute group", |
|
1524 |
"element declaration", |
|
1525 |
"group", |
|
1526 |
"identity constraint", |
|
1527 |
"notation", |
|
1528 |
"type definition", |
|
1529 |
}; |
|
1530 |
||
1531 |
private static final String[] CIRCULAR_CODES = { |
|
1532 |
"Internal-Error", |
|
1533 |
"Internal-Error", |
|
1534 |
"src-attribute_group.3", |
|
1535 |
"e-props-correct.6", |
|
1536 |
"mg-props-correct.2", |
|
1537 |
"Internal-Error", |
|
1538 |
"Internal-Error", |
|
1539 |
"st-props-correct.2", //or ct-props-correct.3 |
|
1540 |
}; |
|
1541 |
||
1542 |
// add a global attribute decl from a current schema load (only if no existing decl is found) |
|
1543 |
void addGlobalAttributeDecl(XSAttributeDecl decl) { |
|
1544 |
final String namespace = decl.getNamespace(); |
|
1545 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1546 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1547 |
||
1548 |
if (fGlobalAttrDecls.get(declKey) == null) { |
|
1549 |
fGlobalAttrDecls.put(declKey, decl); |
|
1550 |
} |
|
1551 |
} |
|
1552 |
||
1553 |
// add a global attribute group decl from a current schema load (only if no existing decl is found) |
|
1554 |
void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { |
|
1555 |
final String namespace = decl.getNamespace(); |
|
1556 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1557 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1558 |
||
1559 |
if (fGlobalAttrGrpDecls.get(declKey) == null) { |
|
1560 |
fGlobalAttrGrpDecls.put(declKey, decl); |
|
1561 |
} |
|
1562 |
} |
|
1563 |
||
1564 |
// add a global element decl from a current schema load (only if no existing decl is found) |
|
1565 |
void addGlobalElementDecl(XSElementDecl decl) { |
|
1566 |
final String namespace = decl.getNamespace(); |
|
1567 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1568 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1569 |
||
1570 |
if (fGlobalElemDecls.get(declKey) == null) { |
|
1571 |
fGlobalElemDecls.put(declKey, decl); |
|
1572 |
} |
|
1573 |
} |
|
1574 |
||
1575 |
// add a global group decl from a current schema load (only if no existing decl is found) |
|
1576 |
void addGlobalGroupDecl(XSGroupDecl decl) { |
|
1577 |
final String namespace = decl.getNamespace(); |
|
1578 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1579 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1580 |
||
1581 |
if (fGlobalGroupDecls.get(declKey) == null) { |
|
1582 |
fGlobalGroupDecls.put(declKey, decl); |
|
1583 |
} |
|
1584 |
} |
|
1585 |
||
1586 |
// add a global notation decl from a current schema load (only if no existing decl is found) |
|
1587 |
void addGlobalNotationDecl(XSNotationDecl decl) { |
|
1588 |
final String namespace = decl.getNamespace(); |
|
1589 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1590 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1591 |
||
1592 |
if (fGlobalNotationDecls.get(declKey) == null) { |
|
1593 |
fGlobalNotationDecls.put(declKey, decl); |
|
1594 |
} |
|
1595 |
} |
|
1596 |
||
1597 |
// add a global type decl from a current schema load (only if no existing decl is found) |
|
1598 |
void addGlobalTypeDecl(XSTypeDefinition decl) { |
|
1599 |
final String namespace = decl.getNamespace(); |
|
1600 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1601 |
? "," + decl.getName() : namespace + "," + decl.getName(); |
|
1602 |
||
1603 |
if (fGlobalTypeDecls.get(declKey) == null) { |
|
1604 |
fGlobalTypeDecls.put(declKey, decl); |
|
1605 |
} |
|
1606 |
} |
|
1607 |
||
1608 |
// add a identity constraint decl from a current schema load (only if no existing decl is found) |
|
1609 |
void addIDConstraintDecl(IdentityConstraint decl) { |
|
1610 |
final String namespace = decl.getNamespace(); |
|
1611 |
final String declKey = (namespace == null || namespace.length() == 0) |
|
1612 |
? "," + decl.getIdentityConstraintName() : namespace + "," + decl.getIdentityConstraintName(); |
|
1613 |
||
1614 |
if (fGlobalIDConstraintDecls.get(declKey) == null) { |
|
1615 |
fGlobalIDConstraintDecls.put(declKey, decl); |
|
1616 |
} |
|
1617 |
} |
|
1618 |
||
1619 |
private XSAttributeDecl getGlobalAttributeDecl(String declKey) { |
|
1620 |
return (XSAttributeDecl)fGlobalAttrDecls.get(declKey); |
|
1621 |
} |
|
1622 |
||
1623 |
private XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declKey) { |
|
1624 |
return (XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declKey); |
|
1625 |
} |
|
1626 |
||
1627 |
private XSElementDecl getGlobalElementDecl(String declKey) { |
|
1628 |
return (XSElementDecl)fGlobalElemDecls.get(declKey); |
|
1629 |
} |
|
1630 |
||
1631 |
private XSGroupDecl getGlobalGroupDecl(String declKey) { |
|
1632 |
return (XSGroupDecl)fGlobalGroupDecls.get(declKey); |
|
1633 |
} |
|
1634 |
||
1635 |
private XSNotationDecl getGlobalNotationDecl(String declKey) { |
|
1636 |
return (XSNotationDecl)fGlobalNotationDecls.get(declKey); |
|
1637 |
} |
|
1638 |
||
1639 |
private XSTypeDefinition getGlobalTypeDecl(String declKey) { |
|
1640 |
return (XSTypeDefinition)fGlobalTypeDecls.get(declKey); |
|
1641 |
} |
|
1642 |
||
1643 |
private IdentityConstraint getIDConstraintDecl(String declKey) { |
|
1644 |
return (IdentityConstraint)fGlobalIDConstraintDecls.get(declKey); |
|
1645 |
} |
|
1646 |
||
1647 |
// since it is forbidden for traversers to talk to each other |
|
1648 |
// directly (except wen a traverser encounters a local declaration), |
|
1649 |
// this provides a generic means for a traverser to call |
|
1650 |
// for the traversal of some declaration. An XSDocumentInfo is |
|
1651 |
// required because the XSDocumentInfo that the traverser is traversing |
|
1652 |
// may bear no relation to the one the handler is operating on. |
|
1653 |
// This method will: |
|
1654 |
// 1. See if a global definition matching declToTraverse exists; |
|
1655 |
// 2. if so, determine if there is a path from currSchema to the |
|
1656 |
// schema document where declToTraverse lives (i.e., do a lookup |
|
1657 |
// in DependencyMap); |
|
1658 |
// 3. depending on declType (which will be relevant to step 1 as |
|
1659 |
// well), call the appropriate traverser with the appropriate |
|
1660 |
// XSDocumentInfo object. |
|
1661 |
// This method returns whatever the traverser it called returned; |
|
1662 |
// this will be an Object of some kind |
|
1663 |
// that lives in the Grammar. |
|
1664 |
protected Object getGlobalDecl(XSDocumentInfo currSchema, |
|
1665 |
int declType, |
|
1666 |
QName declToTraverse, |
|
1667 |
Element elmNode) { |
|
1668 |
||
1669 |
if (DEBUG_NODE_POOL) { |
|
1670 |
System.out.println("TRAVERSE_GL: "+declToTraverse.toString()); |
|
1671 |
} |
|
1672 |
||
1673 |
// from the schema spec, all built-in types are present in all schemas, |
|
1674 |
// so if the requested component is a type, and could be found in the |
|
1675 |
// default schema grammar, we should return that type. |
|
1676 |
// otherwise (since we would support user-defined schema grammar) we'll |
|
1677 |
// use the normal way to get the decl |
|
1678 |
if (declToTraverse.uri != null && |
|
1679 |
declToTraverse.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) { |
|
1680 |
if (declType == TYPEDECL_TYPE) { |
|
1681 |
Object retObj = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(declToTraverse.localpart); |
|
1682 |
if (retObj != null) |
|
1683 |
return retObj; |
|
1684 |
} |
|
1685 |
} |
|
1686 |
||
1687 |
// now check whether this document can access the requsted namespace |
|
1688 |
if (!currSchema.isAllowedNS(declToTraverse.uri)) { |
|
1689 |
// cannot get to this schema from the one containing the requesting decl |
|
1690 |
if (currSchema.needReportTNSError(declToTraverse.uri)) { |
|
1691 |
String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2"; |
|
1692 |
reportSchemaError(code, new Object[]{fDoc2SystemId.get(currSchema.fSchemaElement), declToTraverse.uri, declToTraverse.rawname}, elmNode); |
|
1693 |
} |
|
1694 |
// Recover and continue to look for the component. |
|
1695 |
// return null; |
|
1696 |
} |
|
1697 |
||
1698 |
// check whether there is grammar for the requested namespace |
|
1699 |
SchemaGrammar sGrammar = fGrammarBucket.getGrammar(declToTraverse.uri); |
|
1700 |
if (sGrammar == null) { |
|
1701 |
if (needReportTNSError(declToTraverse.uri)) |
|
1702 |
reportSchemaError("src-resolve", new Object[]{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode); |
|
1703 |
return null; |
|
1704 |
} |
|
1705 |
||
1706 |
// if there is such grammar, check whether the requested component is in the grammar |
|
1707 |
Object retObj = getGlobalDeclFromGrammar(sGrammar, declType, declToTraverse.localpart); |
|
1708 |
String declKey = declToTraverse.uri == null? ","+declToTraverse.localpart: |
|
1709 |
declToTraverse.uri+","+declToTraverse.localpart; |
|
1710 |
||
1711 |
// if the component is parsed, return it |
|
1712 |
if (!fTolerateDuplicates) { |
|
1713 |
if (retObj != null) { |
|
1714 |
return retObj; |
|
1715 |
} |
|
1716 |
} |
|
1717 |
else { |
|
1718 |
Object retObj2 = getGlobalDecl(declKey, declType); |
|
1719 |
if (retObj2 != null) { |
|
1720 |
return retObj2; |
|
1721 |
} |
|
1722 |
} |
|
1723 |
||
1724 |
XSDocumentInfo schemaWithDecl = null; |
|
1725 |
Element decl = null; |
|
1726 |
XSDocumentInfo declDoc = null; |
|
1727 |
||
1728 |
// the component is not parsed, try to find a DOM element for it |
|
1729 |
switch (declType) { |
|
1730 |
case ATTRIBUTE_TYPE : |
|
1731 |
decl = getElementFromMap(fUnparsedAttributeRegistry, declKey); |
|
1732 |
declDoc = getDocInfoFromMap(fUnparsedAttributeRegistrySub, declKey); |
|
1733 |
break; |
|
1734 |
case ATTRIBUTEGROUP_TYPE : |
|
1735 |
decl = getElementFromMap(fUnparsedAttributeGroupRegistry, declKey); |
|
1736 |
declDoc = getDocInfoFromMap(fUnparsedAttributeGroupRegistrySub, declKey); |
|
1737 |
break; |
|
1738 |
case ELEMENT_TYPE : |
|
1739 |
decl = getElementFromMap(fUnparsedElementRegistry, declKey); |
|
1740 |
declDoc = getDocInfoFromMap(fUnparsedElementRegistrySub, declKey); |
|
1741 |
break; |
|
1742 |
case GROUP_TYPE : |
|
1743 |
decl = getElementFromMap(fUnparsedGroupRegistry, declKey); |
|
1744 |
declDoc = getDocInfoFromMap(fUnparsedGroupRegistrySub, declKey); |
|
1745 |
break; |
|
1746 |
case IDENTITYCONSTRAINT_TYPE : |
|
1747 |
decl = getElementFromMap(fUnparsedIdentityConstraintRegistry, declKey); |
|
1748 |
declDoc = getDocInfoFromMap(fUnparsedIdentityConstraintRegistrySub, declKey); |
|
1749 |
break; |
|
1750 |
case NOTATION_TYPE : |
|
1751 |
decl = getElementFromMap(fUnparsedNotationRegistry, declKey); |
|
1752 |
declDoc = getDocInfoFromMap(fUnparsedNotationRegistrySub, declKey); |
|
1753 |
break; |
|
1754 |
case TYPEDECL_TYPE : |
|
1755 |
decl = getElementFromMap(fUnparsedTypeRegistry, declKey); |
|
1756 |
declDoc = getDocInfoFromMap(fUnparsedTypeRegistrySub, declKey); |
|
1757 |
break; |
|
1758 |
default: |
|
1759 |
reportSchemaError("Internal-Error", new Object [] {"XSDHandler asked to locate component of type " + declType + "; it does not recognize this type!"}, elmNode); |
|
1760 |
} |
|
1761 |
||
1762 |
// no DOM element found, so the component can't be located |
|
1763 |
if (decl == null) { |
|
1764 |
if (retObj == null) { |
|
1765 |
reportSchemaError("src-resolve", new Object[]{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode); |
|
1766 |
} |
|
1767 |
return retObj; |
|
1768 |
} |
|
1769 |
||
1770 |
// get the schema doc containing the component to be parsed |
|
1771 |
// it should always return non-null value, but since null-checking |
|
1772 |
// comes for free, let's be safe and check again |
|
1773 |
schemaWithDecl = findXSDocumentForDecl(currSchema, decl, declDoc); |
|
1774 |
if (schemaWithDecl == null) { |
|
1775 |
// cannot get to this schema from the one containing the requesting decl |
|
1776 |
if (retObj == null) { |
|
1777 |
String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2"; |
|
1778 |
reportSchemaError(code, new Object[]{fDoc2SystemId.get(currSchema.fSchemaElement), declToTraverse.uri, declToTraverse.rawname}, elmNode); |
|
1779 |
} |
|
1780 |
return retObj; |
|
1781 |
} |
|
1782 |
||
1783 |
// a component is hidden, meaning either it's traversed, or being traversed. |
|
1784 |
// but we didn't find it in the grammar, so it's the latter case, and |
|
1785 |
// a circular reference. error! |
|
1786 |
if (DOMUtil.isHidden(decl, fHiddenNodes)) { |
|
1787 |
if (retObj == null) { |
|
1788 |
String code = CIRCULAR_CODES[declType]; |
|
1789 |
if (declType == TYPEDECL_TYPE) { |
|
1790 |
if (SchemaSymbols.ELT_COMPLEXTYPE.equals(DOMUtil.getLocalName(decl))) { |
|
1791 |
code = "ct-props-correct.3"; |
|
1792 |
} |
|
1793 |
} |
|
1794 |
// decl must not be null if we're here... |
|
1795 |
reportSchemaError(code, new Object [] {declToTraverse.prefix+":"+declToTraverse.localpart}, elmNode); |
|
1796 |
} |
|
1797 |
return retObj; |
|
1798 |
} |
|
1799 |
||
1800 |
return traverseGlobalDecl(declType, decl, schemaWithDecl, sGrammar); |
|
1801 |
} // getGlobalDecl(XSDocumentInfo, int, QName): Object |
|
1802 |
||
1803 |
// If we are tolerating duplicate declarations and allowing namespace growth |
|
1804 |
// use the declaration from the current schema load (if it exists) |
|
1805 |
protected Object getGlobalDecl(String declKey, int declType) { |
|
1806 |
Object retObj = null; |
|
1807 |
||
1808 |
switch (declType) { |
|
1809 |
case ATTRIBUTE_TYPE : |
|
1810 |
retObj = getGlobalAttributeDecl(declKey); |
|
1811 |
break; |
|
1812 |
case ATTRIBUTEGROUP_TYPE : |
|
1813 |
retObj = getGlobalAttributeGroupDecl(declKey); |
|
1814 |
break; |
|
1815 |
case ELEMENT_TYPE : |
|
1816 |
retObj = getGlobalElementDecl(declKey); |
|
1817 |
break; |
|
1818 |
case GROUP_TYPE : |
|
1819 |
retObj = getGlobalGroupDecl(declKey); |
|
1820 |
break; |
|
1821 |
case IDENTITYCONSTRAINT_TYPE : |
|
1822 |
retObj = getIDConstraintDecl(declKey); |
|
1823 |
break; |
|
1824 |
case NOTATION_TYPE : |
|
1825 |
retObj = getGlobalNotationDecl(declKey); |
|
1826 |
break; |
|
1827 |
case TYPEDECL_TYPE : |
|
1828 |
retObj = getGlobalTypeDecl(declKey); |
|
1829 |
break; |
|
1830 |
} |
|
1831 |
||
1832 |
return retObj; |
|
1833 |
} |
|
1834 |
||
1835 |
protected Object getGlobalDeclFromGrammar(SchemaGrammar sGrammar, int declType, String localpart) { |
|
1836 |
Object retObj = null; |
|
1837 |
||
1838 |
switch (declType) { |
|
1839 |
case ATTRIBUTE_TYPE : |
|
1840 |
retObj = sGrammar.getGlobalAttributeDecl(localpart); |
|
1841 |
break; |
|
1842 |
case ATTRIBUTEGROUP_TYPE : |
|
1843 |
retObj = sGrammar.getGlobalAttributeGroupDecl(localpart); |
|
1844 |
break; |
|
1845 |
case ELEMENT_TYPE : |
|
1846 |
retObj = sGrammar.getGlobalElementDecl(localpart); |
|
1847 |
break; |
|
1848 |
case GROUP_TYPE : |
|
1849 |
retObj = sGrammar.getGlobalGroupDecl(localpart); |
|
1850 |
break; |
|
1851 |
case IDENTITYCONSTRAINT_TYPE : |
|
1852 |
retObj = sGrammar.getIDConstraintDecl(localpart); |
|
1853 |
break; |
|
1854 |
case NOTATION_TYPE : |
|
1855 |
retObj = sGrammar.getGlobalNotationDecl(localpart); |
|
1856 |
break; |
|
1857 |
case TYPEDECL_TYPE : |
|
1858 |
retObj = sGrammar.getGlobalTypeDecl(localpart); |
|
1859 |
break; |
|
1860 |
} |
|
1861 |
||
1862 |
return retObj; |
|
1863 |
} |
|
1864 |
||
1865 |
protected Object getGlobalDeclFromGrammar(SchemaGrammar sGrammar, int declType, String localpart, String schemaLoc) { |
|
1866 |
Object retObj = null; |
|
1867 |
||
1868 |
switch (declType) { |
|
1869 |
case ATTRIBUTE_TYPE : |
|
1870 |
retObj = sGrammar.getGlobalAttributeDecl(localpart, schemaLoc); |
|
1871 |
break; |
|
1872 |
case ATTRIBUTEGROUP_TYPE : |
|
1873 |
retObj = sGrammar.getGlobalAttributeGroupDecl(localpart, schemaLoc); |
|
1874 |
break; |
|
1875 |
case ELEMENT_TYPE : |
|
1876 |
retObj = sGrammar.getGlobalElementDecl(localpart, schemaLoc); |
|
1877 |
break; |
|
1878 |
case GROUP_TYPE : |
|
1879 |
retObj = sGrammar.getGlobalGroupDecl(localpart, schemaLoc); |
|
1880 |
break; |
|
1881 |
case IDENTITYCONSTRAINT_TYPE : |
|
1882 |
retObj = sGrammar.getIDConstraintDecl(localpart, schemaLoc); |
|
1883 |
break; |
|
1884 |
case NOTATION_TYPE : |
|
1885 |
retObj = sGrammar.getGlobalNotationDecl(localpart, schemaLoc); |
|
1886 |
break; |
|
1887 |
case TYPEDECL_TYPE : |
|
1888 |
retObj = sGrammar.getGlobalTypeDecl(localpart, schemaLoc); |
|
1889 |
break; |
|
1890 |
} |
|
1891 |
||
1892 |
return retObj; |
|
1893 |
} |
|
1894 |
||
1895 |
protected Object traverseGlobalDecl(int declType, Element decl, XSDocumentInfo schemaDoc, SchemaGrammar grammar) { |
|
1896 |
Object retObj = null; |
|
1897 |
||
1898 |
DOMUtil.setHidden(decl, fHiddenNodes); |
|
1899 |
SchemaNamespaceSupport nsSupport = null; |
|
1900 |
// if the parent is <redefine> use the namespace delcs for it. |
|
1901 |
Element parent = DOMUtil.getParent(decl); |
|
1902 |
if (DOMUtil.getLocalName(parent).equals(SchemaSymbols.ELT_REDEFINE)) |
|
1903 |
nsSupport = (fRedefine2NSSupport!=null)?(SchemaNamespaceSupport)fRedefine2NSSupport.get(parent):null; |
|
1904 |
// back up the current SchemaNamespaceSupport, because we need to provide |
|
1905 |
// a fresh one to the traverseGlobal methods. |
|
1906 |
schemaDoc.backupNSSupport(nsSupport); |
|
1907 |
||
1908 |
// traverse the referenced global component |
|
1909 |
switch (declType) { |
|
1910 |
case TYPEDECL_TYPE : |
|
1911 |
if (DOMUtil.getLocalName(decl).equals(SchemaSymbols.ELT_COMPLEXTYPE)) { |
|
1912 |
retObj = fComplexTypeTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1913 |
} |
|
1914 |
else { |
|
1915 |
retObj = fSimpleTypeTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1916 |
} |
|
1917 |
break; |
|
1918 |
case ATTRIBUTE_TYPE : |
|
1919 |
retObj = fAttributeTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1920 |
break; |
|
1921 |
case ELEMENT_TYPE : |
|
1922 |
retObj = fElementTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1923 |
break; |
|
1924 |
case ATTRIBUTEGROUP_TYPE : |
|
1925 |
retObj = fAttributeGroupTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1926 |
break; |
|
1927 |
case GROUP_TYPE : |
|
1928 |
retObj = fGroupTraverser.traverseGlobal(decl, schemaDoc, grammar); |
|
1929 |
break; |
|
1930 |
case NOTATION_TYPE : |
|
1931 |
retObj = fNotationTraverser.traverse(decl, schemaDoc, grammar); |
|
1932 |
break; |
|
1933 |
case IDENTITYCONSTRAINT_TYPE : |
|
1934 |
// identity constraints should have been parsed already... |
|
1935 |
// we should never get here |
|
1936 |
break; |
|
1937 |
} |
|
1938 |
||
1939 |
// restore the previous SchemaNamespaceSupport, so that the caller can get |
|
1940 |
// proper namespace binding. |
|
1941 |
schemaDoc.restoreNSSupport(); |
|
1942 |
||
1943 |
return retObj; |
|
1944 |
} |
|
1945 |
||
1946 |
public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) { |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
1947 |
return fDoc2SystemId.get(schemaDoc.fSchemaElement); |
12005 | 1948 |
} |
1949 |
||
1950 |
// This method determines whether there is a group |
|
1951 |
// (attributeGroup) which the given one has redefined by |
|
1952 |
// restriction. If so, it returns it; else it returns null. |
|
1953 |
// @param type: whether what's been redefined is an |
|
1954 |
// attributeGroup or a group; |
|
1955 |
// @param name: the QName of the component doing the redefining. |
|
1956 |
// @param currSchema: schema doc in which the redefining component lives. |
|
1957 |
// @return: Object representing decl redefined if present, null |
|
1958 |
// otherwise. |
|
1959 |
Object getGrpOrAttrGrpRedefinedByRestriction(int type, QName name, XSDocumentInfo currSchema, Element elmNode) { |
|
1960 |
String realName = name.uri != null?name.uri+","+name.localpart: |
|
1961 |
","+name.localpart; |
|
1962 |
String nameToFind = null; |
|
1963 |
switch (type) { |
|
1964 |
case ATTRIBUTEGROUP_TYPE: |
|
1965 |
nameToFind = (String)fRedefinedRestrictedAttributeGroupRegistry.get(realName); |
|
1966 |
break; |
|
1967 |
case GROUP_TYPE: |
|
1968 |
nameToFind = (String)fRedefinedRestrictedGroupRegistry.get(realName); |
|
1969 |
break; |
|
1970 |
default: |
|
1971 |
return null; |
|
1972 |
} |
|
1973 |
if (nameToFind == null) return null; |
|
1974 |
int commaPos = nameToFind.indexOf(","); |
|
1975 |
QName qNameToFind = new QName(XMLSymbols.EMPTY_STRING, nameToFind.substring(commaPos+1), |
|
1976 |
nameToFind.substring(commaPos), (commaPos == 0)? null : nameToFind.substring(0, commaPos)); |
|
1977 |
Object retObj = getGlobalDecl(currSchema, type, qNameToFind, elmNode); |
|
1978 |
if(retObj == null) { |
|
1979 |
switch (type) { |
|
1980 |
case ATTRIBUTEGROUP_TYPE: |
|
1981 |
reportSchemaError("src-redefine.7.2.1", new Object []{name.localpart}, elmNode); |
|
1982 |
break; |
|
1983 |
case GROUP_TYPE: |
|
1984 |
reportSchemaError("src-redefine.6.2.1", new Object []{name.localpart}, elmNode); |
|
1985 |
break; |
|
1986 |
} |
|
1987 |
return null; |
|
1988 |
} |
|
1989 |
return retObj; |
|
1990 |
} // getGrpOrAttrGrpRedefinedByRestriction(int, QName, XSDocumentInfo): Object |
|
1991 |
||
1992 |
// Since ID constraints can occur in local elements, unless we |
|
1993 |
// wish to completely traverse all our DOM trees looking for ID |
|
1994 |
// constraints while we're building our global name registries, |
|
1995 |
// which seems terribly inefficient, we need to resolve keyrefs |
|
1996 |
// after all parsing is complete. This we can simply do by running through |
|
1997 |
// fIdentityConstraintRegistry and calling traverseKeyRef on all |
|
1998 |
// of the KeyRef nodes. This unfortunately removes this knowledge |
|
1999 |
// from the elementTraverser class (which must ignore keyrefs), |
|
2000 |
// but there seems to be no efficient way around this... |
|
2001 |
protected void resolveKeyRefs() { |
|
2002 |
for (int i=0; i<fKeyrefStackPos; i++) { |
|
2003 |
XSDocumentInfo keyrefSchemaDoc = fKeyrefsMapXSDocumentInfo[i]; |
|
2004 |
keyrefSchemaDoc.fNamespaceSupport.makeGlobal(); |
|
2005 |
keyrefSchemaDoc.fNamespaceSupport.setEffectiveContext( fKeyrefNamespaceContext[i] ); |
|
2006 |
SchemaGrammar keyrefGrammar = fGrammarBucket.getGrammar(keyrefSchemaDoc.fTargetNamespace); |
|
2007 |
// need to set <keyref> to hidden before traversing it, |
|
2008 |
// because it has global scope |
|
2009 |
DOMUtil.setHidden(fKeyrefs[i], fHiddenNodes); |
|
2010 |
fKeyrefTraverser.traverse(fKeyrefs[i], fKeyrefElems[i], keyrefSchemaDoc, keyrefGrammar); |
|
2011 |
} |
|
2012 |
} // end resolveKeyRefs |
|
2013 |
||
2014 |
// an accessor method. Just makes sure callers |
|
2015 |
// who want the Identity constraint registry vaguely know what they're about. |
|
2016 |
protected Map getIDRegistry() { |
|
2017 |
return fUnparsedIdentityConstraintRegistry; |
|
2018 |
} |
|
2019 |
// an accessor method. |
|
2020 |
protected Map getIDRegistry_sub() { |
|
2021 |
return fUnparsedIdentityConstraintRegistrySub; |
|
2022 |
} |
|
2023 |
||
2024 |
||
2025 |
||
2026 |
// This method squirrels away <keyref> declarations--along with the element |
|
2027 |
// decls and namespace bindings they might find handy. |
|
2028 |
protected void storeKeyRef (Element keyrefToStore, XSDocumentInfo schemaDoc, |
|
2029 |
XSElementDecl currElemDecl) { |
|
2030 |
String keyrefName = DOMUtil.getAttrValue(keyrefToStore, SchemaSymbols.ATT_NAME); |
|
2031 |
if (keyrefName.length() != 0) { |
|
2032 |
String keyrefQName = schemaDoc.fTargetNamespace == null? |
|
2033 |
"," + keyrefName: schemaDoc.fTargetNamespace+","+keyrefName; |
|
2034 |
checkForDuplicateNames(keyrefQName, IDENTITYCONSTRAINT_TYPE, fUnparsedIdentityConstraintRegistry, fUnparsedIdentityConstraintRegistrySub, keyrefToStore, schemaDoc); |
|
2035 |
} |
|
2036 |
// now set up all the registries we'll need... |
|
2037 |
||
2038 |
// check array sizes |
|
2039 |
if (fKeyrefStackPos == fKeyrefs.length) { |
|
2040 |
Element [] elemArray = new Element [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT]; |
|
2041 |
System.arraycopy(fKeyrefs, 0, elemArray, 0, fKeyrefStackPos); |
|
2042 |
fKeyrefs = elemArray; |
|
2043 |
XSElementDecl [] declArray = new XSElementDecl [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT]; |
|
2044 |
System.arraycopy(fKeyrefElems, 0, declArray, 0, fKeyrefStackPos); |
|
2045 |
fKeyrefElems = declArray; |
|
2046 |
String[][] stringArray = new String [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT][]; |
|
2047 |
System.arraycopy(fKeyrefNamespaceContext, 0, stringArray, 0, fKeyrefStackPos); |
|
2048 |
fKeyrefNamespaceContext = stringArray; |
|
2049 |
||
2050 |
XSDocumentInfo [] xsDocumentInfo = new XSDocumentInfo [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT]; |
|
2051 |
System.arraycopy(fKeyrefsMapXSDocumentInfo, 0, xsDocumentInfo, 0, fKeyrefStackPos); |
|
2052 |
fKeyrefsMapXSDocumentInfo = xsDocumentInfo; |
|
2053 |
||
2054 |
} |
|
2055 |
fKeyrefs[fKeyrefStackPos] = keyrefToStore; |
|
2056 |
fKeyrefElems[fKeyrefStackPos] = currElemDecl; |
|
2057 |
fKeyrefNamespaceContext[fKeyrefStackPos] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext(); |
|
2058 |
||
2059 |
fKeyrefsMapXSDocumentInfo[fKeyrefStackPos++] = schemaDoc; |
|
2060 |
} // storeKeyref (Element, XSDocumentInfo, XSElementDecl): void |
|
2061 |
||
2062 |
||
2063 |
/** |
|
2064 |
* resolveSchema method is responsible for resolving location of the schema (using XMLEntityResolver), |
|
39080
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
36146
diff
changeset
|
2065 |
* and if it was successfully resolved getting the schema Document. |
12005 | 2066 |
* @param desc |
2067 |
* @param mustResolve |
|
2068 |
* @param referElement |
|
2069 |
* @return A schema Element or null. |
|
2070 |
*/ |
|
2071 |
private Element resolveSchema(XSDDescription desc, boolean mustResolve, |
|
2072 |
Element referElement, boolean usePairs) { |
|
2073 |
XMLInputSource schemaSource = null; |
|
2074 |
try { |
|
33349 | 2075 |
Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap(); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2076 |
schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager); |
12005 | 2077 |
} |
2078 |
catch (IOException ex) { |
|
2079 |
if (mustResolve) { |
|
2080 |
reportSchemaError("schema_reference.4", |
|
2081 |
new Object[]{desc.getLocationHints()[0]}, |
|
2082 |
referElement); |
|
2083 |
} |
|
2084 |
else { |
|
2085 |
reportSchemaWarning("schema_reference.4", |
|
2086 |
new Object[]{desc.getLocationHints()[0]}, |
|
2087 |
referElement); |
|
2088 |
} |
|
2089 |
} |
|
2090 |
if (schemaSource instanceof DOMInputSource) { |
|
2091 |
return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2092 |
} // DOMInputSource |
|
2093 |
else if (schemaSource instanceof SAXInputSource) { |
|
2094 |
return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2095 |
} // SAXInputSource |
|
2096 |
else if (schemaSource instanceof StAXInputSource) { |
|
2097 |
return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2098 |
} // StAXInputSource |
|
2099 |
else if (schemaSource instanceof XSInputSource) { |
|
2100 |
return getSchemaDocument((XSInputSource) schemaSource, desc); |
|
2101 |
} // XSInputSource |
|
2102 |
return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2103 |
} // getSchema(String, String, String, boolean, short): Document |
|
2104 |
||
2105 |
private Element resolveSchema(XMLInputSource schemaSource, XSDDescription desc, |
|
2106 |
boolean mustResolve, Element referElement) { |
|
2107 |
||
2108 |
if (schemaSource instanceof DOMInputSource) { |
|
2109 |
return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2110 |
} // DOMInputSource |
|
2111 |
else if (schemaSource instanceof SAXInputSource) { |
|
2112 |
return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2113 |
} // SAXInputSource |
|
2114 |
else if (schemaSource instanceof StAXInputSource) { |
|
2115 |
return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2116 |
} // StAXInputSource |
|
2117 |
else if (schemaSource instanceof XSInputSource) { |
|
2118 |
return getSchemaDocument((XSInputSource) schemaSource, desc); |
|
2119 |
} // XSInputSource |
|
2120 |
return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement); |
|
2121 |
} |
|
2122 |
||
2123 |
private XMLInputSource resolveSchemaSource(XSDDescription desc, boolean mustResolve, |
|
2124 |
Element referElement, boolean usePairs) { |
|
2125 |
||
2126 |
XMLInputSource schemaSource = null; |
|
2127 |
try { |
|
33349 | 2128 |
Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap(); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2129 |
schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager); |
12005 | 2130 |
} |
2131 |
catch (IOException ex) { |
|
2132 |
if (mustResolve) { |
|
2133 |
reportSchemaError("schema_reference.4", |
|
2134 |
new Object[]{desc.getLocationHints()[0]}, |
|
2135 |
referElement); |
|
2136 |
} |
|
2137 |
else { |
|
2138 |
reportSchemaWarning("schema_reference.4", |
|
2139 |
new Object[]{desc.getLocationHints()[0]}, |
|
2140 |
referElement); |
|
2141 |
} |
|
2142 |
} |
|
2143 |
||
2144 |
return schemaSource; |
|
2145 |
} |
|
2146 |
||
2147 |
/** |
|
2148 |
* getSchemaDocument method uses XMLInputSource to parse a schema document. |
|
2149 |
* @param schemaNamespace |
|
2150 |
* @param schemaSource |
|
2151 |
* @param mustResolve |
|
2152 |
* @param referType |
|
2153 |
* @param referElement |
|
2154 |
* @return A schema Element. |
|
2155 |
*/ |
|
2156 |
private Element getSchemaDocument(String schemaNamespace, XMLInputSource schemaSource, |
|
2157 |
boolean mustResolve, short referType, Element referElement) { |
|
2158 |
||
2159 |
boolean hasInput = true; |
|
2160 |
IOException exception = null; |
|
2161 |
// contents of this method will depend on the system we adopt for entity resolution--i.e., XMLEntityHandler, EntityHandler, etc. |
|
2162 |
Element schemaElement = null; |
|
2163 |
try { |
|
2164 |
// when the system id and byte stream and character stream |
|
2165 |
// of the input source are all null, it's |
|
2166 |
// impossible to find the schema document. so we skip in |
|
2167 |
// this case. otherwise we'll receive some NPE or |
|
2168 |
// file not found errors. but schemaHint=="" is perfectly |
|
2169 |
// legal for import. |
|
2170 |
if (schemaSource != null && |
|
2171 |
(schemaSource.getSystemId() != null || |
|
2172 |
schemaSource.getByteStream() != null || |
|
2173 |
schemaSource.getCharacterStream() != null)) { |
|
2174 |
||
2175 |
// When the system id of the input source is used, first try to |
|
2176 |
// expand it, and check whether the same document has been |
|
2177 |
// parsed before. If so, return the document corresponding to |
|
2178 |
// that system id. |
|
2179 |
XSDKey key = null; |
|
2180 |
String schemaId = null; |
|
2181 |
if (referType != XSDDescription.CONTEXT_PREPARSE){ |
|
2182 |
schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); |
|
2183 |
key = new XSDKey(schemaId, referType, schemaNamespace); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2184 |
if((schemaElement = fTraversed.get(key)) != null) { |
12005 | 2185 |
fLastSchemaWasDuplicate = true; |
2186 |
return schemaElement; |
|
2187 |
} |
|
39080
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
36146
diff
changeset
|
2188 |
if ((!schemaSource.isCreatedByResolver()) && |
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
36146
diff
changeset
|
2189 |
(referType == XSDDescription.CONTEXT_IMPORT || referType == XSDDescription.CONTEXT_INCLUDE |
57563e513b11
8158204: accessExternalSchema property handling is inconsistent and differs from spec.
joehw
parents:
36146
diff
changeset
|
2190 |
|| referType == XSDDescription.CONTEXT_REDEFINE)) { |
17534 | 2191 |
String accessError = SecuritySupport.checkAccess(schemaId, fAccessExternalSchema, Constants.ACCESS_EXTERNAL_ALL); |
2192 |
if (accessError != null) { |
|
2193 |
reportSchemaFatalError("schema_reference.access", |
|
2194 |
new Object[] { SecuritySupport.sanitizePath(schemaId), accessError }, |
|
2195 |
referElement); |
|
2196 |
} |
|
2197 |
} |
|
12005 | 2198 |
} |
2199 |
||
2200 |
fSchemaParser.parse(schemaSource); |
|
2201 |
Document schemaDocument = fSchemaParser.getDocument(); |
|
2202 |
schemaElement = schemaDocument != null ? DOMUtil.getRoot(schemaDocument) : null; |
|
2203 |
return getSchemaDocument0(key, schemaId, schemaElement); |
|
2204 |
} |
|
2205 |
else { |
|
2206 |
hasInput = false; |
|
2207 |
} |
|
2208 |
} |
|
2209 |
catch (IOException ex) { |
|
2210 |
exception = ex; |
|
2211 |
} |
|
2212 |
return getSchemaDocument1(mustResolve, hasInput, schemaSource, referElement, exception); |
|
2213 |
} // getSchemaDocument(String, XMLInputSource, boolean, short, Element): Element |
|
2214 |
||
2215 |
/** |
|
2216 |
* getSchemaDocument method uses SAXInputSource to parse a schema document. |
|
2217 |
* @param schemaNamespace |
|
2218 |
* @param schemaSource |
|
2219 |
* @param mustResolve |
|
2220 |
* @param referType |
|
2221 |
* @param referElement |
|
2222 |
* @return A schema Element. |
|
2223 |
*/ |
|
2224 |
private Element getSchemaDocument(String schemaNamespace, SAXInputSource schemaSource, |
|
2225 |
boolean mustResolve, short referType, Element referElement) { |
|
2226 |
XMLReader parser = schemaSource.getXMLReader(); |
|
2227 |
InputSource inputSource = schemaSource.getInputSource(); |
|
2228 |
boolean hasInput = true; |
|
2229 |
IOException exception = null; |
|
2230 |
Element schemaElement = null; |
|
2231 |
try { |
|
2232 |
if (inputSource != null && |
|
2233 |
(inputSource.getSystemId() != null || |
|
2234 |
inputSource.getByteStream() != null || |
|
2235 |
inputSource.getCharacterStream() != null)) { |
|
2236 |
||
2237 |
// check whether the same document has been parsed before. |
|
2238 |
// If so, return the document corresponding to that system id. |
|
2239 |
XSDKey key = null; |
|
2240 |
String schemaId = null; |
|
2241 |
if (referType != XSDDescription.CONTEXT_PREPARSE) { |
|
2242 |
schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false); |
|
2243 |
key = new XSDKey(schemaId, referType, schemaNamespace); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2244 |
if ((schemaElement = fTraversed.get(key)) != null) { |
12005 | 2245 |
fLastSchemaWasDuplicate = true; |
2246 |
return schemaElement; |
|
2247 |
} |
|
2248 |
} |
|
2249 |
||
2250 |
boolean namespacePrefixes = false; |
|
2251 |
if (parser != null) { |
|
2252 |
try { |
|
2253 |
namespacePrefixes = parser.getFeature(NAMESPACE_PREFIXES); |
|
2254 |
} |
|
2255 |
catch (SAXException se) {} |
|
2256 |
} |
|
2257 |
else { |
|
2258 |
try { |
|
2259 |
parser = XMLReaderFactory.createXMLReader(); |
|
2260 |
} |
|
2261 |
// If something went wrong with the factory |
|
2262 |
// just use our own SAX parser. |
|
2263 |
catch (SAXException se) { |
|
2264 |
parser = new SAXParser(); |
|
2265 |
} |
|
2266 |
try { |
|
2267 |
parser.setFeature(NAMESPACE_PREFIXES, true); |
|
2268 |
namespacePrefixes = true; |
|
2269 |
// If this is a Xerces SAX parser set the security manager if there is one |
|
2270 |
if (parser instanceof SAXParser) { |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2271 |
if (fSecurityManager != null) { |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2272 |
parser.setProperty(SECURITY_MANAGER, fSecurityManager); |
12005 | 2273 |
} |
2274 |
} |
|
2275 |
} |
|
2276 |
catch (SAXException se) {} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
2277 |
|
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
2278 |
try { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
2279 |
parser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, fAccessExternalDTD); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
2280 |
} catch (SAXNotRecognizedException exc) { |
35729
49f1515c5f5c
8144593: Suppress not recognized property/feature warning messages from SAXParser
aefimov
parents:
33349
diff
changeset
|
2281 |
XMLSecurityManager.printWarning(parser.getClass().getName(), |
49f1515c5f5c
8144593: Suppress not recognized property/feature warning messages from SAXParser
aefimov
parents:
33349
diff
changeset
|
2282 |
XMLConstants.ACCESS_EXTERNAL_DTD, exc); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
2283 |
} |
12005 | 2284 |
} |
2285 |
// If XML names and Namespace URIs are already internalized we |
|
2286 |
// can avoid running them through the SymbolTable. |
|
2287 |
boolean stringsInternalized = false; |
|
2288 |
try { |
|
2289 |
stringsInternalized = parser.getFeature(STRING_INTERNING); |
|
2290 |
} |
|
2291 |
catch (SAXException exc) { |
|
2292 |
// The feature isn't recognized or getting it is not supported. |
|
2293 |
// In either case, assume that strings are not internalized. |
|
2294 |
} |
|
2295 |
if (fXSContentHandler == null) { |
|
2296 |
fXSContentHandler = new SchemaContentHandler(); |
|
2297 |
} |
|
2298 |
fXSContentHandler.reset(fSchemaParser, fSymbolTable, |
|
2299 |
namespacePrefixes, stringsInternalized); |
|
2300 |
parser.setContentHandler(fXSContentHandler); |
|
2301 |
parser.setErrorHandler(fErrorReporter.getSAXErrorHandler()); |
|
2302 |
||
2303 |
parser.parse(inputSource); |
|
2304 |
// Disconnect the schema loader and other objects from the XMLReader |
|
2305 |
try { |
|
2306 |
parser.setContentHandler(null); |
|
2307 |
parser.setErrorHandler(null); |
|
2308 |
} |
|
2309 |
// Ignore any exceptions thrown by the XMLReader. Old versions of SAX |
|
2310 |
// required an XMLReader to throw a NullPointerException if an attempt |
|
2311 |
// to set a handler to null was made. |
|
2312 |
catch (Exception e) {} |
|
2313 |
||
2314 |
Document schemaDocument = fXSContentHandler.getDocument(); |
|
2315 |
schemaElement = schemaDocument != null ? DOMUtil.getRoot(schemaDocument) : null; |
|
2316 |
return getSchemaDocument0(key, schemaId, schemaElement); |
|
2317 |
} |
|
2318 |
else { |
|
2319 |
hasInput = false; |
|
2320 |
} |
|
2321 |
} |
|
2322 |
catch (SAXParseException spe) { |
|
2323 |
throw SAX2XNIUtil.createXMLParseException0(spe); |
|
2324 |
} |
|
2325 |
catch (SAXException se) { |
|
2326 |
throw SAX2XNIUtil.createXNIException0(se); |
|
2327 |
} |
|
2328 |
catch (IOException ioe) { |
|
2329 |
exception = ioe; |
|
2330 |
} |
|
2331 |
return getSchemaDocument1(mustResolve, hasInput, schemaSource, referElement, exception); |
|
2332 |
} // getSchemaDocument(String, SAXInputSource, boolean, short, Element): Element |
|
2333 |
||
2334 |
/** |
|
2335 |
* getSchemaDocument method uses DOMInputSource to parse a schema document. |
|
2336 |
* @param schemaNamespace |
|
2337 |
* @param schemaSource |
|
2338 |
* @param mustResolve |
|
2339 |
* @param referType |
|
2340 |
* @param referElement |
|
2341 |
* @return A schema Element. |
|
2342 |
*/ |
|
2343 |
private Element getSchemaDocument(String schemaNamespace, DOMInputSource schemaSource, |
|
2344 |
boolean mustResolve, short referType, Element referElement) { |
|
2345 |
boolean hasInput = true; |
|
2346 |
IOException exception = null; |
|
2347 |
Element schemaElement = null; |
|
2348 |
Element schemaRootElement = null; |
|
2349 |
||
2350 |
final Node node = schemaSource.getNode(); |
|
2351 |
short nodeType = -1; |
|
2352 |
if (node != null) { |
|
2353 |
nodeType = node.getNodeType(); |
|
2354 |
if (nodeType == Node.DOCUMENT_NODE) { |
|
2355 |
schemaRootElement = DOMUtil.getRoot((Document) node); |
|
2356 |
} |
|
2357 |
else if (nodeType == Node.ELEMENT_NODE) { |
|
2358 |
schemaRootElement = (Element) node; |
|
2359 |
} |
|
2360 |
} |
|
2361 |
||
2362 |
try { |
|
2363 |
if (schemaRootElement != null) { |
|
2364 |
// check whether the same document has been parsed before. |
|
2365 |
// If so, return the document corresponding to that system id. |
|
2366 |
XSDKey key = null; |
|
2367 |
String schemaId = null; |
|
2368 |
if (referType != XSDDescription.CONTEXT_PREPARSE) { |
|
2369 |
schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); |
|
2370 |
boolean isDocument = (nodeType == Node.DOCUMENT_NODE); |
|
2371 |
if (!isDocument) { |
|
2372 |
Node parent = schemaRootElement.getParentNode(); |
|
2373 |
if (parent != null) { |
|
2374 |
isDocument = (parent.getNodeType() == Node.DOCUMENT_NODE); |
|
2375 |
} |
|
2376 |
} |
|
2377 |
if (isDocument) { |
|
2378 |
key = new XSDKey(schemaId, referType, schemaNamespace); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2379 |
if ((schemaElement = fTraversed.get(key)) != null) { |
12005 | 2380 |
fLastSchemaWasDuplicate = true; |
2381 |
return schemaElement; |
|
2382 |
} |
|
2383 |
} |
|
2384 |
} |
|
2385 |
||
2386 |
schemaElement = schemaRootElement; |
|
2387 |
return getSchemaDocument0(key, schemaId, schemaElement); |
|
2388 |
} |
|
2389 |
else { |
|
2390 |
hasInput = false; |
|
2391 |
} |
|
2392 |
} |
|
2393 |
catch (IOException ioe) { |
|
2394 |
exception = ioe; |
|
2395 |
} |
|
2396 |
return getSchemaDocument1(mustResolve, hasInput, schemaSource, referElement, exception); |
|
2397 |
} // getSchemaDocument(String, DOMInputSource, boolean, short, Element): Element |
|
2398 |
||
2399 |
/** |
|
2400 |
* getSchemaDocument method uses StAXInputSource to parse a schema document. |
|
2401 |
* @param schemaNamespace |
|
2402 |
* @param schemaSource |
|
2403 |
* @param mustResolve |
|
2404 |
* @param referType |
|
2405 |
* @param referElement |
|
2406 |
* @return A schema Element. |
|
2407 |
*/ |
|
2408 |
private Element getSchemaDocument(String schemaNamespace, StAXInputSource schemaSource, |
|
2409 |
boolean mustResolve, short referType, Element referElement) { |
|
2410 |
IOException exception = null; |
|
2411 |
Element schemaElement = null; |
|
2412 |
try { |
|
2413 |
final boolean consumeRemainingContent = schemaSource.shouldConsumeRemainingContent(); |
|
2414 |
final XMLStreamReader streamReader = schemaSource.getXMLStreamReader(); |
|
2415 |
final XMLEventReader eventReader = schemaSource.getXMLEventReader(); |
|
2416 |
||
2417 |
// check whether the same document has been parsed before. |
|
2418 |
// If so, return the document corresponding to that system id. |
|
2419 |
XSDKey key = null; |
|
2420 |
String schemaId = null; |
|
2421 |
if (referType != XSDDescription.CONTEXT_PREPARSE) { |
|
2422 |
schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); |
|
2423 |
boolean isDocument = consumeRemainingContent; |
|
2424 |
if (!isDocument) { |
|
2425 |
if (streamReader != null) { |
|
2426 |
isDocument = (streamReader.getEventType() == XMLStreamReader.START_DOCUMENT); |
|
2427 |
} |
|
2428 |
else { |
|
2429 |
isDocument = eventReader.peek().isStartDocument(); |
|
2430 |
} |
|
2431 |
} |
|
2432 |
if (isDocument) { |
|
2433 |
key = new XSDKey(schemaId, referType, schemaNamespace); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
2434 |
if ((schemaElement = fTraversed.get(key)) != null) { |
12005 | 2435 |
fLastSchemaWasDuplicate = true; |
2436 |
return schemaElement; |
|
2437 |
} |
|
2438 |
} |
|
2439 |
} |
|
2440 |
||
2441 |
if (fStAXSchemaParser == null) { |
|
2442 |
fStAXSchemaParser = new StAXSchemaParser(); |
|
2443 |
} |
|
2444 |
fStAXSchemaParser.reset(fSchemaParser, fSymbolTable); |
|
2445 |
||
2446 |
if (streamReader != null) { |
|
2447 |
fStAXSchemaParser.parse(streamReader); |
|
2448 |
if (consumeRemainingContent) { |
|
2449 |
while (streamReader.hasNext()) { |
|
2450 |
streamReader.next(); |
|
2451 |
} |
|
2452 |
} |
|
2453 |
} |
|
2454 |
else { |
|
2455 |
fStAXSchemaParser.parse(eventReader); |
|
2456 |
if (consumeRemainingContent) { |
|
2457 |
while (eventReader.hasNext()) { |
|
2458 |
eventReader.nextEvent(); |
|
2459 |
} |
|
2460 |
} |
|
2461 |
} |
|
2462 |
Document schemaDocument = fStAXSchemaParser.getDocument(); |
|
2463 |
schemaElement = schemaDocument != null ? DOMUtil.getRoot(schemaDocument) : null; |
|
2464 |
return getSchemaDocument0(key, schemaId, schemaElement); |
|
2465 |
} |
|
2466 |
catch (XMLStreamException e) { |
|
2467 |
StAXLocationWrapper slw = new StAXLocationWrapper(); |
|
2468 |
slw.setLocation(e.getLocation()); |
|
2469 |
throw new XMLParseException(slw, e.getMessage(), e); |
|
2470 |
} |
|
2471 |
catch (IOException e) { |
|
2472 |
exception = e; |
|
2473 |
} |
|
2474 |
return getSchemaDocument1(mustResolve, true, schemaSource, referElement, exception); |
|
2475 |
} // getSchemaDocument(String, StAXInputSource, boolean, short, Element): Element |
|
2476 |
||
2477 |
/** |
|
2478 |
* Code shared between the various getSchemaDocument() methods which |
|
2479 |
* stores mapping information for the document. |
|
2480 |
*/ |
|
2481 |
private Element getSchemaDocument0(XSDKey key, String schemaId, Element schemaElement) { |
|
2482 |
// now we need to store the mapping information from system id |
|
2483 |
// to the document. also from the document to the system id. |
|
2484 |
if (key != null) { |
|
2485 |
fTraversed.put(key, schemaElement); |
|
2486 |
} |
|
2487 |
if (schemaId != null) { |
|
2488 |
fDoc2SystemId.put(schemaElement, schemaId); |
|
2489 |
} |
|
2490 |
fLastSchemaWasDuplicate = false; |
|
2491 |
return schemaElement; |
|
2492 |
} // getSchemaDocument0(XSDKey, String, Element): Element |
|
2493 |
||
2494 |
/** |
|
2495 |
* Error handling code shared between the various getSchemaDocument() methods. |
|
2496 |
*/ |
|
2497 |
private Element getSchemaDocument1(boolean mustResolve, boolean hasInput, |
|
2498 |
XMLInputSource schemaSource, Element referElement, IOException ioe) { |
|
2499 |
// either an error occured (exception), or empty input source was |
|
2500 |
// returned, we need to report an error or a warning |
|
2501 |
if (mustResolve) { |
|
2502 |
if (hasInput) { |
|
2503 |
reportSchemaError("schema_reference.4", |
|
2504 |
new Object[]{schemaSource.getSystemId()}, |
|
2505 |
referElement, ioe); |
|
2506 |
} |
|
2507 |
else { |
|
2508 |
reportSchemaError("schema_reference.4", |
|
2509 |
new Object[]{schemaSource == null ? "" : schemaSource.getSystemId()}, |
|
2510 |
referElement, ioe); |
|
2511 |
} |
|
2512 |
} |
|
2513 |
else if (hasInput) { |
|
2514 |
reportSchemaWarning("schema_reference.4", |
|
2515 |
new Object[]{schemaSource.getSystemId()}, |
|
2516 |
referElement, ioe); |
|
2517 |
} |
|
2518 |
||
2519 |
fLastSchemaWasDuplicate = false; |
|
2520 |
return null; |
|
2521 |
} // getSchemaDocument1(boolean, boolean, XMLInputSource, Element): Element |
|
2522 |
||
2523 |
/** |
|
2524 |
* getSchemaDocument method uses XMLInputSource to parse a schema document. |
|
2525 |
* @param schemaNamespace |
|
2526 |
* @param schemaSource |
|
2527 |
* @param mustResolve |
|
2528 |
* @param referType |
|
2529 |
* @param referElement |
|
2530 |
* @return A schema Element. |
|
2531 |
*/ |
|
2532 |
private Element getSchemaDocument(XSInputSource schemaSource, XSDDescription desc) { |
|
2533 |
||
2534 |
SchemaGrammar[] grammars = schemaSource.getGrammars(); |
|
2535 |
short referType = desc.getContextType(); |
|
2536 |
||
2537 |
if (grammars != null && grammars.length > 0) { |
|
2538 |
Vector expandedGrammars = expandGrammars(grammars); |
|
2539 |
// check for existing grammars in our bucket |
|
2540 |
// and if there exist any, and namespace growth is |
|
2541 |
// not enabled - we do nothing |
|
2542 |
if (fNamespaceGrowth || !existingGrammars(expandedGrammars)) { |
|
2543 |
addGrammars(expandedGrammars); |
|
2544 |
if (referType == XSDDescription.CONTEXT_PREPARSE) { |
|
2545 |
desc.setTargetNamespace(grammars[0].getTargetNamespace()); |
|
2546 |
} |
|
2547 |
} |
|
2548 |
} |
|
2549 |
else { |
|
2550 |
XSObject[] components = schemaSource.getComponents(); |
|
2551 |
if (components != null && components.length > 0) { |
|
2552 |
Map<String, Vector> importDependencies = new HashMap(); |
|
2553 |
Vector expandedComponents = expandComponents(components, importDependencies); |
|
2554 |
if (fNamespaceGrowth || canAddComponents(expandedComponents)) { |
|
2555 |
addGlobalComponents(expandedComponents, importDependencies); |
|
2556 |
if (referType == XSDDescription.CONTEXT_PREPARSE) { |
|
2557 |
desc.setTargetNamespace(components[0].getNamespace()); |
|
2558 |
} |
|
2559 |
} |
|
2560 |
} |
|
2561 |
} |
|
2562 |
return null; |
|
2563 |
} // getSchemaDocument(String, XSInputSource, boolean, short, Element): Element |
|
2564 |
||
2565 |
private Vector expandGrammars(SchemaGrammar[] grammars) { |
|
2566 |
Vector currGrammars = new Vector(); |
|
2567 |
||
2568 |
for (int i=0; i<grammars.length; i++) { |
|
2569 |
if (!currGrammars.contains(grammars[i])) { |
|
2570 |
currGrammars.add(grammars[i]); |
|
2571 |
} |
|
2572 |
} |
|
2573 |
||
2574 |
// for all (recursively) imported grammars |
|
2575 |
SchemaGrammar sg1, sg2; |
|
2576 |
Vector gs; |
|
2577 |
for (int i = 0; i < currGrammars.size(); i++) { |
|
2578 |
// get the grammar |
|
2579 |
sg1 = (SchemaGrammar)currGrammars.elementAt(i); |
|
2580 |
// we need to add grammars imported by sg1 too |
|
2581 |
gs = sg1.getImportedGrammars(); |
|
2582 |
// for all grammars imported by sg2, but not in the vector |
|
2583 |
// we add them to the vector |
|
2584 |
if (gs == null) { |
|
2585 |
continue; |
|
2586 |
} |
|
2587 |
||
2588 |
for (int j = gs.size() - 1; j >= 0; j--) { |
|
2589 |
sg2 = (SchemaGrammar)gs.elementAt(j); |
|
2590 |
if (!currGrammars.contains(sg2)) { |
|
2591 |
currGrammars.addElement(sg2); |
|
2592 |
} |
|
2593 |
} |
|
2594 |
} |
|
2595 |
||
2596 |
return currGrammars; |
|
2597 |
} |
|
2598 |
||
2599 |
private boolean existingGrammars(Vector grammars) { |
|
2600 |
int length = grammars.size(); |
|
2601 |
final XSDDescription desc = new XSDDescription(); |
|
2602 |
||
2603 |
for (int i=0; i < length; i++) { |
|
2604 |
final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i); |
|
2605 |
desc.setNamespace(sg1.getTargetNamespace()); |
|
2606 |
||
2607 |
final SchemaGrammar sg2 = findGrammar(desc, false); |
|
2608 |
if (sg2 != null) { |
|
2609 |
return true; |
|
2610 |
} |
|
2611 |
} |
|
2612 |
||
2613 |
return false; |
|
2614 |
} |
|
2615 |
||
2616 |
private boolean canAddComponents(Vector components) { |
|
2617 |
final int size = components.size(); |
|
2618 |
final XSDDescription desc = new XSDDescription(); |
|
2619 |
for (int i=0; i<size; i++) { |
|
2620 |
XSObject component = (XSObject) components.elementAt(i); |
|
2621 |
if (!canAddComponent(component, desc)) { |
|
2622 |
return false; |
|
2623 |
} |
|
2624 |
} |
|
2625 |
return true; |
|
2626 |
} |
|
2627 |
||
2628 |
private boolean canAddComponent(XSObject component, XSDDescription desc) { |
|
2629 |
desc.setNamespace(component.getNamespace()); |
|
2630 |
||
2631 |
final SchemaGrammar sg = findGrammar(desc, false); |
|
2632 |
if (sg == null) { |
|
2633 |
return true; |
|
2634 |
} |
|
2635 |
else if (sg.isImmutable()) { |
|
2636 |
return false; |
|
2637 |
} |
|
2638 |
||
2639 |
short componentType = component.getType(); |
|
2640 |
final String name = component.getName(); |
|
2641 |
||
2642 |
switch (componentType) { |
|
2643 |
case XSConstants.TYPE_DEFINITION : |
|
2644 |
if (sg.getGlobalTypeDecl(name) == component) { |
|
2645 |
return true; |
|
2646 |
} |
|
2647 |
break; |
|
2648 |
case XSConstants.ATTRIBUTE_DECLARATION : |
|
2649 |
if (sg.getGlobalAttributeDecl(name) == component) { |
|
2650 |
return true; |
|
2651 |
} |
|
2652 |
break; |
|
2653 |
case XSConstants.ATTRIBUTE_GROUP : |
|
2654 |
if (sg.getGlobalAttributeDecl(name) == component) { |
|
2655 |
return true; |
|
2656 |
} |
|
2657 |
break; |
|
2658 |
case XSConstants.ELEMENT_DECLARATION : |
|
2659 |
if (sg.getGlobalElementDecl(name) == component) { |
|
2660 |
return true; |
|
2661 |
} |
|
2662 |
break; |
|
2663 |
case XSConstants.MODEL_GROUP_DEFINITION : |
|
2664 |
if (sg.getGlobalGroupDecl(name) == component) { |
|
2665 |
return true; |
|
2666 |
} |
|
2667 |
break; |
|
2668 |
case XSConstants.NOTATION_DECLARATION : |
|
2669 |
if (sg.getGlobalNotationDecl(name) == component) { |
|
2670 |
return true; |
|
2671 |
} |
|
2672 |
break; |
|
2673 |
case XSConstants.IDENTITY_CONSTRAINT : |
|
2674 |
case XSConstants.ATTRIBUTE_USE : |
|
2675 |
default : |
|
2676 |
return true; |
|
2677 |
} |
|
2678 |
return false; |
|
2679 |
} |
|
2680 |
||
2681 |
private void addGrammars(Vector grammars) { |
|
2682 |
int length = grammars.size(); |
|
2683 |
XSDDescription desc = new XSDDescription(); |
|
2684 |
||
2685 |
for (int i=0; i < length; i++) { |
|
2686 |
final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i); |
|
2687 |
desc.setNamespace(sg1.getTargetNamespace()); |
|
2688 |
||
2689 |
final SchemaGrammar sg2 = findGrammar(desc, fNamespaceGrowth); |
|
2690 |
if (sg1 != sg2) { |
|
2691 |
addGrammarComponents(sg1, sg2); |
|
2692 |
} |
|
2693 |
} |
|
2694 |
} |
|
2695 |
||
2696 |
private void addGrammarComponents(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2697 |
if (dstGrammar == null) { |
|
2698 |
createGrammarFrom(srcGrammar); |
|
2699 |
return; |
|
2700 |
} |
|
2701 |
||
2702 |
SchemaGrammar tmpGrammar = dstGrammar; |
|
2703 |
if (tmpGrammar.isImmutable()) { |
|
2704 |
tmpGrammar = createGrammarFrom(dstGrammar); |
|
2705 |
} |
|
2706 |
||
2707 |
// add any new locations |
|
2708 |
addNewGrammarLocations(srcGrammar, tmpGrammar); |
|
2709 |
||
2710 |
// add any new imported grammars |
|
2711 |
addNewImportedGrammars(srcGrammar, tmpGrammar); |
|
2712 |
||
2713 |
// add any new global components |
|
2714 |
addNewGrammarComponents(srcGrammar, tmpGrammar); |
|
2715 |
} |
|
2716 |
||
2717 |
private SchemaGrammar createGrammarFrom(SchemaGrammar grammar) { |
|
2718 |
SchemaGrammar newGrammar = new SchemaGrammar(grammar); |
|
2719 |
fGrammarBucket.putGrammar(newGrammar); |
|
2720 |
// update all the grammars in the bucket to point to the new grammar. |
|
2721 |
updateImportListWith(newGrammar); |
|
2722 |
// update import list of the new grammar |
|
2723 |
updateImportListFor(newGrammar); |
|
2724 |
return newGrammar; |
|
2725 |
} |
|
2726 |
||
2727 |
private void addNewGrammarLocations(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2728 |
final StringList locations = srcGrammar.getDocumentLocations(); |
|
2729 |
final int locSize = locations.size(); |
|
2730 |
final StringList locations2 = dstGrammar.getDocumentLocations(); |
|
2731 |
||
2732 |
for (int i=0; i<locSize; i++) { |
|
2733 |
String loc = locations.item(i); |
|
2734 |
if (!locations2.contains(loc)) { |
|
2735 |
dstGrammar.addDocument(null, loc); |
|
2736 |
} |
|
2737 |
} |
|
2738 |
} |
|
2739 |
||
2740 |
private void addNewImportedGrammars(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2741 |
final Vector igs1 = srcGrammar.getImportedGrammars(); |
|
2742 |
if (igs1 != null) { |
|
2743 |
Vector igs2 = dstGrammar.getImportedGrammars(); |
|
2744 |
||
2745 |
if (igs2 == null) { |
|
2746 |
igs2 = ((Vector) igs1.clone()); |
|
2747 |
dstGrammar.setImportedGrammars(igs2); |
|
2748 |
} |
|
2749 |
else { |
|
2750 |
updateImportList(igs1, igs2); |
|
2751 |
} |
|
2752 |
} |
|
2753 |
} |
|
2754 |
||
2755 |
private void updateImportList(Vector importedSrc, Vector importedDst) |
|
2756 |
{ |
|
2757 |
final int size = importedSrc.size(); |
|
2758 |
||
2759 |
for (int i=0; i<size; i++) { |
|
2760 |
final SchemaGrammar sg = (SchemaGrammar) importedSrc.elementAt(i); |
|
2761 |
if (!containedImportedGrammar(importedDst, sg)) { |
|
2762 |
importedDst.add(sg); |
|
2763 |
} |
|
2764 |
} |
|
2765 |
} |
|
2766 |
||
2767 |
private void addNewGrammarComponents(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2768 |
dstGrammar.resetComponents(); |
|
2769 |
addGlobalElementDecls(srcGrammar, dstGrammar); |
|
2770 |
addGlobalAttributeDecls(srcGrammar, dstGrammar); |
|
2771 |
addGlobalAttributeGroupDecls(srcGrammar, dstGrammar); |
|
2772 |
addGlobalGroupDecls(srcGrammar, dstGrammar); |
|
2773 |
addGlobalTypeDecls(srcGrammar, dstGrammar); |
|
2774 |
addGlobalNotationDecls(srcGrammar, dstGrammar); |
|
2775 |
} |
|
2776 |
||
2777 |
private void addGlobalElementDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2778 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.ELEMENT_DECLARATION); |
|
2779 |
int len = components.getLength(); |
|
2780 |
XSElementDecl srcDecl, dstDecl; |
|
2781 |
||
2782 |
// add global components |
|
2783 |
for (int i=0; i<len; i++) { |
|
2784 |
srcDecl = (XSElementDecl) components.item(i); |
|
2785 |
dstDecl = dstGrammar.getGlobalElementDecl(srcDecl.getName()); |
|
2786 |
if (dstDecl == null) { |
|
2787 |
dstGrammar.addGlobalElementDecl(srcDecl); |
|
2788 |
} |
|
2789 |
else if (dstDecl != srcDecl){ |
|
2790 |
// TODO: if not tolerating duplicate, generate an error message |
|
2791 |
} |
|
2792 |
} |
|
2793 |
||
2794 |
// add any extended (duplicate) global components |
|
2795 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.ELEMENT_DECLARATION); |
|
2796 |
len = componentsExt.getLength(); |
|
2797 |
||
2798 |
for (int i=0; i<len; i+= 2) { |
|
2799 |
final String key = (String) componentsExt.item(i); |
|
2800 |
final int index = key.indexOf(','); |
|
2801 |
final String location = key.substring(0, index); |
|
2802 |
final String name = key.substring(index + 1, key.length()); |
|
2803 |
||
2804 |
srcDecl = (XSElementDecl)componentsExt.item(i+1); |
|
2805 |
dstDecl = dstGrammar.getGlobalElementDecl(name, location); |
|
2806 |
if ( dstDecl == null) { |
|
2807 |
dstGrammar.addGlobalElementDecl(srcDecl, location); |
|
2808 |
} |
|
2809 |
else if (dstDecl != srcDecl){ |
|
2810 |
// TODO: if not tolerating duplicate, generate an error message |
|
2811 |
} |
|
2812 |
} |
|
2813 |
} |
|
2814 |
||
2815 |
private void addGlobalAttributeDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2816 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.ATTRIBUTE_DECLARATION); |
|
2817 |
int len = components.getLength(); |
|
2818 |
XSAttributeDecl srcDecl, dstDecl; |
|
2819 |
||
2820 |
// add global components |
|
2821 |
for (int i=0; i<len; i++) { |
|
2822 |
srcDecl = (XSAttributeDecl) components.item(i); |
|
2823 |
dstDecl = dstGrammar.getGlobalAttributeDecl(srcDecl.getName()); |
|
2824 |
if (dstDecl == null) { |
|
2825 |
dstGrammar.addGlobalAttributeDecl(srcDecl); |
|
2826 |
} |
|
2827 |
else if (dstDecl != srcDecl && !fTolerateDuplicates) { |
|
2828 |
reportSharingError(srcDecl.getNamespace(), srcDecl.getName()); |
|
2829 |
} |
|
2830 |
} |
|
2831 |
||
2832 |
// add any extended (duplicate) global components |
|
2833 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.ATTRIBUTE_DECLARATION); |
|
2834 |
len = componentsExt.getLength(); |
|
2835 |
||
2836 |
for (int i=0; i<len; i+= 2) { |
|
2837 |
final String key = (String) componentsExt.item(i); |
|
2838 |
final int index = key.indexOf(','); |
|
2839 |
final String location = key.substring(0, index); |
|
2840 |
final String name = key.substring(index + 1, key.length()); |
|
2841 |
||
2842 |
srcDecl = (XSAttributeDecl)componentsExt.item(i+1); |
|
2843 |
dstDecl = dstGrammar.getGlobalAttributeDecl(name, location); |
|
2844 |
if (dstDecl == null) { |
|
2845 |
dstGrammar.addGlobalAttributeDecl(srcDecl, location); |
|
2846 |
} |
|
2847 |
// REVISIT - do we report an error? |
|
2848 |
else if (dstDecl != srcDecl) { |
|
2849 |
} |
|
2850 |
} |
|
2851 |
} |
|
2852 |
||
2853 |
private void addGlobalAttributeGroupDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2854 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.ATTRIBUTE_GROUP); |
|
2855 |
int len = components.getLength(); |
|
2856 |
XSAttributeGroupDecl srcDecl, dstDecl; |
|
2857 |
||
2858 |
// add global components |
|
2859 |
for (int i=0; i<len; i++) { |
|
2860 |
srcDecl = (XSAttributeGroupDecl) components.item(i); |
|
2861 |
dstDecl = dstGrammar.getGlobalAttributeGroupDecl(srcDecl.getName()); |
|
2862 |
if (dstDecl == null) { |
|
2863 |
dstGrammar.addGlobalAttributeGroupDecl(srcDecl); |
|
2864 |
} |
|
2865 |
else if (dstDecl != srcDecl && !fTolerateDuplicates) { |
|
2866 |
reportSharingError(srcDecl.getNamespace(), srcDecl.getName()); |
|
2867 |
} |
|
2868 |
} |
|
2869 |
||
2870 |
// add any extended (duplicate) global components |
|
2871 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.ATTRIBUTE_GROUP); |
|
2872 |
len = componentsExt.getLength(); |
|
2873 |
||
2874 |
for (int i=0; i<len; i+= 2) { |
|
2875 |
final String key = (String) componentsExt.item(i); |
|
2876 |
final int index = key.indexOf(','); |
|
2877 |
final String location = key.substring(0, index); |
|
2878 |
final String name = key.substring(index + 1, key.length()); |
|
2879 |
||
2880 |
srcDecl = (XSAttributeGroupDecl)componentsExt.item(i+1); |
|
2881 |
dstDecl = dstGrammar.getGlobalAttributeGroupDecl(name, location); |
|
2882 |
if (dstDecl == null) { |
|
2883 |
dstGrammar.addGlobalAttributeGroupDecl(srcDecl, location); |
|
2884 |
} |
|
2885 |
// REVISIT - do we report an error? |
|
2886 |
else if (dstDecl != srcDecl) { |
|
2887 |
} |
|
2888 |
} |
|
2889 |
} |
|
2890 |
||
2891 |
private void addGlobalNotationDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2892 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.NOTATION_DECLARATION); |
|
2893 |
int len = components.getLength(); |
|
2894 |
XSNotationDecl srcDecl, dstDecl; |
|
2895 |
||
2896 |
// add global components |
|
2897 |
for (int i=0; i<len; i++) { |
|
2898 |
srcDecl = (XSNotationDecl) components.item(i); |
|
2899 |
dstDecl = dstGrammar.getGlobalNotationDecl(srcDecl.getName()); |
|
2900 |
if (dstDecl == null) { |
|
2901 |
dstGrammar.addGlobalNotationDecl(srcDecl); |
|
2902 |
} |
|
2903 |
else if (dstDecl != srcDecl && !fTolerateDuplicates) { |
|
2904 |
reportSharingError(srcDecl.getNamespace(), srcDecl.getName()); |
|
2905 |
} |
|
2906 |
} |
|
2907 |
||
2908 |
// add any extended (duplicate) global components |
|
2909 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.NOTATION_DECLARATION); |
|
2910 |
len = componentsExt.getLength(); |
|
2911 |
||
2912 |
for (int i=0; i<len; i+= 2) { |
|
2913 |
final String key = (String) componentsExt.item(i); |
|
2914 |
final int index = key.indexOf(','); |
|
2915 |
final String location = key.substring(0, index); |
|
2916 |
final String name = key.substring(index + 1, key.length()); |
|
2917 |
||
2918 |
srcDecl = (XSNotationDecl)componentsExt.item(i+1); |
|
2919 |
dstDecl = dstGrammar.getGlobalNotationDecl(name, location); |
|
2920 |
if (dstDecl == null) { |
|
2921 |
dstGrammar.addGlobalNotationDecl(srcDecl, location); |
|
2922 |
} |
|
2923 |
// REVISIT - do we report an error? |
|
2924 |
else if (dstDecl != srcDecl) { |
|
2925 |
} |
|
2926 |
} |
|
2927 |
} |
|
2928 |
||
2929 |
private void addGlobalGroupDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2930 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.MODEL_GROUP_DEFINITION); |
|
2931 |
int len = components.getLength(); |
|
2932 |
XSGroupDecl srcDecl, dstDecl; |
|
2933 |
||
2934 |
// add global components |
|
2935 |
for (int i=0; i<len; i++) { |
|
2936 |
srcDecl = (XSGroupDecl) components.item(i); |
|
2937 |
dstDecl = dstGrammar.getGlobalGroupDecl(srcDecl.getName()); |
|
2938 |
if (dstDecl == null) { |
|
2939 |
dstGrammar.addGlobalGroupDecl(srcDecl); |
|
2940 |
} |
|
2941 |
else if (srcDecl != dstDecl && !fTolerateDuplicates) { |
|
2942 |
reportSharingError(srcDecl.getNamespace(), srcDecl.getName()); |
|
2943 |
} |
|
2944 |
} |
|
2945 |
||
2946 |
// add any extended (duplicate) global components |
|
2947 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.MODEL_GROUP_DEFINITION); |
|
2948 |
len = componentsExt.getLength(); |
|
2949 |
||
2950 |
for (int i=0; i<len; i+= 2) { |
|
2951 |
final String key = (String) componentsExt.item(i); |
|
2952 |
final int index = key.indexOf(','); |
|
2953 |
final String location = key.substring(0, index); |
|
2954 |
final String name = key.substring(index + 1, key.length()); |
|
2955 |
||
2956 |
srcDecl = (XSGroupDecl)componentsExt.item(i+1); |
|
2957 |
dstDecl = dstGrammar.getGlobalGroupDecl(name, location); |
|
2958 |
if (dstDecl == null) { |
|
2959 |
dstGrammar.addGlobalGroupDecl(srcDecl, location); |
|
2960 |
} |
|
2961 |
// REVIST - do we report an error? |
|
2962 |
else if (dstDecl != srcDecl) { |
|
2963 |
} |
|
2964 |
} |
|
2965 |
} |
|
2966 |
||
2967 |
private void addGlobalTypeDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) { |
|
2968 |
XSNamedMap components = srcGrammar.getComponents(XSConstants.TYPE_DEFINITION); |
|
2969 |
int len = components.getLength(); |
|
2970 |
XSTypeDefinition srcDecl, dstDecl; |
|
2971 |
||
2972 |
// add global components |
|
2973 |
for (int i=0; i<len; i++) { |
|
2974 |
srcDecl = (XSTypeDefinition) components.item(i); |
|
2975 |
dstDecl = dstGrammar.getGlobalTypeDecl(srcDecl.getName()); |
|
2976 |
if (dstDecl == null) { |
|
2977 |
dstGrammar.addGlobalTypeDecl(srcDecl); |
|
2978 |
} |
|
2979 |
else if (dstDecl != srcDecl && !fTolerateDuplicates) { |
|
2980 |
reportSharingError(srcDecl.getNamespace(), srcDecl.getName()); |
|
2981 |
} |
|
2982 |
} |
|
2983 |
||
2984 |
// add any extended (duplicate) global components |
|
2985 |
ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.TYPE_DEFINITION); |
|
2986 |
len = componentsExt.getLength(); |
|
2987 |
||
2988 |
for (int i=0; i<len; i+= 2) { |
|
2989 |
final String key = (String) componentsExt.item(i); |
|
2990 |
final int index = key.indexOf(','); |
|
2991 |
final String location = key.substring(0, index); |
|
2992 |
final String name = key.substring(index + 1, key.length()); |
|
2993 |
||
2994 |
srcDecl = (XSTypeDefinition)componentsExt.item(i+1); |
|
2995 |
dstDecl = dstGrammar.getGlobalTypeDecl(name, location); |
|
2996 |
if (dstDecl == null) { |
|
2997 |
dstGrammar.addGlobalTypeDecl(srcDecl, location); |
|
2998 |
} |
|
2999 |
// REVISIT - do we report an error? |
|
3000 |
else if (dstDecl != srcDecl) { |
|
3001 |
} |
|
3002 |
} |
|
3003 |
} |
|
3004 |
||
3005 |
private Vector expandComponents(XSObject[] components, Map<String, Vector> dependencies) { |
|
3006 |
Vector newComponents = new Vector(); |
|
3007 |
||
3008 |
for (int i=0; i<components.length; i++) { |
|
3009 |
if (!newComponents.contains(components[i])) { |
|
3010 |
newComponents.add(components[i]); |
|
3011 |
} |
|
3012 |
} |
|
3013 |
||
3014 |
for (int i=0; i<newComponents.size(); i++) { |
|
3015 |
final XSObject component = (XSObject) newComponents.elementAt(i); |
|
3016 |
expandRelatedComponents(component, newComponents, dependencies); |
|
3017 |
} |
|
3018 |
||
3019 |
return newComponents; |
|
3020 |
} |
|
3021 |
||
3022 |
private void expandRelatedComponents(XSObject component, Vector componentList, Map<String, Vector> dependencies) { |
|
3023 |
short componentType = component.getType(); |
|
3024 |
switch (componentType) { |
|
3025 |
case XSConstants.TYPE_DEFINITION : |
|
3026 |
expandRelatedTypeComponents((XSTypeDefinition) component, componentList, component.getNamespace(), dependencies); |
|
3027 |
break; |
|
3028 |
case XSConstants.ATTRIBUTE_DECLARATION : |
|
3029 |
expandRelatedAttributeComponents((XSAttributeDeclaration) component, componentList, component.getNamespace(), dependencies); |
|
3030 |
break; |
|
3031 |
case XSConstants.ATTRIBUTE_GROUP : |
|
3032 |
expandRelatedAttributeGroupComponents((XSAttributeGroupDefinition) component, componentList, component.getNamespace(), dependencies); |
|
3033 |
case XSConstants.ELEMENT_DECLARATION : |
|
3034 |
expandRelatedElementComponents((XSElementDeclaration) component, componentList, component.getNamespace(), dependencies); |
|
3035 |
break; |
|
3036 |
case XSConstants.MODEL_GROUP_DEFINITION : |
|
3037 |
expandRelatedModelGroupDefinitionComponents((XSModelGroupDefinition) component, componentList, component.getNamespace(), dependencies); |
|
3038 |
case XSConstants.ATTRIBUTE_USE : |
|
3039 |
//expandRelatedAttributeUseComponents((XSAttributeUse)component, componentList, dependencies); |
|
3040 |
case XSConstants.NOTATION_DECLARATION : |
|
3041 |
case XSConstants.IDENTITY_CONSTRAINT : |
|
3042 |
default : |
|
3043 |
break; |
|
3044 |
} |
|
3045 |
} |
|
3046 |
||
3047 |
private void expandRelatedAttributeComponents(XSAttributeDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3048 |
addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies); |
|
3049 |
||
3050 |
/*final XSComplexTypeDefinition enclosingType = decl.getEnclosingCTDefinition(); |
|
3051 |
if (enclosingType != null) { |
|
3052 |
addRelatedType(enclosingType, componentList, namespace, dependencies); |
|
3053 |
}*/ |
|
3054 |
} |
|
3055 |
||
3056 |
private void expandRelatedElementComponents(XSElementDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3057 |
addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies); |
|
3058 |
||
3059 |
/*final XSTypeDefinition enclosingType = decl.getEnclosingCTDefinition(); |
|
3060 |
if (enclosingType != null) { |
|
3061 |
addRelatedType(enclosingType, componentList, namespace, dependencies); |
|
3062 |
}*/ |
|
3063 |
||
3064 |
final XSElementDeclaration subElemDecl = decl.getSubstitutionGroupAffiliation(); |
|
3065 |
if (subElemDecl != null) { |
|
3066 |
addRelatedElement(subElemDecl, componentList, namespace, dependencies); |
|
3067 |
} |
|
3068 |
} |
|
3069 |
||
3070 |
private void expandRelatedTypeComponents(XSTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3071 |
if (type instanceof XSComplexTypeDecl) { |
|
3072 |
expandRelatedComplexTypeComponents((XSComplexTypeDecl) type, componentList, namespace, dependencies); |
|
3073 |
} |
|
3074 |
else if (type instanceof XSSimpleTypeDecl) { |
|
3075 |
expandRelatedSimpleTypeComponents((XSSimpleTypeDefinition) type, componentList, namespace, dependencies); |
|
3076 |
} |
|
3077 |
} |
|
3078 |
||
3079 |
private void expandRelatedModelGroupDefinitionComponents(XSModelGroupDefinition modelGroupDef, Vector componentList, |
|
3080 |
String namespace, Map<String, Vector> dependencies) { |
|
3081 |
expandRelatedModelGroupComponents(modelGroupDef.getModelGroup(), componentList, namespace, dependencies); |
|
3082 |
} |
|
3083 |
||
3084 |
private void expandRelatedAttributeGroupComponents(XSAttributeGroupDefinition attrGroup, Vector componentList |
|
3085 |
, String namespace, Map<String, Vector> dependencies) { |
|
3086 |
expandRelatedAttributeUsesComponents(attrGroup.getAttributeUses(), componentList, namespace, dependencies); |
|
3087 |
} |
|
3088 |
||
3089 |
private void expandRelatedComplexTypeComponents(XSComplexTypeDecl type, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3090 |
addRelatedType(type.getBaseType(), componentList, namespace, dependencies); |
|
3091 |
expandRelatedAttributeUsesComponents(type.getAttributeUses(), componentList, namespace, dependencies); |
|
3092 |
final XSParticle particle = type.getParticle(); |
|
3093 |
if (particle != null) { |
|
3094 |
expandRelatedParticleComponents(particle, componentList, namespace, dependencies); |
|
3095 |
} |
|
3096 |
} |
|
3097 |
||
3098 |
private void expandRelatedSimpleTypeComponents(XSSimpleTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3099 |
final XSTypeDefinition baseType = type.getBaseType(); |
|
3100 |
if (baseType != null) { |
|
3101 |
addRelatedType(baseType, componentList, namespace, dependencies); |
|
3102 |
} |
|
3103 |
||
3104 |
final XSTypeDefinition itemType = type.getItemType(); |
|
3105 |
if (itemType != null) { |
|
3106 |
addRelatedType(itemType, componentList, namespace, dependencies); |
|
3107 |
} |
|
3108 |
||
3109 |
final XSTypeDefinition primitiveType = type.getPrimitiveType(); |
|
3110 |
if (primitiveType != null) { |
|
3111 |
addRelatedType(primitiveType, componentList, namespace, dependencies); |
|
3112 |
} |
|
3113 |
||
3114 |
final XSObjectList memberTypes = type.getMemberTypes(); |
|
3115 |
if (memberTypes.size() > 0) { |
|
3116 |
for (int i=0; i<memberTypes.size(); i++) { |
|
3117 |
addRelatedType((XSTypeDefinition)memberTypes.item(i), componentList, namespace, dependencies); |
|
3118 |
} |
|
3119 |
} |
|
3120 |
} |
|
3121 |
||
3122 |
private void expandRelatedAttributeUsesComponents(XSObjectList attrUses, Vector componentList, |
|
3123 |
String namespace, Map<String, Vector> dependencies) { |
|
3124 |
final int attrUseSize = (attrUses == null) ? 0 : attrUses.size(); |
|
3125 |
for (int i=0; i<attrUseSize; i++) { |
|
3126 |
expandRelatedAttributeUseComponents((XSAttributeUse)attrUses.item(i), componentList, namespace, dependencies); |
|
3127 |
} |
|
3128 |
} |
|
3129 |
||
3130 |
private void expandRelatedAttributeUseComponents(XSAttributeUse component, Vector componentList, |
|
3131 |
String namespace, Map<String, Vector> dependencies) { |
|
3132 |
addRelatedAttribute(component.getAttrDeclaration(), componentList, namespace, dependencies); |
|
3133 |
} |
|
3134 |
||
3135 |
private void expandRelatedParticleComponents(XSParticle component, Vector componentList, |
|
3136 |
String namespace, Map<String, Vector> dependencies) { |
|
3137 |
XSTerm term = component.getTerm(); |
|
3138 |
switch (term.getType()) { |
|
3139 |
case XSConstants.ELEMENT_DECLARATION : |
|
3140 |
addRelatedElement((XSElementDeclaration) term, componentList, namespace, dependencies); |
|
3141 |
break; |
|
3142 |
case XSConstants.MODEL_GROUP : |
|
3143 |
expandRelatedModelGroupComponents((XSModelGroup) term, componentList, namespace, dependencies); |
|
3144 |
break; |
|
3145 |
default: |
|
3146 |
break; |
|
3147 |
} |
|
3148 |
} |
|
3149 |
||
3150 |
private void expandRelatedModelGroupComponents(XSModelGroup modelGroup, Vector componentList, |
|
3151 |
String namespace, Map<String, Vector> dependencies) { |
|
3152 |
XSObjectList particles = modelGroup.getParticles(); |
|
3153 |
final int length = (particles == null) ? 0 : particles.getLength(); |
|
3154 |
for (int i=0; i<length; i++) { |
|
3155 |
expandRelatedParticleComponents((XSParticle)particles.item(i), componentList, namespace, dependencies); |
|
3156 |
} |
|
3157 |
} |
|
3158 |
||
3159 |
private void addRelatedType(XSTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3160 |
if (!type.getAnonymous()) { |
|
3161 |
if (!type.getNamespace().equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) { //REVISIT - do we use == instead |
|
3162 |
if (!componentList.contains(type)) { |
|
3163 |
final Vector importedNamespaces = findDependentNamespaces(namespace, dependencies); |
|
3164 |
addNamespaceDependency(namespace, type.getNamespace(), importedNamespaces); |
|
3165 |
componentList.add(type); |
|
3166 |
} |
|
3167 |
} |
|
3168 |
} |
|
3169 |
else { |
|
3170 |
expandRelatedTypeComponents(type, componentList, namespace, dependencies); |
|
3171 |
} |
|
3172 |
} |
|
3173 |
||
3174 |
private void addRelatedElement(XSElementDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3175 |
if (decl.getScope() == XSConstants.SCOPE_GLOBAL) { |
|
3176 |
if (!componentList.contains(decl)) { |
|
3177 |
Vector importedNamespaces = findDependentNamespaces(namespace, dependencies); |
|
3178 |
addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces); |
|
3179 |
componentList.add(decl); |
|
3180 |
} |
|
3181 |
} |
|
3182 |
else { |
|
3183 |
expandRelatedElementComponents(decl, componentList, namespace, dependencies); |
|
3184 |
} |
|
3185 |
} |
|
3186 |
||
3187 |
private void addRelatedAttribute(XSAttributeDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) { |
|
3188 |
if (decl.getScope() == XSConstants.SCOPE_GLOBAL) { |
|
3189 |
if (!componentList.contains(decl)) { |
|
3190 |
Vector importedNamespaces = findDependentNamespaces(namespace, dependencies); |
|
3191 |
addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces); |
|
3192 |
componentList.add(decl); |
|
3193 |
} |
|
3194 |
} |
|
3195 |
else { |
|
3196 |
expandRelatedAttributeComponents(decl, componentList, namespace, dependencies); |
|
3197 |
} |
|
3198 |
} |
|
3199 |
||
3200 |
private void addGlobalComponents(Vector components, Map<String, Vector> importDependencies) { |
|
3201 |
final XSDDescription desc = new XSDDescription(); |
|
3202 |
final int size = components.size(); |
|
3203 |
||
3204 |
for (int i=0; i<size; i++) { |
|
3205 |
addGlobalComponent((XSObject) components.elementAt(i), desc); |
|
3206 |
} |
|
3207 |
updateImportDependencies(importDependencies); |
|
3208 |
} |
|
3209 |
||
3210 |
private void addGlobalComponent(XSObject component, XSDDescription desc) { |
|
3211 |
final String namespace = component.getNamespace(); |
|
3212 |
||
3213 |
desc.setNamespace(namespace); |
|
3214 |
final SchemaGrammar sg = getSchemaGrammar(desc); |
|
3215 |
||
3216 |
short componentType = component.getType(); |
|
3217 |
final String name = component.getName(); |
|
3218 |
||
3219 |
switch (componentType) { |
|
3220 |
case XSConstants.TYPE_DEFINITION : |
|
3221 |
if (!((XSTypeDefinition) component).getAnonymous()) { |
|
3222 |
if (sg.getGlobalTypeDecl(name) == null) { |
|
3223 |
sg.addGlobalTypeDecl((XSTypeDefinition) component); |
|
3224 |
} |
|
3225 |
// store the declaration in the extended map, using an empty location |
|
3226 |
if (sg.getGlobalTypeDecl(name, "") == null) { |
|
3227 |
sg.addGlobalTypeDecl((XSTypeDefinition) component, ""); |
|
3228 |
} |
|
3229 |
} |
|
3230 |
break; |
|
3231 |
case XSConstants.ATTRIBUTE_DECLARATION : |
|
3232 |
if (((XSAttributeDecl) component).getScope() == XSAttributeDecl.SCOPE_GLOBAL) { |
|
3233 |
if (sg.getGlobalAttributeDecl(name) == null) { |
|
3234 |
sg.addGlobalAttributeDecl((XSAttributeDecl) component); |
|
3235 |
} |
|
3236 |
// store the declaration in the extended map, using an empty location |
|
3237 |
if (sg.getGlobalAttributeDecl(name, "") == null) { |
|
3238 |
sg.addGlobalAttributeDecl((XSAttributeDecl) component, ""); |
|
3239 |
} |
|
3240 |
} |
|
3241 |
break; |
|
3242 |
case XSConstants.ATTRIBUTE_GROUP : |
|
3243 |
if (sg.getGlobalAttributeDecl(name) == null) { |
|
3244 |
sg.addGlobalAttributeGroupDecl((XSAttributeGroupDecl) component); |
|
3245 |
} |
|
3246 |
// store the declaration in the extended map, using an empty location |
|
3247 |
if (sg.getGlobalAttributeDecl(name, "") == null) { |
|
3248 |
sg.addGlobalAttributeGroupDecl((XSAttributeGroupDecl) component, ""); |
|
3249 |
} |
|
3250 |
break; |
|
3251 |
case XSConstants.ELEMENT_DECLARATION : |
|
3252 |
if (((XSElementDecl) component).getScope() == XSElementDecl.SCOPE_GLOBAL) { |
|
3253 |
sg.addGlobalElementDeclAll((XSElementDecl) component); |
|
3254 |
||
3255 |
if (sg.getGlobalElementDecl(name) == null) { |
|
3256 |
sg.addGlobalElementDecl((XSElementDecl) component); |
|
3257 |
} |
|
3258 |
// store the declaration in the extended map, using an empty location |
|
3259 |
if (sg.getGlobalElementDecl(name, "") == null) { |
|
3260 |
sg.addGlobalElementDecl((XSElementDecl) component, ""); |
|
3261 |
} |
|
3262 |
} |
|
3263 |
break; |
|
3264 |
case XSConstants.MODEL_GROUP_DEFINITION : |
|
3265 |
if (sg.getGlobalGroupDecl(name) == null) { |
|
3266 |
sg.addGlobalGroupDecl((XSGroupDecl) component); |
|
3267 |
} |
|
3268 |
// store the declaration in the extended map, using an empty location |
|
3269 |
if (sg.getGlobalGroupDecl(name, "") == null) { |
|
3270 |
sg.addGlobalGroupDecl((XSGroupDecl) component, ""); |
|
3271 |
} |
|
3272 |
break; |
|
3273 |
case XSConstants.NOTATION_DECLARATION : |
|
3274 |
if (sg.getGlobalNotationDecl(name) == null) { |
|
3275 |
sg.addGlobalNotationDecl((XSNotationDecl) component); |
|
3276 |
} |
|
3277 |
// store the declaration in the extended map, using an empty location |
|
3278 |
if (sg.getGlobalNotationDecl(name, "") == null) { |
|
3279 |
sg.addGlobalNotationDecl((XSNotationDecl) component, ""); |
|
3280 |
} |
|
3281 |
break; |
|
3282 |
case XSConstants.IDENTITY_CONSTRAINT : |
|
3283 |
case XSConstants.ATTRIBUTE_USE : |
|
3284 |
default : |
|
3285 |
break; |
|
3286 |
} |
|
3287 |
} |
|
3288 |
||
3289 |
private void updateImportDependencies(Map<String, Vector> table) { |
|
3290 |
if (table == null) return; |
|
3291 |
String namespace; |
|
3292 |
Vector importList; |
|
3293 |
||
3294 |
for(Map.Entry<String, Vector> entry : table.entrySet()){ |
|
3295 |
namespace = entry.getKey(); |
|
3296 |
importList = entry.getValue(); |
|
3297 |
if (importList.size() > 0) { |
|
3298 |
expandImportList(namespace, importList); |
|
3299 |
} |
|
3300 |
} |
|
3301 |
} |
|
3302 |
||
3303 |
private void expandImportList(String namespace, Vector namespaceList) { |
|
3304 |
SchemaGrammar sg = fGrammarBucket.getGrammar(namespace); |
|
3305 |
// shouldn't be null |
|
3306 |
if (sg != null) { |
|
3307 |
Vector isgs = sg.getImportedGrammars(); |
|
3308 |
if (isgs == null) { |
|
3309 |
isgs = new Vector(); |
|
3310 |
addImportList(sg, isgs, namespaceList); |
|
3311 |
sg.setImportedGrammars(isgs); |
|
3312 |
} |
|
3313 |
else { |
|
3314 |
updateImportList(sg, isgs, namespaceList); |
|
3315 |
} |
|
3316 |
} |
|
3317 |
} |
|
3318 |
||
3319 |
private void addImportList(SchemaGrammar sg, Vector importedGrammars, Vector namespaceList) { |
|
3320 |
final int size = namespaceList.size(); |
|
3321 |
SchemaGrammar isg; |
|
3322 |
||
3323 |
for (int i=0; i<size; i++) { |
|
3324 |
isg = fGrammarBucket.getGrammar((String)namespaceList.elementAt(i)); |
|
3325 |
if (isg != null) { |
|
3326 |
importedGrammars.add(isg); |
|
3327 |
} |
|
3328 |
else { |
|
3329 |
//REVIST: report an error message |
|
3330 |
} |
|
3331 |
} |
|
3332 |
} |
|
3333 |
||
3334 |
private void updateImportList(SchemaGrammar sg, Vector importedGrammars, Vector namespaceList) { |
|
3335 |
final int size = namespaceList.size(); |
|
3336 |
SchemaGrammar isg; |
|
3337 |
||
3338 |
for (int i=0; i<size; i++) { |
|
3339 |
isg = fGrammarBucket.getGrammar((String)namespaceList.elementAt(i)); |
|
3340 |
if (isg != null) { |
|
3341 |
if (!containedImportedGrammar(importedGrammars, isg)) { |
|
3342 |
importedGrammars.add(isg); |
|
3343 |
} |
|
3344 |
} |
|
3345 |
else { |
|
3346 |
//REVIST: report an error message |
|
3347 |
} |
|
3348 |
} |
|
3349 |
} |
|
3350 |
||
3351 |
private boolean containedImportedGrammar(Vector importedGrammar, SchemaGrammar grammar) { |
|
3352 |
final int size = importedGrammar.size(); |
|
3353 |
SchemaGrammar sg; |
|
3354 |
||
3355 |
for (int i=0; i<size; i++) { |
|
3356 |
sg = (SchemaGrammar) importedGrammar.elementAt(i); |
|
3357 |
if (null2EmptyString(sg.getTargetNamespace()).equals(null2EmptyString(grammar.getTargetNamespace()))) { |
|
3358 |
return true; |
|
3359 |
} |
|
3360 |
} |
|
3361 |
return false; |
|
3362 |
} |
|
3363 |
||
3364 |
// NOTE: always assuming that fNamespaceGrowth is enabled |
|
3365 |
// otherwise the grammar should have existed |
|
3366 |
private SchemaGrammar getSchemaGrammar(XSDDescription desc) { |
|
3367 |
SchemaGrammar sg = findGrammar(desc, fNamespaceGrowth); |
|
3368 |
||
3369 |
if (sg == null) { |
|
3370 |
sg = new SchemaGrammar(desc.getNamespace(), desc.makeClone(), fSymbolTable); |
|
3371 |
fGrammarBucket.putGrammar(sg); |
|
3372 |
} |
|
3373 |
else if (sg.isImmutable()){ |
|
3374 |
sg = createGrammarFrom(sg); |
|
3375 |
} |
|
3376 |
||
3377 |
return sg; |
|
3378 |
} |
|
3379 |
||
3380 |
private Vector findDependentNamespaces(String namespace, Map table) { |
|
3381 |
final String ns = null2EmptyString(namespace); |
|
3382 |
Vector namespaceList = (Vector) getFromMap(table, ns); |
|
3383 |
||
3384 |
if (namespaceList == null) { |
|
3385 |
namespaceList = new Vector(); |
|
3386 |
table.put(ns, namespaceList); |
|
3387 |
} |
|
3388 |
||
3389 |
return namespaceList; |
|
3390 |
} |
|
3391 |
||
3392 |
private void addNamespaceDependency(String namespace1, String namespace2, Vector list) { |
|
3393 |
final String ns1 = null2EmptyString(namespace1); |
|
3394 |
final String ns2 = null2EmptyString(namespace2); |
|
3395 |
if (!ns1.equals(ns2)) { |
|
3396 |
if (!list.contains(ns2)) { |
|
3397 |
list.add(ns2); |
|
3398 |
} |
|
3399 |
} |
|
3400 |
} |
|
3401 |
||
3402 |
private void reportSharingError(String namespace, String name) { |
|
3403 |
final String qName = (namespace == null) |
|
3404 |
? "," + name : namespace + "," + name; |
|
3405 |
||
3406 |
reportSchemaError("sch-props-correct.2", new Object [] {qName}, null); |
|
3407 |
} |
|
3408 |
||
3409 |
// initialize all the traversers. |
|
3410 |
// this should only need to be called once during the construction |
|
3411 |
// of this object; it creates the traversers that will be used to |
|
3412 |
||
3413 |
// construct schemaGrammars. |
|
3414 |
private void createTraversers() { |
|
3415 |
fAttributeChecker = new XSAttributeChecker(this); |
|
3416 |
fAttributeGroupTraverser = new XSDAttributeGroupTraverser(this, fAttributeChecker); |
|
3417 |
fAttributeTraverser = new XSDAttributeTraverser(this, fAttributeChecker); |
|
3418 |
fComplexTypeTraverser = new XSDComplexTypeTraverser(this, fAttributeChecker); |
|
3419 |
fElementTraverser = new XSDElementTraverser(this, fAttributeChecker); |
|
3420 |
fGroupTraverser = new XSDGroupTraverser(this, fAttributeChecker); |
|
3421 |
fKeyrefTraverser = new XSDKeyrefTraverser(this, fAttributeChecker); |
|
3422 |
fNotationTraverser = new XSDNotationTraverser(this, fAttributeChecker); |
|
3423 |
fSimpleTypeTraverser = new XSDSimpleTypeTraverser(this, fAttributeChecker); |
|
3424 |
fUniqueOrKeyTraverser = new XSDUniqueOrKeyTraverser(this, fAttributeChecker); |
|
3425 |
fWildCardTraverser = new XSDWildcardTraverser(this, fAttributeChecker); |
|
3426 |
} // createTraversers() |
|
3427 |
||
3428 |
// before parsing a schema, need to clear registries associated with |
|
3429 |
// parsing schemas |
|
3430 |
void prepareForParse() { |
|
3431 |
fTraversed.clear(); |
|
3432 |
fDoc2SystemId.clear(); |
|
3433 |
fHiddenNodes.clear(); |
|
3434 |
fLastSchemaWasDuplicate = false; |
|
3435 |
} |
|
3436 |
||
3437 |
// before traversing a schema's parse tree, need to reset all traversers and |
|
3438 |
// clear all registries |
|
3439 |
void prepareForTraverse() { |
|
3440 |
if (!registryEmpty) { |
|
3441 |
fUnparsedAttributeRegistry.clear(); |
|
3442 |
fUnparsedAttributeGroupRegistry.clear(); |
|
3443 |
fUnparsedElementRegistry.clear(); |
|
3444 |
fUnparsedGroupRegistry.clear(); |
|
3445 |
fUnparsedIdentityConstraintRegistry.clear(); |
|
3446 |
fUnparsedNotationRegistry.clear(); |
|
3447 |
fUnparsedTypeRegistry.clear(); |
|
3448 |
||
3449 |
fUnparsedAttributeRegistrySub.clear(); |
|
3450 |
fUnparsedAttributeGroupRegistrySub.clear(); |
|
3451 |
fUnparsedElementRegistrySub.clear(); |
|
3452 |
fUnparsedGroupRegistrySub.clear(); |
|
3453 |
fUnparsedIdentityConstraintRegistrySub.clear(); |
|
3454 |
fUnparsedNotationRegistrySub.clear(); |
|
3455 |
fUnparsedTypeRegistrySub.clear(); |
|
3456 |
} |
|
3457 |
||
3458 |
for (int i=1; i<= TYPEDECL_TYPE; i++) { |
|
3459 |
if (fUnparsedRegistriesExt[i] != null) |
|
3460 |
fUnparsedRegistriesExt[i].clear(); |
|
3461 |
} |
|
3462 |
||
3463 |
fDependencyMap.clear(); |
|
3464 |
fDoc2XSDocumentMap.clear(); |
|
3465 |
if (fRedefine2XSDMap != null) fRedefine2XSDMap.clear(); |
|
3466 |
if (fRedefine2NSSupport != null) fRedefine2NSSupport.clear(); |
|
3467 |
fAllTNSs.removeAllElements(); |
|
3468 |
fImportMap.clear(); |
|
3469 |
fRoot = null; |
|
3470 |
||
3471 |
// clear local element stack |
|
3472 |
for (int i = 0; i < fLocalElemStackPos; i++) { |
|
3473 |
fParticle[i] = null; |
|
3474 |
fLocalElementDecl[i] = null; |
|
3475 |
fLocalElementDecl_schema[i] = null; |
|
3476 |
fLocalElemNamespaceContext[i] = null; |
|
3477 |
} |
|
3478 |
fLocalElemStackPos = 0; |
|
3479 |
||
3480 |
// and do same for keyrefs. |
|
3481 |
for (int i = 0; i < fKeyrefStackPos; i++) { |
|
3482 |
fKeyrefs[i] = null; |
|
3483 |
fKeyrefElems[i] = null; |
|
3484 |
fKeyrefNamespaceContext[i] = null; |
|
3485 |
fKeyrefsMapXSDocumentInfo[i] = null; |
|
3486 |
} |
|
3487 |
fKeyrefStackPos = 0; |
|
3488 |
||
3489 |
// create traversers if necessary |
|
3490 |
if (fAttributeChecker == null) { |
|
3491 |
createTraversers(); |
|
3492 |
} |
|
3493 |
||
3494 |
// reset traversers |
|
3495 |
Locale locale = fErrorReporter.getLocale(); |
|
3496 |
fAttributeChecker.reset(fSymbolTable); |
|
3497 |
fAttributeGroupTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3498 |
fAttributeTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3499 |
fComplexTypeTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3500 |
fElementTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3501 |
fGroupTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3502 |
fKeyrefTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3503 |
fNotationTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3504 |
fSimpleTypeTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3505 |
fUniqueOrKeyTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3506 |
fWildCardTraverser.reset(fSymbolTable, fValidateAnnotations, locale); |
|
3507 |
||
3508 |
fRedefinedRestrictedAttributeGroupRegistry.clear(); |
|
3509 |
fRedefinedRestrictedGroupRegistry.clear(); |
|
3510 |
||
3511 |
fGlobalAttrDecls.clear(); |
|
3512 |
fGlobalAttrGrpDecls.clear(); |
|
3513 |
fGlobalElemDecls.clear(); |
|
3514 |
fGlobalGroupDecls.clear(); |
|
3515 |
fGlobalNotationDecls.clear(); |
|
3516 |
fGlobalIDConstraintDecls.clear(); |
|
3517 |
fGlobalTypeDecls.clear(); |
|
3518 |
} |
|
3519 |
public void setDeclPool (XSDeclarationPool declPool){ |
|
3520 |
fDeclPool = declPool; |
|
3521 |
} |
|
3522 |
public void setDVFactory(SchemaDVFactory dvFactory){ |
|
3523 |
fDVFactory = dvFactory; |
|
3524 |
} |
|
3525 |
public SchemaDVFactory getDVFactory(){ |
|
3526 |
return fDVFactory; |
|
3527 |
} |
|
3528 |
||
3529 |
public void reset(XMLComponentManager componentManager) { |
|
3530 |
||
3531 |
// set symbol table |
|
3532 |
fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); |
|
3533 |
||
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3534 |
// set security manager |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3535 |
fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3536 |
|
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3537 |
//set entity manager |
39907 | 3538 |
fEntityManager = (XMLEntityManager) componentManager.getProperty(ENTITY_MANAGER); |
12005 | 3539 |
|
3540 |
//set entity resolver |
|
3541 |
XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER); |
|
3542 |
if (er != null) |
|
3543 |
fSchemaParser.setEntityResolver(er); |
|
3544 |
||
3545 |
// set error reporter |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3546 |
fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3547 |
fErrorHandler = fErrorReporter.getErrorHandler(); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3548 |
fLocale = fErrorReporter.getLocale(); |
12005 | 3549 |
|
3550 |
fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false); |
|
3551 |
fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false); |
|
3552 |
fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false); |
|
3553 |
fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false); |
|
3554 |
||
3555 |
try { |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3556 |
// Setting a parser property can be much more expensive |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3557 |
// than checking its value. Don't set the ERROR_HANDLER |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3558 |
// or LOCALE properties unless they've actually changed. |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3559 |
if (fErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) { |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3560 |
fSchemaParser.setProperty(ERROR_HANDLER, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3561 |
(fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3562 |
if (fAnnotationValidator != null) { |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3563 |
fAnnotationValidator.setProperty(ERROR_HANDLER, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3564 |
(fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3565 |
} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3566 |
} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3567 |
if (fLocale != fSchemaParser.getProperty(LOCALE)) { |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3568 |
fSchemaParser.setProperty(LOCALE, fLocale); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3569 |
if (fAnnotationValidator != null) { |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3570 |
fAnnotationValidator.setProperty(LOCALE, fLocale); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3571 |
} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3572 |
} |
12005 | 3573 |
} |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3574 |
catch (XMLConfigurationException e) {} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3575 |
|
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3576 |
try { |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3577 |
fSchemaParser.setFeature(CONTINUE_AFTER_FATAL_ERROR, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3578 |
fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR)); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3579 |
} catch (XMLConfigurationException e) {} |
12005 | 3580 |
|
3581 |
try { |
|
3582 |
if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) { |
|
3583 |
fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true); |
|
3584 |
} |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3585 |
} catch (XMLConfigurationException e) {} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3586 |
|
12005 | 3587 |
try { |
3588 |
if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) { |
|
3589 |
fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true); |
|
3590 |
} |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3591 |
} catch (XMLConfigurationException e) {} |
12005 | 3592 |
|
3593 |
try { |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3594 |
fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL); |
12005 | 3595 |
} catch (XMLConfigurationException e) { |
3596 |
fGrammarPool = null; |
|
3597 |
} |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3598 |
|
12005 | 3599 |
// security features |
3600 |
try { |
|
3601 |
if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) { |
|
3602 |
fSchemaParser.setFeature(DISALLOW_DOCTYPE, true); |
|
3603 |
} |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3604 |
} catch (XMLConfigurationException e) {} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3605 |
|
12005 | 3606 |
try { |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3607 |
if (fSecurityManager != null) { |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3608 |
fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager); |
12005 | 3609 |
} |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3610 |
} catch (XMLConfigurationException e) {} |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3611 |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3612 |
fSecurityPropertyMgr = (XMLSecurityPropertyManager) |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3613 |
componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER); |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3614 |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
3615 |
//Passing on the setting to the parser |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3616 |
fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
3617 |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3618 |
fAccessExternalDTD = fSecurityPropertyMgr.getValue( |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3619 |
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3620 |
fAccessExternalSchema = fSecurityPropertyMgr.getValue( |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3621 |
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
3622 |
|
39907 | 3623 |
// Passing the Catalog settings to the parser |
3624 |
fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG); |
|
3625 |
fSchemaParser.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); |
|
3626 |
fEntityManager.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); |
|
3627 |
||
3628 |
fCatalogFile = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_FILES); |
|
3629 |
fDefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_DEFER); |
|
3630 |
fPrefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_PREFER); |
|
3631 |
fResolve = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_RESOLVE); |
|
3632 |
||
3633 |
for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3634 |
fSchemaParser.setProperty(f.getPropertyName(), |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3635 |
componentManager.getProperty(f.getPropertyName())); |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3636 |
fEntityManager.setProperty(f.getPropertyName(), |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3637 |
componentManager.getProperty(f.getPropertyName())); |
39907 | 3638 |
} |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3639 |
|
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3640 |
fSchemaParser.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3641 |
componentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE)); |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3642 |
fEntityManager.setProperty(JdkXmlUtils.CDATA_CHUNK_SIZE, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3643 |
componentManager.getProperty(JdkXmlUtils.CDATA_CHUNK_SIZE)); |
12005 | 3644 |
} // reset(XMLComponentManager) |
3645 |
||
3646 |
||
3647 |
/** |
|
3648 |
* Traverse all the deferred local elements. This method should be called |
|
3649 |
* by traverseSchemas after we've done with all the global declarations. |
|
3650 |
*/ |
|
3651 |
void traverseLocalElements() { |
|
3652 |
fElementTraverser.fDeferTraversingLocalElements = false; |
|
3653 |
||
3654 |
for (int i = 0; i < fLocalElemStackPos; i++) { |
|
3655 |
Element currElem = fLocalElementDecl[i]; |
|
3656 |
XSDocumentInfo currSchema = fLocalElementDecl_schema[i]; |
|
3657 |
SchemaGrammar currGrammar = fGrammarBucket.getGrammar(currSchema.fTargetNamespace); |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3658 |
fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
3659 |
currGrammar, fAllContext[i], fParent[i], fLocalElemNamespaceContext[i]); |
12005 | 3660 |
// If it's an empty particle, remove it from the containing component. |
3661 |
if (fParticle[i].fType == XSParticleDecl.PARTICLE_EMPTY) { |
|
3662 |
XSModelGroupImpl group = null; |
|
3663 |
if (fParent[i] instanceof XSComplexTypeDecl) { |
|
3664 |
XSParticle p = ((XSComplexTypeDecl)fParent[i]).getParticle(); |
|
3665 |
if (p != null) |
|
3666 |
group = (XSModelGroupImpl)p.getTerm(); |
|
3667 |
} |
|
3668 |
else { |
|
3669 |
group = ((XSGroupDecl)fParent[i]).fModelGroup; |
|
3670 |
} |
|
3671 |
if (group != null) |
|
3672 |
removeParticle(group, fParticle[i]); |
|
3673 |
} |
|
3674 |
} |
|
3675 |
} |
|
3676 |
||
3677 |
private boolean removeParticle(XSModelGroupImpl group, XSParticleDecl particle) { |
|
3678 |
XSParticleDecl member; |
|
3679 |
for (int i = 0; i < group.fParticleCount; i++) { |
|
3680 |
member = group.fParticles[i]; |
|
3681 |
if (member == particle) { |
|
3682 |
for (int j = i; j < group.fParticleCount-1; j++) |
|
3683 |
group.fParticles[j] = group.fParticles[j+1]; |
|
3684 |
group.fParticleCount--; |
|
3685 |
return true; |
|
3686 |
} |
|
3687 |
if (member.fType == XSParticleDecl.PARTICLE_MODELGROUP) { |
|
3688 |
if (removeParticle((XSModelGroupImpl)member.fValue, particle)) |
|
3689 |
return true; |
|
3690 |
} |
|
3691 |
} |
|
3692 |
return false; |
|
3693 |
} |
|
3694 |
||
3695 |
// the purpose of this method is to keep up-to-date structures |
|
3696 |
// we'll need for the feferred traversal of local elements. |
|
3697 |
void fillInLocalElemInfo(Element elmDecl, |
|
3698 |
XSDocumentInfo schemaDoc, |
|
3699 |
int allContextFlags, |
|
3700 |
XSObject parent, |
|
3701 |
XSParticleDecl particle) { |
|
3702 |
||
3703 |
// if the stack is full, increase the size |
|
3704 |
if (fParticle.length == fLocalElemStackPos) { |
|
3705 |
// increase size |
|
3706 |
XSParticleDecl[] newStackP = new XSParticleDecl[fLocalElemStackPos+INC_STACK_SIZE]; |
|
3707 |
System.arraycopy(fParticle, 0, newStackP, 0, fLocalElemStackPos); |
|
3708 |
fParticle = newStackP; |
|
3709 |
Element[] newStackE = new Element[fLocalElemStackPos+INC_STACK_SIZE]; |
|
3710 |
System.arraycopy(fLocalElementDecl, 0, newStackE, 0, fLocalElemStackPos); |
|
3711 |
fLocalElementDecl = newStackE; |
|
3712 |
XSDocumentInfo [] newStackE_schema = new XSDocumentInfo[fLocalElemStackPos+INC_STACK_SIZE]; |
|
3713 |
System.arraycopy(fLocalElementDecl_schema, 0, newStackE_schema, 0, fLocalElemStackPos); |
|
3714 |
fLocalElementDecl_schema = newStackE_schema; |
|
3715 |
int[] newStackI = new int[fLocalElemStackPos+INC_STACK_SIZE]; |
|
3716 |
System.arraycopy(fAllContext, 0, newStackI, 0, fLocalElemStackPos); |
|
3717 |
fAllContext = newStackI; |
|
3718 |
XSObject[] newStackC = new XSObject[fLocalElemStackPos+INC_STACK_SIZE]; |
|
3719 |
System.arraycopy(fParent, 0, newStackC, 0, fLocalElemStackPos); |
|
3720 |
fParent = newStackC; |
|
3721 |
String [][] newStackN = new String [fLocalElemStackPos+INC_STACK_SIZE][]; |
|
3722 |
System.arraycopy(fLocalElemNamespaceContext, 0, newStackN, 0, fLocalElemStackPos); |
|
3723 |
fLocalElemNamespaceContext = newStackN; |
|
3724 |
} |
|
3725 |
||
3726 |
fParticle[fLocalElemStackPos] = particle; |
|
3727 |
fLocalElementDecl[fLocalElemStackPos] = elmDecl; |
|
3728 |
fLocalElementDecl_schema[fLocalElemStackPos] = schemaDoc; |
|
3729 |
fAllContext[fLocalElemStackPos] = allContextFlags; |
|
3730 |
fParent[fLocalElemStackPos] = parent; |
|
3731 |
fLocalElemNamespaceContext[fLocalElemStackPos++] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext(); |
|
3732 |
} // end fillInLocalElemInfo(...) |
|
3733 |
||
3734 |
/** This method makes sure that |
|
3735 |
* if this component is being redefined that it lives in the |
|
3736 |
* right schema. It then renames the component correctly. If it |
|
3737 |
* detects a collision--a duplicate definition--then it complains. |
|
3738 |
* Note that redefines must be handled carefully: if there |
|
3739 |
* is a collision, it may be because we're redefining something we know about |
|
3740 |
* or because we've found the thing we're redefining. |
|
3741 |
*/ |
|
3742 |
void checkForDuplicateNames(String qName, int declType, |
|
3743 |
Map<String,Element> registry, Map<String,XSDocumentInfo> registry_sub, Element currComp, |
|
3744 |
XSDocumentInfo currSchema) { |
|
3745 |
Object objElem = null; |
|
3746 |
// REVISIT: when we add derivation checking, we'll have to make |
|
3747 |
// sure that ID constraint collisions don't necessarily result in error messages. |
|
3748 |
if ((objElem = registry.get(qName)) == null) { |
|
3749 |
// need to check whether we have a global declaration in the corresponding |
|
3750 |
// grammar |
|
3751 |
if (fNamespaceGrowth && !fTolerateDuplicates) { |
|
3752 |
checkForDuplicateNames(qName, declType, currComp); |
|
3753 |
} |
|
3754 |
// just add it in! |
|
3755 |
registry.put(qName, currComp); |
|
3756 |
registry_sub.put(qName, currSchema); |
|
3757 |
} |
|
3758 |
else { |
|
3759 |
Element collidingElem = (Element)objElem; |
|
3760 |
XSDocumentInfo collidingElemSchema = (XSDocumentInfo)registry_sub.get(qName); |
|
3761 |
if (collidingElem == currComp) return; |
|
3762 |
Element elemParent = null; |
|
3763 |
XSDocumentInfo redefinedSchema = null; |
|
3764 |
// case where we've collided with a redefining element |
|
3765 |
// (the parent of the colliding element is a redefine) |
|
3766 |
boolean collidedWithRedefine = true; |
|
3767 |
if ((DOMUtil.getLocalName((elemParent = DOMUtil.getParent(collidingElem))).equals(SchemaSymbols.ELT_REDEFINE))) { |
|
3768 |
redefinedSchema = (fRedefine2XSDMap != null)?(XSDocumentInfo) (fRedefine2XSDMap.get(elemParent)): null; |
|
3769 |
// case where we're a redefining element. |
|
3770 |
} |
|
3771 |
else if ((DOMUtil.getLocalName(DOMUtil.getParent(currComp)).equals(SchemaSymbols.ELT_REDEFINE))) { |
|
3772 |
redefinedSchema = collidingElemSchema; |
|
3773 |
collidedWithRedefine = false; |
|
3774 |
} |
|
3775 |
if (redefinedSchema != null) { //redefinition involved somehow |
|
3776 |
// If both components belong to the same document then |
|
3777 |
// report an error and return. |
|
3778 |
if(collidingElemSchema == currSchema){ |
|
3779 |
reportSchemaError("sch-props-correct.2", new Object[]{qName}, currComp); |
|
3780 |
return; |
|
3781 |
} |
|
3782 |
||
3783 |
String newName = qName.substring(qName.lastIndexOf(',')+1)+REDEF_IDENTIFIER; |
|
3784 |
if (redefinedSchema == currSchema) { // object comp. okay here |
|
3785 |
// now have to do some renaming... |
|
3786 |
currComp.setAttribute(SchemaSymbols.ATT_NAME, newName); |
|
3787 |
if (currSchema.fTargetNamespace == null){ |
|
3788 |
registry.put(","+newName, currComp); |
|
3789 |
registry_sub.put(","+newName, currSchema); |
|
3790 |
} |
|
3791 |
else{ |
|
3792 |
registry.put(currSchema.fTargetNamespace+","+newName, currComp); |
|
3793 |
registry_sub.put(currSchema.fTargetNamespace+","+newName, currSchema); |
|
3794 |
} |
|
3795 |
// and take care of nested redefines by calling recursively: |
|
3796 |
if (currSchema.fTargetNamespace == null) |
|
3797 |
checkForDuplicateNames(","+newName, declType, registry, registry_sub, currComp, currSchema); |
|
3798 |
else |
|
3799 |
checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, declType, registry, registry_sub, currComp, currSchema); |
|
3800 |
} |
|
3801 |
else { // we may be redefining the wrong schema |
|
3802 |
if (collidedWithRedefine) { |
|
3803 |
if (currSchema.fTargetNamespace == null) |
|
3804 |
checkForDuplicateNames(","+newName, declType, registry, registry_sub, currComp, currSchema); |
|
3805 |
else |
|
3806 |
checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, declType, registry, registry_sub, currComp, currSchema); |
|
3807 |
} |
|
3808 |
else { |
|
3809 |
// error that redefined element in wrong schema |
|
3810 |
reportSchemaError("sch-props-correct.2", new Object [] {qName}, currComp); |
|
3811 |
} |
|
3812 |
} |
|
3813 |
} |
|
3814 |
else { |
|
3815 |
// we've just got a flat-out collision (we tolerate duplicate |
|
3816 |
// declarations, only if they are defined in different schema |
|
3817 |
// documents) |
|
3818 |
if (!fTolerateDuplicates) { |
|
3819 |
reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp); |
|
3820 |
} else if (fUnparsedRegistriesExt[declType] != null) { |
|
3821 |
if (fUnparsedRegistriesExt[declType].get(qName) == currSchema) { |
|
3822 |
reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp); |
|
3823 |
} |
|
3824 |
} |
|
3825 |
} |
|
3826 |
} |
|
3827 |
||
3828 |
// store the lastest current document info |
|
3829 |
if (fTolerateDuplicates) { |
|
3830 |
if (fUnparsedRegistriesExt[declType] == null) |
|
3831 |
fUnparsedRegistriesExt[declType] = new HashMap(); |
|
3832 |
fUnparsedRegistriesExt[declType].put(qName, currSchema); |
|
3833 |
} |
|
3834 |
||
33349 | 3835 |
} // checkForDuplicateNames(String, Map, Element, XSDocumentInfo):void |
12005 | 3836 |
|
3837 |
void checkForDuplicateNames(String qName, int declType, Element currComp) { |
|
3838 |
int namespaceEnd = qName.indexOf(','); |
|
3839 |
String namespace = qName.substring(0, namespaceEnd); |
|
3840 |
SchemaGrammar grammar = fGrammarBucket.getGrammar(emptyString2Null(namespace)); |
|
3841 |
||
3842 |
if (grammar != null) { |
|
3843 |
Object obj = getGlobalDeclFromGrammar(grammar, declType, qName.substring(namespaceEnd + 1)); |
|
3844 |
if (obj != null) { |
|
3845 |
reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp); |
|
3846 |
} |
|
3847 |
} |
|
3848 |
} |
|
3849 |
||
3850 |
// the purpose of this method is to take the component of the |
|
3851 |
// specified type and rename references to itself so that they |
|
3852 |
// refer to the object being redefined. It takes special care of |
|
3853 |
// <group>s and <attributeGroup>s to ensure that information |
|
3854 |
// relating to implicit restrictions is preserved for those |
|
3855 |
// traversers. |
|
3856 |
private void renameRedefiningComponents(XSDocumentInfo currSchema, |
|
3857 |
Element child, String componentType, |
|
3858 |
String oldName, String newName) { |
|
3859 |
if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { |
|
3860 |
Element grandKid = DOMUtil.getFirstChildElement(child); |
|
3861 |
if (grandKid == null) { |
|
3862 |
reportSchemaError("src-redefine.5.a.a", null, child); |
|
3863 |
} |
|
3864 |
else { |
|
3865 |
String grandKidName = DOMUtil.getLocalName(grandKid); |
|
3866 |
if (grandKidName.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
3867 |
grandKid = DOMUtil.getNextSiblingElement(grandKid); |
|
3868 |
} |
|
3869 |
if (grandKid == null) { |
|
3870 |
reportSchemaError("src-redefine.5.a.a", null, child); |
|
3871 |
} |
|
3872 |
else { |
|
3873 |
grandKidName = DOMUtil.getLocalName(grandKid); |
|
3874 |
if (!grandKidName.equals(SchemaSymbols.ELT_RESTRICTION)) { |
|
3875 |
reportSchemaError("src-redefine.5.a.b", new Object[]{grandKidName}, child); |
|
3876 |
} |
|
3877 |
else { |
|
3878 |
Object[] attrs = fAttributeChecker.checkAttributes(grandKid, false, currSchema); |
|
3879 |
QName derivedBase = (QName)attrs[XSAttributeChecker.ATTIDX_BASE]; |
|
3880 |
if (derivedBase == null || |
|
3881 |
derivedBase.uri != currSchema.fTargetNamespace || |
|
3882 |
!derivedBase.localpart.equals(oldName)) { |
|
3883 |
reportSchemaError("src-redefine.5.a.c", |
|
3884 |
new Object[]{grandKidName, |
|
3885 |
(currSchema.fTargetNamespace==null?"":currSchema.fTargetNamespace) |
|
3886 |
+ "," + oldName}, |
|
3887 |
child); |
|
3888 |
} |
|
3889 |
else { |
|
3890 |
// now we have to do the renaming... |
|
3891 |
if (derivedBase.prefix != null && derivedBase.prefix.length() > 0) |
|
3892 |
grandKid.setAttribute( SchemaSymbols.ATT_BASE, |
|
3893 |
derivedBase.prefix + ":" + newName ); |
|
3894 |
else |
|
3895 |
grandKid.setAttribute( SchemaSymbols.ATT_BASE, newName ); |
|
3896 |
// return true; |
|
3897 |
} |
|
3898 |
fAttributeChecker.returnAttrArray(attrs, currSchema); |
|
3899 |
} |
|
3900 |
} |
|
3901 |
} |
|
3902 |
} |
|
3903 |
else if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { |
|
3904 |
Element grandKid = DOMUtil.getFirstChildElement(child); |
|
3905 |
if (grandKid == null) { |
|
3906 |
reportSchemaError("src-redefine.5.b.a", null, child); |
|
3907 |
} |
|
3908 |
else { |
|
3909 |
if (DOMUtil.getLocalName(grandKid).equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
3910 |
grandKid = DOMUtil.getNextSiblingElement(grandKid); |
|
3911 |
} |
|
3912 |
if (grandKid == null) { |
|
3913 |
reportSchemaError("src-redefine.5.b.a", null, child); |
|
3914 |
} |
|
3915 |
else { |
|
3916 |
// have to go one more level down; let another pass worry whether complexType is valid. |
|
3917 |
Element greatGrandKid = DOMUtil.getFirstChildElement(grandKid); |
|
3918 |
if (greatGrandKid == null) { |
|
3919 |
reportSchemaError("src-redefine.5.b.b", null, grandKid); |
|
3920 |
} |
|
3921 |
else { |
|
3922 |
String greatGrandKidName = DOMUtil.getLocalName(greatGrandKid); |
|
3923 |
if (greatGrandKidName.equals(SchemaSymbols.ELT_ANNOTATION)) { |
|
3924 |
greatGrandKid = DOMUtil.getNextSiblingElement(greatGrandKid); |
|
3925 |
} |
|
3926 |
if (greatGrandKid == null) { |
|
3927 |
reportSchemaError("src-redefine.5.b.b", null, grandKid); |
|
3928 |
} |
|
3929 |
else { |
|
3930 |
greatGrandKidName = DOMUtil.getLocalName(greatGrandKid); |
|
3931 |
if (!greatGrandKidName.equals(SchemaSymbols.ELT_RESTRICTION) && |
|
3932 |
!greatGrandKidName.equals(SchemaSymbols.ELT_EXTENSION)) { |
|
3933 |
reportSchemaError("src-redefine.5.b.c", new Object[]{greatGrandKidName}, greatGrandKid); |
|
3934 |
} |
|
3935 |
else { |
|
3936 |
Object[] attrs = fAttributeChecker.checkAttributes(greatGrandKid, false, currSchema); |
|
3937 |
QName derivedBase = (QName)attrs[XSAttributeChecker.ATTIDX_BASE]; |
|
3938 |
if (derivedBase == null || |
|
3939 |
derivedBase.uri != currSchema.fTargetNamespace || |
|
3940 |
!derivedBase.localpart.equals(oldName)) { |
|
3941 |
reportSchemaError("src-redefine.5.b.d", |
|
3942 |
new Object[]{greatGrandKidName, |
|
3943 |
(currSchema.fTargetNamespace==null?"":currSchema.fTargetNamespace) |
|
3944 |
+ "," + oldName}, |
|
3945 |
greatGrandKid); |
|
3946 |
} |
|
3947 |
else { |
|
3948 |
// now we have to do the renaming... |
|
3949 |
if (derivedBase.prefix != null && derivedBase.prefix.length() > 0) |
|
3950 |
greatGrandKid.setAttribute( SchemaSymbols.ATT_BASE, |
|
3951 |
derivedBase.prefix + ":" + newName ); |
|
3952 |
else |
|
3953 |
greatGrandKid.setAttribute( SchemaSymbols.ATT_BASE, |
|
3954 |
newName ); |
|
3955 |
// return true; |
|
3956 |
} |
|
3957 |
} |
|
3958 |
} |
|
3959 |
} |
|
3960 |
} |
|
3961 |
} |
|
3962 |
} |
|
3963 |
else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { |
|
3964 |
String processedBaseName = (currSchema.fTargetNamespace == null)? |
|
3965 |
","+oldName:currSchema.fTargetNamespace+","+oldName; |
|
3966 |
int attGroupRefsCount = changeRedefineGroup(processedBaseName, componentType, newName, child, currSchema); |
|
3967 |
if (attGroupRefsCount > 1) { |
|
3968 |
reportSchemaError("src-redefine.7.1", new Object []{new Integer(attGroupRefsCount)}, child); |
|
3969 |
} |
|
3970 |
else if (attGroupRefsCount == 1) { |
|
3971 |
// return true; |
|
3972 |
} |
|
3973 |
else |
|
3974 |
if (currSchema.fTargetNamespace == null) |
|
3975 |
fRedefinedRestrictedAttributeGroupRegistry.put(processedBaseName, ","+newName); |
|
3976 |
else |
|
3977 |
fRedefinedRestrictedAttributeGroupRegistry.put(processedBaseName, currSchema.fTargetNamespace+","+newName); |
|
3978 |
} |
|
3979 |
else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { |
|
3980 |
String processedBaseName = (currSchema.fTargetNamespace == null)? |
|
3981 |
","+oldName:currSchema.fTargetNamespace+","+oldName; |
|
3982 |
int groupRefsCount = changeRedefineGroup(processedBaseName, componentType, newName, child, currSchema); |
|
3983 |
if (groupRefsCount > 1) { |
|
3984 |
reportSchemaError("src-redefine.6.1.1", new Object []{new Integer(groupRefsCount)}, child); |
|
3985 |
} |
|
3986 |
else if (groupRefsCount == 1) { |
|
3987 |
// return true; |
|
3988 |
} |
|
3989 |
else { |
|
3990 |
if (currSchema.fTargetNamespace == null) |
|
3991 |
fRedefinedRestrictedGroupRegistry.put(processedBaseName, ","+newName); |
|
3992 |
else |
|
3993 |
fRedefinedRestrictedGroupRegistry.put(processedBaseName, currSchema.fTargetNamespace+","+newName); |
|
3994 |
} |
|
3995 |
} |
|
3996 |
else { |
|
3997 |
reportSchemaError("Internal-Error", new Object [] {"could not handle this particular <redefine>; please submit your schemas and instance document in a bug report!"}, child); |
|
3998 |
} |
|
3999 |
// if we get here then we must have reported an error and failed somewhere... |
|
4000 |
// return false; |
|
4001 |
} // renameRedefiningComponents(XSDocumentInfo, Element, String, String, String):void |
|
4002 |
||
4003 |
// this method takes a name of the form a:b, determines the URI mapped |
|
4004 |
// to by a in the current SchemaNamespaceSupport object, and returns this |
|
4005 |
// information in the form (nsURI,b) suitable for lookups in the global |
|
33349 | 4006 |
// decl maps. |
12005 | 4007 |
// REVISIT: should have it return QName, instead of String. this would |
4008 |
// save lots of string concatenation time. we can use |
|
4009 |
// QName#equals() to compare two QNames, and use QName directly |
|
4010 |
// as a key to the SymbolHash. |
|
4011 |
// And when the DV's are ready to return compiled values from |
|
4012 |
// validate() method, we should just call QNameDV.validate() |
|
4013 |
// in this method. |
|
4014 |
private String findQName(String name, XSDocumentInfo schemaDoc) { |
|
4015 |
SchemaNamespaceSupport currNSMap = schemaDoc.fNamespaceSupport; |
|
4016 |
int colonPtr = name.indexOf(':'); |
|
4017 |
String prefix = XMLSymbols.EMPTY_STRING; |
|
4018 |
if (colonPtr > 0) |
|
4019 |
prefix = name.substring(0, colonPtr); |
|
4020 |
String uri = currNSMap.getURI(fSymbolTable.addSymbol(prefix)); |
|
4021 |
String localpart = (colonPtr == 0)?name:name.substring(colonPtr+1); |
|
4022 |
if (prefix == XMLSymbols.EMPTY_STRING && uri == null && schemaDoc.fIsChameleonSchema) |
|
4023 |
uri = schemaDoc.fTargetNamespace; |
|
4024 |
if (uri == null) |
|
4025 |
return ","+localpart; |
|
4026 |
return uri+","+localpart; |
|
4027 |
} // findQName(String, XSDocumentInfo): String |
|
4028 |
||
4029 |
// This function looks among the children of curr for an element of type elementSought. |
|
4030 |
// If it finds one, it evaluates whether its ref attribute contains a reference |
|
4031 |
// to originalQName. If it does, it returns 1 + the value returned by |
|
4032 |
// calls to itself on all other children. In all other cases it returns 0 plus |
|
4033 |
// the sum of the values returned by calls to itself on curr's children. |
|
4034 |
// It also resets the value of ref so that it will refer to the renamed type from the schema |
|
4035 |
// being redefined. |
|
4036 |
private int changeRedefineGroup(String originalQName, String elementSought, |
|
4037 |
String newName, Element curr, XSDocumentInfo schemaDoc) { |
|
4038 |
int result = 0; |
|
4039 |
for (Element child = DOMUtil.getFirstChildElement(curr); |
|
4040 |
child != null; child = DOMUtil.getNextSiblingElement(child)) { |
|
4041 |
String name = DOMUtil.getLocalName(child); |
|
4042 |
if (!name.equals(elementSought)) |
|
4043 |
result += changeRedefineGroup(originalQName, elementSought, newName, child, schemaDoc); |
|
4044 |
else { |
|
4045 |
String ref = child.getAttribute( SchemaSymbols.ATT_REF ); |
|
4046 |
if (ref.length() != 0) { |
|
4047 |
String processedRef = findQName(ref, schemaDoc); |
|
4048 |
if (originalQName.equals(processedRef)) { |
|
4049 |
String prefix = XMLSymbols.EMPTY_STRING; |
|
4050 |
int colonptr = ref.indexOf(":"); |
|
4051 |
if (colonptr > 0) { |
|
4052 |
prefix = ref.substring(0,colonptr); |
|
4053 |
child.setAttribute(SchemaSymbols.ATT_REF, prefix + ":" + newName); |
|
4054 |
} |
|
4055 |
else |
|
4056 |
child.setAttribute(SchemaSymbols.ATT_REF, newName); |
|
4057 |
result++; |
|
4058 |
if (elementSought.equals(SchemaSymbols.ELT_GROUP)) { |
|
4059 |
String minOccurs = child.getAttribute( SchemaSymbols.ATT_MINOCCURS ); |
|
4060 |
String maxOccurs = child.getAttribute( SchemaSymbols.ATT_MAXOCCURS ); |
|
4061 |
if (!((maxOccurs.length() == 0 || maxOccurs.equals("1")) |
|
4062 |
&& (minOccurs.length() == 0 || minOccurs.equals("1")))) { |
|
4063 |
reportSchemaError("src-redefine.6.1.2", new Object [] {ref}, child); |
|
4064 |
} |
|
4065 |
} |
|
4066 |
} |
|
4067 |
} // if ref was null some other stage of processing will flag the error |
|
4068 |
} |
|
4069 |
} |
|
4070 |
return result; |
|
4071 |
} // changeRedefineGroup |
|
4072 |
||
4073 |
// this method returns the XSDocumentInfo object that contains the |
|
4074 |
// component corresponding to decl. If components from this |
|
4075 |
// document cannot be referred to from those of currSchema, this |
|
4076 |
// method returns null; it's up to the caller to throw an error. |
|
4077 |
// @param: currSchema: the XSDocumentInfo object containing the |
|
4078 |
// decl ref'ing us. |
|
4079 |
// @param: decl: the declaration being ref'd. |
|
4080 |
// this method is superficial now. ---Jack |
|
4081 |
private XSDocumentInfo findXSDocumentForDecl(XSDocumentInfo currSchema, |
|
4082 |
Element decl, XSDocumentInfo decl_Doc) { |
|
4083 |
||
4084 |
if (DEBUG_NODE_POOL) { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
4085 |
System.out.println("DOCUMENT NS:" + currSchema.fTargetNamespace + " hashcode:" + |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
4086 |
((Object)currSchema.fSchemaElement).hashCode()); |
12005 | 4087 |
} |
4088 |
Object temp = decl_Doc; |
|
4089 |
if (temp == null) { |
|
4090 |
// something went badly wrong; we don't know this doc? |
|
4091 |
return null; |
|
4092 |
} |
|
4093 |
XSDocumentInfo declDocInfo = (XSDocumentInfo)temp; |
|
4094 |
return declDocInfo; |
|
4095 |
/********* |
|
4096 |
Logic here is unnecessary after schema WG's recent decision to allow |
|
4097 |
schema components from one document to refer to components of any other, |
|
4098 |
so long as there's some include/import/redefine path amongst them. |
|
4099 |
If they rver reverse this decision the code's right here though... - neilg |
|
4100 |
// now look in fDependencyMap to see if this is reachable |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
4101 |
if((fDependencyMap.get(currSchema)).contains(declDocInfo)) { |
12005 | 4102 |
return declDocInfo; |
4103 |
} |
|
4104 |
// obviously the requesting doc didn't include, redefine or |
|
4105 |
// import the one containing decl... |
|
4106 |
return null; |
|
4107 |
**********/ |
|
4108 |
} // findXSDocumentForDecl(XSDocumentInfo, Element): XSDocumentInfo |
|
4109 |
||
4110 |
// returns whether more than <annotation>s occur in children of elem |
|
4111 |
private boolean nonAnnotationContent(Element elem) { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
4112 |
for(Element child = DOMUtil.getFirstChildElement(elem); child != null; |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
39907
diff
changeset
|
4113 |
child = DOMUtil.getNextSiblingElement(child)) { |
12005 | 4114 |
if(!(DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION))) return true; |
4115 |
} |
|
4116 |
return false; |
|
4117 |
} // nonAnnotationContent(Element): boolean |
|
4118 |
||
4119 |
private void setSchemasVisible(XSDocumentInfo startSchema) { |
|
4120 |
if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) { |
|
4121 |
// make it visible |
|
4122 |
DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
4123 |
Vector<XSDocumentInfo> dependingSchemas = fDependencyMap.get(startSchema); |
12005 | 4124 |
for (int i = 0; i < dependingSchemas.size(); i++) { |
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
4125 |
setSchemasVisible(dependingSchemas.elementAt(i)); |
12005 | 4126 |
} |
4127 |
} |
|
4128 |
// if it's visible already than so must be its children |
|
4129 |
} // setSchemasVisible(XSDocumentInfo): void |
|
4130 |
||
4131 |
private SimpleLocator xl = new SimpleLocator(); |
|
4132 |
||
4133 |
/** |
|
4134 |
* Extract location information from an Element node, and create a |
|
4135 |
* new SimpleLocator object from such information. Returning null means |
|
4136 |
* no information can be retrieved from the element. |
|
4137 |
*/ |
|
4138 |
public SimpleLocator element2Locator(Element e) { |
|
4139 |
if (!( e instanceof ElementImpl)) |
|
4140 |
return null; |
|
4141 |
||
4142 |
SimpleLocator l = new SimpleLocator(); |
|
4143 |
return element2Locator(e, l) ? l : null; |
|
4144 |
} |
|
4145 |
||
4146 |
/** |
|
4147 |
* Extract location information from an Element node, store such |
|
4148 |
* information in the passed-in SimpleLocator object, then return |
|
4149 |
* true. Returning false means can't extract or store such information. |
|
4150 |
*/ |
|
4151 |
public boolean element2Locator(Element e, SimpleLocator l) { |
|
4152 |
if (l == null) |
|
4153 |
return false; |
|
4154 |
if (e instanceof ElementImpl) { |
|
4155 |
ElementImpl ele = (ElementImpl)e; |
|
4156 |
// get system id from document object |
|
4157 |
Document doc = ele.getOwnerDocument(); |
|
36146
eca249f3c768
8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE
joehw
parents:
35729
diff
changeset
|
4158 |
String sid = fDoc2SystemId.get(DOMUtil.getRoot(doc)); |
12005 | 4159 |
// line/column numbers are stored in the element node |
4160 |
int line = ele.getLineNumber(); |
|
4161 |
int column = ele.getColumnNumber(); |
|
4162 |
l.setValues(sid, sid, line, column, ele.getCharacterOffset()); |
|
4163 |
return true; |
|
4164 |
} |
|
4165 |
return false; |
|
4166 |
} |
|
4167 |
||
4168 |
private Element getElementFromMap(Map<String, Element> registry, String declKey) { |
|
4169 |
if (registry == null) return null; |
|
4170 |
return registry.get(declKey); |
|
4171 |
} |
|
4172 |
||
4173 |
private XSDocumentInfo getDocInfoFromMap(Map<String, XSDocumentInfo> registry, String declKey) { |
|
4174 |
if (registry == null) return null; |
|
4175 |
return registry.get(declKey); |
|
4176 |
} |
|
4177 |
||
4178 |
private Object getFromMap(Map registry, String key) { |
|
4179 |
if (registry == null) return null; |
|
4180 |
return registry.get(key); |
|
4181 |
} |
|
4182 |
||
4183 |
void reportSchemaFatalError(String key, Object[] args, Element ele) { |
|
4184 |
reportSchemaErr(key, args, ele, XMLErrorReporter.SEVERITY_FATAL_ERROR, null); |
|
4185 |
} |
|
4186 |
||
4187 |
void reportSchemaError(String key, Object[] args, Element ele) { |
|
4188 |
reportSchemaErr(key, args, ele, XMLErrorReporter.SEVERITY_ERROR, null); |
|
4189 |
} |
|
4190 |
||
4191 |
void reportSchemaError(String key, Object[] args, Element ele, Exception exception) { |
|
4192 |
reportSchemaErr(key, args, ele, XMLErrorReporter.SEVERITY_ERROR, exception); |
|
4193 |
} |
|
4194 |
||
4195 |
void reportSchemaWarning(String key, Object[] args, Element ele) { |
|
4196 |
reportSchemaErr(key, args, ele, XMLErrorReporter.SEVERITY_WARNING, null); |
|
4197 |
} |
|
4198 |
||
4199 |
void reportSchemaWarning(String key, Object[] args, Element ele, Exception exception) { |
|
4200 |
reportSchemaErr(key, args, ele, XMLErrorReporter.SEVERITY_WARNING, exception); |
|
4201 |
} |
|
4202 |
||
4203 |
void reportSchemaErr(String key, Object[] args, Element ele, short type, Exception exception) { |
|
4204 |
if (element2Locator(ele, xl)) { |
|
4205 |
fErrorReporter.reportError(xl, XSMessageFormatter.SCHEMA_DOMAIN, |
|
4206 |
key, args, type, exception); |
|
4207 |
} |
|
4208 |
else { |
|
4209 |
fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, |
|
4210 |
key, args, type, exception); |
|
4211 |
} |
|
4212 |
} |
|
4213 |
||
4214 |
/** |
|
4215 |
* Grammar pool used for validating annotations. This will return all of the |
|
4216 |
* grammars from the grammar bucket. It will also return an object for the |
|
4217 |
* schema for schemas which will contain at least the relevant declarations |
|
4218 |
* for annotations. |
|
4219 |
*/ |
|
4220 |
private static class XSAnnotationGrammarPool implements XMLGrammarPool { |
|
4221 |
||
4222 |
private XSGrammarBucket fGrammarBucket; |
|
4223 |
private Grammar [] fInitialGrammarSet; |
|
4224 |
||
4225 |
public Grammar[] retrieveInitialGrammarSet(String grammarType) { |
|
4226 |
if (grammarType == XMLGrammarDescription.XML_SCHEMA) { |
|
4227 |
if (fInitialGrammarSet == null) { |
|
4228 |
if (fGrammarBucket == null) { |
|
4229 |
fInitialGrammarSet = new Grammar [] {SchemaGrammar.Schema4Annotations.INSTANCE}; |
|
4230 |
} |
|
4231 |
else { |
|
4232 |
SchemaGrammar [] schemaGrammars = fGrammarBucket.getGrammars(); |
|
4233 |
/** |
|
4234 |
* If the grammar bucket already contains the schema for schemas |
|
4235 |
* then we already have the definitions for the parts relevant |
|
4236 |
* to annotations. |
|
4237 |
*/ |
|
4238 |
for (int i = 0; i < schemaGrammars.length; ++i) { |
|
4239 |
if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(schemaGrammars[i].getTargetNamespace())) { |
|
4240 |
fInitialGrammarSet = schemaGrammars; |
|
4241 |
return fInitialGrammarSet; |
|
4242 |
} |
|
4243 |
} |
|
4244 |
Grammar [] grammars = new Grammar[schemaGrammars.length + 1]; |
|
4245 |
System.arraycopy(schemaGrammars, 0, grammars, 0, schemaGrammars.length); |
|
4246 |
grammars[grammars.length - 1] = SchemaGrammar.Schema4Annotations.INSTANCE; |
|
4247 |
fInitialGrammarSet = grammars; |
|
4248 |
} |
|
4249 |
} |
|
4250 |
return fInitialGrammarSet; |
|
4251 |
} |
|
4252 |
return new Grammar[0]; |
|
4253 |
} |
|
4254 |
||
4255 |
public void cacheGrammars(String grammarType, Grammar[] grammars) { |
|
4256 |
||
4257 |
} |
|
4258 |
||
4259 |
public Grammar retrieveGrammar(XMLGrammarDescription desc) { |
|
4260 |
if (desc.getGrammarType() == XMLGrammarDescription.XML_SCHEMA) { |
|
4261 |
final String tns = ((XMLSchemaDescription) desc).getTargetNamespace(); |
|
4262 |
if (fGrammarBucket != null) { |
|
4263 |
Grammar grammar = fGrammarBucket.getGrammar(tns); |
|
4264 |
if (grammar != null) { |
|
4265 |
return grammar; |
|
4266 |
} |
|
4267 |
} |
|
4268 |
if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(tns)) { |
|
4269 |
return SchemaGrammar.Schema4Annotations.INSTANCE; |
|
4270 |
} |
|
4271 |
} |
|
4272 |
return null; |
|
4273 |
} |
|
4274 |
||
4275 |
public void refreshGrammars(XSGrammarBucket gBucket) { |
|
4276 |
fGrammarBucket = gBucket; |
|
4277 |
fInitialGrammarSet = null; |
|
4278 |
} |
|
4279 |
||
4280 |
public void lockPool() {} |
|
4281 |
||
4282 |
public void unlockPool() {} |
|
4283 |
||
4284 |
public void clear() {} |
|
4285 |
} |
|
4286 |
||
4287 |
/** |
|
4288 |
* used to identify a reference to a schema document |
|
4289 |
* if the same document is referenced twice with the same key, then |
|
4290 |
* we only need to parse it once. |
|
4291 |
* |
|
4292 |
* When 2 XSDKey's are compared, the following table can be used to |
|
4293 |
* determine whether they are equal: |
|
4294 |
* inc red imp pre ins |
|
4295 |
* inc N/L ? N/L N/L N/L |
|
4296 |
* red ? N/L ? ? ? |
|
4297 |
* imp N/L ? N/P N/P N/P |
|
4298 |
* pre N/L ? N/P N/P N/P |
|
4299 |
* ins N/L ? N/P N/P N/P |
|
4300 |
* |
|
4301 |
* Where: N/L: duplicate when they have the same namespace and location. |
|
4302 |
* ? : not clear from the spec. |
|
4303 |
* REVISIT: to simplify the process, also considering |
|
4304 |
* it's very rare, we treat them as not duplicate. |
|
4305 |
* N/P: not possible. imp/pre/ins are referenced by namespace. |
|
4306 |
* when the first time we encounter a schema document for a |
|
4307 |
* namespace, we create a grammar and store it in the grammar |
|
4308 |
* bucket. when we see another reference to the same namespace, |
|
4309 |
* we first check whether a grammar with the same namespace is |
|
4310 |
* already in the bucket, which is true in this case, so we |
|
4311 |
* won't create another XSDKey. |
|
4312 |
* |
|
4313 |
* Conclusion from the table: two XSDKey's are duplicate only when all of |
|
4314 |
* the following are true: |
|
4315 |
* 1. They are both "redefine", or neither is "redefine"; |
|
4316 |
* 2. They have the same namespace; |
|
4317 |
* 3. They have the same non-null location. |
|
4318 |
* |
|
4319 |
* About 3: if neither has a non-null location, then it's the case where |
|
4320 |
* 2 input streams are provided, but no system ID is provided. We can't tell |
|
4321 |
* whether the 2 streams have the same content, so we treat them as not |
|
4322 |
* duplicate. |
|
4323 |
*/ |
|
4324 |
private static class XSDKey { |
|
4325 |
String systemId; |
|
4326 |
short referType; |
|
4327 |
// for inclue/redefine, this is the enclosing namespace |
|
4328 |
// for import/preparse/instance, this is the target namespace |
|
4329 |
String referNS; |
|
4330 |
||
4331 |
XSDKey(String systemId, short referType, String referNS) { |
|
4332 |
this.systemId = systemId; |
|
4333 |
this.referType = referType; |
|
4334 |
this.referNS = referNS; |
|
4335 |
} |
|
4336 |
||
4337 |
public int hashCode() { |
|
4338 |
// according to the description at the beginning of this class, |
|
4339 |
// we use the hashcode of the namespace as the hashcoe of this key. |
|
4340 |
return referNS == null ? 0 : referNS.hashCode(); |
|
4341 |
} |
|
4342 |
||
4343 |
public boolean equals(Object obj) { |
|
4344 |
if (!(obj instanceof XSDKey)) { |
|
4345 |
return false; |
|
4346 |
} |
|
4347 |
XSDKey key = (XSDKey)obj; |
|
4348 |
||
4349 |
// condition 1: both are redefine |
|
4350 |
/** if (referType == XSDDescription.CONTEXT_REDEFINE || |
|
4351 |
key.referType == XSDDescription.CONTEXT_REDEFINE) { |
|
4352 |
if (referType != key.referType) |
|
4353 |
return false; |
|
4354 |
}**/ |
|
4355 |
||
4356 |
// condition 2: same namespace |
|
4357 |
if (referNS != key.referNS) |
|
4358 |
return false; |
|
4359 |
||
4360 |
// condition 3: same non-null location |
|
4361 |
if (systemId == null || !systemId.equals(key.systemId)) { |
|
4362 |
return false; |
|
4363 |
} |
|
4364 |
||
4365 |
return true; |
|
4366 |
} |
|
4367 |
} |
|
4368 |
||
4369 |
private static final class SAX2XNIUtil extends ErrorHandlerWrapper { |
|
4370 |
public static XMLParseException createXMLParseException0(SAXParseException exception) { |
|
4371 |
return createXMLParseException(exception); |
|
4372 |
} |
|
4373 |
public static XNIException createXNIException0(SAXException exception) { |
|
4374 |
return createXNIException(exception); |
|
4375 |
} |
|
4376 |
} |
|
4377 |
||
4378 |
/** |
|
4379 |
* @param state |
|
4380 |
*/ |
|
4381 |
public void setGenerateSyntheticAnnotations(boolean state) { |
|
4382 |
fSchemaParser.setFeature(GENERATE_SYNTHETIC_ANNOTATIONS, state); |
|
4383 |
} |
|
4384 |
||
4385 |
} // XSDHandler |