1 /*
   2  * Copyright (c) 2005, 2010, 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 package com.sun.xml.internal.rngom.ast.builder;
  27 
  28 import com.sun.xml.internal.rngom.ast.om.Location;
  29 import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation;
  30 import com.sun.xml.internal.rngom.ast.om.ParsedPattern;
  31 
  32 /**
  33  * The container that can have <define> elements.
  34  * <p>
  35  * {@link Div}, {@link Grammar}, {@link Include}, or {@link IncludedGrammar}.
  36  */
  37 public interface GrammarSection<
  38     P extends ParsedPattern,
  39     E extends ParsedElementAnnotation,
  40     L extends Location,
  41     A extends Annotations<E,L,CL>,
  42     CL extends CommentList<L>> {
  43 
  44     static final class Combine {
  45         private final String name;
  46         private Combine(String name) {
  47             this.name = name;
  48         }
  49         final public String toString() {
  50             return name;
  51         }
  52     }
  53 
  54     static final Combine COMBINE_CHOICE = new Combine("choice");
  55     static final Combine COMBINE_INTERLEAVE = new Combine("interleave");
  56 
  57     // using \u0000 guarantees that the name will be never used as
  58     // a user-defined pattern name.
  59     static final String START = "\u0000#start\u0000";
  60 
  61     /**
  62      * Called when a pattern is defined.
  63      *
  64      * @param name
  65      *      Name of the pattern. For the definition by a &lt;start/> element,
  66      *      this parameter is the same as {@link #START}.
  67      *      to test if it's a named pattern definition or the start pattern definition.
  68      * @param combine
  69      *      null or {@link #COMBINE_CHOICE} or {@link #COMBINE_INTERLEAVE} depending
  70      *      on the value of the combine attribute.
  71      * @param pattern
  72      *      The pattern to be defined.
  73      */
  74     void define( String name, Combine combine, P pattern, L loc, A anno) throws BuildException;
  75 
  76     /**
  77      * Called when an annotation is found.
  78      */
  79     void topLevelAnnotation(E ea) throws BuildException;
  80 
  81     /**
  82      * Called when a comment is found.
  83      */
  84     void topLevelComment(CL comments) throws BuildException;
  85 
  86     /**
  87      * Called when &lt;div> is found.
  88      *
  89      * @return
  90      *      the returned {@link Div} object will receive callbacks for structures
  91      *      inside the &lt;div> element.
  92      */
  93     Div<P,E,L,A,CL> makeDiv();
  94 
  95     /**
  96      * Returns null if already in an include.
  97      */
  98     Include<P,E,L,A,CL> makeInclude();
  99 }