#108 Add a class like the Java Peroperties class.

Next_Release
closed
David Ashley
Classes (154)
5
2012-08-14
2007-02-14
Rick McGuire
No

A class that functions like the Java Properties class would be very handy. Key features of such a class would be:

1) both keys and values must be strings (like, directory, but more restrictive).
2) Able to load/save to a file or stream.
3) Have some support for extracting common values such as "true" and "false" as boolean representations.

Discussion

  • Logged In: YES
    user_id=662126
    Originator: NO

    Also:

    • optionally supplying a (default) value which should be returned, if the property is not available,
    • allow reading/writing XML encoded property file (like in Java).
     
  • Logged In: YES
    user_id=662126
    Originator: NO

    Also:

    • optionally supplying a (default) value which should be returned, if the property is not available,
    • allow reading/writing XML encoded property file (like in Java).
     
  • Logged In: YES
    user_id=662126
    Originator: NO

    The current implementation of Properties does expect a stream object for its load and save methods (class and instance). Is this intentional?

    It would be more flexible/less restrictive, if one could supply the name of the property file as a string object and use the BIFs LINEIN() (LINEOUT() in save) instead of the stream method LINEIN/LINEOUT.

    [Supplying a stream object in addition would be o.k. as the required string value of a stream object would resolve to the filename for which the stream object got created. Maybe now, that we have isInstanceOf the load/save parts could take advantage of it and use whatever is appropriate for the passed-in argument.]

     
  • Rick McGuire
    Rick McGuire
    2007-03-21

    Logged In: YES
    user_id=1125291
    Originator: YES

    This is intentional, and is MORE flexible than providing a file name, since you really only have to provide an object that pretends it is a stream (i.e, implements linein()). This allows you to source the information from anywhere, including in-memory locations.

     
  • Logged In: YES
    user_id=662126
    Originator: NO

    There is a little glitch in the "getLogical" method, the error number that should get raised is 34.904 (instead of the present 26.901 which refers to expecting a whole number).


    Ad load and save: would you object if I added the ability to allow a string containing a filename to be passed (creating a stream object for it)?

    Something like:

    ::method load
    use arg input
    if input~isInstanceOf(.string) then
    input=.stream~new(input)
    ...

    ::method save
    use arg output
    if output~isInstanceOf(.string) then
    output=.stream~new(output)
    ...

     
  • Rick McGuire
    Rick McGuire
    2007-03-21

    Logged In: YES
    user_id=1125291
    Originator: YES

    I have no objections to that being added, though I think if you do that, then it should create the stream, recursively call load/save and then explicitly close the stream.

     
  • Logged In: YES
    user_id=662126
    Originator: NO

    Here's the diff, if o.k., I will commit it (tested with an adapted testUnit):

    Index: SystemObjects.orx

    --- SystemObjects.orx (revision 175)
    +++ SystemObjects.orx (working copy)
    @@ -1121,6 +1121,14 @@
    if arg(1, 'o') then
    raise syntax 93.903 array (1) -- raise an error

    • if input~isInstanceOf(.string) then -- if a string use it as a filename
    • do
    • stream=.stream~new(input) -- create stream object
    • self~load(stream) -- load its properties
    • stream~close -- close stream
    • return
    • end
      +
      signal on notready

    do forever
    @@ -1147,6 +1155,14 @@
    if arg(1, 'o') then
    raise syntax 93.903 array (1) -- raise an error

    • if output~isInstanceOf(.string) then -- if a string use it as a filename
    • do
    • stream=.stream~new(output) -- create stream object
    • self~save(stream) -- load its properties
    • stream~close -- close stream
    • return
    • end
      +
      supplier = self~supplier

    do while supplier~available
    @@ -1244,7 +1260,7 @@
    return .true
    else if value == '0' | value == 'false' then
    return .false
    - raise syntax 26.901 array (value) -- raise an error
    + raise syntax 34.904 array (value) -- raise an error

    ::METHOD "[]="

     
  • Rick McGuire
    Rick McGuire
    2007-03-21

    Logged In: YES
    user_id=1125291
    Originator: YES

    Looks good to me.

     
  • Rick McGuire
    Rick McGuire
    2007-04-05

    Logged In: YES
    user_id=1125291
    Originator: YES

    Doc updates still need to be done.

     


Anonymous


Cancel   Add attachments