|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
org.apache.hivemind.parse.AbstractParser
public abstract class AbstractParser
Abstract super-class for parsers based around the SAX event model. This class provides support
for managing a stack of elements, making it reasonable to establish relationships between
elements. It also assists in setting the Location of elements as they
are created.
This support is structured around both XML but is suited towards configuration files rather than documents, in that the content (parsable character data) within an element is concatinated together and tracked as a single blob.
| Constructor Summary | |
|---|---|
AbstractParser()
|
|
| Method Summary | |
|---|---|
protected abstract void |
begin(java.lang.String elementName,
java.util.Map attributes)
Invoked when an element's start tag is recognized. |
void |
characters(char[] ch,
int start,
int length)
Accepts parseable character data from within an element and applies it to the top stack element. |
protected abstract void |
end(java.lang.String elementName)
Invoked when an element's close tag is recognized. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
|
void |
error(org.xml.sax.SAXParseException ex)
Invokes fatalError(SAXParseException). |
void |
fatalError(org.xml.sax.SAXParseException ex)
|
protected java.lang.String |
getElementPath()
Returns a "path" to the current element, as a series of element names seperated by slashes, i.e., "top/middle/leaf". |
protected Location |
getLocation()
Returns the current lcoation, as reported by the parser. |
protected Resource |
getResource()
Returns the Resource being parsed (as set by initializeParser(Resource, int). |
protected int |
getState()
Returns the current state of the parser. |
protected void |
initializeParser(Resource resource,
int startState)
Initializes the parser; this should be called before any SAX parse events are received. |
protected java.lang.String |
peekContent()
Peeks at the top element on the stack, and returns its content (the accumuulated parseable character data directly enclosed by its start/end tags. |
protected java.lang.String |
peekElementName()
Peeks at the top element on the stack and returns its element name. |
protected java.lang.Object |
peekObject()
Peeks at the top element on the stack and returns the object for that element. |
protected void |
pop()
Invoked when the closing tag for an element is enountered {i.e, from endElement(String, String, String). |
protected void |
push(java.lang.String elementName,
java.lang.Object object,
int state)
Enters a new state, pushing an object onto the stack. |
protected void |
push(java.lang.String elementName,
java.lang.Object object,
int state,
boolean ignoreCharacterData)
Enters a new state, pusubhing an object onto the stack. |
protected void |
resetParser()
Resets all state after a parse. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Invoked by the parser, the locator is stored and later used by getLocation(). |
protected void |
setState(int state)
Forces a change to a specific state. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attributes)
|
protected void |
unexpectedElement(java.lang.String elementName)
Invoked when an unexpected element is parsed (useful for parses that don't perform validation, or when there's no DTD). |
protected void |
updateObject(java.lang.Object object)
Ocassionaly it is necessary to "change our mind" about what's on the top of the stack. |
void |
warning(org.xml.sax.SAXParseException ex)
Invokes fatalError(SAXParseException). |
| Methods inherited from class org.xml.sax.helpers.DefaultHandler |
|---|
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractParser()
| Method Detail |
|---|
public void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
peekContent().
characters in interface org.xml.sax.ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void error(org.xml.sax.SAXParseException ex)
throws org.xml.sax.SAXException
fatalError(SAXParseException).
error in interface org.xml.sax.ErrorHandlererror in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void fatalError(org.xml.sax.SAXParseException ex)
throws org.xml.sax.SAXException
fatalError in interface org.xml.sax.ErrorHandlerfatalError in class org.xml.sax.helpers.DefaultHandlerex - exception to be thrown
org.xml.sax.SAXParseException
org.xml.sax.SAXExceptionprotected java.lang.String getElementPath()
protected Location getLocation()
protected Resource getResource()
Resource being parsed (as set by initializeParser(Resource, int).
protected int getState()
initializeParser(Resource, int) and is later updated by
push(String, Object, int, boolean) and pop().
protected void initializeParser(Resource resource,
int startState)
resource - the resource being parsed (used for some error messages)startState - the initial state of the parser (the interpretation of state is determined by
subclasses)protected java.lang.String peekContent()
protected java.lang.String peekElementName()
protected java.lang.Object peekObject()
protected void pop()
endElement(String, String, String). This removes the corresponding item from the
stack, and sets the parser state back to the (new) top element's state.
protected void push(java.lang.String elementName,
java.lang.Object object,
int state)
push(String, Object, int, boolean), and ignores character data within the element.
elementName - the element whose start tag was just parsedobject - the object created to represent the new objectstate - the new state for the parse
protected void push(java.lang.String elementName,
java.lang.Object object,
int state,
boolean ignoreCharacterData)
LocationHolder then its location property is set to the
current location.
elementName - the element whose start tag was just parsedobject - the object created to represent the new objectstate - the new state for the parseignoreCharacterData - if true, then any character data (typically whitespace) directly enclosed by the
element is ignoredprotected void resetParser()
public void setDocumentLocator(org.xml.sax.Locator locator)
getLocation().
setDocumentLocator in interface org.xml.sax.ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandlerprotected void setState(int state)
protected void unexpectedElement(java.lang.String elementName)
ApplicationRuntimeException - describing the situationprotected void updateObject(java.lang.Object object)
object - the new object for the top stack element
public void warning(org.xml.sax.SAXParseException ex)
throws org.xml.sax.SAXException
fatalError(SAXParseException).
warning in interface org.xml.sax.ErrorHandlerwarning in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
protected abstract void begin(java.lang.String elementName,
java.util.Map attributes)
protected abstract void end(java.lang.String elementName)
peekContent().
public void endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
public void startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attributes)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||