Ejemplo n.º 1
0
  private void _inferFiringCounts(SymbolicScheduleElement element, String expression)
      throws IllegalActionException, NameDuplicationException {
    String recursiveExpression;

    if (expression == null) {
      recursiveExpression = element.expression();
    } else {
      recursiveExpression = expression + "*" + element.expression();
    }

    if (element instanceof SymbolicFiring) {
      SymbolicFiring firing = (SymbolicFiring) element;
      Entity actor = (Entity) firing.getActor();
      Variable parameter = (Variable) actor.getAttribute("firingsPerIteration");

      if (parameter == null) {
        parameter = new Parameter(actor, "firingsPerIteration");
        parameter.setVisibility(Settable.NOT_EDITABLE);
        parameter.setPersistent(false);
      }

      parameter.setExpression(recursiveExpression);
    } else if (element instanceof SymbolicSchedule) {
      SymbolicSchedule schedule = (SymbolicSchedule) element;

      for (Iterator i = schedule.iterator(); i.hasNext(); ) {
        _inferFiringCounts((SymbolicScheduleElement) i.next(), recursiveExpression);
      }
    } else {
      throw new RuntimeException("Unexpected Schedule Element");
    }
  }
Ejemplo n.º 2
0
  /**
   * Construct an attribute with the given name contained by the specified container. The container
   * argument must not be null, or a NullPointerException will be thrown. This attribute will use
   * the workspace of the container for synchronization and version counts. If the name argument is
   * null, then the name is set to the empty string. Increment the version of the workspace.
   *
   * @param container The container.
   * @param name The name of this attribute.
   * @exception IllegalActionException If the attribute is not of an acceptable class for the
   *     container, or if the name contains a period.
   * @exception NameDuplicationException If the name coincides with an attribute already in the
   *     container.
   */
  public IDAttribute(Entity container, String name)
      throws IllegalActionException, NameDuplicationException {
    super(container, name);

    // name for the model
    this.name = new StringAttribute(this, "name");
    this.name.setExpression(container.getName());

    // This should not be persistent, in case the name changes outside
    // of this parameter.
    this.name.setPersistent(false);

    // This should not be editable, since the name is set by saveAs.
    this.name.setVisibility(Settable.NOT_EDITABLE);

    // FIXME: Need to listen for changes to the name.
    // How to do that?
    // The current design is also a solution in that the name of this
    // attribute and model must be consistent with the name of the file.
    // boolean isClass = false;
    // if (container instanceof InstantiableNamedObj) {
    /* isClass = */ ((InstantiableNamedObj) container).isClassDefinition();
    // }

    String className = container.getClassName();

    baseClass = new StringAttribute(this, "baseClass");
    baseClass.setExpression(className);

    // This should not be persistent, because the base class
    // is set already, generally.
    baseClass.setPersistent(false);

    // Cannot change the base class.
    baseClass.setVisibility(Settable.NOT_EDITABLE);

    URIAttribute modelURI = (URIAttribute) container.getAttribute("_uri", URIAttribute.class);

    if (modelURI != null) {
      StringAttribute definedIn = new StringAttribute(this, "definedIn");
      definedIn.setExpression(modelURI.getURI().toString());
      definedIn.setPersistent(false);
      definedIn.setVisibility(Settable.NOT_EDITABLE);
    }

    // The date when this model is created.
    // Actually, it is the date when this attribute is created.
    // We assume that when the model is created, this attribute
    // is also created.
    // We may force this to happen.:-) Further more, we may force
    // that only the top level contains an model ID.
    created = new StringAttribute(this, "created");
    created.setExpression(DateFormat.getDateTimeInstance().format(new Date()));
    created.setVisibility(Settable.NOT_EDITABLE);
    created.setPersistent(true);

    // The date when this model is modified.
    // Everytime the model gets modified, the updateContent method
    // defined below is called and the lastUpdated attribute gets
    // updated.
    lastUpdated = new StringAttribute(this, "lastUpdated");
    _updateDate();
    lastUpdated.setVisibility(Settable.NOT_EDITABLE);
    lastUpdated.setPersistent(true);

    // The name of the author who creates the model.
    // This attribute can not be changed so that the
    // intellectual property (IP) is preserved.
    author = new StringAttribute(this, "author");
    author.setVisibility(Settable.NOT_EDITABLE);

    String userName = null;

    try {
      userName = StringUtilities.getProperty("user.name");
    } catch (Exception ex) {
      System.out.println(
          "Warning, in IDAttribute, failed to read "
              + "'user.name' property (-sandbox or applets always cause "
              + "this)");
    }

    if (userName != null) {
      author.setExpression(userName);
    }

    author.setPersistent(true);

    // The names of the contributors who modify the model.
    contributors = new StringAttribute(this, "contributors");

    String contributorsNames = "";
    contributors.setExpression(contributorsNames);
    author.setPersistent(true);

    // Hide the name of this ID attribute.
    SingletonParameter hide = new SingletonParameter(this, "_hideName");
    hide.setToken(BooleanToken.TRUE);
    hide.setVisibility(Settable.EXPERT);

    BoxedValuesIcon icon = new BoxedValuesIcon(this, "_icon");
    icon.setPersistent(false);

    // No need to display any parameters when the "_showParameters"
    // preference asks for such display because presumably all the
    // parameters are reflected in the visual display already.
    Parameter hideAllParameters = new Parameter(this, "_hideAllParameters");
    hideAllParameters.setVisibility(Settable.EXPERT);
    hideAllParameters.setExpression("true");
  }