Class XmlConfiguration.JettyXmlConfiguration
- All Implemented Interfaces:
ConfigurationProcessor
- Enclosing class:
- XmlConfiguration
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) XmlConfiguration
(package private) XmlParser.Node
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
appendDefaultPropertyValues
(StringBuilder defValues, XmlParser.Node node) private Object
call
(Class<?> oClass, String methodName, Object obj, XmlConfiguration.JettyXmlConfiguration.Args args) private Object
call
(Object obj, XmlParser.Node node) Calls a method.void
configure
(Object obj, XmlParser.Node cfg, int i) Recursive configuration routine.private Object
construct
(Class<?> klass, XmlConfiguration.JettyXmlConfiguration.Args args) convertArrayToArrayList
(Object array) private static Collection<?>
convertArrayToCollection
(Object array, Class<?> collectionType) private String
defaultValue
(Object obj, XmlParser.Node node) Check children for all<Property>
and<SystemProperty>
and return the String representation of any declareddefault="value"
attributes.private Object
envObj
(XmlParser.Node node) Returns the value of an environment property.private Object
get
(Object obj, XmlParser.Node node) Calls a getter method.private Object
void
init
(URL url, XmlParser.Node root, XmlConfiguration configuration) void
init
(Resource resource, XmlParser.Node root, XmlConfiguration configuration) Initialize a ConfigurationProcessor from provided Resource and XMLprivate Object
invokeConstructor
(Constructor<?> constructor, Object... args) private Object
invokeMethod
(Method method, Object obj, Object[] args) private Object
invokeMethod
(Method method, Object obj, Object[] args, boolean isUsingDefaultValue) private static boolean
isTypeMatchingClass
(String type, Class<?> classToMatch) private Object
Returns recursively the value of an element.private Object
newArray
(Object obj, XmlParser.Node node) Creates a new array object.private Object
newMap
(Object obj, XmlParser.Node node) Creates a new map object.private Object
newObj
(Object obj, XmlParser.Node node) Creates a new value object.private static Class<?>
nodeClass
(XmlParser.Node node) private Object
propertyObj
(XmlParser.Node node) Returns the value of a property.private void
put
(Object obj, XmlParser.Node node) Calls a put method.private Object
refObj
(XmlParser.Node node) Returns a reference object mapped to an id.private void
set
(Object obj, XmlParser.Node node) Call a setter method.private void
private Object
Returns the value of a system property.private Object
value
(Object obj, XmlParser.Node node) Returns the scalar value of an element
-
Field Details
-
_root
XmlParser.Node _root -
_configuration
XmlConfiguration _configuration
-
-
Constructor Details
-
JettyXmlConfiguration
private JettyXmlConfiguration()
-
-
Method Details
-
init
- Specified by:
init
in interfaceConfigurationProcessor
-
init
Description copied from interface:ConfigurationProcessor
Initialize a ConfigurationProcessor from provided Resource and XML- Specified by:
init
in interfaceConfigurationProcessor
- Parameters:
resource
- the resource being readroot
- the parsed XML root node for the resourceconfiguration
- the configuration being used (typically for ref IDs)
-
configure
- Specified by:
configure
in interfaceConfigurationProcessor
- Throws:
Exception
-
configure
- Specified by:
configure
in interfaceConfigurationProcessor
- Throws:
Exception
-
nodeClass
- Throws:
ClassNotFoundException
-
configure
Recursive configuration routine. This method applies the nested Set, Put, Call, etc. elements to the given object.- Parameters:
obj
- the object to configurecfg
- the XML nodes of the configurationi
- the index of the XML nodes- Throws:
Exception
- if the configuration fails
-
set
Call a setter method.
This method makes a best effort to find a matching set method. The type of the value is used to find a suitable set method by:
- Trying for a trivial type match
- Looking for a native type match
- Trying all correctly named methods for an auto conversion
- Attempting to construct a suitable value from original value
- Parameters:
obj
- the enclosing objectnode
- the <Set> XML node- Throws:
Exception
-
invokeConstructor
private Object invokeConstructor(Constructor<?> constructor, Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException -
invokeMethod
private Object invokeMethod(Method method, Object obj, Object[] args) throws IllegalAccessException, InvocationTargetException -
invokeMethod
private Object invokeMethod(Method method, Object obj, Object[] args, boolean isUsingDefaultValue) throws IllegalAccessException, InvocationTargetException -
getField
- Throws:
IllegalAccessException
-
setField
private void setField(Field field, Object obj, Object arg, boolean isUsingDefaultValue) throws IllegalAccessException - Throws:
IllegalAccessException
-
convertArrayToCollection
- Parameters:
array
- the array to convertcollectionType
- the desired collection type- Returns:
- a collection of the desired type if the array can be converted
-
convertArrayToArrayList
-
put
Calls a put method.
- Parameters:
obj
- the enclosing map objectnode
- the <Put> XML node- Throws:
Exception
-
get
Calls a getter method.
Any object returned from the call is passed to the configure method to consume the remaining elements.
If the "class" attribute is present and its value is "class", then the class instance itself is returned.
- Parameters:
obj
- the enclosing objectnode
- the <Get> XML node- Returns:
- the result of the getter invocation
- Throws:
Exception
-
call
Calls a method.
A method is selected by trying all methods with matching names and number of arguments. Any object returned from the call is passed to the configure method to consume the remaining elements. Note that if this is a static call we consider only methods declared directly in the given class, i.e. we ignore any static methods in superclasses.
- Parameters:
obj
- the enclosing objectnode
- the <Call> XML node- Returns:
- the result of the method invocation
- Throws:
Exception
-
call
private Object call(Class<?> oClass, String methodName, Object obj, XmlConfiguration.JettyXmlConfiguration.Args args) throws InvocationTargetException, NoSuchMethodException -
newObj
Creates a new value object.
- Parameters:
obj
- the enclosing objectnode
- the <New> XML node- Returns:
- the result of the constructor invocation
- Throws:
Exception
-
construct
private Object construct(Class<?> klass, XmlConfiguration.JettyXmlConfiguration.Args args) throws InvocationTargetException, NoSuchMethodException -
refObj
Returns a reference object mapped to an id.
- Parameters:
node
- the <Ref> XML node- Returns:
- the result of the reference invocation
- Throws:
Exception
-
newArray
Creates a new array object.
- Parameters:
obj
- the enclosing objectnode
- the <Array> XML node- Returns:
- the newly created array
- Throws:
Exception
-
newMap
Creates a new map object.
- Parameters:
obj
- the enclosing objectnode
- the <Map> XML node- Returns:
- the newly created map
- Throws:
Exception
-
propertyObj
Returns the value of a property.
- Parameters:
node
- the <Property> XML node- Returns:
- the property value
- Throws:
Exception
-
systemPropertyObj
Returns the value of a system property.
- Parameters:
node
- the <SystemProperty> XML node- Returns:
- the property value
- Throws:
Exception
-
envObj
Returns the value of an environment property.
- Parameters:
node
- the <Env> XML node- Returns:
- the environment property value
- Throws:
Exception
-
defaultValue
Check children for all<Property>
and<SystemProperty>
and return the String representation of any declareddefault="value"
attributes.- Parameters:
obj
- the enclosing objnode
- the XML node- Returns:
- a String representing all
<Property default="...">
and<SystemProperty default="...">
values appended together - Throws:
Exception
-
appendDefaultPropertyValues
private void appendDefaultPropertyValues(StringBuilder defValues, XmlParser.Node node) throws Exception - Throws:
Exception
-
value
Returns the scalar value of an element
.If no value type is specified, then white space is trimmed out of the value. If it contains multiple value elements they are added as strings before being converted to any specified type.
- Parameters:
obj
- the enclosing objectnode
- the XML node- Returns:
- the value of the XML node
- Throws:
Exception
-
isTypeMatchingClass
-
itemValue
Returns recursively the value of an element.
- Parameters:
obj
- the enclosing objectitem
- the initial element value- Returns:
- the recursive value of the element
- Throws:
Exception
-