Top Description Inners Fields Constructors Methods
net.sf.ehcache.config

pack-priv final Class BeanHandler

extends DefaultHandler
Class Inheritance
Imports
java.lang.reflect.Constructor, .InvocationTargetException, .Method, .Modifier, java.util.ArrayList, .HashSet, .Set, org.slf4j.Logger, .LoggerFactory, org.xml.sax.Attributes, .Locator, .SAXException, org.xml.sax.helpers.DefaultHandler

A SAX handler that configures a bean.
Authors
Adam Murdoch, Greg Luck
Version
$Id: BeanHandler.java 5594 2012-05-07 16:04:31Z cdennis $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BeanHandler.ElementInfo

Element info class

Field Summary

Modifier and TypeField and Description
private final Object
private BeanHandler.ElementInfo
private Locator
private static final Logger
private String
private Method
private StringBuilder

Constructor Summary

AccessConstructor and Description
public
BeanHandler(final Object bean)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private void
addChild(final Object parent, final Object child, final String name)

Attaches a child element to its parent.

private void
appendToSubtree(String text)

Append to the current extracted subtree text

private void
appendToSubtree(char[] text, int start, int length)

Append to the current extracted subtree text

public void
characters(char[]
The characters.
ch
,
int
The start position in the character array.
start
,
int
The number of characters to use from the character array.
length
)

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data within an element - only used currently when extracting an xml subtree
private Method
chooseSetMethod(final Class<T> objClass, final String prefix, final String name, final Class<T> preferredParameterType)

private static Object
convert(String
Name of attribute
attributeName
,
final Class<T> toClass, final String value)

Converts a string to an object of a particular class.

private Object
createChild(final BeanHandler.ElementInfo parent, final String name)

Creates a child element of an object.

private static Object
createInstance(Object parent, Class<T> childClass)

Creates a child object.

public final void
endElement(final String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
uri
,
final String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
final String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
)

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
private boolean
endsSubtree(String endName)

Determine whether the current endName tag ends the subtree matching

private void
private boolean
private static Method
findCreateMethod(Class<T> objClass, String name)

Finds a creator method.

private Method
findSetMethod(final Class<T> objClass, final String prefix, final String name)

Finds a setter method.

private String
getLocation()

Formats the current document location.

private String
private static String
makeMethodName(final String prefix, final String name)

Builds a method name from an element or attribute name.

private void
setAttribute(final BeanHandler.ElementInfo element, final String attrName, final String attrValue)

Sets an attribute.

public final void
setDocumentLocator(Locator
A locator for all SAX document events.
locator
)

Overrides org.xml.sax.helpers.DefaultHandler.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive a Locator object for document events.
public final void
startElement(final String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
uri
,
final String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
final String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
,
final Attributes
The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
attributes
)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the start of an element.
private boolean
startExtractingSubtree(String name)

Determine whether we should start extracting a subtree, based on whether there is an extract method for this tag in the parent bean.

Inherited from org.xml.sax.helpers.DefaultHandler:
endDocumentendPrefixMappingerrorfatalErrorignorableWhitespacenotationDeclprocessingInstructionresolveEntityskippedEntitystartDocumentstartPrefixMappingunparsedEntityDeclwarning

Field Detail

beanback to summary
private final Object bean
elementback to summary
private BeanHandler.ElementInfo element
locatorback to summary
private Locator locator
LOGback to summary
private static final Logger LOG
subtreeMatchingQnameback to summary
private String subtreeMatchingQname
subtreeMethodback to summary
private Method subtreeMethod
subtreeTextback to summary
private StringBuilder subtreeText

Constructor Detail

BeanHandlerback to summary
public BeanHandler(final Object bean)

Constructor.

Method Detail

addChildback to summary
private void addChild(final Object parent, final Object child, final String name) throws SAXException

Attaches a child element to its parent.

appendToSubtreeback to summary
private void appendToSubtree(String text)

Append to the current extracted subtree text

appendToSubtreeback to summary
private void appendToSubtree(char[] text, int start, int length)

Append to the current extracted subtree text

charactersback to summary
public void characters(char[] ch, int start, int length) throws SAXException

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data within an element - only used currently when extracting an xml subtree

Parameters
ch:char[]

Doc from org.xml.sax.helpers.DefaultHandler.characters.

The characters.

start:int

Doc from org.xml.sax.helpers.DefaultHandler.characters.

The start position in the character array.

length:int

Doc from org.xml.sax.helpers.DefaultHandler.characters.

The number of characters to use from the character array.

Annotations
@Override
Exceptions
SAXException:

Doc from org.xml.sax.helpers.DefaultHandler.characters.

Any SAX exception, possibly wrapping another exception.

chooseSetMethodback to summary
private Method chooseSetMethod(final Class<T> objClass, final String prefix, final String name, final Class<T> preferredParameterType) throws Exception
convertback to summary
private static Object convert(String attributeName, final Class<T> toClass, final String value) throws Exception

Converts a string to an object of a particular class.

Parameters
attributeName:String

Name of attribute

createChildback to summary
private Object createChild(final BeanHandler.ElementInfo parent, final String name) throws SAXException

Creates a child element of an object.

createInstanceback to summary
private static Object createInstance(Object parent, Class<T> childClass) throws Exception

Creates a child object.

endElementback to summary
public final void endElement(final String uri, final String localName, final String qName) throws SAXException

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.

Parameters
uri:String

Doc from org.xml.sax.helpers.DefaultHandler.endElement.

The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.

localName:String

Doc from org.xml.sax.helpers.DefaultHandler.endElement.

The local name (without prefix), or the empty string if Namespace processing is not being performed.

qName:String

Doc from org.xml.sax.helpers.DefaultHandler.endElement.

The qualified name (with prefix), or the empty string if qualified names are not available.

Annotations
@Override
Exceptions
SAXException:

Doc from org.xml.sax.helpers.DefaultHandler.endElement.

Any SAX exception, possibly wrapping another exception.

endsSubtreeback to summary
private boolean endsSubtree(String endName)

Determine whether the current endName tag ends the subtree matching

endSubtreeback to summary
private void endSubtree() throws SAXException
extractingSubtreeback to summary
private boolean extractingSubtree()
findCreateMethodback to summary
private static Method findCreateMethod(Class<T> objClass, String name)

Finds a creator method.

findSetMethodback to summary
private Method findSetMethod(final Class<T> objClass, final String prefix, final String name) throws Exception

Finds a setter method.

getLocationback to summary
private String getLocation()

Formats the current document location.

getTagPartback to summary
private String getTagPart(String qName)
makeMethodNameback to summary
private static String makeMethodName(final String prefix, final String name)

Builds a method name from an element or attribute name.

setAttributeback to summary
private void setAttribute(final BeanHandler.ElementInfo element, final String attrName, final String attrValue) throws SAXException

Sets an attribute.

setDocumentLocatorback to summary
public final void setDocumentLocator(Locator locator)

Overrides org.xml.sax.helpers.DefaultHandler.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive a Locator object for document events.

Parameters
locator:Locator

Doc from org.xml.sax.helpers.DefaultHandler.setDocumentLocator.

A locator for all SAX document events.

Annotations
@Override
startElementback to summary
public final void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the start of an element.

Parameters
uri:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.

localName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The local name (without prefix), or the empty string if Namespace processing is not being performed.

qName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The qualified name (with prefix), or the empty string if qualified names are not available.

attributes:Attributes

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.

Annotations
@Override
Exceptions
SAXException:

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

Any SAX exception, possibly wrapping another exception.

startExtractingSubtreeback to summary
private boolean startExtractingSubtree(String name) throws SAXException

Determine whether we should start extracting a subtree, based on whether there is an extract method for this tag in the parent bean.

net.sf.ehcache.config back to summary

private final Class BeanHandler.ElementInfo

extends Object
Class Inheritance

Element info class

Field Summary

Modifier and TypeField and Description
private final Object
private final String
private final BeanHandler.ElementInfo

Constructor Summary

AccessConstructor and Description
public
ElementInfo(final String elementName, final Object bean)

public
ElementInfo(final BeanHandler.ElementInfo parent, final String elementName, final Object bean)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanback to summary
private final Object bean
elementNameback to summary
private final String elementName
parentback to summary
private final BeanHandler.ElementInfo parent

Constructor Detail

ElementInfoback to summary
public ElementInfo(final String elementName, final Object bean)
ElementInfoback to summary
public ElementInfo(final BeanHandler.ElementInfo parent, final String elementName, final Object bean)