public class MasterContentHandler extends Object implements ContentHandler, AAFSpecifiedClasses
The master content handler is the root of all SAX content handlers used to deserialize XML documents and fragments into object instances of this AAF implementation. The SAX parser included with the core Java APIs provides an efficient, event-driven approach to parsing XML documents. This class and its subclasses provide content handlers that respond to the parser's generated events and create object instances. This content handler is designed so that every object that can be deserialized from a known XML element name can do so by first registering an appropriate handler.
To make use of the parsing capabilities of a master content handler, call
XMLBuilder.createFromXML(InputSource). This will create a master content handler,
parse the input source and return any resulting object.
registerHandler(Class). The handler must extend LocalHandler,
which is in turn a direct subclass of this class. To intiialize all the XML handlers required to
parse AAF XML files, call registerCoreHandlers().
One approach that can be taken to providing an element specific handler is to implement a static inner class within the object to be created from the given element. For example:
public class VersionNumber {
...
public final static class XMLHandler
extends tv.amwa.maj.io.xml.LocalHandler
implements org.xml.sax.ContentHandler.ContentHandler {
...
}
...
}
More information on how to do this is provided in the documentation for the LocalHandler
class.
abstractInterchangeable, abstractMeta, existingMeta, interchangeable, meta| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] ch,
int start,
int length) |
void |
endDocument()
Called at the end of the document represented by the input source of this master content
handler.
|
void |
endElement(String uri,
String localName,
String name)
Called if an end element event is sent by the SAX parser to a master content handler.
|
void |
endPrefixMapping(String prefix) |
Map<String,String> |
getAttributesForThis()
Returns the attributes of the element associated with this content handler.
|
String |
getAttributeValueThisElement(String attributeName)
Retrieve the value of an attribute of the element associated with this local handler.
|
String |
getElementName()
Returns the element name of the element associated with this content handler.
|
String |
getFullElementName() |
String |
getNamespace() |
void |
ignorableWhitespace(char[] ch,
int start,
int length) |
void |
processingInstruction(String target,
String data) |
void |
registerCoreHandlers()
Registers handlers for the core elements of AAF XML.
|
boolean |
registerHandler(Class<? extends LocalHandler> handler)
Registers an XML handling class for a given element name.
|
void |
registerHandlersForClass(Class<?> containsHandler) |
void |
setDocumentLocator(Locator locator) |
void |
skippedEntity(String name) |
void |
startDocument() |
void |
startElement(String uri,
String localName,
String name,
Attributes atts)
Called by the SAX parser when the root element of the input source of this master
content handler has been read.
|
void |
startPrefixMapping(String prefix,
String uri) |
public void characters(char[] ch,
int start,
int length)
throws SAXException
characters in interface ContentHandlerSAXExceptionContentHandler.characters(char[], int, int)public void endDocument()
throws SAXException
Called at the end of the document represented by the input source of this master content handler. The result of the master content handler parse is the result of its only subelement.
endDocument in interface ContentHandlerSAXExceptionContentHandler.endDocument()public void endElement(String uri, String localName, String name) throws SAXException
Called if an end element event is sent by the SAX parser to a master content handler. This should not happen and so an exception will be thrown.
endElement in interface ContentHandlerSAXExceptionContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)public final void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping in interface ContentHandlerSAXExceptionContentHandler.endPrefixMapping(java.lang.String)public final void ignorableWhitespace(char[] ch,
int start,
int length)
throws SAXException
ignorableWhitespace in interface ContentHandlerSAXExceptionContentHandler.ignorableWhitespace(char[], int, int)public final void processingInstruction(String target, String data) throws SAXException
processingInstruction in interface ContentHandlerSAXExceptionContentHandler.processingInstruction(java.lang.String, java.lang.String)public final void setDocumentLocator(Locator locator)
setDocumentLocator in interface ContentHandlerContentHandler.setDocumentLocator(org.xml.sax.Locator)public final void skippedEntity(String name) throws SAXException
skippedEntity in interface ContentHandlerSAXExceptionContentHandler.skippedEntity(java.lang.String)public final void startDocument()
throws SAXException
startDocument in interface ContentHandlerSAXExceptionContentHandler.startDocument()public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException
Called by the SAX parser when the root element of the input source of this master content handler has been read. A sub element content handler is created from the register of handlers and parsing of the document continues using this newly created handler.
startElement in interface ContentHandlerSAXExceptionContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)public final void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping in interface ContentHandlerSAXExceptionContentHandler.startPrefixMapping(java.lang.String, java.lang.String)public final boolean registerHandler(Class<? extends LocalHandler> handler) throws NullPointerException, IllegalArgumentException
Registers an XML handling class for a given element name. The handler must be class
that extends LocalHandler. If a handler is already registered for the given
element name, it is not replaced. This is to ensure that if registerCoreHandlers()
has been called, core handlers are not overridden. If the given handler is successfully
registered, true is returned, otherwise false.
handler - Content handler for the given element name.NullPointerException - The handler argument is null.IllegalArgumentException - The given handler does not contain an accessible
"elementName" static string value.public final void registerHandlersForClass(Class<?> containsHandler)
public final void registerCoreHandlers()
Registers handlers for the core elements of AAF XML. To extend the range of elements
parsed by this master content handler, call registerHandler(Class).
public final Map<String,String> getAttributesForThis()
Returns the attributes of the element associated with this content handler.
public final String getAttributeValueThisElement(String attributeName) throws NullPointerException
Retrieve the value of an attribute of the element associated with this local handler. The value of the attribute may not be available for one of two reasons:
attributeName - Name of an attribute of the element associated with this local handler.null is the value
of the attribute is not available.NullPointerException - The attribute name argument is null.public final String getElementName()
Returns the element name of the element associated with this content handler. This will
be the same as the "elementName" static value of the content handler.
public final String getNamespace()
public final String getFullElementName()
(c)2007-2016 Richard Cartwright, all rights reserved. Licensed under Apache 2 license and subject to the AMWA IPR policy.