Properties class and Streams

Help
2012-08-21
2012-08-23
  • Staffan Tylen
    Staffan Tylen
    2012-08-21

    The documentation for the Properties class states that the input to the load method can be either the string name of a file or a stream object. It also says that linein() is used to read the input. With this in mind I've tried to use a subclass to stream as input to the load method and under certain circumstances it works but never they way I want it to. Consider the following examples:

    myProp = .Properties~new
    myFile = .Stream~new(input.txt)
    myProp~load(myFile)
    exit

    The above works fine.

    myProp = .Properties~new
    myFile = .myStream~new(input.txt)
    myProp~load(myFile)
    exit
    ::class myStream subclass Stream

    The above also works fine.

    myProp = .Properties~new
    myFile = .myStream~new(input.txt)
    myProp~load(myFile)
    exit
    ::class myStream subclass Stream
    ::method linein
    forward class(super)

    Again, this works fine.

    myProp = .Properties~new
    myFile = .myStream~new(input.txt)
    myProp~load(myFile)
    exit
    ::class myStream subclass Stream
    ::method linein
    forward class(super) continue
    return result

    The above causes a loop in the load method.

    myProp = .Properties~new
    myFile = .myStream~new(input.txt)
    myProp~load(myFile)
    exit
    ::class myStream subclass Stream
    ::method linein
    return self~linein:super

    The above also causes a loop in the load method. In fact, every attempt to return from the linein method in the subclass causes a loop in the Properties load method, which keeps calling the linein method forever, even if the lines method returns zero.

    My question is simple: what am I doing wrong?

     
    • Rick McGuire
      Rick McGuire
      2012-08-21

      I suspect it is because your linein override method is swallowing any
      NOTREADY condition raised by the base method. You should probably have
      something like this:

      ::method linein
      signal on notready
      return self~linein:super

      notready: raise propagate

      Rick

      On Tue, Aug 21, 2012 at 4:09 PM, Staffan Tylen st2430@users.sf.net wrote:

      The documentation for the Properties class states that the input to the
      load method can be either the string name of a file or a stream object. It
      also says that linein() is used to read the input. With this in mind I've
      tried to use a subclass to stream as input to the load method and under
      certain circumstances it works but never they way I want it to. Consider
      the following examples:

      myProp = .Properties~new
      myFile = .Stream~new(input.txt)
      myProp~load(myFile)
      exit

      The above works fine.

      myProp = .Properties~new
      myFile = .myStream~new(input.txt)
      myProp~load(myFile)
      exit
      ::class myStream subclass Stream

      The above also works fine.

      myProp = .Properties~new
      myFile = .myStream~new(input.txt)
      myProp~load(myFile)
      exit
      ::class myStream subclass Stream
      ::method linein
      forward class(super)

      Again, this works fine.

      myProp = .Properties~new
      myFile = .myStream~new(input.txt)
      myProp~load(myFile)
      exit
      ::class myStream subclass Stream
      ::method linein
      forward class(super) continue
      return result

      The above causes a loop in the load method.

      myProp = .Properties~new
      myFile = .myStream~new(input.txt)
      myProp~load(myFile)
      exit
      ::class myStream subclass Stream
      ::method linein
      return self~linein:super

      The above also causes a loop in the load method. In fact, every attempt to
      return from the linein method in the subclass causes a loop in the
      Properties load method, which keeps calling the linein method forever, even
      if the lines method returns zero.

      My question is simple: what am I doing wrong?


      Sent from sourceforge.net because you indicated interest in <
      https://sourceforge.net/p/oorexx/discussion/408478/>

      To unsubscribe from further messages, please visit <
      https://sourceforge.net/auth/prefs/>

       
  • Staffan Tylen
    Staffan Tylen
    2012-08-23

    Spot on! Many thanks :)