예제 #1
0
 /** Set the current date for the <i>lastUpdated</i> parameter. */
 private void _updateDate() {
   try {
     lastUpdated.setExpression(DateFormat.getDateTimeInstance().format(new Date()));
   } catch (IllegalActionException e) {
     throw new InternalErrorException(e);
   }
 }
예제 #2
0
  /**
   * @param entity Description of the Parameter
   * @return Description of the Return Value
   * @exception IllegalActionException Description of the Exception
   */
  private EntityLibrary copyEntityLibrary(EntityLibrary entity) throws IllegalActionException {
    if (entity == null) return null;
    try {
      if (isDebugging) log.debug("copyCompositeEntity(" + entity.getName() + ")");
      if (isDebugging) log.debug(entity.getClass().getName());
      EntityLibrary el = null;

      if (entity instanceof OntologyEntityLibrary) {
        el = new OntologyEntityLibrary(new CompositeEntity(this.workspace), entity.getName());
      } else if (entity instanceof KAREntityLibrary) {
        el = new KAREntityLibrary(new CompositeEntity(this.workspace), entity.getName());
      } else if (entity instanceof FolderEntityLibrary) {
        el = new FolderEntityLibrary(new CompositeEntity(this.workspace), entity.getName());
      } else if (entity instanceof DownloadableKAREntityLibrary) {
        el =
            new DownloadableKAREntityLibrary(
                new CompositeEntity(this.workspace), (DownloadableKAREntityLibrary) entity);
      } else if (entity instanceof RemoteRepositoryEntityLibrary) {
        el =
            new RemoteRepositoryEntityLibrary(
                new CompositeEntity(this.workspace), entity.getName());
      } else if (entity instanceof KARErrorEntityLibrary) {
        el = new KARErrorEntityLibrary(new CompositeEntity(this.workspace), entity.getName());
      } else if (entity instanceof RemoteKARErrorEntityLibrary) {
        el = new RemoteKARErrorEntityLibrary(new CompositeEntity(this.workspace), entity.getName());
        ((RemoteKARErrorEntityLibrary) el)
            .setKarXml(((RemoteKARErrorEntityLibrary) entity).getKarXml());
      } else {
        el = new EntityLibrary(new CompositeEntity(this.workspace), entity.getName());
      }
      if (el == null) {
        log.warn("Unrecognized Composite Entity");
      } else {

        // set the display name to be the source's display name.
        // the display name may be different than the name returned
        // by getName(), e.g., the name may end in ",kar" but the
        // display name ends in ".kar".
        el.setDisplayName(entity.getDisplayName());

        int liid = LibraryManager.getLiidFor(entity);
        StringAttribute liidSA = new StringAttribute(el, LibraryManager.LIID_LABEL);
        liidSA.setExpression("" + liid);
        if (isDebugging) log.debug(el.getClass().getName());
      }
      return el;
    } catch (IllegalActionException iae) {
      throw new IllegalActionException("cannot copy composite entity: " + iae);
    } catch (NameDuplicationException nde) {
      throw new IllegalActionException(
          "cannot set container because the name " + "already exists: " + nde);
    }
  }
예제 #3
0
  /**
   * Construct an integrator with the specified name and a container. The integrator is in the same
   * workspace as the container.
   *
   * @param container The container.
   * @param name The name.
   * @exception NameDuplicationException If the name is used by another actor in the container.
   * @exception IllegalActionException If ports can not be created, or thrown by the super class.
   */
  public ContinuousIntegrator(CompositeEntity container, String name)
      throws NameDuplicationException, IllegalActionException {
    super(container, name);

    impulse = new TypedIOPort(this, "impulse", true, false);
    impulse.setTypeEquals(BaseType.DOUBLE);
    StringAttribute cardinality = new StringAttribute(impulse, "_cardinal");
    cardinality.setExpression("SOUTH");

    derivative = new TypedIOPort(this, "derivative", true, false);
    derivative.setTypeEquals(BaseType.DOUBLE);

    state = new TypedIOPort(this, "state", false, true);
    state.setTypeEquals(BaseType.DOUBLE);

    initialState = new PortParameter(this, "initialState", new DoubleToken(0.0));
    initialState.setTypeEquals(BaseType.DOUBLE);
    cardinality = new StringAttribute(initialState.getPort(), "_cardinal");
    cardinality.setExpression("SOUTH");

    _causalityInterface = new IntegratorCausalityInterface(this, BooleanDependency.OTIMES_IDENTITY);
  }
예제 #4
0
  /**
   * Override the base class to remove this instance from its container if the argument is an empty
   * string. The removal is done in a change request, so it may not take effect immediately.
   *
   * @param expression The value of the string attribute.
   * @exception IllegalActionException If the change is not acceptable to the container.
   */
  public void setExpression(String expression) throws IllegalActionException {
    if (expression.equals("")) {
      ChangeRequest request =
          new ChangeRequest(this, "Delete empty doc tag.") {
            protected void _execute() throws Exception {
              setContainer(null);
            }
          };

      requestChange(request);
    } else {
      super.setExpression(expression);
    }
  }
예제 #5
0
  /**
   * Construct an actor in the specified container with the specified name.
   *
   * @param container The container.
   * @param name The name of this actor within the container.
   * @exception IllegalActionException If the actor cannot be contained by the proposed container.
   * @exception NameDuplicationException If the name coincides with an actor already in the
   *     container.
   */
  public BooleanSwitch(CompositeEntity container, String name)
      throws IllegalActionException, NameDuplicationException {
    super(container, name);

    input = new TypedIOPort(this, "input", true, false);
    control = new TypedIOPort(this, "control", true, false);
    control.setTypeEquals(BaseType.BOOLEAN);
    trueOutput = new TypedIOPort(this, "trueOutput", false, true);
    falseOutput = new TypedIOPort(this, "falseOutput", false, true);
    trueOutput.setTypeAtLeast(input);
    falseOutput.setTypeAtLeast(input);

    // Put the control input on the bottom of the actor.
    StringAttribute controlCardinal = new StringAttribute(control, "_cardinal");
    controlCardinal.setExpression("SOUTH");
  }
예제 #6
0
  /**
   * Construct an actor in the specified container with the specified name.
   *
   * @param container The container.
   * @param name The name of this actor within the container.
   * @exception IllegalActionException If the actor cannot be contained by the proposed container.
   * @exception NameDuplicationException If the name coincides with an actor already in the
   *     container.
   */
  public EnabledComposite(CompositeEntity container, String name)
      throws IllegalActionException, NameDuplicationException {
    super(container, name);

    // NOTE: this might be non-strict because it may
    // contain actors that are non-strict.

    enable = new TypedIOPort(this, "enable", true, false);
    enable.setTypeEquals(BaseType.BOOLEAN);

    StringAttribute controlCardinal = new StringAttribute(enable, "_cardinal");
    controlCardinal.setExpression("SOUTH");

    Location location = new Location(enable, "_location");
    location.setExpression("[140.0, 35.0]");

    // Create an inside director.
    SRDirector director = new SRDirector(this, "SRDirector");
    location = new Location(director, "_location");
    location.setExpression("[65.0, 35.0]");
  }
예제 #7
0
 /** @param mode */
 public void setMode(PortMode mode) {
   this.mode = mode;
   if (!PortMode.PULL.equals(mode)) {
     // we're outside of normal ptolemy-like port handling
     // so store this in the moml
     if (modeAttr == null) {
       try {
         modeAttr = new StringAttribute(this, "portMode");
         modeAttr.setExpression(mode.name());
       } catch (Exception e) {
         // ignore, if it doesn't work it's because the attribute is already there
       }
     }
   } else if (modeAttr != null) {
     try {
       modeAttr.setContainer(null);
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     modeAttr = null;
   }
 }
예제 #8
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");
  }