jaxws/src/jdk.xml.bind/share/classes/com/sun/xml/internal/xsom/impl/parser/state/NGCCRuntime.java
changeset 33547 e4c76ac38b12
parent 32795 5a5710ee05a0
equal deleted inserted replaced
33390:d131f4b8433a 33547:e4c76ac38b12
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    48  *  <li>Keep track of all Attributes.
    48  *  <li>Keep track of all Attributes.
    49  *
    49  *
    50  *  <li>manage mapping between namespace URIs and prefixes.
    50  *  <li>manage mapping between namespace URIs and prefixes.
    51  *
    51  *
    52  *  <li>TODO: provide support for interleaving.
    52  *  <li>TODO: provide support for interleaving.
    53  *
    53  *  </ol>
       
    54  *
       
    55  * <p><b>
       
    56  *     Auto-generated, do not edit.
       
    57  * </b></p>
    54  * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
    58  * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
    55  * @author Kohsuke Kawaguchi (kk@kohsuke.org)
    59  * @author Kohsuke Kawaguchi (kk@kohsuke.org)
    56  */
    60  */
    57 public class NGCCRuntime implements ContentHandler, NGCCEventSource {
    61 public class NGCCRuntime implements ContentHandler, NGCCEventSource {
    58 
    62 
    66      * <p>
    70      * <p>
    67      * This method can be called right after the object is created
    71      * This method can be called right after the object is created
    68      * or the reset method is called. You can't replace the root
    72      * or the reset method is called. You can't replace the root
    69      * handler while parsing is in progress.
    73      * handler while parsing is in progress.
    70      * <p>
    74      * <p>
    71      * Usually a generated class that corresponds to the &lt;start>
    75      * Usually a generated class that corresponds to the {@code <start>}
    72      * pattern will be used as the root handler, but any NGCCHandler
    76      * pattern will be used as the root handler, but any NGCCHandler
    73      * can be a root handler.
    77      * can be a root handler.
    74      *
    78      *
    75      * @exception IllegalStateException
    79      * @exception IllegalStateException
    76      *      If this method is called but it doesn't satisfy the
    80      *      If this method is called but it doesn't satisfy the
   176      * <pre>{@code
   180      * <pre>{@code
   177      * <foo> <bar/></foo>
   181      * <foo> <bar/></foo>
   178      * }</pre>
   182      * }</pre>
   179      *
   183      *
   180      * Then this first space needs to be ignored (for otherwise, we will
   184      * Then this first space needs to be ignored (for otherwise, we will
   181      * end up treating this space as the match to &lt;text/> and won't
   185      * end up treating this space as the match to {@code <text/>} and won't
   182      * be able to process &lt;bar>.)
   186      * be able to process {@code <bar>}.)
   183      *
   187      *
   184      * Now assume the following instance:
   188      * Now assume the following instance:
   185      * <pre>{@code
   189      * <pre>{@code
   186      * <foo/>
   190      * <foo/>
   187      * }</pre>
   191      * }</pre>
   192      * <p>
   196      * <p>
   193      * This is very difficult to solve in general, but one seemingly
   197      * This is very difficult to solve in general, but one seemingly
   194      * easy solution is to use the type of next event. If a text is
   198      * easy solution is to use the type of next event. If a text is
   195      * followed by a start tag, it follows from the constraint on
   199      * followed by a start tag, it follows from the constraint on
   196      * RELAX NG that that text must be either whitespaces or a match
   200      * RELAX NG that that text must be either whitespaces or a match
   197      * to &lt;text/>.
   201      * to {@code <text/>}.
   198      *
   202      *
   199      * <p>
   203      * <p>
   200      * On the contrary, if a text is followed by a end tag, then it
   204      * On the contrary, if a text is followed by a end tag, then it
   201      * cannot be whitespace unless the content model can accept empty,
   205      * cannot be whitespace unless the content model can accept empty,
   202      * in which case sending a text event will be harmlessly ignored
   206      * in which case sending a text event will be harmlessly ignored
   207      * behavior of this method.
   211      * behavior of this method.
   208      *
   212      *
   209      * <p>
   213      * <p>
   210      * TODO: according to the constraint of RELAX NG, if characters
   214      * TODO: according to the constraint of RELAX NG, if characters
   211      * follow an end tag, then they must be either whitespaces or
   215      * follow an end tag, then they must be either whitespaces or
   212      * must match to &lt;text/>.
   216      * must match to {@code <text/>}.
   213      *
   217      *
   214      * @param   possiblyWhitespace
   218      * @param ignorable
   215      *      True if the buffered character can be ignorabale. False if
   219      *      True if the buffered character can be ignorabale. False if
   216      *      it needs to be consumed.
   220      *      it needs to be consumed.
   217      */
   221      */
   218     private void processPendingText(boolean ignorable) throws SAXException {
   222     private void processPendingText(boolean ignorable) throws SAXException {
   219         if(ignorable && text.toString().trim().length()==0)
   223         if(ignorable && text.toString().trim().length()==0)
   238         if(redirect!=null) {
   242         if(redirect!=null) {
   239             redirect.startElement(uri,localname,qname,atts);
   243             redirect.startElement(uri,localname,qname,atts);
   240             redirectionDepth++;
   244             redirectionDepth++;
   241         } else {
   245         } else {
   242             processPendingText(true);
   246             processPendingText(true);
   243     //        System.out.println("startElement:"+localname+"->"+_attrStack.size());
   247             //        System.out.println("startElement:"+localname+"->"+_attrStack.size());
   244             currentHandler.enterElement(uri, localname, qname, atts);
   248             currentHandler.enterElement(uri, localname, qname, atts);
   245         }
   249         }
   246     }
   250     }
   247 
   251 
   248     /**
   252     /**
   259      * <p>
   263      * <p>
   260      * This method will be called from one of handlers when it truely
   264      * This method will be called from one of handlers when it truely
   261      * consumes the enterElement event.
   265      * consumes the enterElement event.
   262      */
   266      */
   263     public void onEnterElementConsumed(
   267     public void onEnterElementConsumed(
   264         String uri, String localName, String qname,Attributes atts) throws SAXException {
   268             String uri, String localName, String qname,Attributes atts) throws SAXException {
   265         attStack.push(currentAtts=new AttributesImpl(atts));
   269         attStack.push(currentAtts=new AttributesImpl(atts));
   266         nsEffectiveStack.push( new Integer(nsEffectivePtr) );
   270         nsEffectiveStack.push( new Integer(nsEffectivePtr) );
   267         nsEffectivePtr = namespaces.size();
   271         nsEffectivePtr = namespaces.size();
   268     }
   272     }
   269 
   273 
   390 // event dispatching methods
   394 // event dispatching methods
   391 //
   395 //
   392 //
   396 //
   393 
   397 
   394     public void sendEnterAttribute( int threadId,
   398     public void sendEnterAttribute( int threadId,
   395         String uri, String local, String qname) throws SAXException {
   399                                     String uri, String local, String qname) throws SAXException {
   396 
   400 
   397         currentHandler.enterAttribute(uri,local,qname);
   401         currentHandler.enterAttribute(uri,local,qname);
   398     }
   402     }
   399 
   403 
   400     public void sendEnterElement( int threadId,
   404     public void sendEnterElement( int threadId,
   401         String uri, String local, String qname, Attributes atts) throws SAXException {
   405                                   String uri, String local, String qname, Attributes atts) throws SAXException {
   402 
   406 
   403         currentHandler.enterElement(uri,local,qname,atts);
   407         currentHandler.enterElement(uri,local,qname,atts);
   404     }
   408     }
   405 
   409 
   406     public void sendLeaveAttribute( int threadId,
   410     public void sendLeaveAttribute( int threadId,
   407         String uri, String local, String qname) throws SAXException {
   411                                     String uri, String local, String qname) throws SAXException {
   408 
   412 
   409         currentHandler.leaveAttribute(uri,local,qname);
   413         currentHandler.leaveAttribute(uri,local,qname);
   410     }
   414     }
   411 
   415 
   412     public void sendLeaveElement( int threadId,
   416     public void sendLeaveElement( int threadId,
   413         String uri, String local, String qname) throws SAXException {
   417                                   String uri, String local, String qname) throws SAXException {
   414 
   418 
   415         currentHandler.leaveElement(uri,local,qname);
   419         currentHandler.leaveElement(uri,local,qname);
   416     }
   420     }
   417 
   421 
   418     public void sendText(int threadId, String value) throws SAXException {
   422     public void sendText(int threadId, String value) throws SAXException {
   446      * @param   uri,local,qname
   450      * @param   uri,local,qname
   447      *      Parameters passed to the enter element event. Used to
   451      *      Parameters passed to the enter element event. Used to
   448      *      simulate the startElement event for the new ContentHandler.
   452      *      simulate the startElement event for the new ContentHandler.
   449      */
   453      */
   450     public void redirectSubtree( ContentHandler child,
   454     public void redirectSubtree( ContentHandler child,
   451         String uri, String local, String qname ) throws SAXException {
   455                                  String uri, String local, String qname ) throws SAXException {
   452 
   456 
   453         redirect = child;
   457         redirect = child;
   454         redirect.setDocumentLocator(locator);
   458         redirect.setDocumentLocator(locator);
   455         redirect.startDocument();
   459         redirect.startDocument();
   456 
   460 
   457         // TODO: when a prefix is re-bound to something else,
   461         // TODO: when a prefix is re-bound to something else,
   458         // the following code is potentially dangerous. It should be
   462         // the following code is potentially dangerous. It should be
   459         // modified to report active bindings only.
   463         // modified to report active bindings only.
   460         for( int i=0; i<namespaces.size(); i+=2 )
   464         for( int i=0; i<namespaces.size(); i+=2 )
   461             redirect.startPrefixMapping(
   465             redirect.startPrefixMapping(
   462                 (String)namespaces.get(i),
   466                     (String)namespaces.get(i),
   463                 (String)namespaces.get(i+1)
   467                     (String)namespaces.get(i+1)
   464             );
   468             );
   465 
   469 
   466         redirect.startElement(uri,local,qname,currentAtts);
   470         redirect.startElement(uri,local,qname,currentAtts);
   467         redirectionDepth=1;
   471         redirectionDepth=1;
   468     }
   472     }
   513             return "http://www.w3.org/XML/1998/namespace";
   517             return "http://www.w3.org/XML/1998/namespace";
   514         else    return null;    // prefix undefined
   518         else    return null;    // prefix undefined
   515     }
   519     }
   516 
   520 
   517 
   521 
   518 // error reporting
   522     // error reporting
   519     protected void unexpectedX(String token) throws SAXException {
   523     protected void unexpectedX(String token) throws SAXException {
   520         throw new SAXParseException(MessageFormat.format(
   524         throw new SAXParseException(MessageFormat.format(
   521             "Unexpected {0} appears at line {1} column {2}",
   525                 "Unexpected {0} appears at line {1} column {2}",
   522             new Object[]{
   526                 new Object[]{
   523                 token,
   527                         token,
   524                 new Integer(getLocator().getLineNumber()),
   528                         new Integer(getLocator().getLineNumber()),
   525                 new Integer(getLocator().getColumnNumber()) }),
   529                         new Integer(getLocator().getColumnNumber()) }),
   526             getLocator());
   530                 getLocator());
   527     }
   531     }
   528 
   532 
   529 
   533 
   530 
   534 
   531 
   535 
   532 //
   536     //
   533 //
   537 //
   534 // trace functions
   538 // trace functions
   535 //
   539 //
   536 //
   540 //
   537     private int indent=0;
   541     private int indent=0;