86 import org.xml.sax.Locator; |
86 import org.xml.sax.Locator; |
87 import org.xml.sax.SAXException; |
87 import org.xml.sax.SAXException; |
88 import org.xml.sax.SAXParseException; |
88 import org.xml.sax.SAXParseException; |
89 |
89 |
90 public class SchemaBuilderImpl implements SchemaBuilder, ElementAnnotationBuilder, CommentList { |
90 public class SchemaBuilderImpl implements SchemaBuilder, ElementAnnotationBuilder, CommentList { |
91 private final SchemaBuilderImpl parent; |
91 |
92 private boolean hadError = false; |
92 private final SchemaBuilderImpl parent; |
93 private final SchemaPatternBuilder pb; |
93 private boolean hadError = false; |
94 private final DatatypeLibraryFactory datatypeLibraryFactory; |
94 private final SchemaPatternBuilder pb; |
95 private final String inheritNs; |
95 private final DatatypeLibraryFactory datatypeLibraryFactory; |
96 private final ErrorHandler eh; |
96 private final String inheritNs; |
97 private final OpenIncludes openIncludes; |
97 private final ErrorHandler eh; |
98 private final NameClassBuilder ncb =new NameClassBuilderImpl(); |
98 private final OpenIncludes openIncludes; |
99 static final Localizer localizer = new Localizer(SchemaBuilderImpl.class); |
99 private final NameClassBuilder ncb = new NameClassBuilderImpl(); |
100 |
100 static final Localizer localizer = new Localizer(SchemaBuilderImpl.class); |
101 static class OpenIncludes { |
101 |
102 final String uri; |
102 static class OpenIncludes { |
103 final OpenIncludes parent; |
103 |
104 |
104 final String uri; |
105 OpenIncludes(String uri, OpenIncludes parent) { |
105 final OpenIncludes parent; |
106 this.uri = uri; |
106 |
107 this.parent = parent; |
107 OpenIncludes(String uri, OpenIncludes parent) { |
108 } |
108 this.uri = uri; |
109 } |
109 this.parent = parent; |
110 |
110 } |
111 public ParsedPattern expandPattern(ParsedPattern _pattern) |
111 } |
112 throws BuildException, IllegalSchemaException { |
112 |
|
113 public ParsedPattern expandPattern(ParsedPattern _pattern) |
|
114 throws BuildException, IllegalSchemaException { |
113 Pattern pattern = (Pattern) _pattern; |
115 Pattern pattern = (Pattern) _pattern; |
114 if (!hadError) { |
116 if (!hadError) { |
115 try { |
117 try { |
116 pattern.checkRecursion(0); |
118 pattern.checkRecursion(0); |
117 pattern = pattern.expand(pb); |
119 pattern = pattern.expand(pb); |
118 pattern.checkRestrictions(Pattern.START_CONTEXT, null, null); |
120 pattern.checkRestrictions(Pattern.START_CONTEXT, null, null); |
119 if (!hadError) return pattern; |
121 if (!hadError) { |
|
122 return pattern; |
|
123 } |
120 } catch (SAXParseException e) { |
124 } catch (SAXParseException e) { |
121 error(e); |
125 error(e); |
122 } catch (SAXException e) { |
126 } catch (SAXException e) { |
123 throw new BuildException(e); |
127 throw new BuildException(e); |
124 } catch (RestrictionViolationException e) { |
128 } catch (RestrictionViolationException e) { |
125 if (e.getName() != null) |
129 if (e.getName() != null) { |
126 error(e.getMessageId(), e.getName().toString(), e |
130 error(e.getMessageId(), e.getName().toString(), e |
127 .getLocator()); |
131 .getLocator()); |
128 else |
132 } else { |
129 error(e.getMessageId(), e.getLocator()); |
133 error(e.getMessageId(), e.getLocator()); |
|
134 } |
130 } |
135 } |
131 } |
136 } |
132 throw new IllegalSchemaException(); |
137 throw new IllegalSchemaException(); |
133 } |
138 } |
134 |
139 |
135 /** |
140 /** |
136 * |
141 * |
137 * @param eh |
142 * @param eh Error handler to receive errors while building the schema. |
138 * Error handler to receive errors while building the schema. |
143 */ |
139 */ |
144 public SchemaBuilderImpl(ErrorHandler eh) { |
140 public SchemaBuilderImpl(ErrorHandler eh) { |
145 this(eh, |
141 this(eh, |
146 new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(), |
142 new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(), |
147 new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())), |
143 new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())), |
148 new SchemaPatternBuilder()); |
144 new SchemaPatternBuilder()); |
149 } |
145 } |
150 |
146 |
151 /** |
147 /** |
152 * |
148 * |
153 * @param eh Error handler to receive errors while building the schema. |
149 * @param eh |
154 * @param datatypeLibraryFactory This is consulted to locate datatype |
150 * Error handler to receive errors while building the schema. |
155 * libraries. |
151 * @param datatypeLibraryFactory |
156 * @param pb Used to build patterns. |
152 * This is consulted to locate datatype libraries. |
157 */ |
153 * @param pb |
158 public SchemaBuilderImpl(ErrorHandler eh, |
154 * Used to build patterns. |
159 DatatypeLibraryFactory datatypeLibraryFactory, |
155 */ |
160 SchemaPatternBuilder pb) { |
156 public SchemaBuilderImpl(ErrorHandler eh, |
161 this.parent = null; |
157 DatatypeLibraryFactory datatypeLibraryFactory, |
162 this.eh = eh; |
158 SchemaPatternBuilder pb) { |
163 this.datatypeLibraryFactory = datatypeLibraryFactory; |
159 this.parent = null; |
164 this.pb = pb; |
160 this.eh = eh; |
165 this.inheritNs = ""; |
161 this.datatypeLibraryFactory = datatypeLibraryFactory; |
166 this.openIncludes = null; |
162 this.pb = pb; |
167 } |
163 this.inheritNs = ""; |
168 |
164 this.openIncludes = null; |
169 private SchemaBuilderImpl(String inheritNs, |
165 } |
170 String uri, |
166 |
171 SchemaBuilderImpl parent) { |
167 private SchemaBuilderImpl(String inheritNs, |
172 this.parent = parent; |
168 String uri, |
173 this.eh = parent.eh; |
169 SchemaBuilderImpl parent) { |
174 this.datatypeLibraryFactory = parent.datatypeLibraryFactory; |
170 this.parent = parent; |
175 this.pb = parent.pb; |
171 this.eh = parent.eh; |
176 this.inheritNs = inheritNs; |
172 this.datatypeLibraryFactory = parent.datatypeLibraryFactory; |
177 this.openIncludes = new OpenIncludes(uri, parent.openIncludes); |
173 this.pb = parent.pb; |
178 } |
174 this.inheritNs = inheritNs; |
179 |
175 this.openIncludes = new OpenIncludes(uri, parent.openIncludes); |
180 public NameClassBuilder getNameClassBuilder() { |
176 } |
181 return ncb; |
177 |
182 } |
178 public NameClassBuilder getNameClassBuilder() { |
183 |
179 return ncb; |
184 public ParsedPattern makeChoice(List patterns, Location loc, Annotations anno) |
180 } |
185 throws BuildException { |
181 |
186 if (patterns.isEmpty()) { |
182 public ParsedPattern makeChoice(List patterns, Location loc, Annotations anno) |
187 throw new IllegalArgumentException(); |
183 throws BuildException { |
188 } |
184 if (patterns.isEmpty()) |
189 Pattern result = (Pattern) patterns.get(0); |
185 throw new IllegalArgumentException(); |
190 for (int i = 1; i < patterns.size(); i++) { |
186 Pattern result = (Pattern)patterns.get(0); |
191 result = pb.makeChoice(result, (Pattern) patterns.get(i)); |
187 for (int i = 1; i < patterns.size(); i++) |
192 } |
188 result = pb.makeChoice(result, (Pattern)patterns.get(i)); |
193 return result; |
189 return result; |
194 } |
190 } |
195 |
191 |
196 public ParsedPattern makeInterleave(List patterns, Location loc, Annotations anno) |
192 public ParsedPattern makeInterleave(List patterns, Location loc, Annotations anno) |
197 throws BuildException { |
193 throws BuildException { |
198 if (patterns.isEmpty()) { |
194 if (patterns.isEmpty()) |
199 throw new IllegalArgumentException(); |
195 throw new IllegalArgumentException(); |
200 } |
196 Pattern result = (Pattern)patterns.get(0); |
201 Pattern result = (Pattern) patterns.get(0); |
197 for (int i = 1; i < patterns.size(); i++) |
202 for (int i = 1; i < patterns.size(); i++) { |
198 result = pb.makeInterleave(result, (Pattern)patterns.get(i)); |
203 result = pb.makeInterleave(result, (Pattern) patterns.get(i)); |
199 return result; |
204 } |
200 } |
205 return result; |
201 |
206 } |
202 public ParsedPattern makeGroup(List patterns, Location loc, Annotations anno) |
207 |
203 throws BuildException { |
208 public ParsedPattern makeGroup(List patterns, Location loc, Annotations anno) |
204 if (patterns.isEmpty()) |
209 throws BuildException { |
205 throw new IllegalArgumentException(); |
210 if (patterns.isEmpty()) { |
206 Pattern result = (Pattern)patterns.get(0); |
211 throw new IllegalArgumentException(); |
207 for (int i = 1; i < patterns.size(); i++) |
212 } |
208 result = pb.makeGroup(result, (Pattern)patterns.get(i)); |
213 Pattern result = (Pattern) patterns.get(0); |
209 return result; |
214 for (int i = 1; i < patterns.size(); i++) { |
210 } |
215 result = pb.makeGroup(result, (Pattern) patterns.get(i)); |
211 |
216 } |
212 public ParsedPattern makeOneOrMore(ParsedPattern p, Location loc, Annotations anno) |
217 return result; |
213 throws BuildException { |
218 } |
214 return pb.makeOneOrMore((Pattern)p); |
219 |
215 } |
220 public ParsedPattern makeOneOrMore(ParsedPattern p, Location loc, Annotations anno) |
216 |
221 throws BuildException { |
217 public ParsedPattern makeZeroOrMore(ParsedPattern p, Location loc, Annotations anno) |
222 return pb.makeOneOrMore((Pattern) p); |
218 throws BuildException { |
223 } |
219 return pb.makeZeroOrMore((Pattern)p); |
224 |
220 } |
225 public ParsedPattern makeZeroOrMore(ParsedPattern p, Location loc, Annotations anno) |
221 |
226 throws BuildException { |
222 public ParsedPattern makeOptional(ParsedPattern p, Location loc, Annotations anno) |
227 return pb.makeZeroOrMore((Pattern) p); |
223 throws BuildException { |
228 } |
224 return pb.makeOptional((Pattern)p); |
229 |
225 } |
230 public ParsedPattern makeOptional(ParsedPattern p, Location loc, Annotations anno) |
226 |
231 throws BuildException { |
227 public ParsedPattern makeList(ParsedPattern p, Location loc, Annotations anno) |
232 return pb.makeOptional((Pattern) p); |
228 throws BuildException { |
233 } |
229 return pb.makeList((Pattern)p, (Locator)loc); |
234 |
230 } |
235 public ParsedPattern makeList(ParsedPattern p, Location loc, Annotations anno) |
231 |
236 throws BuildException { |
232 public ParsedPattern makeMixed(ParsedPattern p, Location loc, Annotations anno) |
237 return pb.makeList((Pattern) p, (Locator) loc); |
233 throws BuildException { |
238 } |
234 return pb.makeMixed((Pattern)p); |
239 |
235 } |
240 public ParsedPattern makeMixed(ParsedPattern p, Location loc, Annotations anno) |
236 |
241 throws BuildException { |
237 public ParsedPattern makeEmpty(Location loc, Annotations anno) { |
242 return pb.makeMixed((Pattern) p); |
238 return pb.makeEmpty(); |
243 } |
239 } |
244 |
240 |
245 public ParsedPattern makeEmpty(Location loc, Annotations anno) { |
241 public ParsedPattern makeNotAllowed(Location loc, Annotations anno) { |
246 return pb.makeEmpty(); |
242 return pb.makeUnexpandedNotAllowed(); |
247 } |
243 } |
248 |
244 |
249 public ParsedPattern makeNotAllowed(Location loc, Annotations anno) { |
245 public ParsedPattern makeText(Location loc, Annotations anno) { |
250 return pb.makeUnexpandedNotAllowed(); |
246 return pb.makeText(); |
251 } |
247 } |
252 |
248 |
253 public ParsedPattern makeText(Location loc, Annotations anno) { |
249 public ParsedPattern makeErrorPattern() { |
254 return pb.makeText(); |
250 return pb.makeError(); |
255 } |
251 } |
256 |
|
257 public ParsedPattern makeErrorPattern() { |
|
258 return pb.makeError(); |
|
259 } |
252 |
260 |
253 // public ParsedNameClass makeErrorNameClass() { |
261 // public ParsedNameClass makeErrorNameClass() { |
254 // return new ErrorNameClass(); |
262 // return new ErrorNameClass(); |
255 // } |
263 // } |
256 |
264 public ParsedPattern makeAttribute(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno) |
257 public ParsedPattern makeAttribute(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno) |
265 throws BuildException { |
258 throws BuildException { |
266 return pb.makeAttribute((NameClass) nc, (Pattern) p, (Locator) loc); |
259 return pb.makeAttribute((NameClass)nc, (Pattern)p, (Locator)loc); |
267 } |
260 } |
268 |
261 |
269 public ParsedPattern makeElement(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno) |
262 public ParsedPattern makeElement(ParsedNameClass nc, ParsedPattern p, Location loc, Annotations anno) |
270 throws BuildException { |
263 throws BuildException { |
271 return pb.makeElement((NameClass) nc, (Pattern) p, (Locator) loc); |
264 return pb.makeElement((NameClass)nc, (Pattern)p, (Locator)loc); |
272 } |
265 } |
273 |
266 |
274 private class DummyDataPatternBuilder implements DataPatternBuilder { |
267 private class DummyDataPatternBuilder implements DataPatternBuilder { |
275 |
268 public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno) |
276 public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno) |
269 throws BuildException { |
277 throws BuildException { |
270 } |
278 } |
271 |
279 |
272 public ParsedPattern makePattern(Location loc, Annotations anno) |
280 public ParsedPattern makePattern(Location loc, Annotations anno) |
273 throws BuildException { |
281 throws BuildException { |
274 return pb.makeError(); |
282 return pb.makeError(); |
275 } |
283 } |
276 |
284 |
277 public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno) |
285 public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno) |
278 throws BuildException { |
286 throws BuildException { |
279 return pb.makeError(); |
287 return pb.makeError(); |
280 } |
288 } |
281 |
289 |
282 public void annotation(ParsedElementAnnotation ea) { |
290 public void annotation(ParsedElementAnnotation ea) { |
283 } |
291 } |
284 } |
292 } |
285 |
293 |
286 private class ValidationContextImpl implements ValidationContext { |
294 private static class ValidationContextImpl implements ValidationContext { |
287 private ValidationContext vc; |
295 |
288 private String ns; |
296 private ValidationContext vc; |
289 |
297 private String ns; |
290 ValidationContextImpl(ValidationContext vc, String ns) { |
298 |
291 this.vc = vc; |
299 ValidationContextImpl(ValidationContext vc, String ns) { |
292 this.ns = ns.length() == 0 ? null : ns; |
300 this.vc = vc; |
293 } |
301 this.ns = ns.length() == 0 ? null : ns; |
294 |
302 } |
295 public String resolveNamespacePrefix(String prefix) { |
303 |
296 return prefix.length() == 0 ? ns : vc.resolveNamespacePrefix(prefix); |
304 public String resolveNamespacePrefix(String prefix) { |
297 } |
305 return prefix.length() == 0 ? ns : vc.resolveNamespacePrefix(prefix); |
298 |
306 } |
299 public String getBaseUri() { |
307 |
300 return vc.getBaseUri(); |
308 public String getBaseUri() { |
301 } |
309 return vc.getBaseUri(); |
302 |
310 } |
303 public boolean isUnparsedEntity(String entityName) { |
311 |
304 return vc.isUnparsedEntity(entityName); |
312 public boolean isUnparsedEntity(String entityName) { |
305 } |
313 return vc.isUnparsedEntity(entityName); |
306 |
314 } |
307 public boolean isNotation(String notationName) { |
315 |
308 return vc.isNotation(notationName); |
316 public boolean isNotation(String notationName) { |
309 } |
317 return vc.isNotation(notationName); |
310 } |
318 } |
311 |
319 } |
312 private class DataPatternBuilderImpl implements DataPatternBuilder { |
320 |
313 private DatatypeBuilder dtb; |
321 private class DataPatternBuilderImpl implements DataPatternBuilder { |
314 DataPatternBuilderImpl(DatatypeBuilder dtb) { |
322 |
315 this.dtb = dtb; |
323 private DatatypeBuilder dtb; |
316 } |
324 |
317 |
325 DataPatternBuilderImpl(DatatypeBuilder dtb) { |
318 public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno) |
326 this.dtb = dtb; |
319 throws BuildException { |
327 } |
320 try { |
328 |
321 dtb.addParameter(name, value, new ValidationContextImpl(context, ns)); |
329 public void addParam(String name, String value, Context context, String ns, Location loc, Annotations anno) |
322 } |
330 throws BuildException { |
323 catch (DatatypeException e) { |
331 try { |
324 String detail = e.getMessage(); |
332 dtb.addParameter(name, value, new ValidationContextImpl(context, ns)); |
325 int pos = e.getIndex(); |
333 } catch (DatatypeException e) { |
326 String displayedParam; |
334 String detail = e.getMessage(); |
327 if (pos == DatatypeException.UNKNOWN) |
335 int pos = e.getIndex(); |
328 displayedParam = null; |
336 String displayedParam; |
329 else |
337 if (pos == DatatypeException.UNKNOWN) { |
330 displayedParam = displayParam(value, pos); |
338 displayedParam = null; |
331 if (displayedParam != null) { |
339 } else { |
332 if (detail != null) |
340 displayedParam = displayParam(value, pos); |
333 error("invalid_param_detail_display", detail, displayedParam, (Locator)loc); |
341 } |
334 else |
342 if (displayedParam != null) { |
335 error("invalid_param_display", displayedParam, (Locator)loc); |
343 if (detail != null) { |
336 } |
344 error("invalid_param_detail_display", detail, displayedParam, (Locator) loc); |
337 else if (detail != null) |
345 } else { |
338 error("invalid_param_detail", detail, (Locator)loc); |
346 error("invalid_param_display", displayedParam, (Locator) loc); |
339 else |
347 } |
340 error("invalid_param", (Locator)loc); |
348 } else if (detail != null) { |
341 } |
349 error("invalid_param_detail", detail, (Locator) loc); |
342 } |
350 } else { |
343 |
351 error("invalid_param", (Locator) loc); |
344 String displayParam(String value, int pos) { |
352 } |
345 if (pos < 0) |
353 } |
346 pos = 0; |
354 } |
347 else if (pos > value.length()) |
355 |
348 pos = value.length(); |
356 String displayParam(String value, int pos) { |
349 return localizer.message("display_param", value.substring(0, pos), value.substring(pos)); |
357 if (pos < 0) { |
350 } |
358 pos = 0; |
351 |
359 } else if (pos > value.length()) { |
352 public ParsedPattern makePattern(Location loc, Annotations anno) |
360 pos = value.length(); |
353 throws BuildException { |
361 } |
354 try { |
362 return localizer.message("display_param", value.substring(0, pos), value.substring(pos)); |
355 return pb.makeData(dtb.createDatatype()); |
363 } |
356 } |
364 |
357 catch (DatatypeException e) { |
365 public ParsedPattern makePattern(Location loc, Annotations anno) |
358 String detail = e.getMessage(); |
366 throws BuildException { |
359 if (detail != null) |
367 try { |
360 error("invalid_params_detail", detail, (Locator)loc); |
368 return pb.makeData(dtb.createDatatype()); |
361 else |
369 } catch (DatatypeException e) { |
362 error("invalid_params", (Locator)loc); |
370 String detail = e.getMessage(); |
|
371 if (detail != null) { |
|
372 error("invalid_params_detail", detail, (Locator) loc); |
|
373 } else { |
|
374 error("invalid_params", (Locator) loc); |
|
375 } |
|
376 return pb.makeError(); |
|
377 } |
|
378 } |
|
379 |
|
380 public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno) |
|
381 throws BuildException { |
|
382 try { |
|
383 return pb.makeDataExcept(dtb.createDatatype(), (Pattern) except, (Locator) loc); |
|
384 } catch (DatatypeException e) { |
|
385 String detail = e.getMessage(); |
|
386 if (detail != null) { |
|
387 error("invalid_params_detail", detail, (Locator) loc); |
|
388 } else { |
|
389 error("invalid_params", (Locator) loc); |
|
390 } |
|
391 return pb.makeError(); |
|
392 } |
|
393 } |
|
394 |
|
395 public void annotation(ParsedElementAnnotation ea) { |
|
396 } |
|
397 } |
|
398 |
|
399 public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, Location loc) |
|
400 throws BuildException { |
|
401 DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary); |
|
402 if (dl == null) { |
|
403 error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc); |
|
404 } else { |
|
405 try { |
|
406 return new DataPatternBuilderImpl(dl.createDatatypeBuilder(type)); |
|
407 } catch (DatatypeException e) { |
|
408 String detail = e.getMessage(); |
|
409 if (detail != null) { |
|
410 error("unsupported_datatype_detail", datatypeLibrary, type, detail, (Locator) loc); |
|
411 } else { |
|
412 error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc); |
|
413 } |
|
414 } |
|
415 } |
|
416 return new DummyDataPatternBuilder(); |
|
417 } |
|
418 |
|
419 public ParsedPattern makeValue(String datatypeLibrary, String type, String value, Context context, String ns, |
|
420 Location loc, Annotations anno) throws BuildException { |
|
421 DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary); |
|
422 if (dl == null) { |
|
423 error("unrecognized_datatype_library", datatypeLibrary, (Locator) loc); |
|
424 } else { |
|
425 try { |
|
426 DatatypeBuilder dtb = dl.createDatatypeBuilder(type); |
|
427 try { |
|
428 Datatype dt = dtb.createDatatype(); |
|
429 Object obj = dt.createValue(value, new ValidationContextImpl(context, ns)); |
|
430 if (obj != null) { |
|
431 return pb.makeValue(dt, obj); |
|
432 } |
|
433 error("invalid_value", value, (Locator) loc); |
|
434 } catch (DatatypeException e) { |
|
435 String detail = e.getMessage(); |
|
436 if (detail != null) { |
|
437 error("datatype_requires_param_detail", detail, (Locator) loc); |
|
438 } else { |
|
439 error("datatype_requires_param", (Locator) loc); |
|
440 } |
|
441 } |
|
442 } catch (DatatypeException e) { |
|
443 error("unrecognized_datatype", datatypeLibrary, type, (Locator) loc); |
|
444 } |
|
445 } |
363 return pb.makeError(); |
446 return pb.makeError(); |
364 } |
447 } |
365 } |
448 |
366 |
449 static class GrammarImpl implements Grammar, Div, IncludedGrammar { |
367 public ParsedPattern makePattern(ParsedPattern except, Location loc, Annotations anno) |
450 |
368 throws BuildException { |
451 private final SchemaBuilderImpl sb; |
369 try { |
452 private final Hashtable defines; |
370 return pb.makeDataExcept(dtb.createDatatype(), (Pattern)except, (Locator)loc); |
453 private final RefPattern startRef; |
371 } |
454 private final Scope parent; |
372 catch (DatatypeException e) { |
455 |
373 String detail = e.getMessage(); |
456 private GrammarImpl(SchemaBuilderImpl sb, Scope parent) { |
374 if (detail != null) |
457 this.sb = sb; |
375 error("invalid_params_detail", detail, (Locator)loc); |
458 this.parent = parent; |
376 else |
459 this.defines = new Hashtable(); |
377 error("invalid_params", (Locator)loc); |
460 this.startRef = new RefPattern(null); |
378 return pb.makeError(); |
461 } |
379 } |
462 |
380 } |
463 protected GrammarImpl(SchemaBuilderImpl sb, GrammarImpl g) { |
381 |
464 this.sb = sb; |
382 public void annotation(ParsedElementAnnotation ea) { |
465 parent = g.parent; |
383 } |
466 startRef = g.startRef; |
384 } |
467 defines = g.defines; |
385 |
468 } |
386 public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, Location loc) |
469 |
387 throws BuildException { |
470 public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException { |
388 DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary); |
471 for (Enumeration e = defines.keys(); |
389 if (dl == null) |
472 e.hasMoreElements();) { |
390 error("unrecognized_datatype_library", datatypeLibrary, (Locator)loc); |
473 String name = (String) e.nextElement(); |
391 else { |
474 RefPattern rp = (RefPattern) defines.get(name); |
392 try { |
475 if (rp.getPattern() == null) { |
393 return new DataPatternBuilderImpl(dl.createDatatypeBuilder(type)); |
476 sb.error("reference_to_undefined", name, rp.getRefLocator()); |
394 } |
477 rp.setPattern(sb.pb.makeError()); |
395 catch (DatatypeException e) { |
478 } |
396 String detail = e.getMessage(); |
479 } |
397 if (detail != null) |
480 Pattern start = startRef.getPattern(); |
398 error("unsupported_datatype_detail", datatypeLibrary, type, detail, (Locator)loc); |
481 if (start == null) { |
399 else |
482 sb.error("missing_start_element", (Locator) loc); |
400 error("unrecognized_datatype", datatypeLibrary, type, (Locator)loc); |
483 start = sb.pb.makeError(); |
401 } |
484 } |
402 } |
485 return start; |
403 return new DummyDataPatternBuilder(); |
486 } |
404 } |
487 |
405 |
488 public void endDiv(Location loc, Annotations anno) throws BuildException { |
406 public ParsedPattern makeValue(String datatypeLibrary, String type, String value, Context context, String ns, |
489 // nothing to do |
407 Location loc, Annotations anno) throws BuildException { |
490 } |
408 DatatypeLibrary dl = datatypeLibraryFactory.createDatatypeLibrary(datatypeLibrary); |
491 |
409 if (dl == null) |
492 public ParsedPattern endIncludedGrammar(Location loc, Annotations anno) throws BuildException { |
410 error("unrecognized_datatype_library", datatypeLibrary, (Locator)loc); |
493 return null; |
411 else { |
494 } |
412 try { |
495 |
413 DatatypeBuilder dtb = dl.createDatatypeBuilder(type); |
496 public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno) |
|
497 throws BuildException { |
|
498 define(lookup(name), combine, pattern, loc); |
|
499 } |
|
500 |
|
501 private void define(RefPattern rp, GrammarSection.Combine combine, ParsedPattern pattern, Location loc) |
|
502 throws BuildException { |
|
503 switch (rp.getReplacementStatus()) { |
|
504 case RefPattern.REPLACEMENT_KEEP: |
|
505 if (combine == null) { |
|
506 if (rp.isCombineImplicit()) { |
|
507 if (rp.getName() == null) { |
|
508 sb.error("duplicate_start", (Locator) loc); |
|
509 } else { |
|
510 sb.error("duplicate_define", rp.getName(), (Locator) loc); |
|
511 } |
|
512 } else { |
|
513 rp.setCombineImplicit(); |
|
514 } |
|
515 } else { |
|
516 byte combineType = (combine == COMBINE_CHOICE ? RefPattern.COMBINE_CHOICE : RefPattern.COMBINE_INTERLEAVE); |
|
517 if (rp.getCombineType() != RefPattern.COMBINE_NONE |
|
518 && rp.getCombineType() != combineType) { |
|
519 if (rp.getName() == null) { |
|
520 sb.error("conflict_combine_start", (Locator) loc); |
|
521 } else { |
|
522 sb.error("conflict_combine_define", rp.getName(), (Locator) loc); |
|
523 } |
|
524 } |
|
525 rp.setCombineType(combineType); |
|
526 } |
|
527 Pattern p = (Pattern) pattern; |
|
528 if (rp.getPattern() == null) { |
|
529 rp.setPattern(p); |
|
530 } else if (rp.getCombineType() == RefPattern.COMBINE_INTERLEAVE) { |
|
531 rp.setPattern(sb.pb.makeInterleave(rp.getPattern(), p)); |
|
532 } else { |
|
533 rp.setPattern(sb.pb.makeChoice(rp.getPattern(), p)); |
|
534 } |
|
535 break; |
|
536 case RefPattern.REPLACEMENT_REQUIRE: |
|
537 rp.setReplacementStatus(RefPattern.REPLACEMENT_IGNORE); |
|
538 break; |
|
539 case RefPattern.REPLACEMENT_IGNORE: |
|
540 break; |
|
541 } |
|
542 } |
|
543 |
|
544 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
|
545 } |
|
546 |
|
547 public void topLevelComment(CommentList comments) throws BuildException { |
|
548 } |
|
549 |
|
550 private RefPattern lookup(String name) { |
|
551 if (name == START) { |
|
552 return startRef; |
|
553 } |
|
554 return lookup1(name); |
|
555 } |
|
556 |
|
557 private RefPattern lookup1(String name) { |
|
558 RefPattern p = (RefPattern) defines.get(name); |
|
559 if (p == null) { |
|
560 p = new RefPattern(name); |
|
561 defines.put(name, p); |
|
562 } |
|
563 return p; |
|
564 } |
|
565 |
|
566 public ParsedPattern makeRef(String name, Location loc, Annotations anno) throws BuildException { |
|
567 RefPattern p = lookup1(name); |
|
568 if (p.getRefLocator() == null && loc != null) { |
|
569 p.setRefLocator((Locator) loc); |
|
570 } |
|
571 return p; |
|
572 } |
|
573 |
|
574 public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException { |
|
575 // TODO: do this check by the caller |
|
576 if (parent == null) { |
|
577 sb.error("parent_ref_outside_grammar", (Locator) loc); |
|
578 return sb.makeErrorPattern(); |
|
579 } |
|
580 return parent.makeRef(name, loc, anno); |
|
581 } |
|
582 |
|
583 public Div makeDiv() { |
|
584 return this; |
|
585 } |
|
586 |
|
587 public Include makeInclude() { |
|
588 return new IncludeImpl(sb, this); |
|
589 } |
|
590 } |
|
591 |
|
592 static class Override { |
|
593 |
|
594 Override(RefPattern prp, Override next) { |
|
595 this.prp = prp; |
|
596 this.next = next; |
|
597 } |
|
598 RefPattern prp; |
|
599 Override next; |
|
600 byte replacementStatus; |
|
601 } |
|
602 |
|
603 private static class IncludeImpl implements Include, Div { |
|
604 |
|
605 private SchemaBuilderImpl sb; |
|
606 private Override overrides; |
|
607 private GrammarImpl grammar; |
|
608 |
|
609 private IncludeImpl(SchemaBuilderImpl sb, GrammarImpl grammar) { |
|
610 this.sb = sb; |
|
611 this.grammar = grammar; |
|
612 } |
|
613 |
|
614 public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno) |
|
615 throws BuildException { |
|
616 RefPattern rp = grammar.lookup(name); |
|
617 overrides = new Override(rp, overrides); |
|
618 grammar.define(rp, combine, pattern, loc); |
|
619 } |
|
620 |
|
621 public void endDiv(Location loc, Annotations anno) throws BuildException { |
|
622 // nothing to do |
|
623 } |
|
624 |
|
625 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
|
626 // nothing to do |
|
627 } |
|
628 |
|
629 public void topLevelComment(CommentList comments) throws BuildException { |
|
630 } |
|
631 |
|
632 public Div makeDiv() { |
|
633 return this; |
|
634 } |
|
635 |
|
636 public void endInclude(Parseable current, String uri, String ns, |
|
637 Location loc, Annotations anno) throws BuildException { |
|
638 for (OpenIncludes inc = sb.openIncludes; |
|
639 inc != null; |
|
640 inc = inc.parent) { |
|
641 if (inc.uri.equals(uri)) { |
|
642 sb.error("recursive_include", uri, (Locator) loc); |
|
643 return; |
|
644 } |
|
645 } |
|
646 |
|
647 for (Override o = overrides; o != null; o = o.next) { |
|
648 o.replacementStatus = o.prp.getReplacementStatus(); |
|
649 o.prp.setReplacementStatus(RefPattern.REPLACEMENT_REQUIRE); |
|
650 } |
|
651 try { |
|
652 SchemaBuilderImpl isb = new SchemaBuilderImpl(ns, uri, sb); |
|
653 current.parseInclude(uri, isb, new GrammarImpl(isb, grammar), ns); |
|
654 for (Override o = overrides; o != null; o = o.next) { |
|
655 if (o.prp.getReplacementStatus() == RefPattern.REPLACEMENT_REQUIRE) { |
|
656 if (o.prp.getName() == null) { |
|
657 sb.error("missing_start_replacement", (Locator) loc); |
|
658 } else { |
|
659 sb.error("missing_define_replacement", o.prp.getName(), (Locator) loc); |
|
660 } |
|
661 } |
|
662 } |
|
663 } catch (IllegalSchemaException e) { |
|
664 sb.noteError(); |
|
665 } finally { |
|
666 for (Override o = overrides; o != null; o = o.next) { |
|
667 o.prp.setReplacementStatus(o.replacementStatus); |
|
668 } |
|
669 } |
|
670 } |
|
671 |
|
672 public Include makeInclude() { |
|
673 return null; |
|
674 } |
|
675 } |
|
676 |
|
677 public Grammar makeGrammar(Scope parent) { |
|
678 return new GrammarImpl(this, parent); |
|
679 } |
|
680 |
|
681 public ParsedPattern annotate(ParsedPattern p, Annotations anno) throws BuildException { |
|
682 return p; |
|
683 } |
|
684 |
|
685 public ParsedPattern annotateAfter(ParsedPattern p, ParsedElementAnnotation e) throws BuildException { |
|
686 return p; |
|
687 } |
|
688 |
|
689 public ParsedPattern commentAfter(ParsedPattern p, CommentList comments) throws BuildException { |
|
690 return p; |
|
691 } |
|
692 |
|
693 public ParsedPattern makeExternalRef(Parseable current, String uri, String ns, Scope scope, |
|
694 Location loc, Annotations anno) |
|
695 throws BuildException { |
|
696 for (OpenIncludes inc = openIncludes; |
|
697 inc != null; |
|
698 inc = inc.parent) { |
|
699 if (inc.uri.equals(uri)) { |
|
700 error("recursive_include", uri, (Locator) loc); |
|
701 return pb.makeError(); |
|
702 } |
|
703 } |
414 try { |
704 try { |
415 Datatype dt = dtb.createDatatype(); |
705 return current.parseExternal(uri, new SchemaBuilderImpl(ns, uri, this), scope, ns); |
416 Object obj = dt.createValue(value, new ValidationContextImpl(context, ns)); |
706 } catch (IllegalSchemaException e) { |
417 if (obj != null) |
707 noteError(); |
418 return pb.makeValue(dt, obj); |
708 return pb.makeError(); |
419 error("invalid_value", value, (Locator)loc); |
709 } |
420 } |
710 } |
421 catch (DatatypeException e) { |
711 |
422 String detail = e.getMessage(); |
712 public Location makeLocation(String systemId, int lineNumber, int columnNumber) { |
423 if (detail != null) |
713 return new LocatorImpl(systemId, lineNumber, columnNumber); |
424 error("datatype_requires_param_detail", detail, (Locator)loc); |
714 } |
425 else |
715 |
426 error("datatype_requires_param", (Locator)loc); |
716 public Annotations makeAnnotations(CommentList comments, Context context) { |
427 } |
717 return this; |
428 } |
718 } |
429 catch (DatatypeException e) { |
719 |
430 error("unrecognized_datatype", datatypeLibrary, type, (Locator)loc); |
720 public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns, String localName, String prefix, |
431 } |
721 Location loc, CommentList comments, Context context) { |
432 } |
722 return this; |
433 return pb.makeError(); |
723 } |
434 } |
724 |
435 |
725 public CommentList makeCommentList() { |
436 static class GrammarImpl implements Grammar, Div, IncludedGrammar { |
726 return this; |
437 private final SchemaBuilderImpl sb; |
727 } |
438 private final Hashtable defines; |
728 |
439 private final RefPattern startRef; |
729 public void addComment(String value, Location loc) throws BuildException { |
440 private final Scope parent; |
730 } |
441 |
731 |
442 private GrammarImpl(SchemaBuilderImpl sb, Scope parent) { |
732 public void addAttribute(String ns, String localName, String prefix, String value, Location loc) { |
443 this.sb = sb; |
733 // nothing needed |
444 this.parent = parent; |
734 } |
445 this.defines = new Hashtable(); |
735 |
446 this.startRef = new RefPattern(null); |
736 public void addElement(ParsedElementAnnotation ea) { |
447 } |
737 // nothing needed |
448 |
738 } |
449 protected GrammarImpl(SchemaBuilderImpl sb, GrammarImpl g) { |
739 |
450 this.sb = sb; |
740 public void addComment(CommentList comments) throws BuildException { |
451 parent = g.parent; |
741 // nothing needed |
452 startRef = g.startRef; |
742 } |
453 defines = g.defines; |
743 |
454 } |
744 public void addLeadingComment(CommentList comments) throws BuildException { |
455 |
745 // nothing needed |
456 public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException { |
746 } |
457 for (Enumeration e = defines.keys(); |
747 |
458 e.hasMoreElements();) { |
748 public ParsedElementAnnotation makeElementAnnotation() { |
459 String name = (String)e.nextElement(); |
|
460 RefPattern rp = (RefPattern)defines.get(name); |
|
461 if (rp.getPattern() == null) { |
|
462 sb.error("reference_to_undefined", name, rp.getRefLocator()); |
|
463 rp.setPattern(sb.pb.makeError()); |
|
464 } |
|
465 } |
|
466 Pattern start = startRef.getPattern(); |
|
467 if (start == null) { |
|
468 sb.error("missing_start_element", (Locator)loc); |
|
469 start = sb.pb.makeError(); |
|
470 } |
|
471 return start; |
|
472 } |
|
473 |
|
474 public void endDiv(Location loc, Annotations anno) throws BuildException { |
|
475 // nothing to do |
|
476 } |
|
477 |
|
478 public ParsedPattern endIncludedGrammar(Location loc, Annotations anno) throws BuildException { |
|
479 return null; |
749 return null; |
480 } |
750 } |
481 |
751 |
482 public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno) |
752 public void addText(String value, Location loc, CommentList comments) throws BuildException { |
483 throws BuildException { |
753 } |
484 define(lookup(name), combine, pattern, loc); |
754 |
485 } |
755 public boolean usesComments() { |
486 |
756 return false; |
487 private void define(RefPattern rp, GrammarSection.Combine combine, ParsedPattern pattern, Location loc) |
757 } |
488 throws BuildException { |
758 |
489 switch (rp.getReplacementStatus()) { |
759 private void error(SAXParseException message) throws BuildException { |
490 case RefPattern.REPLACEMENT_KEEP: |
760 noteError(); |
491 if (combine == null) { |
761 try { |
492 if (rp.isCombineImplicit()) { |
762 if (eh != null) { |
493 if (rp.getName() == null) |
763 eh.error(message); |
494 sb.error("duplicate_start", (Locator)loc); |
764 } |
495 else |
765 } catch (SAXException e) { |
496 sb.error("duplicate_define", rp.getName(), (Locator)loc); |
766 throw new BuildException(e); |
497 } |
767 } |
498 else |
768 } |
499 rp.setCombineImplicit(); |
769 |
500 } |
770 private void error(String key, Locator loc) throws BuildException { |
501 else { |
771 error(new SAXParseException(localizer.message(key), loc)); |
502 byte combineType = (combine == COMBINE_CHOICE ? RefPattern.COMBINE_CHOICE : RefPattern.COMBINE_INTERLEAVE); |
772 } |
503 if (rp.getCombineType() != RefPattern.COMBINE_NONE |
773 |
504 && rp.getCombineType() != combineType) { |
774 private void error(String key, String arg, Locator loc) throws BuildException { |
505 if (rp.getName() == null) |
775 error(new SAXParseException(localizer.message(key, arg), loc)); |
506 sb.error("conflict_combine_start", (Locator)loc); |
776 } |
507 else |
777 |
508 sb.error("conflict_combine_define", rp.getName(), (Locator)loc); |
778 private void error(String key, String arg1, String arg2, Locator loc) throws BuildException { |
509 } |
779 error(new SAXParseException(localizer.message(key, arg1, arg2), loc)); |
510 rp.setCombineType(combineType); |
780 } |
511 } |
781 |
512 Pattern p = (Pattern)pattern; |
782 private void error(String key, String arg1, String arg2, String arg3, Locator loc) throws BuildException { |
513 if (rp.getPattern() == null) |
783 error(new SAXParseException(localizer.message(key, new Object[]{arg1, arg2, arg3}), loc)); |
514 rp.setPattern(p); |
784 } |
515 else if (rp.getCombineType() == RefPattern.COMBINE_INTERLEAVE) |
785 |
516 rp.setPattern(sb.pb.makeInterleave(rp.getPattern(), p)); |
786 private void noteError() { |
517 else |
787 if (!hadError && parent != null) { |
518 rp.setPattern(sb.pb.makeChoice(rp.getPattern(), p)); |
788 parent.noteError(); |
519 break; |
789 } |
520 case RefPattern.REPLACEMENT_REQUIRE: |
790 hadError = true; |
521 rp.setReplacementStatus(RefPattern.REPLACEMENT_IGNORE); |
791 } |
522 break; |
|
523 case RefPattern.REPLACEMENT_IGNORE: |
|
524 break; |
|
525 } |
|
526 } |
|
527 |
|
528 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
|
529 } |
|
530 |
|
531 public void topLevelComment(CommentList comments) throws BuildException { |
|
532 } |
|
533 |
|
534 private RefPattern lookup(String name) { |
|
535 if (name == START) |
|
536 return startRef; |
|
537 return lookup1(name); |
|
538 } |
|
539 |
|
540 private RefPattern lookup1(String name) { |
|
541 RefPattern p = (RefPattern)defines.get(name); |
|
542 if (p == null) { |
|
543 p = new RefPattern(name); |
|
544 defines.put(name, p); |
|
545 } |
|
546 return p; |
|
547 } |
|
548 |
|
549 public ParsedPattern makeRef(String name, Location loc, Annotations anno) throws BuildException { |
|
550 RefPattern p = lookup1(name); |
|
551 if (p.getRefLocator() == null && loc != null) |
|
552 p.setRefLocator((Locator)loc); |
|
553 return p; |
|
554 } |
|
555 |
|
556 public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException { |
|
557 // TODO: do this check by the caller |
|
558 if (parent == null) { |
|
559 sb.error("parent_ref_outside_grammar", (Locator)loc); |
|
560 return sb.makeErrorPattern(); |
|
561 } |
|
562 return parent.makeRef(name, loc, anno); |
|
563 } |
|
564 |
|
565 public Div makeDiv() { |
|
566 return this; |
|
567 } |
|
568 |
|
569 public Include makeInclude() { |
|
570 return new IncludeImpl(sb, this); |
|
571 } |
|
572 |
|
573 } |
|
574 |
|
575 |
|
576 static class Override { |
|
577 Override(RefPattern prp, Override next) { |
|
578 this.prp = prp; |
|
579 this.next = next; |
|
580 } |
|
581 |
|
582 RefPattern prp; |
|
583 Override next; |
|
584 byte replacementStatus; |
|
585 } |
|
586 |
|
587 |
|
588 private static class IncludeImpl implements Include, Div { |
|
589 private SchemaBuilderImpl sb; |
|
590 private Override overrides; |
|
591 private GrammarImpl grammar; |
|
592 |
|
593 private IncludeImpl(SchemaBuilderImpl sb, GrammarImpl grammar) { |
|
594 this.sb = sb; |
|
595 this.grammar = grammar; |
|
596 } |
|
597 |
|
598 public void define(String name, GrammarSection.Combine combine, ParsedPattern pattern, Location loc, Annotations anno) |
|
599 throws BuildException { |
|
600 RefPattern rp = grammar.lookup(name); |
|
601 overrides = new Override(rp, overrides); |
|
602 grammar.define(rp, combine, pattern, loc); |
|
603 } |
|
604 |
|
605 public void endDiv(Location loc, Annotations anno) throws BuildException { |
|
606 // nothing to do |
|
607 } |
|
608 |
|
609 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
|
610 // nothing to do |
|
611 } |
|
612 |
|
613 public void topLevelComment(CommentList comments) throws BuildException { |
|
614 } |
|
615 |
|
616 public Div makeDiv() { |
|
617 return this; |
|
618 } |
|
619 |
|
620 public void endInclude(Parseable current,String uri, String ns, |
|
621 Location loc, Annotations anno) throws BuildException { |
|
622 for (OpenIncludes inc = sb.openIncludes; |
|
623 inc != null; |
|
624 inc = inc.parent) { |
|
625 if (inc.uri.equals(uri)) { |
|
626 sb.error("recursive_include", uri, (Locator)loc); |
|
627 return; |
|
628 } |
|
629 } |
|
630 |
|
631 for (Override o = overrides; o != null; o = o.next) { |
|
632 o.replacementStatus = o.prp.getReplacementStatus(); |
|
633 o.prp.setReplacementStatus(RefPattern.REPLACEMENT_REQUIRE); |
|
634 } |
|
635 try { |
|
636 SchemaBuilderImpl isb = new SchemaBuilderImpl(ns, uri, sb); |
|
637 current.parseInclude(uri, isb, new GrammarImpl(isb, grammar), ns); |
|
638 for (Override o = overrides; o != null; o = o.next) { |
|
639 if (o.prp.getReplacementStatus() == RefPattern.REPLACEMENT_REQUIRE) { |
|
640 if (o.prp.getName() == null) |
|
641 sb.error("missing_start_replacement", (Locator)loc); |
|
642 else |
|
643 sb.error("missing_define_replacement", o.prp.getName(), (Locator)loc); |
|
644 } |
|
645 } |
|
646 } |
|
647 catch (IllegalSchemaException e) { |
|
648 sb.noteError(); |
|
649 } |
|
650 finally { |
|
651 for (Override o = overrides; o != null; o = o.next) |
|
652 o.prp.setReplacementStatus(o.replacementStatus); |
|
653 } |
|
654 } |
|
655 |
|
656 public Include makeInclude() { |
|
657 return null; |
|
658 } |
|
659 } |
|
660 |
|
661 public Grammar makeGrammar(Scope parent) { |
|
662 return new GrammarImpl(this, parent); |
|
663 } |
|
664 |
|
665 public ParsedPattern annotate(ParsedPattern p, Annotations anno) throws BuildException { |
|
666 return p; |
|
667 } |
|
668 |
|
669 |
|
670 public ParsedPattern annotateAfter(ParsedPattern p, ParsedElementAnnotation e) throws BuildException { |
|
671 return p; |
|
672 } |
|
673 |
|
674 public ParsedPattern commentAfter(ParsedPattern p, CommentList comments) throws BuildException { |
|
675 return p; |
|
676 } |
|
677 |
|
678 |
|
679 public ParsedPattern makeExternalRef(Parseable current, String uri, String ns, Scope scope, |
|
680 Location loc, Annotations anno) |
|
681 throws BuildException { |
|
682 for (OpenIncludes inc = openIncludes; |
|
683 inc != null; |
|
684 inc = inc.parent) { |
|
685 if (inc.uri.equals(uri)) { |
|
686 error("recursive_include", uri, (Locator)loc); |
|
687 return pb.makeError(); |
|
688 } |
|
689 } |
|
690 try { |
|
691 return current.parseExternal(uri, new SchemaBuilderImpl(ns, uri, this), scope, ns ); |
|
692 } |
|
693 catch (IllegalSchemaException e) { |
|
694 noteError(); |
|
695 return pb.makeError(); |
|
696 } |
|
697 } |
|
698 |
|
699 |
|
700 |
|
701 public Location makeLocation(String systemId, int lineNumber, int columnNumber) { |
|
702 return new LocatorImpl(systemId, lineNumber, columnNumber); |
|
703 } |
|
704 |
|
705 public Annotations makeAnnotations(CommentList comments, Context context) { |
|
706 return this; |
|
707 } |
|
708 |
|
709 public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns, String localName, String prefix, |
|
710 Location loc, CommentList comments, Context context) { |
|
711 return this; |
|
712 } |
|
713 |
|
714 public CommentList makeCommentList() { |
|
715 return this; |
|
716 } |
|
717 |
|
718 public void addComment(String value, Location loc) throws BuildException { |
|
719 } |
|
720 |
|
721 public void addAttribute(String ns, String localName, String prefix, String value, Location loc) { |
|
722 // nothing needed |
|
723 } |
|
724 |
|
725 public void addElement(ParsedElementAnnotation ea) { |
|
726 // nothing needed |
|
727 } |
|
728 |
|
729 public void addComment(CommentList comments) throws BuildException { |
|
730 // nothing needed |
|
731 } |
|
732 |
|
733 public void addLeadingComment(CommentList comments) throws BuildException { |
|
734 // nothing needed |
|
735 } |
|
736 |
|
737 public ParsedElementAnnotation makeElementAnnotation() { |
|
738 return null; |
|
739 } |
|
740 |
|
741 public void addText(String value, Location loc, CommentList comments) throws BuildException { |
|
742 } |
|
743 |
|
744 public boolean usesComments() { |
|
745 return false; |
|
746 } |
|
747 |
|
748 private void error(SAXParseException message) throws BuildException { |
|
749 noteError(); |
|
750 try { |
|
751 if (eh != null) |
|
752 eh.error(message); |
|
753 } |
|
754 catch (SAXException e) { |
|
755 throw new BuildException(e); |
|
756 } |
|
757 } |
|
758 |
|
759 private void warning(SAXParseException message) throws BuildException { |
|
760 try { |
|
761 if (eh != null) |
|
762 eh.warning(message); |
|
763 } |
|
764 catch (SAXException e) { |
|
765 throw new BuildException(e); |
|
766 } |
|
767 } |
|
768 |
|
769 private void error(String key, Locator loc) throws BuildException { |
|
770 error(new SAXParseException(localizer.message(key), loc)); |
|
771 } |
|
772 |
|
773 private void error(String key, String arg, Locator loc) throws BuildException { |
|
774 error(new SAXParseException(localizer.message(key, arg), loc)); |
|
775 } |
|
776 |
|
777 private void error(String key, String arg1, String arg2, Locator loc) throws BuildException { |
|
778 error(new SAXParseException(localizer.message(key, arg1, arg2), loc)); |
|
779 } |
|
780 |
|
781 private void error(String key, String arg1, String arg2, String arg3, Locator loc) throws BuildException { |
|
782 error(new SAXParseException(localizer.message(key, new Object[]{arg1, arg2, arg3}), loc)); |
|
783 } |
|
784 private void noteError() { |
|
785 if (!hadError && parent != null) |
|
786 parent.noteError(); |
|
787 hadError = true; |
|
788 } |
|
789 |
|
790 } |
792 } |