src/share/jaxws_classes/com/sun/xml/internal/rngom/parse/host/SchemaBuilderHost.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25 /*
aoqi@0 26 * Copyright (C) 2004-2011
aoqi@0 27 *
aoqi@0 28 * Permission is hereby granted, free of charge, to any person obtaining a copy
aoqi@0 29 * of this software and associated documentation files (the "Software"), to deal
aoqi@0 30 * in the Software without restriction, including without limitation the rights
aoqi@0 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
aoqi@0 32 * copies of the Software, and to permit persons to whom the Software is
aoqi@0 33 * furnished to do so, subject to the following conditions:
aoqi@0 34 *
aoqi@0 35 * The above copyright notice and this permission notice shall be included in
aoqi@0 36 * all copies or substantial portions of the Software.
aoqi@0 37 *
aoqi@0 38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
aoqi@0 39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
aoqi@0 40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
aoqi@0 41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
aoqi@0 42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
aoqi@0 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
aoqi@0 44 * THE SOFTWARE.
aoqi@0 45 */
aoqi@0 46 package com.sun.xml.internal.rngom.parse.host;
aoqi@0 47
aoqi@0 48 import com.sun.xml.internal.rngom.ast.builder.Annotations;
aoqi@0 49 import com.sun.xml.internal.rngom.ast.builder.BuildException;
aoqi@0 50 import com.sun.xml.internal.rngom.ast.builder.CommentList;
aoqi@0 51 import com.sun.xml.internal.rngom.ast.builder.DataPatternBuilder;
aoqi@0 52 import com.sun.xml.internal.rngom.ast.builder.ElementAnnotationBuilder;
aoqi@0 53 import com.sun.xml.internal.rngom.ast.builder.Grammar;
aoqi@0 54 import com.sun.xml.internal.rngom.ast.builder.NameClassBuilder;
aoqi@0 55 import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
aoqi@0 56 import com.sun.xml.internal.rngom.ast.builder.Scope;
aoqi@0 57 import com.sun.xml.internal.rngom.ast.om.Location;
aoqi@0 58 import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
aoqi@0 59 import com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
aoqi@0 60 import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
aoqi@0 61 import com.sun.xml.internal.rngom.parse.Context;
aoqi@0 62 import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
aoqi@0 63 import com.sun.xml.internal.rngom.parse.Parseable;
aoqi@0 64
aoqi@0 65 import java.util.List;
aoqi@0 66 import java.util.ArrayList;
aoqi@0 67
aoqi@0 68 /**
aoqi@0 69 *
aoqi@0 70 * @author
aoqi@0 71 * Kohsuke Kawaguchi (kk@kohsuke.org)
aoqi@0 72 */
aoqi@0 73 public class SchemaBuilderHost extends Base implements SchemaBuilder {
aoqi@0 74 final SchemaBuilder lhs;
aoqi@0 75 final SchemaBuilder rhs;
aoqi@0 76
aoqi@0 77 public SchemaBuilderHost( SchemaBuilder lhs, SchemaBuilder rhs ) {
aoqi@0 78 this.lhs = lhs;
aoqi@0 79 this.rhs = rhs;
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 public ParsedPattern annotate(ParsedPattern _p, Annotations _anno)
aoqi@0 83 throws BuildException {
aoqi@0 84
aoqi@0 85 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 86 AnnotationsHost a = cast(_anno);
aoqi@0 87
aoqi@0 88 return new ParsedPatternHost(
aoqi@0 89 lhs.annotate(p.lhs, a.lhs),
aoqi@0 90 rhs.annotate(p.lhs, a.lhs) );
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 public ParsedPattern annotateAfter(ParsedPattern _p,
aoqi@0 94 ParsedElementAnnotation _e) throws BuildException {
aoqi@0 95
aoqi@0 96 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 97 ParsedElementAnnotationHost e = (ParsedElementAnnotationHost) _e;
aoqi@0 98 return new ParsedPatternHost(
aoqi@0 99 lhs.annotateAfter(p.lhs, e.lhs),
aoqi@0 100 rhs.annotateAfter(p.rhs, e.rhs));
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public ParsedPattern commentAfter(ParsedPattern _p, CommentList _comments)
aoqi@0 104 throws BuildException {
aoqi@0 105
aoqi@0 106 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 107 CommentListHost comments = (CommentListHost) _comments;
aoqi@0 108
aoqi@0 109 return new ParsedPatternHost(
aoqi@0 110 lhs.commentAfter(p.lhs, comments==null?null:comments.lhs),
aoqi@0 111 rhs.commentAfter(p.rhs, comments==null?null:comments.rhs));
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 public ParsedPattern expandPattern(ParsedPattern _p) throws BuildException, IllegalSchemaException {
aoqi@0 115 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 116 return new ParsedPatternHost(
aoqi@0 117 lhs.expandPattern(p.lhs),
aoqi@0 118 rhs.expandPattern(p.rhs));
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 public NameClassBuilder getNameClassBuilder() throws BuildException {
aoqi@0 122 return new NameClassBuilderHost( lhs.getNameClassBuilder(), rhs.getNameClassBuilder() );
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 public Annotations makeAnnotations(CommentList _comments, Context context) {
aoqi@0 126 CommentListHost comments = (CommentListHost) _comments;
aoqi@0 127 Annotations l = lhs.makeAnnotations((comments!=null)?comments.lhs:null, context);
aoqi@0 128 Annotations r = rhs.makeAnnotations((comments!=null)?comments.rhs:null, context);
aoqi@0 129 if(l==null || r==null)
aoqi@0 130 throw new IllegalArgumentException("annotations cannot be null");
aoqi@0 131 return new AnnotationsHost(l,r);
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 public ParsedPattern makeAttribute(ParsedNameClass _nc, ParsedPattern _p,
aoqi@0 135 Location _loc, Annotations _anno) throws BuildException {
aoqi@0 136
aoqi@0 137 ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
aoqi@0 138 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 139 LocationHost loc = cast(_loc);
aoqi@0 140 AnnotationsHost anno = cast(_anno);
aoqi@0 141
aoqi@0 142 return new ParsedPatternHost(
aoqi@0 143 lhs.makeAttribute(nc.lhs, p.lhs, loc.lhs, anno.lhs),
aoqi@0 144 rhs.makeAttribute(nc.rhs, p.rhs, loc.rhs, anno.rhs));
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 public ParsedPattern makeChoice(List patterns,
aoqi@0 148 Location _loc, Annotations _anno) throws BuildException {
aoqi@0 149
aoqi@0 150 List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
aoqi@0 151 List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
aoqi@0 152 for( int i=0; i<patterns.size(); i++ ) {
aoqi@0 153 lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
aoqi@0 154 rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
aoqi@0 155 }
aoqi@0 156 LocationHost loc = cast(_loc);
aoqi@0 157 AnnotationsHost anno = cast(_anno);
aoqi@0 158
aoqi@0 159 return new ParsedPatternHost(
aoqi@0 160 lhs.makeChoice(lp, loc.lhs, anno.lhs),
aoqi@0 161 rhs.makeChoice(rp, loc.rhs, anno.rhs));
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 public CommentList makeCommentList() {
aoqi@0 165 return new CommentListHost(
aoqi@0 166 lhs.makeCommentList(),
aoqi@0 167 rhs.makeCommentList() );
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 public DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary,
aoqi@0 171 String type, Location _loc) throws BuildException {
aoqi@0 172 LocationHost loc = cast(_loc);
aoqi@0 173
aoqi@0 174 return new DataPatternBuilderHost(
aoqi@0 175 lhs.makeDataPatternBuilder(datatypeLibrary, type, loc.lhs),
aoqi@0 176 rhs.makeDataPatternBuilder(datatypeLibrary, type, loc.rhs) );
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 public ParsedPattern makeElement(ParsedNameClass _nc, ParsedPattern _p,
aoqi@0 180 Location _loc, Annotations _anno) throws BuildException {
aoqi@0 181
aoqi@0 182 ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
aoqi@0 183 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 184 LocationHost loc = cast(_loc);
aoqi@0 185 AnnotationsHost anno = cast(_anno);
aoqi@0 186
aoqi@0 187 return new ParsedPatternHost(
aoqi@0 188 lhs.makeElement(nc.lhs, p.lhs, loc.lhs, anno.lhs),
aoqi@0 189 rhs.makeElement(nc.rhs, p.rhs, loc.rhs, anno.rhs));
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 public ElementAnnotationBuilder makeElementAnnotationBuilder(String ns,
aoqi@0 193 String localName, String prefix, Location _loc, CommentList _comments,
aoqi@0 194 Context context) {
aoqi@0 195 LocationHost loc = cast(_loc);
aoqi@0 196 CommentListHost comments = (CommentListHost) _comments;
aoqi@0 197
aoqi@0 198 return new ElementAnnotationBuilderHost(
aoqi@0 199 lhs.makeElementAnnotationBuilder(ns, localName, prefix, loc.lhs, comments==null?null:comments.lhs, context),
aoqi@0 200 rhs.makeElementAnnotationBuilder(ns, localName, prefix, loc.rhs, comments==null?null:comments.rhs, context) );
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 public ParsedPattern makeEmpty(Location _loc, Annotations _anno) {
aoqi@0 204 LocationHost loc = cast(_loc);
aoqi@0 205 AnnotationsHost anno = cast(_anno);
aoqi@0 206
aoqi@0 207 return new ParsedPatternHost(
aoqi@0 208 lhs.makeEmpty(loc.lhs, anno.lhs),
aoqi@0 209 rhs.makeEmpty(loc.rhs, anno.rhs));
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 public ParsedPattern makeErrorPattern() {
aoqi@0 213 return new ParsedPatternHost(
aoqi@0 214 lhs.makeErrorPattern(),
aoqi@0 215 rhs.makeErrorPattern() );
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 public ParsedPattern makeExternalRef(Parseable current, String uri,
aoqi@0 219 String ns, Scope _scope, Location _loc, Annotations _anno)
aoqi@0 220 throws BuildException, IllegalSchemaException {
aoqi@0 221
aoqi@0 222 ScopeHost scope = (ScopeHost) _scope;
aoqi@0 223 LocationHost loc = cast(_loc);
aoqi@0 224 AnnotationsHost anno = cast(_anno);
aoqi@0 225
aoqi@0 226 return new ParsedPatternHost(
aoqi@0 227 lhs.makeExternalRef(current, uri, ns, scope.lhs, loc.lhs, anno.lhs),
aoqi@0 228 rhs.makeExternalRef(current, uri, ns, scope.rhs, loc.rhs, anno.rhs) );
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 public Grammar makeGrammar(Scope _parent) {
aoqi@0 232 ScopeHost parent = (ScopeHost) _parent;
aoqi@0 233
aoqi@0 234 return new GrammarHost(
aoqi@0 235 lhs.makeGrammar((parent!=null)?parent.lhs:null),
aoqi@0 236 rhs.makeGrammar((parent!=null)?parent.rhs:null) );
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 public ParsedPattern makeGroup(List patterns,
aoqi@0 240 Location _loc, Annotations _anno) throws BuildException {
aoqi@0 241
aoqi@0 242 List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
aoqi@0 243 List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
aoqi@0 244 for( int i=0; i<patterns.size(); i++ ) {
aoqi@0 245 lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
aoqi@0 246 rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
aoqi@0 247 }
aoqi@0 248 LocationHost loc = cast(_loc);
aoqi@0 249 AnnotationsHost anno = cast(_anno);
aoqi@0 250
aoqi@0 251 return new ParsedPatternHost(
aoqi@0 252 lhs.makeGroup(lp, loc.lhs, anno.lhs),
aoqi@0 253 rhs.makeGroup(rp, loc.rhs, anno.rhs));
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 public ParsedPattern makeInterleave(List patterns,
aoqi@0 257 Location _loc, Annotations _anno) throws BuildException {
aoqi@0 258
aoqi@0 259 List<ParsedPattern> lp = new ArrayList<ParsedPattern>();
aoqi@0 260 List<ParsedPattern> rp = new ArrayList<ParsedPattern>();
aoqi@0 261 for( int i=0; i<patterns.size(); i++ ) {
aoqi@0 262 lp.add( ((ParsedPatternHost)patterns.get(i)).lhs);
aoqi@0 263 rp.add( ((ParsedPatternHost)patterns.get(i)).rhs);
aoqi@0 264 }
aoqi@0 265 LocationHost loc = cast(_loc);
aoqi@0 266 AnnotationsHost anno = cast(_anno);
aoqi@0 267
aoqi@0 268 return new ParsedPatternHost(
aoqi@0 269 lhs.makeInterleave(lp, loc.lhs, anno.lhs),
aoqi@0 270 rhs.makeInterleave(rp, loc.rhs, anno.rhs));
aoqi@0 271 }
aoqi@0 272
aoqi@0 273 public ParsedPattern makeList(ParsedPattern _p, Location _loc,
aoqi@0 274 Annotations _anno) throws BuildException {
aoqi@0 275
aoqi@0 276 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 277 LocationHost loc = cast(_loc);
aoqi@0 278 AnnotationsHost anno = cast(_anno);
aoqi@0 279
aoqi@0 280 return new ParsedPatternHost(
aoqi@0 281 lhs.makeList(p.lhs, loc.lhs, anno.lhs),
aoqi@0 282 rhs.makeList(p.rhs, loc.rhs, anno.rhs));
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 public Location makeLocation(String systemId, int lineNumber,
aoqi@0 286 int columnNumber) {
aoqi@0 287 return new LocationHost(
aoqi@0 288 lhs.makeLocation(systemId, lineNumber, columnNumber),
aoqi@0 289 rhs.makeLocation(systemId, lineNumber, columnNumber));
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 public ParsedPattern makeMixed(ParsedPattern _p, Location _loc,
aoqi@0 293 Annotations _anno) throws BuildException {
aoqi@0 294
aoqi@0 295 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 296 LocationHost loc = cast(_loc);
aoqi@0 297 AnnotationsHost anno = cast(_anno);
aoqi@0 298
aoqi@0 299 return new ParsedPatternHost(
aoqi@0 300 lhs.makeMixed(p.lhs, loc.lhs, anno.lhs),
aoqi@0 301 rhs.makeMixed(p.rhs, loc.rhs, anno.rhs));
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 public ParsedPattern makeNotAllowed(Location _loc, Annotations _anno) {
aoqi@0 305 LocationHost loc = cast(_loc);
aoqi@0 306 AnnotationsHost anno = cast(_anno);
aoqi@0 307
aoqi@0 308 return new ParsedPatternHost(
aoqi@0 309 lhs.makeNotAllowed(loc.lhs, anno.lhs),
aoqi@0 310 rhs.makeNotAllowed(loc.rhs, anno.rhs));
aoqi@0 311 }
aoqi@0 312
aoqi@0 313 public ParsedPattern makeOneOrMore(ParsedPattern _p, Location _loc,
aoqi@0 314 Annotations _anno) throws BuildException {
aoqi@0 315
aoqi@0 316 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 317 LocationHost loc = cast(_loc);
aoqi@0 318 AnnotationsHost anno = cast(_anno);
aoqi@0 319
aoqi@0 320 return new ParsedPatternHost(
aoqi@0 321 lhs.makeOneOrMore(p.lhs, loc.lhs, anno.lhs),
aoqi@0 322 rhs.makeOneOrMore(p.rhs, loc.rhs, anno.rhs));
aoqi@0 323 }
aoqi@0 324
aoqi@0 325 public ParsedPattern makeZeroOrMore(ParsedPattern _p, Location _loc,
aoqi@0 326 Annotations _anno) throws BuildException {
aoqi@0 327
aoqi@0 328 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 329 LocationHost loc = cast(_loc);
aoqi@0 330 AnnotationsHost anno = cast(_anno);
aoqi@0 331
aoqi@0 332 return new ParsedPatternHost(
aoqi@0 333 lhs.makeZeroOrMore(p.lhs, loc.lhs, anno.lhs),
aoqi@0 334 rhs.makeZeroOrMore(p.rhs, loc.rhs, anno.rhs));
aoqi@0 335 }
aoqi@0 336
aoqi@0 337 public ParsedPattern makeOptional(ParsedPattern _p, Location _loc,
aoqi@0 338 Annotations _anno) throws BuildException {
aoqi@0 339
aoqi@0 340 ParsedPatternHost p = (ParsedPatternHost) _p;
aoqi@0 341 LocationHost loc = cast(_loc);
aoqi@0 342 AnnotationsHost anno = cast(_anno);
aoqi@0 343
aoqi@0 344 return new ParsedPatternHost(
aoqi@0 345 lhs.makeOptional(p.lhs, loc.lhs, anno.lhs),
aoqi@0 346 rhs.makeOptional(p.rhs, loc.rhs, anno.rhs));
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 public ParsedPattern makeText(Location _loc, Annotations _anno) {
aoqi@0 350 LocationHost loc = cast(_loc);
aoqi@0 351 AnnotationsHost anno = cast(_anno);
aoqi@0 352
aoqi@0 353 return new ParsedPatternHost(
aoqi@0 354 lhs.makeText(loc.lhs, anno.lhs),
aoqi@0 355 rhs.makeText(loc.rhs, anno.rhs));
aoqi@0 356 }
aoqi@0 357
aoqi@0 358 public ParsedPattern makeValue(String datatypeLibrary, String type,
aoqi@0 359 String value, Context c, String ns, Location _loc, Annotations _anno)
aoqi@0 360 throws BuildException {
aoqi@0 361 LocationHost loc = cast(_loc);
aoqi@0 362 AnnotationsHost anno = cast(_anno);
aoqi@0 363
aoqi@0 364 return new ParsedPatternHost(
aoqi@0 365 lhs.makeValue(datatypeLibrary,type,value,c,ns,loc.lhs,anno.lhs),
aoqi@0 366 rhs.makeValue(datatypeLibrary,type,value,c,ns,loc.rhs,anno.rhs));
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 public boolean usesComments() {
aoqi@0 370 return lhs.usesComments() || rhs.usesComments();
aoqi@0 371 }
aoqi@0 372 }

mercurial