Class XmlConfiguration.JettyXmlConfiguration
- java.lang.Object
-
- org.eclipse.jetty.xml.XmlConfiguration.JettyXmlConfiguration
-
- All Implemented Interfaces:
ConfigurationProcessor
- Enclosing class:
- XmlConfiguration
private static class XmlConfiguration.JettyXmlConfiguration extends java.lang.Object implements ConfigurationProcessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
XmlConfiguration.JettyXmlConfiguration.Args
private class
XmlConfiguration.JettyXmlConfiguration.AttrOrElementNode
-
Field Summary
Fields Modifier and Type Field Description (package private) XmlConfiguration
_configuration
(package private) XmlParser.Node
_root
-
Constructor Summary
Constructors Modifier Constructor Description private
JettyXmlConfiguration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendDefaultPropertyValues(java.lang.StringBuilder defValues, XmlParser.Node node)
private java.lang.Object
call(java.lang.Class<?> oClass, java.lang.String methodName, java.lang.Object obj, XmlConfiguration.JettyXmlConfiguration.Args args)
private java.lang.Object
call(java.lang.Object obj, XmlParser.Node node)
Calls a method.java.lang.Object
configure()
java.lang.Object
configure(java.lang.Object obj)
void
configure(java.lang.Object obj, XmlParser.Node cfg, int i)
Recursive configuration routine.private java.lang.Object
construct(java.lang.Class<?> klass, XmlConfiguration.JettyXmlConfiguration.Args args)
private static java.util.ArrayList<java.lang.Object>
convertArrayToArrayList(java.lang.Object array)
private static java.util.Collection<?>
convertArrayToCollection(java.lang.Object array, java.lang.Class<?> collectionType)
private java.lang.String
defaultValue(java.lang.Object obj, XmlParser.Node node)
Check children for all<Property>
and<SystemProperty>
and return the String representation of any declareddefault="value"
attributes.private java.lang.Object
envObj(XmlParser.Node node)
Returns the value of an environment property.private java.lang.Object
get(java.lang.Object obj, XmlParser.Node node)
Calls a getter method.private java.lang.Object
getField(java.lang.reflect.Field field, java.lang.Object object)
void
init(java.net.URL url, XmlParser.Node root, XmlConfiguration configuration)
void
init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
Initialize a ConfigurationProcessor from provided Resource and XMLprivate java.lang.Object
invokeConstructor(java.lang.reflect.Constructor<?> constructor, java.lang.Object... args)
private java.lang.Object
invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args)
private java.lang.Object
invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args, boolean isUsingDefaultValue)
private static boolean
isTypeMatchingClass(java.lang.String type, java.lang.Class<?> classToMatch)
private java.lang.Object
itemValue(java.lang.Object obj, java.lang.Object item)
Returns recursively the value of an element.private java.lang.Object
newArray(java.lang.Object obj, XmlParser.Node node)
Creates a new array object.private java.lang.Object
newMap(java.lang.Object obj, XmlParser.Node node)
Creates a new map object.private java.lang.Object
newObj(java.lang.Object obj, XmlParser.Node node)
Creates a new value object.private static java.lang.Class<?>
nodeClass(XmlParser.Node node)
private java.lang.Object
propertyObj(XmlParser.Node node)
Returns the value of a property.private void
put(java.lang.Object obj, XmlParser.Node node)
Calls a put method.private java.lang.Object
refObj(XmlParser.Node node)
Returns a reference object mapped to an id.private void
set(java.lang.Object obj, XmlParser.Node node)
Call a setter method.private void
setField(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object arg, boolean isUsingDefaultValue)
private java.lang.Object
systemPropertyObj(XmlParser.Node node)
Returns the value of a system property.private java.lang.Object
value(java.lang.Object obj, XmlParser.Node node)
Returns the scalar value of an element
-
-
-
Field Detail
-
_root
XmlParser.Node _root
-
_configuration
XmlConfiguration _configuration
-
-
Method Detail
-
init
public void init(java.net.URL url, XmlParser.Node root, XmlConfiguration configuration)
- Specified by:
init
in interfaceConfigurationProcessor
-
init
public void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration)
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
public java.lang.Object configure(java.lang.Object obj) throws java.lang.Exception
- Specified by:
configure
in interfaceConfigurationProcessor
- Throws:
java.lang.Exception
-
configure
public java.lang.Object configure() throws java.lang.Exception
- Specified by:
configure
in interfaceConfigurationProcessor
- Throws:
java.lang.Exception
-
nodeClass
private static java.lang.Class<?> nodeClass(XmlParser.Node node) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
configure
public void configure(java.lang.Object obj, XmlParser.Node cfg, int i) throws java.lang.Exception
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:
java.lang.Exception
- if the configuration fails
-
set
private void set(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
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:
java.lang.Exception
-
invokeConstructor
private java.lang.Object invokeConstructor(java.lang.reflect.Constructor<?> constructor, java.lang.Object... args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
-
invokeMethod
private java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
invokeMethod
private java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object obj, java.lang.Object[] args, boolean isUsingDefaultValue) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
-
getField
private java.lang.Object getField(java.lang.reflect.Field field, java.lang.Object object) throws java.lang.IllegalAccessException
- Throws:
java.lang.IllegalAccessException
-
setField
private void setField(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object arg, boolean isUsingDefaultValue) throws java.lang.IllegalAccessException
- Throws:
java.lang.IllegalAccessException
-
convertArrayToCollection
private static java.util.Collection<?> convertArrayToCollection(java.lang.Object array, java.lang.Class<?> collectionType)
- Parameters:
array
- the array to convertcollectionType
- the desired collection type- Returns:
- a collection of the desired type if the array can be converted
-
convertArrayToArrayList
private static java.util.ArrayList<java.lang.Object> convertArrayToArrayList(java.lang.Object array)
-
put
private void put(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
Calls a put method.
- Parameters:
obj
- the enclosing map objectnode
- the <Put> XML node- Throws:
java.lang.Exception
-
get
private java.lang.Object get(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
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:
java.lang.Exception
-
call
private java.lang.Object call(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
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:
java.lang.Exception
-
call
private java.lang.Object call(java.lang.Class<?> oClass, java.lang.String methodName, java.lang.Object obj, XmlConfiguration.JettyXmlConfiguration.Args args) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
- Throws:
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
-
newObj
private java.lang.Object newObj(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
Creates a new value object.
- Parameters:
obj
- the enclosing objectnode
- the <New> XML node- Returns:
- the result of the constructor invocation
- Throws:
java.lang.Exception
-
construct
private java.lang.Object construct(java.lang.Class<?> klass, XmlConfiguration.JettyXmlConfiguration.Args args) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
- Throws:
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
-
refObj
private java.lang.Object refObj(XmlParser.Node node) throws java.lang.Exception
Returns a reference object mapped to an id.
- Parameters:
node
- the <Ref> XML node- Returns:
- the result of the reference invocation
- Throws:
java.lang.Exception
-
newArray
private java.lang.Object newArray(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
Creates a new array object.
- Parameters:
obj
- the enclosing objectnode
- the <Array> XML node- Returns:
- the newly created array
- Throws:
java.lang.Exception
-
newMap
private java.lang.Object newMap(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
Creates a new map object.
- Parameters:
obj
- the enclosing objectnode
- the <Map> XML node- Returns:
- the newly created map
- Throws:
java.lang.Exception
-
propertyObj
private java.lang.Object propertyObj(XmlParser.Node node) throws java.lang.Exception
Returns the value of a property.
- Parameters:
node
- the <Property> XML node- Returns:
- the property value
- Throws:
java.lang.Exception
-
systemPropertyObj
private java.lang.Object systemPropertyObj(XmlParser.Node node) throws java.lang.Exception
Returns the value of a system property.
- Parameters:
node
- the <SystemProperty> XML node- Returns:
- the property value
- Throws:
java.lang.Exception
-
envObj
private java.lang.Object envObj(XmlParser.Node node) throws java.lang.Exception
Returns the value of an environment property.
- Parameters:
node
- the <Env> XML node- Returns:
- the environment property value
- Throws:
java.lang.Exception
-
defaultValue
private java.lang.String defaultValue(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
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:
java.lang.Exception
-
appendDefaultPropertyValues
private void appendDefaultPropertyValues(java.lang.StringBuilder defValues, XmlParser.Node node) throws java.lang.Exception
- Throws:
java.lang.Exception
-
value
private java.lang.Object value(java.lang.Object obj, XmlParser.Node node) throws java.lang.Exception
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:
java.lang.Exception
-
isTypeMatchingClass
private static boolean isTypeMatchingClass(java.lang.String type, java.lang.Class<?> classToMatch)
-
itemValue
private java.lang.Object itemValue(java.lang.Object obj, java.lang.Object item) throws java.lang.Exception
Returns recursively the value of an element.
- Parameters:
obj
- the enclosing objectitem
- the initial element value- Returns:
- the recursive value of the element
- Throws:
java.lang.Exception
-
-