/* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.xml.internal.rngom.parse.host; import com.sun.xml.internal.rngom.ast.builder.Annotations; import com.sun.xml.internal.rngom.ast.builder.BuildException; import com.sun.xml.internal.rngom.ast.builder.CommentList; import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder; import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder; import com.sun.xml.internal.rngom.ast.builder.Grammar; import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder; import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder; import com.sun.xml.internal.rngom.ast.builder.Scope; import com.sun.xml.internal.rngom.ast.om.Location; import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation; import com.sun.xml.internal.rngom.ast.om.ParsedNameClass; import com.sun.xml.internal.rngom.ast.om.ParsedPattern; import com.sun.xml.internal.rngom.parse.Context; import com.sun.xml.internal.rngom.parse.IllegalSchemaException; import com.sun.xml.internal.rngom.parse.Parseable; import java.util.List; import java.util.ArrayList; /** * * @author * Kohsuke Kawaguchi (kk@kohsuke.org) */ public class SchemaBuilderHost extends Base implements SchemaBuilder { final SchemaBuilder lhs; final SchemaBuilder rhs; public SchemaBuilderHost( SchemaBuilder lhs, SchemaBuilder rhs ) { this.lhs = lhs; this.rhs = rhs; } public ParsedPattern annotate(ParsedPattern _p, Annotations _anno) throws BuildException { ParsedPatternHost p = (ParsedPatternHost) _p; AnnotationsHost a = cast(_anno); return new ParsedPatternHost( lhs.annotate(p.lhs, a.lhs), rhs.annotate(p.lhs, a.lhs) ); } public ParsedPattern annotateAfter(ParsedPattern _p, ParsedElementAnnotation _e) throws BuildException { ParsedPatternHost p = (ParsedPatternHost) _p; ParsedElementAnnotationHost e = (ParsedElementAnnotationHost) _e; return new ParsedPatternHost( lhs.annotateAfter(p.lhs, e.lhs), rhs.annotateAfter(p.rhs, e.rhs)); } public ParsedPattern commentAfter(ParsedPattern _p, CommentList _comments) throws BuildException { ParsedPatternHost p = (ParsedPatternHost) _p; CommentListHost comments = (CommentListHost) _comments; return new ParsedPatternHost( lhs.commentAfter(p.lhs, comments==null?null:comments.lhs), rhs.commentAfter(p.rhs, comments==null?null:comments.rhs)); } public ParsedPattern expandPattern(ParsedPattern _p) throws BuildException, IllegalSchemaException { ParsedPatternHost p = (ParsedPatternHost) _p; return new ParsedPatternHost( lhs.expandPattern(p.lhs), rhs.expandPattern(p.rhs)); } public NameClassBuilder getNameClassBuilder() throws BuildException { return new NameClassBuilderHost( lhs.getNameClassBuilder(), rhs.getNameClassBuilder() ); } public Annotations makeAnnotations(CommentList _comments, Context context) { CommentListHost comments = (CommentListHost) _comments; Annotations l = lhs.makeAnnotations((comments!=null)?comments.lhs:null, context); Annotations r = rhs.makeAnnotations((comments!=null)?comments.rhs:null, context); if(l==null || r==null) throw new IllegalArgumentException("annotations cannot be null"); return new AnnotationsHost(l,r); } public ParsedPattern makeAttribute(ParsedNameClass _nc, ParsedPattern _p, Location _loc, Annotations _anno) throws BuildException { ParsedNameClassHost nc = (ParsedNameClassHost) _nc; ParsedPatternHost p = (ParsedPatternHost) _p; LocationHost loc = cast(_loc); AnnotationsHost anno = cast(_anno); return new ParsedPatternHost( lhs.makeAttribute(nc.lhs, p.lhs, loc.lhs, anno.lhs), rhs.makeAttribute(nc.rhs, p.rhs, loc.rhs, anno.rhs)); } public ParsedPattern makeChoice(List patterns, Location _loc, Annotations _anno) throws BuildException { List lp = new ArrayList(); List rp = new ArrayList(); for( int i=0; i lp = new ArrayList(); List rp = new ArrayList(); for( int i=0; i lp = new ArrayList(); List rp = new ArrayList(); for( int i=0; i