Package org.openjdk.jmc.common.util
Class StateToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.StateToolkit
-
public class StateToolkit extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
StateToolkit.StateHandler
An SAX event handler that saves elements to awritable state
.
-
Constructor Summary
Constructors Constructor Description StateToolkit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IWritableState
createWriter(java.lang.String rootName)
Create a new writable state.static IState
fromXMLFile(java.io.File document)
Read an XML document from a file and return its structure as astate
.static IState
fromXMLString(java.lang.String document)
Read an XML document from a string and return its structure as astate
.static java.lang.Boolean
readBoolean(IState state, java.lang.String attribute, java.lang.Boolean defaultValue)
Read a boolean value from a state.static <T extends java.lang.Enum<T>>
TreadEnum(IState state, java.lang.String attribute, T defaultValue, java.lang.Class<T> klass)
Read an enum value from a state.static java.lang.Float
readFloat(IState state, java.lang.String attribute, java.lang.Float defaultValue)
Read a float value from a state.static java.lang.Integer
readInt(IState state, java.lang.String attribute, java.lang.Integer defaultValue)
Read an integer value from a state.static void
saveXMLDocumentTo(java.io.Reader reader, IWritableState state)
Read an XML document from a reader and write its structure to awritable state
.static IStateful
statefulFromXMLFile(java.io.File document, java.nio.charset.Charset charset)
Read an XML document from a file and return its structure as astateful object
.static IStateful
statefulFromXMLString(java.lang.String document)
Read an XML document from a string and return its structure as astateful object
.static java.lang.String
toXMLString(IStateful state)
Write a stateful state as an XML string.static void
writeAsXml(IStateful state, java.io.Writer writer)
Write a stateful state to a reader as an XML string.static void
writeBoolean(IWritableState state, java.lang.String attribute, java.lang.Boolean value)
Write a boolean value to a state.static <T extends java.lang.Enum<T>>
voidwriteEnum(IWritableState state, java.lang.String attribute, T value)
Write an enum value to a state.static void
writeFloat(IWritableState state, java.lang.String attribute, java.lang.Float value)
Write a float value to a state.static void
writeInt(IWritableState state, java.lang.String attribute, java.lang.Integer value)
Write an integer value to a state.
-
-
-
Method Detail
-
saveXMLDocumentTo
public static void saveXMLDocumentTo(java.io.Reader reader, IWritableState state) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
Read an XML document from a reader and write its structure to awritable state
.- Parameters:
reader
- reader to read XML fromstate
- writable state to write data to- Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
-
fromXMLString
public static IState fromXMLString(java.lang.String document) throws org.xml.sax.SAXException
Read an XML document from a string and return its structure as astate
.- Parameters:
document
- string to read XML from- Returns:
- state reflecting the XML document
- Throws:
org.xml.sax.SAXException
-
statefulFromXMLString
public static IStateful statefulFromXMLString(java.lang.String document)
Read an XML document from a string and return its structure as astateful object
.- Parameters:
document
- string to read XML from- Returns:
- stateful object reflecting the XML document
-
statefulFromXMLFile
public static IStateful statefulFromXMLFile(java.io.File document, java.nio.charset.Charset charset)
Read an XML document from a file and return its structure as astateful object
.- Parameters:
document
- file to read XML from- Returns:
- stateful object reflecting the XML document
-
fromXMLFile
public static IState fromXMLFile(java.io.File document) throws org.xml.sax.SAXException, java.io.IOException
Read an XML document from a file and return its structure as astate
.- Parameters:
document
- file to read XML from- Returns:
- state reflecting the XML document
- Throws:
org.xml.sax.SAXException
java.io.IOException
-
createWriter
public static IWritableState createWriter(java.lang.String rootName) throws java.io.IOException
Create a new writable state.- Parameters:
rootName
- root name of the writable state- Returns:
- a new writable state
- Throws:
java.io.IOException
-
toXMLString
public static java.lang.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, java.io.Writer writer) throws java.io.IOException
Write a stateful state to a reader as an XML string.- Parameters:
state
- state to write as XMLwriter
- write to write the XML to- Throws:
java.io.IOException
-
writeBoolean
public static void writeBoolean(IWritableState state, java.lang.String attribute, java.lang.Boolean value)
Write a boolean value to a state.- Parameters:
state
- state to write toattribute
- attribute namevalue
- attribute value- See Also:
readBoolean(IState, String, Boolean)
-
readBoolean
public static java.lang.Boolean readBoolean(IState state, java.lang.String attribute, java.lang.Boolean defaultValue)
Read a boolean value from a state.- Parameters:
state
- state to read fromattribute
- attribute namedefaultValue
- default attribute value- Returns:
- attribute value if it is set in the state,
defaultValue
if not - See Also:
writeBoolean(IWritableState, String, Boolean)
-
writeFloat
public static void writeFloat(IWritableState state, java.lang.String attribute, java.lang.Float value)
Write a float value to a state.- Parameters:
state
- state to write toattribute
- attribute namevalue
- attribute value- See Also:
readFloat(IState, String, Float)
-
readFloat
public static java.lang.Float readFloat(IState state, java.lang.String attribute, java.lang.Float defaultValue)
Read a float value from a state.- Parameters:
state
- state to read fromattribute
- attribute namedefaultValue
- default attribute value- Returns:
- attribute value if it is set in the state,
defaultValue
if not - See Also:
writeFloat(IWritableState, String, Float)
-
writeInt
public static void writeInt(IWritableState state, java.lang.String attribute, java.lang.Integer value)
Write an integer value to a state.- Parameters:
state
- state to write toattribute
- attribute namevalue
- attribute value- See Also:
readInt(IState, String, Integer)
-
readInt
public static java.lang.Integer readInt(IState state, java.lang.String attribute, java.lang.Integer defaultValue)
Read an integer value from a state.- Parameters:
state
- state to read fromattribute
- attribute namedefaultValue
- default attribute value- Returns:
- attribute value if it is set in the state,
defaultValue
if not - See Also:
writeInt(IWritableState, String, Integer)
-
writeEnum
public static <T extends java.lang.Enum<T>> void writeEnum(IWritableState state, java.lang.String attribute, T value)
Write an enum value to a state.- Parameters:
state
- state to write toattribute
- attribute namevalue
- attribute value- See Also:
readEnum(IState, String, Enum, Class)
-
readEnum
public static <T extends java.lang.Enum<T>> T readEnum(IState state, java.lang.String attribute, T defaultValue, java.lang.Class<T> klass)
Read an enum value from a state.- Parameters:
state
- state to read fromattribute
- attribute namedefaultValue
- default attribute valueklass
- 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)
-
-