public class JsonSimpleConfig extends JsonSimple
An extension of the JsonSimple class specifically to access configuration.
Aside from offering a constructor that takes care of finding and accessing the system configuration file, this class also offers a selection of methods for management of the system configuration, such as backup and version testing.
Finally, whatever configuration is provided to this class, it will be backed by the full system configuration file. Nodes not found in the provided config will also be checked in the System config.
| Constructor and Description |
|---|
JsonSimpleConfig()
Creates JSON Configuration object from the system config file
|
JsonSimpleConfig(java.io.File jsonFile)
Creates JSON Configuration object from the provided config file
|
JsonSimpleConfig(java.io.InputStream jsonIn)
Creates JSON Configuration object from the provided input stream
|
JsonSimpleConfig(java.lang.String jsonString)
Creates JSON Configuration object from the provided config string
|
| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
backupSystemFile()
Performs a backup on the system-wide configuration file from the default
config dir if it exists.
|
org.json.simple.JSONArray |
getArray(java.lang.Object... path)
Walk down the JSON nodes specified by the path and retrieve the target
JSONArray.
|
java.lang.Boolean |
getBoolean(java.lang.Boolean defaultValue,
java.lang.Object... path)
Retrieve the Boolean value on the given path.
|
java.lang.Integer |
getInteger(java.lang.Integer defaultValue,
java.lang.Object... path)
Retrieve the Integer value on the given path.
|
java.util.List<JsonSimple> |
getJsonSimpleList(java.lang.Object... path)
Retrieve a list of JsonSimple objects found on the given path.
|
java.util.Map<java.lang.String,JsonSimple> |
getJsonSimpleMap(java.lang.Object... path)
Retrieve a map of JsonSimple objects found on the given path.
|
JsonObject |
getObject(java.lang.Object... path)
Walk down the JSON nodes specified by the path and retrieve the target
JsonObject.
|
java.lang.Object |
getPath(java.lang.Object... path)
Walk down the JSON nodes specified by the path and retrieve the target.
|
java.lang.String |
getString(java.lang.String defaultValue,
java.lang.Object... path)
Retrieve the String value on the given path.
|
java.util.List<java.lang.String> |
getStringList(java.lang.Object... path)
Retrieve a list of Strings found on the given path.
|
static java.io.File |
getSystemFile()
Gets the system-wide configuration file from the default config dir.
|
boolean |
isConfigured()
Tests whether or not the system-config has been properly configured.
|
boolean |
isOutdated()
To check if configuration file is outdated
|
java.util.List<java.lang.Object> |
search(java.lang.String node)
Search through the JSON for any nodes (at any depth) matching the
requested name and return them.
|
void |
storeSystemConfig()
Store the underlying system configuration on disk in the appropriate
location.
|
JsonObject |
writableSystemConfig()
Returns a reference to the underlying system configuration object.
|
fromJavaMap, getJsonArray, getJsonObject, getStringList, getStringList, setPropertySubstitution, toJavaList, toJavaMap, toString, toString, writeArray, writeObjectpublic JsonSimpleConfig()
throws java.io.IOException
java.io.IOException - if there was an error during creationpublic JsonSimpleConfig(java.io.File jsonFile)
throws java.io.IOException
jsonFile - : The file containing JSONjava.io.IOException - if there was an error during creationpublic JsonSimpleConfig(java.io.InputStream jsonIn)
throws java.io.IOException
jsonIn - : The input stream to readjava.io.IOException - if there was an error during creationpublic JsonSimpleConfig(java.lang.String jsonString)
throws java.io.IOException
jsonString - : The JSON in string formjava.io.IOException - if there was an error during creationpublic static java.io.File backupSystemFile()
throws java.io.IOException
java.io.IOException - if there was an error reading or writing either filepublic static java.io.File getSystemFile()
throws java.io.IOException
java.io.IOException - if there was an error reading or writing the system
configuration filepublic boolean isConfigured()
true if configured, false if still
using defaultspublic boolean isOutdated()
true if outdated, false otherwisepublic org.json.simple.JSONArray getArray(java.lang.Object... path)
getArray in class JsonSimplepath - : Variable length array of path segmentspublic JsonObject getObject(java.lang.Object... path)
getObject in class JsonSimplepath - : Variable length array of path segmentspublic java.lang.Object getPath(java.lang.Object... path)
getPath in class JsonSimplepath - : Variable length array of path segmentspublic java.lang.Boolean getBoolean(java.lang.Boolean defaultValue,
java.lang.Object... path)
getBoolean in class JsonSimpledefaultValue - : The fallback value to use if the path is invalid or
not foundpath - : An array of indeterminate length to use as the pathpublic java.lang.Integer getInteger(java.lang.Integer defaultValue,
java.lang.Object... path)
getInteger in class JsonSimpledefaultValue - : The fallback value to use if the path is invalid or
not foundpath - : An array of indeterminate length to use as the pathpublic java.lang.String getString(java.lang.String defaultValue,
java.lang.Object... path)
getString in class JsonSimpledefaultValue - : The fallback value to use if the path is invalid or
not foundpath - : An array of indeterminate length to use as the pathpublic java.util.List<java.lang.String> getStringList(java.lang.Object... path)
Retrieve a list of Strings found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve Strings found on the provided node, and the node must be a JSONArray.
getStringList in class JsonSimplepath - : An array of indeterminate length to use as the pathpublic java.util.List<JsonSimple> getJsonSimpleList(java.lang.Object... path)
Retrieve a list of JsonSimple objects found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve valid JsonObjects found on the provided node, and wrap them in JsonSimple objects.
Other objects found on that path will be ignored, and if the path itself is not a JSONArray or not found, the function will return NULL.
getJsonSimpleList in class JsonSimplepath - : An array of indeterminate length to use as the pathpublic java.util.Map<java.lang.String,JsonSimple> getJsonSimpleMap(java.lang.Object... path)
Retrieve a map of JsonSimple objects found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve valid JsonObjects found on the provided node, and wrap them in JsonSimple objects.
Other objects found on that path will be ignored, and if the path itself is not a JsonObject or not found, the function will return NULL.
getJsonSimpleMap in class JsonSimplepath - : An array of indeterminate length to use as the pathpublic java.util.List<java.lang.Object> search(java.lang.String node)
Search through the JSON for any nodes (at any depth) matching the requested name and return them. The returned List will be of type Object and require type interrogation for detailed use, but will be implemented as a LinkedList to preserve order.
search in class JsonSimplenode - : The node name we are looking forpublic JsonObject writableSystemConfig()
Returns a reference to the underlying system configuration object. This is meant to be used on conjunction with storeSystemConfig() to make changes to the config file on disk.
Normal modifications to this objects JSON are not written to disk unless they they are made via writableSystemConfig().
public void storeSystemConfig()
throws java.io.IOException
Store the underlying system configuration on disk in the appropriate location.
Normal modifications to this objects JSON are not written to disk unless they they are made via writableSystemConfig().
java.io.IOExceptionCopyright © 2009-2018. All Rights Reserved.