The Configurator is an idea borrowed by the Ant project.
It is a SAX2 handler that reads a config file which is
represented by a hierarchy of Java beans. For example:
<outerBean foo="true" bar="Quite right">
<innerBean whatever="57">
</innerBean
</outerBean>
The example would create an object outerBean and call its
methods
setFoo(boolean)
and
setBar(String)
to process the attributes.
It would also create a bean innerBean by calling the
outerBeans method
createInnerBean()
.
Finally the innerBean is configured by calling
setWhatever(int)
.
characters
public void characters(char[] ch,
int start,
int length)
throws SAXException
Handles atomic child elements by invoking their method
addText(String pText)
. Note that it may happen,
that this method is invoked multiple times, if the parser
splits a piece of text into multiple SAX events.
endDocument
public void endDocument()
throws SAXException
endElement
public void endElement(String namespaceURI,
String qName,
String localName)
throws SAXException
Terminates parsing the current bean by calling its
finish()
method, if any.
endPrefixMapping
public void endPrefixMapping(String pPrefix)
throws SAXException
getBeanFactory
public Object getBeanFactory()
Returns the bean factory, creating the outermost element.
The bean factory must have a matching createElementName()
method, with ElementName being the element name
of the document element.
getDocumentLocator
public Locator getDocumentLocator()
Returns the Locator being used in error messages.
getMethodNameFor
protected String getMethodNameFor(String pPrefix,
String pName)
Given a prefix and a name, creates a method name matching
the prefix and the name.
getNamespaces
public String[] getNamespaces()
Returns the namespaces handled by the configurator. Defaults
to no namespace.
getResult
public Object getResult()
Returns the parsed result bean.
getRootObject
public Object getRootObject()
An alternative to using the bean factory. This object
is used as the root object, regardless of its name.
ignorableWhitespace
public void ignorableWhitespace(char[] ch,
int start,
int length)
throws SAXException
invokeMethod
protected Object invokeMethod(String pMethodName,
Object pBean,
Class[] pSignature,
Object[] pArgs)
throws SAXException
isNamespaceMatching
protected boolean isNamespaceMatching(String pNamespace)
Returns whether a namespace is matching the configured
namespace.
processName
public boolean processName(String pName,
String[] parts)
Splits the XML name
pName
into its
namespace URI, qualified name and local name, which
are stored into the array parts:
parts[0]
: namespace URI; empty if no namespace is usedparts[1]
: local name, with the prefix removedparts[2]
: qualified name (same as pName)
- processName in interface NamespaceResolver
- True, if the namespace prefix of
pName
was successfully resolved. False otherwise.
processingInstruction
public void processingInstruction(String target,
String data)
throws SAXException
setBeanFactory
public void setBeanFactory(Object pFactory)
Sets the bean factory, creating the outermost element.
The bean factory must have a matching createElementName()
method, with ElementName being the element name
of the document element.
setDocumentLocator
public void setDocumentLocator(Locator pLocator)
Sets the Locator being used in error messages.
setNamespace
public void setNamespace(String pNamespace)
Sets the namespace handled by the configurator. Defaults
to no namespace. Shortcut for
setNamespace(new String[]{pNamespace})
.
pNamespace
- The namespace being set
setNamespaces
public void setNamespaces(String[] pNamespaces)
Sets the namespaces handled by the configurator. Defaults
to no namespace.
pNamespaces
- The namespaces being set
setRootObject
public void setRootObject(Object pRootObject)
An alternative to using the bean factory. This object
is used as the root object, regardless of its name.
skippedEntity
public void skippedEntity(String name)
throws SAXException
startDocument
public void startDocument()
throws SAXException
startElement
public void startElement(String pNamespaceURI,
String pQName,
String pLocalName,
Attributes pAttr)
throws SAXException
Creates a new bean, matching the element name pLocalName
.
If this is the outermost bean, calls the bean factorys
createBeanName()
method, otherwise calls the current beans
createBeanName()
method, with beanName
being the value of the pLocalName
parameter.
startPrefixMapping
public void startPrefixMapping(String pPrefix,
String pURI)
throws SAXException