|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.fascinator.common.JsonSimple
com.googlecode.fascinator.common.JsonSimpleConfig
public class JsonSimpleConfig
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 Summary | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class com.googlecode.fascinator.common.JsonSimple |
|---|
fromJavaMap, getJsonObject, getStringList, getStringList, setPropertySubstitution, toJavaList, toJavaMap, toString, toString, writeArray, writeObject |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JsonSimpleConfig()
throws IOException
IOException - if there was an error during creation
public JsonSimpleConfig(File jsonFile)
throws IOException
jsonFile - : The file containing JSON
IOException - if there was an error during creation
public JsonSimpleConfig(InputStream jsonIn)
throws IOException
jsonIn - : The input stream to read
IOException - if there was an error during creation
public JsonSimpleConfig(String jsonString)
throws IOException
jsonString - : The JSON in string form
IOException - if there was an error during creation| Method Detail |
|---|
public static File backupSystemFile()
throws IOException
IOException - if there was an error reading or writing either file
public 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 segments
public JsonObject getObject(Object... path)
getObject in class JsonSimplepath - : Variable length array of path segments
public Object getPath(Object... path)
getPath in class JsonSimplepath - : Variable length array of path segments
public 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 path
public 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 path
public 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 path
public 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 path
public 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 path
public 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 path
public 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 for
public 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().
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||