Log4j 1.3alpha-3

org.apache.joran
Class Interpreter

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--org.apache.joran.Interpreter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class Interpreter
extends DefaultHandler

Interpreter is Joran's main driving class. It extends SAX DefaultHandler which invokes various actions according to predefined patterns.

Patterns are kept in a RuleStore which is programmed to store and then later produce the applicable actions for a given pattern.

The pattern corresponding to a top level <a> element is the string "a".

The pattern corresponding to an element <b> embeded within a top level <a> element is the string "a/b".

The pattern corresponding to an <b> and any level of nesting is "*/b. Thus, the * character placed at the beginning of a pattern serves as a wildcard for the level of nesting. Conceptually, this is very similar to the API of commons-digester. Joran offers several small advantages. First and foremost, it offers support for implicit actions which result in a significant leap in flexibility. Second, in our opinion better error reporting capability. Third, it is self-reliant. It does not depend on other APIs, in particular commons-logging which is a big no-no for log4j. Last but not least, joran is quite tiny and is expected to remain so.

Author:
Ceki Gülcuü

Constructor Summary
Interpreter(RuleStore rs)
           
 
Method Summary
 void addImplcitAction(ImplicitAction ia)
           
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
 void endPrefixMapping(java.lang.String prefix)
           
 void error(SAXParseException spe)
           
 void fatalError(SAXParseException spe)
           
 EntityResolver getEntityResolver()
           
 ExecutionContext getExecutionContext()
           
 Locator getLocator()
           
 RuleStore getRuleStore()
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          If a specific entityResolver is set for this Interpreter instance, then we use it to resolve entities.
 void setDocumentLocator(Locator l)
           
 void setEntityResolver(EntityResolver entityResolver)
           
 void setRuleStore(RuleStore ruleStore)
           
 void skippedEntity(java.lang.String name)
           
 void startDocument()
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, Attributes atts)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 void warning(SAXParseException spe)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, notationDecl, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter(RuleStore rs)
Method Detail

getExecutionContext

public ExecutionContext getExecutionContext()

startDocument

public void startDocument()
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         Attributes atts)
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler

getLocator

public Locator getLocator()

setDocumentLocator

public void setDocumentLocator(Locator l)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler

addImplcitAction

public void addImplcitAction(ImplicitAction ia)

getRuleStore

public RuleStore getRuleStore()

setRuleStore

public void setRuleStore(RuleStore ruleStore)

error

public void error(SAXParseException spe)
           throws SAXException
Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
SAXException

fatalError

public void fatalError(SAXParseException spe)
                throws SAXException
Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
SAXException

warning

public void warning(SAXParseException spe)
             throws SAXException
Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class DefaultHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class DefaultHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class DefaultHandler

skippedEntity

public void skippedEntity(java.lang.String name)
Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class DefaultHandler

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class DefaultHandler

getEntityResolver

public EntityResolver getEntityResolver()

setEntityResolver

public void setEntityResolver(EntityResolver entityResolver)

resolveEntity

public InputSource resolveEntity(java.lang.String publicId,
                                 java.lang.String systemId)
                          throws SAXException
If a specific entityResolver is set for this Interpreter instance, then we use it to resolve entities. Otherwise, we use the default implementation offered by the super class.

Due to inexplicable voodoo, the original resolveEntity method in org.xml.sax.helpers.DefaultHandler declares throwing an IOException, whereas the org.xml.sax.helpers.DefaultHandler class included in JDK 1.4 masks this exception.

In order to compile under JDK 1.4, we are forced to mask the IOException as well. Since its signatures varies, we cannot call our super class' resolveEntity method. We are forced to implement the default behavior ourselves, which in this case, is just returning null.

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class DefaultHandler
SAXException

Log4j 1.3alpha-3

Copyright 2000-2003 Apache Software Foundation.