1 /* 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 /* 26 * Copyright (C) 2004-2011 27 * 28 * Permission is hereby granted, free of charge, to any person obtaining a copy 29 * of this software and associated documentation files (the "Software"), to deal 30 * in the Software without restriction, including without limitation the rights 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 32 * copies of the Software, and to permit persons to whom the Software is 33 * furnished to do so, subject to the following conditions: 34 * 35 * The above copyright notice and this permission notice shall be included in 36 * all copies or substantial portions of the Software. 37 * 38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 44 * THE SOFTWARE. 45 */ 46 package com.sun.xml.internal.rngom.ast.builder; 47 48 import com.sun.xml.internal.rngom.ast.om.Location; 49 import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation; 50 import com.sun.xml.internal.rngom.ast.om.ParsedNameClass; 51 import com.sun.xml.internal.rngom.ast.om.ParsedPattern; 52 import com.sun.xml.internal.rngom.parse.*; 53 import com.sun.xml.internal.rngom.parse.IllegalSchemaException; 54 import com.sun.xml.internal.rngom.parse.Parseable; 55 56 import java.util.List; 57 58 // TODO: define combine error check should be done by the parser. 59 public interface SchemaBuilder< 60 N extends ParsedNameClass, 61 P extends ParsedPattern, 62 E extends ParsedElementAnnotation, 63 L extends Location, 64 A extends Annotations<E,L,CL>, 65 CL extends CommentList<L>> { 66 67 /** 68 * Returns the {@link NameClassBuilder}, which is used to build name 69 * classes for this {@link SchemaBuilder}. The 70 * {@link com.sun.xml.internal.rngom.nc.NameClass}es that are built will then be 71 * fed into this {@link SchemaBuilder}to further build RELAX NG patterns. 72 * 73 * @return always return a non-null valid object. This method can (and 74 * probably should) always return the same object. 75 */ 76 NameClassBuilder<N,E,L,A,CL> getNameClassBuilder() throws BuildException; 77 78 P makeChoice(List<P> patterns, L loc, A anno) throws BuildException; 79 80 P makeInterleave(List<P> patterns, L loc, A anno) throws BuildException; 81 82 P makeGroup(List<P> patterns, L loc, A anno) throws BuildException; 83 84 P makeOneOrMore(P p, L loc, A anno) throws BuildException; 85 86 P makeZeroOrMore(P p, L loc, A anno) throws BuildException; 87 88 P makeOptional(P p, L loc, A anno) throws BuildException; 89 90 P makeList(P p, L loc, A anno) throws BuildException; 91 92 P makeMixed(P p, L loc, A anno) throws BuildException; 93 94 P makeEmpty(L loc, A anno); 95 96 P makeNotAllowed(L loc, A anno); 97 98 P makeText(L loc, A anno); 99 100 P makeAttribute(N nc, P p, L loc, A anno) throws BuildException; 101 102 P makeElement(N nc, P p, L loc, A anno) throws BuildException; 103 104 DataPatternBuilder makeDataPatternBuilder(String datatypeLibrary, String type, L loc) throws BuildException; 105 106 P makeValue(String datatypeLibrary, String type, String value, 107 Context c, String ns, L loc, A anno) throws BuildException; 108 109 /** 110 * 111 * @param parent 112 * The parent scope. null if there's no parent scope. 113 * For example, if the complete document looks like the following: 114 * <pre>{@code 115 * <grammar> 116 * <start><element name="root"><empty/></element></start> 117 * </grammar> 118 * }</pre> 119 * Then when the outer-most {@link Grammar} is created, it will 120 * receive the {@code null} parent. 121 */ 122 Grammar<P,E,L,A,CL> makeGrammar(Scope<P,E,L,A,CL> parent); 123 124 /** 125 * Called when annotation is found right inside a pattern 126 * 127 * such as, 128 * 129 * <pre>{@code 130 * <element name="foo"> <!-- this becomes 'P' --> 131 * <foreign:annotation /> <!-- this becomes 'A' --> 132 * ... 133 * </element> 134 * }</pre> 135 */ 136 P annotate(P p, A anno) throws BuildException; 137 138 /** 139 * Called when element annotation is found after a pattern. 140 * 141 * such as, 142 * 143 * <pre>{@code 144 * <element name="foo"> 145 * <empty /> <!-- this becomes 'P' --> 146 * <foreign:annotation /> <!-- this becomes 'E' --> 147 * </element> 148 * }</pre> 149 */ 150 P annotateAfter(P p, E e) throws BuildException; 151 152 P commentAfter(P p, CL comments) throws BuildException; 153 154 /** 155 * 156 * @param current 157 * Current grammar that we are parsing. This is what contains 158 * externalRef. 159 * @param scope 160 * The parent scope. null if there's no parent scope. 161 * See {@link #makeGrammar(Scope)} for more details about 162 * when this parameter can be null. 163 */ 164 P makeExternalRef(Parseable current, String uri, String ns, Scope<P,E,L,A,CL> scope, 165 L loc, A anno) throws BuildException, IllegalSchemaException; 166 167 L makeLocation(String systemId, int lineNumber, int columnNumber); 168 169 /** 170 * Creates {@link Annotations} object to parse annotations on patterns. 171 * 172 * @return 173 * must be non-null. 174 */ 175 A makeAnnotations(CL comments, Context context); 176 177 ElementAnnotationBuilder<P,E,L,A,CL> makeElementAnnotationBuilder(String ns, 178 String localName, String prefix, L loc, CL comments, 179 Context context); 180 181 CL makeCommentList(); 182 183 P makeErrorPattern(); 184 185 /** 186 * If this {@link SchemaBuilder}is interested in actually parsing 187 * comments, this method returns true. 188 * <p> 189 * Returning false allows the schema parser to speed up the processing by 190 * skiping comment-related handlings. 191 */ 192 boolean usesComments(); 193 194 /** 195 * Called after all the parsing is done. 196 * 197 * <p> 198 * This hook typically allows as {@link SchemaBuilder} to expand 199 * notAllowed (if it's following the simplification as in the spec.) 200 */ 201 P expandPattern( P p ) throws BuildException, IllegalSchemaException; 202 }