< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/gen/config/NGCCRuntime.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, 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


  33 import org.xml.sax.Attributes;
  34 import org.xml.sax.ContentHandler;
  35 import org.xml.sax.Locator;
  36 import org.xml.sax.SAXException;
  37 import org.xml.sax.SAXParseException;
  38 
  39 /**
  40  * Runtime Engine for RELAXNGCC execution.
  41  *
  42  * This class has the following functionalities:
  43  *
  44  * <ol>
  45  *  <li>Managing a stack of NGCCHandler objects and
  46  *      switching between them appropriately.
  47  *
  48  *  <li>Keep track of all Attributes.
  49  *
  50  *  <li>manage mapping between namespace URIs and prefixes.
  51  *
  52  *  <li>TODO: provide support for interleaving.

  53  * <p><b>
  54  *     Auto-generated, do not edit.
  55  * </b></p>
  56  * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
  57  * @author Kohsuke Kawaguchi (kk@kohsuke.org)
  58  */
  59 public class NGCCRuntime implements ContentHandler, NGCCEventSource {
  60 
  61     public NGCCRuntime() {
  62         reset();
  63     }
  64 
  65     /**
  66      * Sets the root handler, which will be used to parse the
  67      * root element.
  68      * <p>
  69      * This method can be called right after the object is created
  70      * or the reset method is called. You can't replace the root
  71      * handler while parsing is in progress.
  72      * <p>
  73      * Usually a generated class that corresponds to the &lt;start>
  74      * pattern will be used as the root handler, but any NGCCHandler
  75      * can be a root handler.
  76      *
  77      * @exception IllegalStateException
  78      *      If this method is called but it doesn't satisfy the
  79      *      pre-condition stated above.
  80      */
  81     public void setRootHandler( NGCCHandler rootHandler ) {
  82         if(currentHandler!=null)
  83             throw new IllegalStateException();
  84         currentHandler = rootHandler;
  85     }
  86 
  87 
  88     /**
  89      * Cleans up all the data structure so that the object can be reused later.
  90      * Normally, applications do not need to call this method directly,
  91      *
  92      * as the runtime resets itself after the endDocument method.
  93      */


 500     private int nsEffectivePtr=0;
 501 
 502     /**
 503      * Stack to preserve old nsEffectivePtr values.
 504      */
 505     private final Stack nsEffectiveStack = new Stack();
 506 
 507     public String resolveNamespacePrefix( String prefix ) {
 508         for( int i = nsEffectivePtr-2; i>=0; i-=2 )
 509             if( namespaces.get(i).equals(prefix) )
 510                 return (String)namespaces.get(i+1);
 511 
 512         // no binding was found.
 513         if(prefix.equals(""))   return "";  // return the default no-namespace
 514         if(prefix.equals("xml"))    // pre-defined xml prefix
 515             return "http://www.w3.org/XML/1998/namespace";
 516         else    return null;    // prefix undefined
 517     }
 518 
 519 
 520 // error reporting
 521     protected void unexpectedX(String token) throws SAXException {
 522         throw new SAXParseException(MessageFormat.format(
 523             "Unexpected {0} appears at line {1} column {2}",
 524             new Object[]{
 525                 token,
 526                 new Integer(getLocator().getLineNumber()),
 527                 new Integer(getLocator().getColumnNumber()) }),
 528             getLocator());
 529     }
 530 
 531 
 532 
 533 
 534 //
 535 //
 536 // trace functions
 537 //
 538 //
 539     private int indent=0;
 540     private boolean needIndent=true;
 541     private void printIndent() {
 542         for( int i=0; i<indent; i++ )
 543             System.out.print("  ");
 544     }
 545     public void trace( String s ) {
 546         if(needIndent) {
 547             needIndent=false;
 548             printIndent();
 549         }
 550         System.out.print(s);
 551     }
 552     public void traceln( String s ) {
 553         trace(s);
 554         trace("\n");
   1 /*
   2  * Copyright (c) 1997, 2015, 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


  33 import org.xml.sax.Attributes;
  34 import org.xml.sax.ContentHandler;
  35 import org.xml.sax.Locator;
  36 import org.xml.sax.SAXException;
  37 import org.xml.sax.SAXParseException;
  38 
  39 /**
  40  * Runtime Engine for RELAXNGCC execution.
  41  *
  42  * This class has the following functionalities:
  43  *
  44  * <ol>
  45  *  <li>Managing a stack of NGCCHandler objects and
  46  *      switching between them appropriately.
  47  *
  48  *  <li>Keep track of all Attributes.
  49  *
  50  *  <li>manage mapping between namespace URIs and prefixes.
  51  *
  52  *  <li>TODO: provide support for interleaving.
  53  * </ol>
  54  * <p><b>
  55  *     Auto-generated, do not edit.
  56  * </b></p>
  57  * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
  58  * @author Kohsuke Kawaguchi (kk@kohsuke.org)
  59  */
  60 public class NGCCRuntime implements ContentHandler, NGCCEventSource {
  61 
  62     public NGCCRuntime() {
  63         reset();
  64     }
  65 
  66     /**
  67      * Sets the root handler, which will be used to parse the
  68      * root element.
  69      * <p>
  70      * This method can be called right after the object is created
  71      * or the reset method is called. You can't replace the root
  72      * handler while parsing is in progress.
  73      * <p>
  74      * Usually a generated class that corresponds to the {@code <start>}
  75      * pattern will be used as the root handler, but any NGCCHandler
  76      * can be a root handler.
  77      *
  78      * @exception IllegalStateException
  79      *      If this method is called but it doesn't satisfy the
  80      *      pre-condition stated above.
  81      */
  82     public void setRootHandler( NGCCHandler rootHandler ) {
  83         if(currentHandler!=null)
  84             throw new IllegalStateException();
  85         currentHandler = rootHandler;
  86     }
  87 
  88 
  89     /**
  90      * Cleans up all the data structure so that the object can be reused later.
  91      * Normally, applications do not need to call this method directly,
  92      *
  93      * as the runtime resets itself after the endDocument method.
  94      */


 501     private int nsEffectivePtr=0;
 502 
 503     /**
 504      * Stack to preserve old nsEffectivePtr values.
 505      */
 506     private final Stack nsEffectiveStack = new Stack();
 507 
 508     public String resolveNamespacePrefix( String prefix ) {
 509         for( int i = nsEffectivePtr-2; i>=0; i-=2 )
 510             if( namespaces.get(i).equals(prefix) )
 511                 return (String)namespaces.get(i+1);
 512 
 513         // no binding was found.
 514         if(prefix.equals(""))   return "";  // return the default no-namespace
 515         if(prefix.equals("xml"))    // pre-defined xml prefix
 516             return "http://www.w3.org/XML/1998/namespace";
 517         else    return null;    // prefix undefined
 518     }
 519 
 520 
 521     // error reporting
 522     protected void unexpectedX(String token) throws SAXException {
 523         throw new SAXParseException(MessageFormat.format(
 524                 "Unexpected {0} appears at line {1} column {2}",
 525                 new Object[]{
 526                         token,
 527                         new Integer(getLocator().getLineNumber()),
 528                         new Integer(getLocator().getColumnNumber()) }),
 529                 getLocator());
 530     }
 531 
 532 
 533 
 534 
 535     //
 536 //
 537 // trace functions
 538 //
 539 //
 540     private int indent=0;
 541     private boolean needIndent=true;
 542     private void printIndent() {
 543         for( int i=0; i<indent; i++ )
 544             System.out.print("  ");
 545     }
 546     public void trace( String s ) {
 547         if(needIndent) {
 548             needIndent=false;
 549             printIndent();
 550         }
 551         System.out.print(s);
 552     }
 553     public void traceln( String s ) {
 554         trace(s);
 555         trace("\n");
< prev index next >