Class ClientJSONConfigUtil
- java.lang.Object
-
- org.oa4mp.delegation.server.scripts.server.ClientJSONConfigUtil
-
- Direct Known Subclasses:
ClientFunctorScriptsUtil
public class ClientJSONConfigUtil extends Object
This will read the configuration. It is meant to be used by theClientScriptsFactory
and its subclasses. to modularize operations on the JSON. Note that the "thingy" refers to a JSON idiom, often used here viz., a configuration entry of the form {"topLevelKey":JSON} where JSON is either an array or json object. These may be done at any level of the configuration file, so be sure to send in the right JSON object with the topLevelKey.
Created by Jeff Gaynor
on 8/30/17 at 3:37 PM
-
-
Field Summary
Fields Modifier and Type Field Description static String
COMMENT_KEY
static String
SAVED_KEY
-
Constructor Summary
Constructors Constructor Description ClientJSONConfigUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static net.sf.json.JSONArray
getComment(net.sf.json.JSONObject config)
Checks if the argument has a comment flag.static net.sf.json.JSONArray
getThingies(String topLevelKey, net.sf.json.JSONObject config, String key)
Return the contents as a JSON array.static net.sf.json.JSONObject
getThingy(String topLevelKey, net.sf.json.JSONObject config, String key)
Return theJSONObject
for the given key.static boolean
hasThingy(String topLevelKey, String key, net.sf.json.JSONObject config)
Drills down a level to check if this thingy has the given object.static void
setComment(net.sf.json.JSONObject config, String comment)
static void
setComment(net.sf.json.JSONObject config, net.sf.json.JSONArray comment)
static void
setThingy(String topLevelKey, net.sf.json.JSONObject config, String key, net.sf.json.JSON thingy)
Sets a JSON object at the given level.
-
-
-
Field Detail
-
SAVED_KEY
public static final String SAVED_KEY
- See Also:
- Constant Field Values
-
COMMENT_KEY
public static final String COMMENT_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
getThingies
public static net.sf.json.JSONArray getThingies(String topLevelKey, net.sf.json.JSONObject config, String key)
Return the contents as a JSON array. This also means that if there is a single object, it will be wrapped in aJSONArray
.Z= {"key0":{ "key1':X } }
This method returns the JSON array[X]
. Another example:OA2Coms Z= {"key0":{ "key1':[X,y,z] } }
This method returns the JSON array[X,y,z]
.- Parameters:
topLevelKey
-config
-key
-- Returns:
-
getThingy
public static net.sf.json.JSONObject getThingy(String topLevelKey, net.sf.json.JSONObject config, String key)
Return theJSONObject
for the given key. This will fail if there is not a single object there,Z= {"key0":{ "key1':X } }
the callgetThingy("key0",Z,"key1")
returns X.- Parameters:
topLevelKey
-config
-key
-- Returns:
-
setThingy
public static void setThingy(String topLevelKey, net.sf.json.JSONObject config, String key, net.sf.json.JSON thingy)
Sets a JSON object at the given level.Z= {"key0":{ ... stuff... } }
The callsetThingy("key0:,Z,"key1",X)
results inZ= {"key0":{ "key1':X, ... stuff ... } }
This may involve replacing the value of key1 with X if there is already a value there.- Parameters:
topLevelKey
-config
-key
-thingy
-
-
hasThingy
public static boolean hasThingy(String topLevelKey, String key, net.sf.json.JSONObject config)
Drills down a level to check if this thingy has the given object. So if you have the followingZ= {"key0":{ "key1':X } }
The call here would behasThingy("key0",Z,"key1');
that would returntrue
- Parameters:
topLevelKey
-key
-config
-- Returns:
-
getComment
public static net.sf.json.JSONArray getComment(net.sf.json.JSONObject config)
Checks if the argument has a comment flag.- Parameters:
config
-- Returns:
-
setComment
public static void setComment(net.sf.json.JSONObject config, net.sf.json.JSONArray comment)
-
setComment
public static void setComment(net.sf.json.JSONObject config, String comment)
-
-