Class NGCCRuntime

  • All Implemented Interfaces:
    NGCCEventSource, org.xml.sax.ContentHandler
    Direct Known Subclasses:
    NGCCRuntimeEx

    public class NGCCRuntime
    extends java.lang.Object
    implements org.xml.sax.ContentHandler, NGCCEventSource
    Runtime Engine for RELAXNGCC execution. This class has the following functionalities:
    1. Managing a stack of NGCCHandler objects and switching between them appropriately.
    2. Keep track of all Attributes.
    3. manage mapping between namespace URIs and prefixes.
    4. TODO: provide support for interleaving.
    Version:
    $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
    Author:
    Kohsuke Kawaguchi (kk@kohsuke.org)
    • Constructor Summary

      Constructors 
      Constructor Description
      NGCCRuntime()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(char[] ch, int start, int length)  
      void consumeAttribute​(int index)  
      void endDocument()  
      void endElement​(java.lang.String uri, java.lang.String localname, java.lang.String qname)  
      void endPrefixMapping​(java.lang.String prefix)  
      int getAttributeIndex​(java.lang.String uri, java.lang.String localname)  
      org.xml.sax.Attributes getCurrentAttributes()
      Attributes that belong to the current element.
      org.xml.sax.Locator getLocator()
      Gets the source location of the current event.
      void ignorableWhitespace​(char[] ch, int start, int length)  
      void onEnterElementConsumed​(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts)
      Called by the generated handler code when an enter element event is consumed.
      void onLeaveElementConsumed​(java.lang.String uri, java.lang.String localName, java.lang.String qname)  
      void processingInstruction​(java.lang.String target, java.lang.String data)  
      void processList​(java.lang.String str)  
      void redirectSubtree​(org.xml.sax.ContentHandler child, java.lang.String uri, java.lang.String local, java.lang.String qname)
      This method can be called only from the enterElement handler.
      int replace​(NGCCEventReceiver o, NGCCEventReceiver n)
      Replaces an old handler with a new handler, and returns ID of the EventReceiver thread.
      void reset()
      Cleans up all the data structure so that the object can be reused later.
      java.lang.String resolveNamespacePrefix​(java.lang.String prefix)  
      void sendEnterAttribute​(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname)  
      void sendEnterElement​(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname, org.xml.sax.Attributes atts)
      Sends an enter element event to the specified EventReceiver thread.
      void sendLeaveAttribute​(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname)  
      void sendLeaveElement​(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname)  
      void sendText​(int threadId, java.lang.String value)  
      void setDocumentLocator​(org.xml.sax.Locator _loc)  
      void setRootHandler​(NGCCHandler rootHandler)
      Sets the root handler, which will be used to parse the root element.
      void skippedEntity​(java.lang.String name)  
      void startDocument()  
      void startElement​(java.lang.String uri, java.lang.String localname, java.lang.String qname, org.xml.sax.Attributes atts)  
      void startPrefixMapping​(java.lang.String prefix, java.lang.String uri)  
      void trace​(java.lang.String s)  
      void traceln​(java.lang.String s)  
      protected void unexpectedX​(java.lang.String token)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NGCCRuntime

        public NGCCRuntime()
    • Method Detail

      • setRootHandler

        public void setRootHandler​(NGCCHandler rootHandler)
        Sets the root handler, which will be used to parse the root element.

        This method can be called right after the object is created or the reset method is called. You can't replace the root handler while parsing is in progress.

        Usually a generated class that corresponds to the <start> pattern will be used as the root handler, but any NGCCHandler can be a root handler.

        Throws:
        java.lang.IllegalStateException - If this method is called but it doesn't satisfy the pre-condition stated above.
      • reset

        public void reset()
        Cleans up all the data structure so that the object can be reused later. Normally, applications do not need to call this method directly, as the runtime resets itself after the endDocument method.
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator _loc)
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
      • getLocator

        public org.xml.sax.Locator getLocator()
        Gets the source location of the current event.

        One can call this method from RelaxNGCC handlers to access the line number information. Note that to

      • getCurrentAttributes

        public org.xml.sax.Attributes getCurrentAttributes()
        Attributes that belong to the current element.

        It's generally not recommended for applications to use this method. RelaxNGCC internally removes processed attributes, so this doesn't correctly reflect all the attributes an element carries.

      • processList

        public void processList​(java.lang.String str)
                         throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localname,
                                 java.lang.String qname,
                                 org.xml.sax.Attributes atts)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • onEnterElementConsumed

        public void onEnterElementConsumed​(java.lang.String uri,
                                           java.lang.String localName,
                                           java.lang.String qname,
                                           org.xml.sax.Attributes atts)
                                    throws org.xml.sax.SAXException
        Called by the generated handler code when an enter element event is consumed.

        Pushes a new attribute set.

        Note that attributes are NOT pushed at the startElement method, because the processing of the enterElement event can trigger other attribute events and etc.

        This method will be called from one of handlers when it truely consumes the enterElement event.

        Throws:
        org.xml.sax.SAXException
      • onLeaveElementConsumed

        public void onLeaveElementConsumed​(java.lang.String uri,
                                           java.lang.String localName,
                                           java.lang.String qname)
                                    throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localname,
                               java.lang.String qname)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • ignorableWhitespace

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
                                 throws org.xml.sax.SAXException
        Specified by:
        ignorableWhitespace in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • getAttributeIndex

        public int getAttributeIndex​(java.lang.String uri,
                                     java.lang.String localname)
      • consumeAttribute

        public void consumeAttribute​(int index)
                              throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • startPrefixMapping

        public void startPrefixMapping​(java.lang.String prefix,
                                       java.lang.String uri)
                                throws org.xml.sax.SAXException
        Specified by:
        startPrefixMapping in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • endPrefixMapping

        public void endPrefixMapping​(java.lang.String prefix)
                              throws org.xml.sax.SAXException
        Specified by:
        endPrefixMapping in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • skippedEntity

        public void skippedEntity​(java.lang.String name)
                           throws org.xml.sax.SAXException
        Specified by:
        skippedEntity in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • processingInstruction

        public void processingInstruction​(java.lang.String target,
                                          java.lang.String data)
                                   throws org.xml.sax.SAXException
        Specified by:
        processingInstruction in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Throws:
        org.xml.sax.SAXException
      • startDocument

        public void startDocument()
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
      • sendEnterAttribute

        public void sendEnterAttribute​(int threadId,
                                       java.lang.String uri,
                                       java.lang.String local,
                                       java.lang.String qname)
                                throws org.xml.sax.SAXException
        Specified by:
        sendEnterAttribute in interface NGCCEventSource
        Throws:
        org.xml.sax.SAXException
      • sendEnterElement

        public void sendEnterElement​(int threadId,
                                     java.lang.String uri,
                                     java.lang.String local,
                                     java.lang.String qname,
                                     org.xml.sax.Attributes atts)
                              throws org.xml.sax.SAXException
        Description copied from interface: NGCCEventSource
        Sends an enter element event to the specified EventReceiver thread.
        Specified by:
        sendEnterElement in interface NGCCEventSource
        Throws:
        org.xml.sax.SAXException
      • sendLeaveAttribute

        public void sendLeaveAttribute​(int threadId,
                                       java.lang.String uri,
                                       java.lang.String local,
                                       java.lang.String qname)
                                throws org.xml.sax.SAXException
        Specified by:
        sendLeaveAttribute in interface NGCCEventSource
        Throws:
        org.xml.sax.SAXException
      • sendLeaveElement

        public void sendLeaveElement​(int threadId,
                                     java.lang.String uri,
                                     java.lang.String local,
                                     java.lang.String qname)
                              throws org.xml.sax.SAXException
        Specified by:
        sendLeaveElement in interface NGCCEventSource
        Throws:
        org.xml.sax.SAXException
      • sendText

        public void sendText​(int threadId,
                             java.lang.String value)
                      throws org.xml.sax.SAXException
        Specified by:
        sendText in interface NGCCEventSource
        Throws:
        org.xml.sax.SAXException
      • redirectSubtree

        public void redirectSubtree​(org.xml.sax.ContentHandler child,
                                    java.lang.String uri,
                                    java.lang.String local,
                                    java.lang.String qname)
                             throws org.xml.sax.SAXException
        This method can be called only from the enterElement handler. The sub-tree rooted at the new element will be redirected to the specified ContentHandler.

        Currently active NGCCHandler will only receive the leaveElement event of the newly started element.

        Parameters:
        uri - ,local,qname Parameters passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.
        Throws:
        org.xml.sax.SAXException
      • resolveNamespacePrefix

        public java.lang.String resolveNamespacePrefix​(java.lang.String prefix)
      • unexpectedX

        protected void unexpectedX​(java.lang.String token)
                            throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException
      • trace

        public void trace​(java.lang.String s)
      • traceln

        public void traceln​(java.lang.String s)