org.apache.ws.jaxme.util

Class Configurator

public class Configurator extends Object implements ContentHandler, NamespaceResolver

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).

Version: $Id: Configurator.java 232067 2005-03-10 10:14:08Z jochen $

Author: Jochen Wiedmann

Method Summary
voidcharacters(char[] ch, int start, int length)

Handles atomic child elements by invoking their method addText(String pText).

voidendDocument()
voidendElement(String namespaceURI, String qName, String localName)

Terminates parsing the current bean by calling its finish() method, if any.

voidendPrefixMapping(String pPrefix)
ObjectgetBeanFactory()

Returns the bean factory, creating the outermost element.

LocatorgetDocumentLocator()

Returns the Locator being used in error messages.

protected StringgetMethodNameFor(String pPrefix, String pName)

Given a prefix and a name, creates a method name matching the prefix and the name.

String[]getNamespaces()

Returns the namespaces handled by the configurator.

ObjectgetResult()
Returns the parsed result bean.
ObjectgetRootObject()

An alternative to using the bean factory.

voidignorableWhitespace(char[] ch, int start, int length)
protected ObjectinvokeMethod(String pMethodName, Object pBean, Class[] pSignature, Object[] pArgs)
protected booleanisNamespaceMatching(String pNamespace)

Returns whether a namespace is matching the configured namespace.

voidprocessingInstruction(String target, String data)
booleanprocessName(String pName, String[] parts)
voidsetBeanFactory(Object pFactory)

Sets the bean factory, creating the outermost element.

voidsetDocumentLocator(Locator pLocator)

Sets the Locator being used in error messages.

voidsetNamespace(String pNamespace)

Sets the namespace handled by the configurator.

voidsetNamespaces(String[] pNamespaces)

Sets the namespaces handled by the configurator.

voidsetRootObject(Object pRootObject)

An alternative to using the bean factory.

voidskippedEntity(String name)
voidstartDocument()
voidstartElement(String pNamespaceURI, String pQName, String pLocalName, Attributes pAttr)

Creates a new bean, matching the element name pLocalName.

voidstartPrefixMapping(String pPrefix, String pURI)

Method Detail

characters

public void characters(char[] ch, int start, int length)

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()

endElement

public void endElement(String namespaceURI, String qName, String localName)

Terminates parsing the current bean by calling its finish() method, if any.

endPrefixMapping

public void endPrefixMapping(String pPrefix)

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)

invokeMethod

protected Object invokeMethod(String pMethodName, Object pBean, Class[] pSignature, Object[] pArgs)

isNamespaceMatching

protected boolean isNamespaceMatching(String pNamespace)

Returns whether a namespace is matching the configured namespace.

processingInstruction

public void processingInstruction(String target, String data)

processName

public boolean processName(String pName, String[] parts)

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}).

Parameters: pNamespace The namespace being set

setNamespaces

public void setNamespaces(String[] pNamespaces)

Sets the namespaces handled by the configurator. Defaults to no namespace.

Parameters: 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)

startDocument

public void startDocument()

startElement

public void startElement(String pNamespaceURI, String pQName, String pLocalName, Attributes pAttr)

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)