Class XmlConfiguration.JettyXmlConfiguration

    • Constructor Detail

      • JettyXmlConfiguration

        private JettyXmlConfiguration()
    • Method Detail

      • 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 interface ConfigurationProcessor
        Parameters:
        resource - the resource being read
        root - the parsed XML root node for the resource
        configuration - 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 interface ConfigurationProcessor
        Throws:
        java.lang.Exception
      • configure

        public java.lang.Object configure()
                                   throws java.lang.Exception
        Specified by:
        configure in interface ConfigurationProcessor
        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 configure
        cfg - the XML nodes of the configuration
        i - 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:

        1. Trying for a trivial type match
        2. Looking for a native type match
        3. Trying all correctly named methods for an auto conversion
        4. Attempting to construct a suitable value from original value
        Parameters:
        obj - the enclosing object
        node - 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 convert
        collectionType - 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 object
        node - 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 object
        node - 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 object
        node - 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 object
        node - 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 object
        node - 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 object
        node - 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 declared default="value" attributes.
        Parameters:
        obj - the enclosing obj
        node - 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 object
        node - 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 object
        item - the initial element value
        Returns:
        the recursive value of the element
        Throws:
        java.lang.Exception