Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.6.3
    • Fix Version/s: 2.7.6
    • Component/s: data
    • Labels:
      None

      Description

      We return a description of factory parameters in terms of an Param[] (or its superclass Parameter[]). This is a bit of a pain since it is hard to find a param entry by key; or sort out what the different utility methods do.

      Often you end up writing the same for loops multiple times; or putting things in a Map<String,Param> just to make programming faster.

      The attached class was combined from a bunch of uDig utility code from handling parameters and operates as a wrapper around a Param[].

      class Params {
        Params(DataAccessFactory)
        lookup(Class<T>, String, Map<String, ?>)
        lookup(Class<T>, Map<String, ?>)
        getParam(String)
        getParam(Class<?>)
      }
      

      An example use is:

      Params params = new Params( factory );
      String host = params.lookup( String.class, "host", connectionParams )
      

      The expected type is passed in; simply to cut down on casting; if "host" is not available in the factory params it will not be blindly returned. In a similar manner the host "sample" value of localhost will be returned if the connectionParams does not contain an "host" entry. This method builds on Param.handle( connectionParams ).

      Please note that the Param superclass Parameter has less helpful utility methods; it is my preference to move such things into this Params class rather then complicate the superclass.

      The approach of a wrapper was taken rather then adding methods to DataUtilities.

      Notes:

      • Params may not be the best name for the class - even the above code example has too many things named "param". Should use a plural form since we are wrapping a set of parameters. Ideas: Parameters, ConnectionParameters
      • Note this is not Andrea's long standing request for a Java Bean; however this class could become a formal DynamicProxy (if we pass the connection parameter values in) or produce a BeanInfo for working with one of the commons bean classes which present a java map as a bean.

        Activity

        Hide
        Andrea Aime added a comment -
        This class seems read only... I wonder how it makes coding easier?
        Like, the main use case I see is people actually building the map to get back a datastore, and this one does not seem to particularly help out?
        Do you have a code example of how it makes things better?
        Show
        Andrea Aime added a comment - This class seems read only... I wonder how it makes coding easier? Like, the main use case I see is people actually building the map to get back a datastore, and this one does not seem to particularly help out? Do you have a code example of how it makes things better?
        Hide
        Jody Garnett added a comment -
        You are correct; it does not contain a Map of params; instead it is used to allow you to evaulate and work with a map of params; look up values with some safety etc.
        Right now it makes the code in gt-swing and factory implementations easier to write; currently is is very tough to write user interface code and look up defaults etc.

        I had also thought of:
        - making it wrap a map of connection paramters and have set methods as well
        - making it be a Map as well (ie act as a proper decorator)

        It sounds this is more like you were thinking Andrea? I can give it a go ...

        Right now this represents the kind of code uDig should be contributing back; and me taking the time to do so.
        Show
        Jody Garnett added a comment - You are correct; it does not contain a Map of params; instead it is used to allow you to evaulate and work with a map of params; look up values with some safety etc. Right now it makes the code in gt-swing and factory implementations easier to write; currently is is very tough to write user interface code and look up defaults etc. I had also thought of: - making it wrap a map of connection paramters and have set methods as well - making it be a Map as well (ie act as a proper decorator) It sounds this is more like you were thinking Andrea? I can give it a go ... Right now this represents the kind of code uDig should be contributing back; and me taking the time to do so.

          People

          • Assignee:
            Jody Garnett
            Reporter:
            Jody Garnett
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: