Class CFXMLConfigurations


  • public class CFXMLConfigurations
    extends Object
    Utility class for processing XML configuration files. This is for managing XML nodes at a low level.
    • Constructor Detail

      • CFXMLConfigurations

        public CFXMLConfigurations()
    • Method Detail

      • getNodeValue

        public static String getNodeValue​(Node node,
                                          String name)
        Convenience method for getting the value of a single node, i.e. the contents, so

        <foo>value</foo>

        would have name equal to 'foo' and return the string 'value'.
        Parameters:
        node -
        name -
        Returns:
      • getFirstNode

        public static Node getFirstNode​(Node node,
                                        String name)
        Return the first named child configuration node of the given node or null if there is no such named child. Very useful if your specification only allows for a single child node.
        Parameters:
        node -
        name -
        Returns:
      • getFirstAttribute

        public static String getFirstAttribute​(Node node,
                                               String name)
        Get the very first attribute with the given name from the Node. A null is returned if there is no such value.
        Parameters:
        node -
        name -
        Returns:
      • getFirstBooleanValue

        public static boolean getFirstBooleanValue​(Node node,
                                                   String attrib,
                                                   boolean defaultValue)
      • getFirstLongValue

        public static long getFirstLongValue​(Node node,
                                             String attrib,
                                             long defaultValue)
        Return the first long value of an attribute. Must have the default value specified. There is no promise as to what "first value" means thanks to the XML spec., so effectively you should restrict your XML to have at most one such value.
        Parameters:
        node -
        attrib -
        defaultValue -
        Returns:
      • getNodeValue

        public static String getNodeValue​(Node node,
                                          String name,
                                          String defaultValue)
        Return the default value if none is found.
        Parameters:
        node -
        name -
        defaultValue -
        Returns:
      • getConfig

        public static Node getConfig​(Document cfg,
                                     String tagName,
                                     String configName)
        Loads the named configuration that resides under the tagName, e.g. tagName might be 'my-server'. This supports aliases too, so if the top level tag contains an alias="x" attribute, then the configuration named "x" is loaded instead. This allows for things like a "default" or "current" configuration which need never change once deployed. The aim is to make this all as configuration driven as possible.
        Parameters:
        cfg -
        tagName -
        configName -
        Returns:
      • resolveAliases

        public static Node resolveAliases​(Document cfg,
                                          String topNodeName,
                                          String configName)
        Given an alias, resolve it to the correct node, checking for cycles.
        Parameters:
        cfg -
        topNodeName - The tag inside the outermost tag you want, e.g. "service", "client"
        configName - The name (i.e. value of name attributes)
        Returns:
      • getAlarms

        public static Collection<LocalTime> getAlarms​(Node node,
                                                      String tag)
        Get alarms that are in a given tag. returns null if no alarms are set
        Parameters:
        node -
        tag -
        Returns:
      • printNode

        public static String printNode​(Node node)