Class StateToolkit

    • Constructor Detail

      • StateToolkit

        public StateToolkit()
    • Method Detail

      • fromXMLString

        public static IState fromXMLString​(String document)
                                    throws SAXException
        Read an XML document from a string and return its structure as a state.
        Parameters:
        document - string to read XML from
        Returns:
        state reflecting the XML document
        Throws:
        SAXException
      • statefulFromXMLString

        public static IStateful statefulFromXMLString​(String document)
        Read an XML document from a string and return its structure as a stateful object.
        Parameters:
        document - string to read XML from
        Returns:
        stateful object reflecting the XML document
      • statefulFromXMLFile

        public static IStateful statefulFromXMLFile​(File document,
                                                    Charset charset)
        Read an XML document from a file and return its structure as a stateful object.
        Parameters:
        document - file to read XML from
        Returns:
        stateful object reflecting the XML document
      • createWriter

        public static IWritableState createWriter​(String rootName)
                                           throws IOException
        Create a new writable state.
        Parameters:
        rootName - root name of the writable state
        Returns:
        a new writable state
        Throws:
        IOException
      • toXMLString

        public static String toXMLString​(IStateful state)
        Write a stateful state as an XML string.
        Parameters:
        state - state to write as XML
        Returns:
        an XML string reflecting the state
      • writeAsXml

        public static void writeAsXml​(IStateful state,
                                      Writer writer)
                               throws IOException
        Write a stateful state to a reader as an XML string.
        Parameters:
        state - state to write as XML
        writer - write to write the XML to
        Throws:
        IOException
      • readBoolean

        public static Boolean readBoolean​(IState state,
                                          String attribute,
                                          Boolean defaultValue)
        Read a boolean value from a state.
        Parameters:
        state - state to read from
        attribute - attribute name
        defaultValue - default attribute value
        Returns:
        attribute value if it is set in the state, defaultValue if not
        See Also:
        writeBoolean(IWritableState, String, Boolean)
      • readFloat

        public static Float readFloat​(IState state,
                                      String attribute,
                                      Float defaultValue)
        Read a float value from a state.
        Parameters:
        state - state to read from
        attribute - attribute name
        defaultValue - default attribute value
        Returns:
        attribute value if it is set in the state, defaultValue if not
        See Also:
        writeFloat(IWritableState, String, Float)
      • readInt

        public static Integer readInt​(IState state,
                                      String attribute,
                                      Integer defaultValue)
        Read an integer value from a state.
        Parameters:
        state - state to read from
        attribute - attribute name
        defaultValue - default attribute value
        Returns:
        attribute value if it is set in the state, defaultValue if not
        See Also:
        writeInt(IWritableState, String, Integer)
      • readEnum

        public static <T extends Enum<T>> T readEnum​(IState state,
                                                     String attribute,
                                                     T defaultValue,
                                                     Class<T> klass)
        Read an enum value from a state.
        Parameters:
        state - state to read from
        attribute - attribute name
        defaultValue - default attribute value
        klass - enum class of the attribute value
        Returns:
        attribute value if it is set in the state, defaultValue if not
        See Also:
        writeEnum(IWritableState, String, Enum)