001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.rngom.binary;
027:
028: import java.util.Enumeration;
029: import java.util.Hashtable;
030: import java.util.List;
031:
032: import com.sun.xml.internal.rngom.ast.builder.Annotations;
033: import com.sun.xml.internal.rngom.ast.builder.BuildException;
034: import com.sun.xml.internal.rngom.ast.builder.CommentList;
035: import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
036: import com.sun.xml.internal.rngom.ast.builder.Div;
037: import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
038: import com.sun.xml.internal.rngom.ast.builder.Grammar;
039: import com.sun.xml.internal.rngom.ast.builder.GrammarSection;
040: import com.sun.xml.internal.rngom.ast.builder.Include;
041: import com.sun.xml.internal.rngom.ast.builder.IncludedGrammar;
042: import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
043: import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
044: import com.sun.xml.internal.rngom.ast.builder.Scope;
045: import com.sun.xml.internal.rngom.ast.om.Location;
046: import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
047: import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
048: import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
049: import com.sun.xml.internal.rngom.ast.util.LocatorImpl;
050: import com.sun.xml.internal.rngom.dt.builtin.BuiltinDatatypeLibraryFactory;
051: import com.sun.xml.internal.rngom.nc.NameClass;
052: import com.sun.xml.internal.rngom.nc.NameClassBuilderImpl;
053: import com.sun.xml.internal.rngom.parse.Context;
054: import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
055: import com.sun.xml.internal.rngom.parse.Parseable;
056: import com.sun.xml.internal.rngom.util.Localizer;
057: import org.relaxng.datatype.Datatype;
058: import org.relaxng.datatype.DatatypeBuilder;
059: import org.relaxng.datatype.DatatypeException;
060: import org.relaxng.datatype.DatatypeLibrary;
061: import org.relaxng.datatype.DatatypeLibraryFactory;
062: import org.relaxng.datatype.ValidationContext;
063: import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
064: import org.xml.sax.ErrorHandler;
065: import org.xml.sax.Locator;
066: import org.xml.sax.SAXException;
067: import org.xml.sax.SAXParseException;
068:
069: public class SchemaBuilderImpl implements SchemaBuilder,
070: ElementAnnotationBuilder, CommentList {
071: private final SchemaBuilderImpl parent;
072: private boolean hadError = false;
073: private final SchemaPatternBuilder pb;
074: private final DatatypeLibraryFactory datatypeLibraryFactory;
075: private final String inheritNs;
076: private final ErrorHandler eh;
077: private final OpenIncludes openIncludes;
078: private final NameClassBuilder ncb = new NameClassBuilderImpl();
079: static final Localizer localizer = new Localizer(
080: SchemaBuilderImpl.class);
081:
082: static class OpenIncludes {
083: final String uri;
084: final OpenIncludes parent;
085:
086: OpenIncludes(String uri, OpenIncludes parent) {
087: this .uri = uri;
088: this .parent = parent;
089: }
090: }
091:
092: public ParsedPattern expandPattern(ParsedPattern _pattern)
093: throws BuildException, IllegalSchemaException {
094: Pattern pattern = (Pattern) _pattern;
095: if (!hadError) {
096: try {
097: pattern.checkRecursion(0);
098: pattern = pattern.expand(pb);
099: pattern.checkRestrictions(Pattern.START_CONTEXT, null,
100: null);
101: if (!hadError)
102: return pattern;
103: } catch (SAXParseException e) {
104: error(e);
105: } catch (SAXException e) {
106: throw new BuildException(e);
107: } catch (RestrictionViolationException e) {
108: if (e.getName() != null)
109: error(e.getMessageId(), e.getName().toString(), e
110: .getLocator());
111: else
112: error(e.getMessageId(), e.getLocator());
113: }
114: }
115: throw new IllegalSchemaException();
116: }
117:
118: /**
119: *
120: * @param eh
121: * Error handler to receive errors while building the schema.
122: */
123: public SchemaBuilderImpl(ErrorHandler eh) {
124: this (eh, new BuiltinDatatypeLibraryFactory(
125: new DatatypeLibraryLoader()),
126: new SchemaPatternBuilder());
127: }
128:
129: /**
130: *
131: * @param eh
132: * Error handler to receive errors while building the schema.
133: * @param datatypeLibraryFactory
134: * This is consulted to locate datatype libraries.
135: * @param pb
136: * Used to build patterns.
137: */
138: public SchemaBuilderImpl(ErrorHandler eh,
139: DatatypeLibraryFactory datatypeLibraryFactory,
140: SchemaPatternBuilder pb) {
141: this .parent = null;
142: this .eh = eh;
143: this .datatypeLibraryFactory = datatypeLibraryFactory;
144: this .pb = pb;
145: this .inheritNs = "";
146: this .openIncludes = null;
147: }
148:
149: private SchemaBuilderImpl(String inheritNs, String uri,
150: SchemaBuilderImpl parent) {
151: this .parent = parent;
152: this .eh = parent.eh;
153: this .datatypeLibraryFactory = parent.datatypeLibraryFactory;
154: this .pb = parent.pb;
155: this .inheritNs = inheritNs;
156: this .openIncludes = new OpenIncludes(uri, parent.openIncludes);
157: }
158:
159: public NameClassBuilder getNameClassBuilder() {
160: return ncb;
161: }
162:
163: public ParsedPattern makeChoice(List patterns, Location loc,
164: Annotations anno) throws BuildException {
165: if (patterns.isEmpty())
166: throw new IllegalArgumentException();
167: Pattern result = (Pattern) patterns.get(0);
168: for (int i = 1; i < patterns.size(); i++)
169: result = pb.makeChoice(result, (Pattern) patterns.get(i));
170: return result;
171: }
172:
173: public ParsedPattern makeInterleave(List patterns, Location loc,
174: Annotations anno) throws BuildException {
175: if (patterns.isEmpty())
176: throw new IllegalArgumentException();
177: Pattern result = (Pattern) patterns.get(0);
178: for (int i = 1; i < patterns.size(); i++)
179: result = pb.makeInterleave(result, (Pattern) patterns
180: .get(i));
181: return result;
182: }
183:
184: public ParsedPattern makeGroup(List patterns, Location loc,
185: Annotations anno) throws BuildException {
186: if (patterns.isEmpty())
187: throw new IllegalArgumentException();
188: Pattern result = (Pattern) patterns.get(0);
189: for (int i = 1; i < patterns.size(); i++)
190: result = pb.makeGroup(result, (Pattern) patterns.get(i));
191: return result;
192: }
193:
194: public ParsedPattern makeOneOrMore(ParsedPattern p, Location loc,
195: Annotations anno) throws BuildException {
196: return pb.makeOneOrMore((Pattern) p);
197: }
198:
199: public ParsedPattern makeZeroOrMore(ParsedPattern p, Location loc,
200: Annotations anno) throws BuildException {
201: return pb.makeZeroOrMore((Pattern) p);
202: }
203:
204: public ParsedPattern makeOptional(ParsedPattern p, Location loc,
205: Annotations anno) throws BuildException {
206: return pb.makeOptional((Pattern) p);
207: }
208:
209: public ParsedPattern makeList(ParsedPattern p, Location loc,
210: Annotations anno) throws BuildException {
211: return pb.makeList((Pattern) p, (Locator) loc);
212: }
213:
214: public ParsedPattern makeMixed(ParsedPattern p, Location loc,
215: Annotations anno) throws BuildException {
216: return pb.makeMixed((Pattern) p);
217: }
218:
219: public ParsedPattern makeEmpty(Location loc, Annotations anno) {
220: return pb.makeEmpty();
221: }
222:
223: public ParsedPattern makeNotAllowed(Location loc, Annotations anno) {
224: return pb.makeUnexpandedNotAllowed();
225: }
226:
227: public ParsedPattern makeText(Location loc, Annotations anno) {
228: return pb.makeText();
229: }
230:
231: public ParsedPattern makeErrorPattern() {
232: return pb.makeError();
233: }
234:
235: // public ParsedNameClass makeErrorNameClass() {
236: // return new ErrorNameClass();
237: // }
238:
239: public ParsedPattern makeAttribute(ParsedNameClass nc,
240: ParsedPattern p, Location loc, Annotations anno)
241: throws BuildException {
242: return pb.makeAttribute((NameClass) nc, (Pattern) p,
243: (Locator) loc);
244: }
245:
246: public ParsedPattern makeElement(ParsedNameClass nc,
247: ParsedPattern p, Location loc, Annotations anno)
248: throws BuildException {
249: return pb.makeElement((NameClass) nc, (Pattern) p,
250: (Locator) loc);
251: }
252:
253: private class DummyDataPatternBuilder implements DataPatternBuilder {
254: public void addParam(String name, String value,
255: Context context, String ns, Location loc,
256: Annotations anno) throws BuildException {
257: }
258:
259: public ParsedPattern makePattern(Location loc, Annotations anno)
260: throws BuildException {
261: return pb.makeError();
262: }
263:
264: public ParsedPattern makePattern(ParsedPattern except,
265: Location loc, Annotations anno) throws BuildException {
266: return pb.makeError();
267: }
268:
269: public void annotation(ParsedElementAnnotation ea) {
270: }
271: }
272:
273: private class ValidationContextImpl implements ValidationContext {
274: private ValidationContext vc;
275: private String ns;
276:
277: ValidationContextImpl(ValidationContext vc, String ns) {
278: this .vc = vc;
279: this .ns = ns.length() == 0 ? null : ns;
280: }
281:
282: public String resolveNamespacePrefix(String prefix) {
283: return prefix.length() == 0 ? ns : vc
284: .resolveNamespacePrefix(prefix);
285: }
286:
287: public String getBaseUri() {
288: return vc.getBaseUri();
289: }
290:
291: public boolean isUnparsedEntity(String entityName) {
292: return vc.isUnparsedEntity(entityName);
293: }
294:
295: public boolean isNotation(String notationName) {
296: return vc.isNotation(notationName);
297: }
298: }
299:
300: private class DataPatternBuilderImpl implements DataPatternBuilder {
301: private DatatypeBuilder dtb;
302:
303: DataPatternBuilderImpl(DatatypeBuilder dtb) {
304: this .dtb = dtb;
305: }
306:
307: public void addParam(String name, String value,
308: Context context, String ns, Location loc,
309: Annotations anno) throws BuildException {
310: try {
311: dtb.addParameter(name, value,
312: new ValidationContextImpl(context, ns));
313: } catch (DatatypeException e) {
314: String detail = e.getMessage();
315: int pos = e.getIndex();
316: String displayedParam;
317: if (pos == DatatypeException.UNKNOWN)
318: displayedParam = null;
319: else
320: displayedParam = displayParam(value, pos);
321: if (displayedParam != null) {
322: if (detail != null)
323: error("invalid_param_detail_display", detail,
324: displayedParam, (Locator) loc);
325: else
326: error("invalid_param_display", displayedParam,
327: (Locator) loc);
328: } else if (detail != null)
329: error("invalid_param_detail", detail, (Locator) loc);
330: else
331: error("invalid_param", (Locator) loc);
332: }
333: }
334:
335: String displayParam(String value, int pos) {
336: if (pos < 0)
337: pos = 0;
338: else if (pos > value.length())
339: pos = value.length();
340: return localizer.message("display_param", value.substring(
341: 0, pos), value.substring(pos));
342: }
343:
344: public ParsedPattern makePattern(Location loc, Annotations anno)
345: throws BuildException {
346: try {
347: return pb.makeData(dtb.createDatatype());
348: } catch (DatatypeException e) {
349: String detail = e.getMessage();
350: if (detail != null)
351: error("invalid_params_detail", detail,
352: (Locator) loc);
353: else
354: error("invalid_params", (Locator) loc);
355: return pb.makeError();
356: }
357: }
358:
359: public ParsedPattern makePattern(ParsedPattern except,
360: Location loc, Annotations anno) throws BuildException {
361: try {
362: return pb.makeDataExcept(dtb.createDatatype(),
363: (Pattern) except, (Locator) loc);
364: } catch (DatatypeException e) {
365: String detail = e.getMessage();
366: if (detail != null)
367: error("invalid_params_detail", detail,
368: (Locator) loc);
369: else
370: error("invalid_params", (Locator) loc);
371: return pb.makeError();
372: }
373: }
374:
375: public void annotation(ParsedElementAnnotation ea) {
376: }
377: }
378:
379: public DataPatternBuilder makeDataPatternBuilder(
380: String datatypeLibrary, String type, Location loc)
381: throws BuildException {
382: DatatypeLibrary dl = datatypeLibraryFactory
383: .createDatatypeLibrary(datatypeLibrary);
384: if (dl == null)
385: error("unrecognized_datatype_library", datatypeLibrary,
386: (Locator) loc);
387: else {
388: try {
389: return new DataPatternBuilderImpl(dl
390: .createDatatypeBuilder(type));
391: } catch (DatatypeException e) {
392: String detail = e.getMessage();
393: if (detail != null)
394: error("unsupported_datatype_detail",
395: datatypeLibrary, type, detail,
396: (Locator) loc);
397: else
398: error("unrecognized_datatype", datatypeLibrary,
399: type, (Locator) loc);
400: }
401: }
402: return new DummyDataPatternBuilder();
403: }
404:
405: public ParsedPattern makeValue(String datatypeLibrary, String type,
406: String value, Context context, String ns, Location loc,
407: Annotations anno) throws BuildException {
408: DatatypeLibrary dl = datatypeLibraryFactory
409: .createDatatypeLibrary(datatypeLibrary);
410: if (dl == null)
411: error("unrecognized_datatype_library", datatypeLibrary,
412: (Locator) loc);
413: else {
414: try {
415: DatatypeBuilder dtb = dl.createDatatypeBuilder(type);
416: try {
417: Datatype dt = dtb.createDatatype();
418: Object obj = dt.createValue(value,
419: new ValidationContextImpl(context, ns));
420: if (obj != null)
421: return pb.makeValue(dt, obj);
422: error("invalid_value", value, (Locator) loc);
423: } catch (DatatypeException e) {
424: String detail = e.getMessage();
425: if (detail != null)
426: error("datatype_requires_param_detail", detail,
427: (Locator) loc);
428: else
429: error("datatype_requires_param", (Locator) loc);
430: }
431: } catch (DatatypeException e) {
432: error("unrecognized_datatype", datatypeLibrary, type,
433: (Locator) loc);
434: }
435: }
436: return pb.makeError();
437: }
438:
439: static class GrammarImpl implements Grammar, Div, IncludedGrammar {
440: private final SchemaBuilderImpl sb;
441: private final Hashtable defines;
442: private final RefPattern startRef;
443: private final Scope parent;
444:
445: private GrammarImpl(SchemaBuilderImpl sb, Scope parent) {
446: this .sb = sb;
447: this .parent = parent;
448: this .defines = new Hashtable();
449: this .startRef = new RefPattern(null);
450: }
451:
452: protected GrammarImpl(SchemaBuilderImpl sb, GrammarImpl g) {
453: this .sb = sb;
454: parent = g.parent;
455: startRef = g.startRef;
456: defines = g.defines;
457: }
458:
459: public ParsedPattern endGrammar(Location loc, Annotations anno)
460: throws BuildException {
461: for (Enumeration e = defines.keys(); e.hasMoreElements();) {
462: String name = (String) e.nextElement();
463: RefPattern rp = (RefPattern) defines.get(name);
464: if (rp.getPattern() == null) {
465: sb.error("reference_to_undefined", name, rp
466: .getRefLocator());
467: rp.setPattern(sb.pb.makeError());
468: }
469: }
470: Pattern start = startRef.getPattern();
471: if (start == null) {
472: sb.error("missing_start_element", (Locator) loc);
473: start = sb.pb.makeError();
474: }
475: return start;
476: }
477:
478: public void endDiv(Location loc, Annotations anno)
479: throws BuildException {
480: // nothing to do
481: }
482:
483: public ParsedPattern endIncludedGrammar(Location loc,
484: Annotations anno) throws BuildException {
485: return null;
486: }
487:
488: public void define(String name, GrammarSection.Combine combine,
489: ParsedPattern pattern, Location loc, Annotations anno)
490: throws BuildException {
491: define(lookup(name), combine, pattern, loc);
492: }
493:
494: private void define(RefPattern rp,
495: GrammarSection.Combine combine, ParsedPattern pattern,
496: Location loc) throws BuildException {
497: switch (rp.getReplacementStatus()) {
498: case RefPattern.REPLACEMENT_KEEP:
499: if (combine == null) {
500: if (rp.isCombineImplicit()) {
501: if (rp.getName() == null)
502: sb.error("duplicate_start", (Locator) loc);
503: else
504: sb.error("duplicate_define", rp.getName(),
505: (Locator) loc);
506: } else
507: rp.setCombineImplicit();
508: } else {
509: byte combineType = (combine == COMBINE_CHOICE ? RefPattern.COMBINE_CHOICE
510: : RefPattern.COMBINE_INTERLEAVE);
511: if (rp.getCombineType() != RefPattern.COMBINE_NONE
512: && rp.getCombineType() != combineType) {
513: if (rp.getName() == null)
514: sb.error("conflict_combine_start",
515: (Locator) loc);
516: else
517: sb.error("conflict_combine_define", rp
518: .getName(), (Locator) loc);
519: }
520: rp.setCombineType(combineType);
521: }
522: Pattern p = (Pattern) pattern;
523: if (rp.getPattern() == null)
524: rp.setPattern(p);
525: else if (rp.getCombineType() == RefPattern.COMBINE_INTERLEAVE)
526: rp.setPattern(sb.pb.makeInterleave(rp.getPattern(),
527: p));
528: else
529: rp.setPattern(sb.pb.makeChoice(rp.getPattern(), p));
530: break;
531: case RefPattern.REPLACEMENT_REQUIRE:
532: rp.setReplacementStatus(RefPattern.REPLACEMENT_IGNORE);
533: break;
534: case RefPattern.REPLACEMENT_IGNORE:
535: break;
536: }
537: }
538:
539: public void topLevelAnnotation(ParsedElementAnnotation ea)
540: throws BuildException {
541: }
542:
543: public void topLevelComment(CommentList comments)
544: throws BuildException {
545: }
546:
547: private RefPattern lookup(String name) {
548: if (name == START)
549: return startRef;
550: return lookup1(name);
551: }
552:
553: private RefPattern lookup1(String name) {
554: RefPattern p = (RefPattern) defines.get(name);
555: if (p == null) {
556: p = new RefPattern(name);
557: defines.put(name, p);
558: }
559: return p;
560: }
561:
562: public ParsedPattern makeRef(String name, Location loc,
563: Annotations anno) throws BuildException {
564: RefPattern p = lookup1(name);
565: if (p.getRefLocator() == null && loc != null)
566: p.setRefLocator((Locator) loc);
567: return p;
568: }
569:
570: public ParsedPattern makeParentRef(String name, Location loc,
571: Annotations anno) throws BuildException {
572: // TODO: do this check by the caller
573: if (parent == null) {
574: sb.error("parent_ref_outside_grammar", (Locator) loc);
575: return sb.makeErrorPattern();
576: }
577: return parent.makeRef(name, loc, anno);
578: }
579:
580: public Div makeDiv() {
581: return this ;
582: }
583:
584: public Include makeInclude() {
585: return new IncludeImpl(sb, this );
586: }
587:
588: }
589:
590: static class Override {
591: Override(RefPattern prp, Override next) {
592: this .prp = prp;
593: this .next = next;
594: }
595:
596: RefPattern prp;
597: Override next;
598: byte replacementStatus;
599: }
600:
601: private static class IncludeImpl implements Include, Div {
602: private SchemaBuilderImpl sb;
603: private Override overrides;
604: private GrammarImpl grammar;
605:
606: private IncludeImpl(SchemaBuilderImpl sb, GrammarImpl grammar) {
607: this .sb = sb;
608: this .grammar = grammar;
609: }
610:
611: public void define(String name, GrammarSection.Combine combine,
612: ParsedPattern pattern, Location loc, Annotations anno)
613: throws BuildException {
614: RefPattern rp = grammar.lookup(name);
615: overrides = new Override(rp, overrides);
616: grammar.define(rp, combine, pattern, loc);
617: }
618:
619: public void endDiv(Location loc, Annotations anno)
620: throws BuildException {
621: // nothing to do
622: }
623:
624: public void topLevelAnnotation(ParsedElementAnnotation ea)
625: throws BuildException {
626: // nothing to do
627: }
628:
629: public void topLevelComment(CommentList comments)
630: throws BuildException {
631: }
632:
633: public Div makeDiv() {
634: return this ;
635: }
636:
637: public void endInclude(Parseable current, String uri,
638: String ns, Location loc, Annotations anno)
639: throws BuildException {
640: for (OpenIncludes inc = sb.openIncludes; inc != null; 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
650: .setReplacementStatus(RefPattern.REPLACEMENT_REQUIRE);
651: }
652: try {
653: SchemaBuilderImpl isb = new SchemaBuilderImpl(ns, uri,
654: sb);
655: current.parseInclude(uri, isb, new GrammarImpl(isb,
656: grammar), ns);
657: for (Override o = overrides; o != null; o = o.next) {
658: if (o.prp.getReplacementStatus() == RefPattern.REPLACEMENT_REQUIRE) {
659: if (o.prp.getName() == null)
660: sb.error("missing_start_replacement",
661: (Locator) loc);
662: else
663: sb.error("missing_define_replacement",
664: o.prp.getName(), (Locator) loc);
665: }
666: }
667: } catch (IllegalSchemaException e) {
668: sb.noteError();
669: } finally {
670: for (Override o = overrides; o != null; o = o.next)
671: o.prp.setReplacementStatus(o.replacementStatus);
672: }
673: }
674:
675: public Include makeInclude() {
676: return null;
677: }
678: }
679:
680: public Grammar makeGrammar(Scope parent) {
681: return new GrammarImpl(this , parent);
682: }
683:
684: public ParsedPattern annotate(ParsedPattern p, Annotations anno)
685: throws BuildException {
686: return p;
687: }
688:
689: public ParsedPattern annotateAfter(ParsedPattern p,
690: ParsedElementAnnotation e) throws BuildException {
691: return p;
692: }
693:
694: public ParsedPattern commentAfter(ParsedPattern p,
695: CommentList comments) throws BuildException {
696: return p;
697: }
698:
699: public ParsedPattern makeExternalRef(Parseable current, String uri,
700: String ns, Scope scope, Location loc, Annotations anno)
701: throws BuildException {
702: for (OpenIncludes inc = openIncludes; inc != null; inc = inc.parent) {
703: if (inc.uri.equals(uri)) {
704: error("recursive_include", uri, (Locator) loc);
705: return pb.makeError();
706: }
707: }
708: try {
709: return current.parseExternal(uri, new SchemaBuilderImpl(ns,
710: uri, this ), scope, ns);
711: } catch (IllegalSchemaException e) {
712: noteError();
713: return pb.makeError();
714: }
715: }
716:
717: public Location makeLocation(String systemId, int lineNumber,
718: int columnNumber) {
719: return new LocatorImpl(systemId, lineNumber, columnNumber);
720: }
721:
722: public Annotations makeAnnotations(CommentList comments,
723: Context context) {
724: return this ;
725: }
726:
727: public ElementAnnotationBuilder makeElementAnnotationBuilder(
728: String ns, String localName, String prefix, Location loc,
729: CommentList comments, Context context) {
730: return this ;
731: }
732:
733: public CommentList makeCommentList() {
734: return this ;
735: }
736:
737: public void addComment(String value, Location loc)
738: throws BuildException {
739: }
740:
741: public void addAttribute(String ns, String localName,
742: String prefix, String value, Location loc) {
743: // nothing needed
744: }
745:
746: public void addElement(ParsedElementAnnotation ea) {
747: // nothing needed
748: }
749:
750: public void addComment(CommentList comments) throws BuildException {
751: // nothing needed
752: }
753:
754: public void addLeadingComment(CommentList comments)
755: throws BuildException {
756: // nothing needed
757: }
758:
759: public ParsedElementAnnotation makeElementAnnotation() {
760: return null;
761: }
762:
763: public void addText(String value, Location loc, CommentList comments)
764: throws BuildException {
765: }
766:
767: public boolean usesComments() {
768: return false;
769: }
770:
771: private void error(SAXParseException message) throws BuildException {
772: noteError();
773: try {
774: if (eh != null)
775: eh.error(message);
776: } catch (SAXException e) {
777: throw new BuildException(e);
778: }
779: }
780:
781: private void warning(SAXParseException message)
782: throws BuildException {
783: try {
784: if (eh != null)
785: eh.warning(message);
786: } catch (SAXException e) {
787: throw new BuildException(e);
788: }
789: }
790:
791: private void error(String key, Locator loc) throws BuildException {
792: error(new SAXParseException(localizer.message(key), loc));
793: }
794:
795: private void error(String key, String arg, Locator loc)
796: throws BuildException {
797: error(new SAXParseException(localizer.message(key, arg), loc));
798: }
799:
800: private void error(String key, String arg1, String arg2, Locator loc)
801: throws BuildException {
802: error(new SAXParseException(localizer.message(key, arg1, arg2),
803: loc));
804: }
805:
806: private void error(String key, String arg1, String arg2,
807: String arg3, Locator loc) throws BuildException {
808: error(new SAXParseException(localizer.message(key,
809: new Object[] { arg1, arg2, arg3 }), loc));
810: }
811:
812: private void noteError() {
813: if (!hadError && parent != null)
814: parent.noteError();
815: hadError = true;
816: }
817:
818: }
|