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(File jsonFile)
Creates JSON Configuration object from the provided config file
|
JsonSimpleConfig(InputStream jsonIn)
Creates JSON Configuration object from the provided input stream
|
JsonSimpleConfig(String jsonString)
Creates JSON Configuration object from the provided config string
|
| Modifier and Type | Method and Description |
|---|---|
static File |
backupSystemFile()
Performs a backup on the system-wide configuration file from the default
config dir if it exists.
|
org.json.simple.JSONArray |
getArray(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target
JSONArray.
|
Boolean |
getBoolean(Boolean defaultValue,
Object... path)
Retrieve the Boolean value on the given path.
|
Integer |
getInteger(Integer defaultValue,
Object... path)
Retrieve the Integer value on the given path.
|
List<JsonSimple> |
getJsonSimpleList(Object... path)
Retrieve a list of JsonSimple objects found on the given path.
|
Map<String,JsonSimple> |
getJsonSimpleMap(Object... path)
Retrieve a map of JsonSimple objects found on the given path.
|
JsonObject |
getObject(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target
JsonObject.
|
Object |
getPath(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target.
|
String |
getString(String defaultValue,
Object... path)
Retrieve the String value on the given path.
|
List<String> |
getStringList(Object... path)
Retrieve a list of Strings found on the given path.
|
static 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
|
List<Object> |
search(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 IOException
IOException - if there was an error during creationpublic JsonSimpleConfig(File jsonFile) throws IOException
jsonFile - : The file containing JSONIOException - if there was an error during creationpublic JsonSimpleConfig(InputStream jsonIn) throws IOException
jsonIn - : The input stream to readIOException - if there was an error during creationpublic JsonSimpleConfig(String jsonString) throws IOException
jsonString - : The JSON in string formIOException - if there was an error during creationpublic static File backupSystemFile() throws IOException
IOException - if there was an error reading or writing either filepublic static File getSystemFile() throws IOException
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(Object... path)
getArray in class JsonSimplepath - : Variable length array of path segmentspublic JsonObject getObject(Object... path)
getObject in class JsonSimplepath - : Variable length array of path segmentspublic Object getPath(Object... path)
getPath in class JsonSimplepath - : Variable length array of path segmentspublic Boolean getBoolean(Boolean defaultValue, 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 Integer getInteger(Integer defaultValue, 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 String getString(String defaultValue, 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 List<String> getStringList(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 List<JsonSimple> getJsonSimpleList(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 Map<String,JsonSimple> getJsonSimpleMap(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 List<Object> search(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 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().
IOExceptionCopyright © 2009-2013. All Rights Reserved.