325N/A/*
325N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A/*
325N/A * Copyright (C) 2004-2011
325N/A *
325N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
325N/A * of this software and associated documentation files (the "Software"), to deal
325N/A * in the Software without restriction, including without limitation the rights
325N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
325N/A * copies of the Software, and to permit persons to whom the Software is
325N/A * furnished to do so, subject to the following conditions:
325N/A *
325N/A * The above copyright notice and this permission notice shall be included in
325N/A * all copies or substantial portions of the Software.
325N/A *
325N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
325N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
325N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
325N/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
325N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
325N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
325N/A * THE SOFTWARE.
325N/A */
325N/Apackage com.sun.xml.internal.rngom.parse.host;
325N/A
325N/Aimport com.sun.xml.internal.rngom.ast.builder.Annotations;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.BuildException;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.CommentList;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.Grammar;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
325N/Aimport com.sun.xml.internal.rngom.ast.builder.Scope;
325N/Aimport com.sun.xml.internal.rngom.ast.om.Location;
325N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
325N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
325N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedPattern;
325N/Aimport com.sun.xml.internal.rngom.parse.Context;
325N/Aimport com.sun.xml.internal.rngom.parse.IllegalSchemaException;
325N/Aimport com.sun.xml.internal.rngom.parse.Parseable;
325N/A
325N/Aimport java.util.List;
325N/Aimport java.util.ArrayList;
325N/A
325N/A/**
325N/A *
325N/A * @author
325N/A * Kohsuke Kawaguchi (kk@kohsuke.org)
325N/A */
325N/Apublic class SchemaBuilderHost extends Base implements SchemaBuilder {
325N/A final SchemaBuilder lhs;
325N/A final SchemaBuilder rhs;
325N/A
325N/A public SchemaBuilderHost( SchemaBuilder lhs, SchemaBuilder rhs ) {
325N/A this.lhs = lhs;
325N/A this.rhs = rhs;
325N/A }
325N/A
325N/A public ParsedPattern annotate(ParsedPattern _p, Annotations _anno)
325N/A throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A AnnotationsHost a = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.annotate(p.lhs, a.lhs),
325N/A rhs.annotate(p.lhs, a.lhs) );
325N/A }
325N/A
325N/A public ParsedPattern annotateAfter(ParsedPattern _p,
325N/A ParsedElementAnnotation _e) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A ParsedElementAnnotationHost e = (ParsedElementAnnotationHost) _e;
325N/A return new ParsedPatternHost(
325N/A lhs.annotateAfter(p.lhs, e.lhs),
325N/A rhs.annotateAfter(p.rhs, e.rhs));
325N/A }
325N/A
325N/A public ParsedPattern commentAfter(ParsedPattern _p, CommentList _comments)
325N/A throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A CommentListHost comments = (CommentListHost) _comments;
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.commentAfter(p.lhs, comments==null?null:comments.lhs),
325N/A rhs.commentAfter(p.rhs, comments==null?null:comments.rhs));
325N/A }
325N/A
325N/A public ParsedPattern expandPattern(ParsedPattern _p) throws BuildException, IllegalSchemaException {
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A return new ParsedPatternHost(
325N/A lhs.expandPattern(p.lhs),
325N/A rhs.expandPattern(p.rhs));
325N/A }
325N/A
325N/A public NameClassBuilder getNameClassBuilder() throws BuildException {
325N/A return new NameClassBuilderHost( lhs.getNameClassBuilder(), rhs.getNameClassBuilder() );
325N/A }
325N/A
325N/A public Annotations makeAnnotations(CommentList _comments, Context context) {
325N/A CommentListHost comments = (CommentListHost) _comments;
325N/A Annotations l = lhs.makeAnnotations((comments!=null)?comments.lhs:null, context);
325N/A Annotations r = rhs.makeAnnotations((comments!=null)?comments.rhs:null, context);
325N/A if(l==null || r==null)
325N/A throw new IllegalArgumentException("annotations cannot be null");
325N/A return new AnnotationsHost(l,r);
325N/A }
325N/A
325N/A public ParsedPattern makeAttribute(ParsedNameClass _nc, ParsedPattern _p,
325N/A Location _loc, Annotations _anno) throws BuildException {
325N/A
325N/A ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeAttribute(nc.lhs, p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeAttribute(nc.rhs, p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeChoice(List patterns,
325N/A Location _loc, Annotations _anno) throws BuildException {
325N/A
325N/A List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
325N/A List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
325N/A for( int i=0; i<patterns.size(); i++ ) {
325N/A lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
325N/A rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
325N/A }
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeChoice(lp, loc.lhs, anno.lhs),
325N/A rhs.makeChoice(rp, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public CommentList makeCommentList() {
325N/A return new CommentListHost(
325N/A lhs.makeCommentList(),
325N/A rhs.makeCommentList() );
325N/A }
325N/A
325N/A public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary,
325N/A String type, Location _loc) throws BuildException {
325N/A LocationHost loc = cast(_loc);
325N/A
325N/A return new DataPatternBuilderHost(
325N/A lhs.makeDataPatternBuilder(datatypeLibrary, type, loc.lhs),
325N/A rhs.makeDataPatternBuilder(datatypeLibrary, type, loc.rhs) );
325N/A }
325N/A
325N/A public ParsedPattern makeElement(ParsedNameClass _nc, ParsedPattern _p,
325N/A Location _loc, Annotations _anno) throws BuildException {
325N/A
325N/A ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeElement(nc.lhs, p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeElement(nc.rhs, p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns,
325N/A String localName, String prefix, Location _loc, CommentList _comments,
325N/A Context context) {
325N/A LocationHost loc = cast(_loc);
325N/A CommentListHost comments = (CommentListHost) _comments;
325N/A
325N/A return new ElementAnnotationBuilderHost(
325N/A lhs.makeElementAnnotationBuilder(ns, localName, prefix, loc.lhs, comments==null?null:comments.lhs, context),
325N/A rhs.makeElementAnnotationBuilder(ns, localName, prefix, loc.rhs, comments==null?null:comments.rhs, context) );
325N/A }
325N/A
325N/A public ParsedPattern makeEmpty(Location _loc, Annotations _anno) {
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeEmpty(loc.lhs, anno.lhs),
325N/A rhs.makeEmpty(loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeErrorPattern() {
325N/A return new ParsedPatternHost(
325N/A lhs.makeErrorPattern(),
325N/A rhs.makeErrorPattern() );
325N/A }
325N/A
325N/A public ParsedPattern makeExternalRef(Parseable current, String uri,
325N/A String ns, Scope _scope, Location _loc, Annotations _anno)
325N/A throws BuildException, IllegalSchemaException {
325N/A
325N/A ScopeHost scope = (ScopeHost) _scope;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeExternalRef(current, uri, ns, scope.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeExternalRef(current, uri, ns, scope.rhs, loc.rhs, anno.rhs) );
325N/A }
325N/A
325N/A public Grammar makeGrammar(Scope _parent) {
325N/A ScopeHost parent = (ScopeHost) _parent;
325N/A
325N/A return new GrammarHost(
325N/A lhs.makeGrammar((parent!=null)?parent.lhs:null),
325N/A rhs.makeGrammar((parent!=null)?parent.rhs:null) );
325N/A }
325N/A
325N/A public ParsedPattern makeGroup(List patterns,
325N/A Location _loc, Annotations _anno) throws BuildException {
325N/A
325N/A List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
325N/A List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
325N/A for( int i=0; i<patterns.size(); i++ ) {
325N/A lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
325N/A rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
325N/A }
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeGroup(lp, loc.lhs, anno.lhs),
325N/A rhs.makeGroup(rp, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeInterleave(List patterns,
325N/A Location _loc, Annotations _anno) throws BuildException {
325N/A
325N/A List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
325N/A List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
325N/A for( int i=0; i<patterns.size(); i++ ) {
325N/A lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
325N/A rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
325N/A }
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeInterleave(lp, loc.lhs, anno.lhs),
325N/A rhs.makeInterleave(rp, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeList(ParsedPattern _p, Location _loc,
325N/A Annotations _anno) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeList(p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeList(p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public Location makeLocation(String systemId, int lineNumber,
325N/A int columnNumber) {
325N/A return new LocationHost(
325N/A lhs.makeLocation(systemId, lineNumber, columnNumber),
325N/A rhs.makeLocation(systemId, lineNumber, columnNumber));
325N/A }
325N/A
325N/A public ParsedPattern makeMixed(ParsedPattern _p, Location _loc,
325N/A Annotations _anno) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeMixed(p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeMixed(p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeNotAllowed(Location _loc, Annotations _anno) {
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeNotAllowed(loc.lhs, anno.lhs),
325N/A rhs.makeNotAllowed(loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeOneOrMore(ParsedPattern _p, Location _loc,
325N/A Annotations _anno) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeOneOrMore(p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeOneOrMore(p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeZeroOrMore(ParsedPattern _p, Location _loc,
325N/A Annotations _anno) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeZeroOrMore(p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeZeroOrMore(p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeOptional(ParsedPattern _p, Location _loc,
325N/A Annotations _anno) throws BuildException {
325N/A
325N/A ParsedPatternHost p = (ParsedPatternHost) _p;
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeOptional(p.lhs, loc.lhs, anno.lhs),
325N/A rhs.makeOptional(p.rhs, loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeText(Location _loc, Annotations _anno) {
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeText(loc.lhs, anno.lhs),
325N/A rhs.makeText(loc.rhs, anno.rhs));
325N/A }
325N/A
325N/A public ParsedPattern makeValue(String datatypeLibrary, String type,
325N/A String value, Context c, String ns, Location _loc, Annotations _anno)
325N/A throws BuildException {
325N/A LocationHost loc = cast(_loc);
325N/A AnnotationsHost anno = cast(_anno);
325N/A
325N/A return new ParsedPatternHost(
325N/A lhs.makeValue(datatypeLibrary,type,value,c,ns,loc.lhs,anno.lhs),
325N/A rhs.makeValue(datatypeLibrary,type,value,c,ns,loc.rhs,anno.rhs));
325N/A }
325N/A
325N/A public boolean usesComments() {
325N/A return lhs.usesComments() || rhs.usesComments();
325N/A }
325N/A}