Class ClientJSONConfigUtil

  • Direct Known Subclasses:
    ClientFunctorScriptsUtil

    public class ClientJSONConfigUtil
    extends Object
    This will read the configuration. It is meant to be used by the ClientScriptsFactory 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

    • Constructor Detail

      • ClientJSONConfigUtil

        public ClientJSONConfigUtil()
    • 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 a JSONArray.
          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 the JSONObject for the given key. This will fail if there is not a single object there,

          Z=   {"key0":{
                 "key1':X
                }
             }
         
        the call getThingy("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 call setThingy("key0:,Z,"key1",X) results in
          Z=   {"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 following
          Z=   {"key0":{
                 "key1':X
                }
             }
         
        The call here would be hasThingy("key0",Z,"key1'); that would return true
        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)