示例#1
0
  /**
   * If the <i>stopTime</i> parameter is changed and the model is executing, then if the new value
   * is greater than zero and greater than the current time, then ask the director to fire this
   * actor at that time. If the new value is less than the current time, then request refiring at
   * the current time.
   *
   * @exception IllegalActionException If the superclass throws it.
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == stopTime) {
      double newStopTimeValue = ((DoubleToken) stopTime.getToken()).doubleValue();

      if (_executing) {
        Time newStopTime = new Time(getDirector(), newStopTimeValue);
        Director director = getDirector();

        if (director != null) {
          Time currentTime = director.getModelTime();

          if (newStopTime.compareTo(currentTime) > 0) {
            director.fireAt(this, newStopTime);
          } else {
            throw new IllegalActionException(
                this, "The stop time " + "is earlier than the current time.");
          }
        }

        _stopTime = newStopTime;
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
示例#2
0
  /**
   * If the specified attribute is <i>URL</i>, then close the current file (if there is one) and
   * open the new one.
   *
   * @param attribute The attribute that has changed.
   * @exception IllegalActionException If the specified attribute is <i>URL</i> and the file cannot
   *     be opened.
   */
  @Override
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == sourceURL) {
      try {
        StringToken URLToken = (StringToken) sourceURL.getToken();

        if (URLToken == null) {
          _source = null;
          setReader(null);
        } else {
          _source = URLToken.stringValue();

          if (_source.equals("")) {
            setReader(null);
          } else {
            URL url = new URL(_source);
            java.io.BufferedReader reader =
                new BufferedReader(new InputStreamReader(url.openStream()));
            setReader(reader);
          }
        }
      } catch (IOException ex) {
        throw new IllegalActionException(this, ex, "attributeChanged(" + attribute + ") failed");
      }
    }

    super.attributeChanged(attribute);
  }