Example #1
0
  /**
   * Return the list of property-able Attributes. A property-able Attribute is a StringAttribute
   * with the name "guardTransition", a StringAttribute in an Expression actor, a StringAttribute
   * with the name "expression" or a Variable with full visibility. However, Variables with certain
   * names are excluded.
   *
   * @return The list of property-able Attributes.
   */
  protected List<Attribute> _getPropertyableAttributes() {
    List<Attribute> result = new LinkedList<Attribute>();
    Iterator attributes = ((Entity) getComponent()).attributeList().iterator();

    while (attributes.hasNext()) {
      Attribute attribute = (Attribute) attributes.next();

      // only consider StringAttributes, ignore all subclasses
      if (attribute.getClass().equals(ptolemy.kernel.util.StringAttribute.class)) {
        if (((StringAttribute) attribute).getName().equalsIgnoreCase("guardTransition")
            || ((StringAttribute) attribute).getContainer() instanceof Expression
                && ((StringAttribute) attribute).getName().equalsIgnoreCase("expression")) {

          result.add(attribute);
        }
      } else if (attribute instanceof Variable) {
        if (((Variable) attribute).getVisibility() == Settable.FULL) {

          // filter Parameters with certain names; ignore all
          // subclasses
          if (attribute instanceof PortParameter) {
            result.add(attribute);
          } else if (attribute.getClass().equals(ptolemy.data.expr.Parameter.class)
              || attribute.getClass().equals(ptolemy.data.expr.StringParameter.class)) {

            // FIXME: implement filter interface, so that adapter
            // classes can specify which attributes
            // need to be filtered (either by name or by class)
            // Currently all filtered attributes need to be
            // specified here
            if (((Parameter) attribute).getName().equals("firingCountLimit")
                || ((Parameter) attribute).getName().equals("NONE")
                || ((Parameter) attribute).getName().equals("_hideName")
                || ((Parameter) attribute).getName().equals("_showName")
                || ((Parameter) attribute).getName().equals("conservativeAnalysis")
                || ((Parameter) attribute).getName().equals("directorClass")
                || ((Parameter) attribute).getName().equals("stateDependentCausality")
                || ((Parameter) attribute).getName().equals("delayed")
                || ((Parameter) attribute).getName().equals("displayWidth")) {

              // do nothing, ignore the parameter
            } else {
              result.add(attribute);
            }
          }
        }
      }
    }

    return result;
  }
Example #2
0
  /**
   * Check the class of the container in which the attribute is to be placed. If the container is
   * not an intended one, throw an IllegalActionException.
   *
   * @param attribute The attribute to check.
   * @param container The container.
   * @param containerClass The intended class of container.
   * @param deep Whether containers of the container should be checked instead, if the container
   *     does not qualify.
   * @exception IllegalActionException If this attribute cannot be used with the given container.
   */
  public static void checkContainerClass(
      Attribute attribute,
      NamedObj container,
      Class<? extends CompositeEntity> containerClass,
      boolean deep)
      throws IllegalActionException {
    while (deep
        && container != null
        && !containerClass.isInstance(container)
        && !(container instanceof EntityLibrary)) {
      container = container.getContainer();
      if (container instanceof EntityLibrary) {
        return;
      }
    }

    if (container == null
        || !containerClass.isInstance(container) && !(container instanceof EntityLibrary)) {
      _delete(attribute);
      throw new IllegalActionException(
          attribute.getClass().getSimpleName()
              + " can only be added to "
              + containerClass.getSimpleName()
              + ".");
    }
  }
Example #3
0
  /**
   * Check whether the attribute is unique in the given container.
   *
   * @param attribute The attribute to check.
   * @param container The container.
   * @exception IllegalActionException If the container already has an attribute in the same class.
   */
  public static void checkUniqueness(Attribute attribute, NamedObj container)
      throws IllegalActionException {
    if (container instanceof EntityLibrary) {
      return;
    }

    try {
      container.workspace().getReadAccess();
      List<? extends Attribute> attributeList = container.attributeList(attribute.getClass());
      for (Attribute existingAttribute : attributeList) {
        if (existingAttribute != attribute && existingAttribute.isPersistent()) {
          _delete(attribute);
          throw new IllegalActionException(
              "Only 1 " + attribute.getClass().getSimpleName() + " can be used.");
        }
      }
    } finally {
      container.workspace().doneReading();
    }
  }