示例#1
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);
    }
  }
示例#2
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);
   }
 }
示例#3
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");
  }
示例#4
0
  /**
   * Return the (presumably Settable) attribute modified by this actor. This is the attribute in the
   * container of this actor with the name given by the variableName attribute. If no such attribute
   * is found, then this method creates a new variable in the actor's container with the correct
   * name. This method gets write access on the workspace.
   *
   * @exception IllegalActionException If the variable cannot be found.
   * @return The attribute modified by this actor.
   */
  public Attribute getModifiedVariable() throws IllegalActionException {
    NamedObj container = getContainer();

    if (container == null) {
      throw new IllegalActionException(this, "No container.");
    }

    String variableNameValue = variableName.getExpression();
    Attribute attribute = null;

    // Look for the variableName anywhere in the hierarchy
    while ((attribute == null) && (container != null)) {
      attribute = container.getAttribute(variableNameValue);

      if (attribute == null) {
        container = container.getContainer();
      }
    }

    if (attribute == null) {
      try {
        workspace().getWriteAccess();

        // container might be null, so create the variable
        // in the container of this actor.
        attribute = new Variable(getContainer(), variableNameValue);
      } catch (NameDuplicationException ex) {
        throw new InternalErrorException(ex);
      } finally {
        workspace().doneWriting();
      }
    }

    return attribute;
  }
示例#5
0
  /**
   * If the argument is the <i>identifier</i> parameter, then set the title of all contained
   * Tableaux to the value of the parameter; if the argument is the <i>uri</i> parameter, then check
   * to see whether it is writable, and call setModifiable() appropriately.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the base class throws it.
   */
  @Override
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == identifier) {
      Iterator tableaux = entityList(Tableau.class).iterator();

      while (tableaux.hasNext()) {
        Tableau tableau = (Tableau) tableaux.next();
        tableau.setTitle(identifier.getExpression());
      }
    } else if (attribute == uri) {
      URI uriValue = uri.getURI();

      if (uriValue == null) {
        // A new model, with no URI, is by default modifiable.
        _modifiableURI = true;
      } else {
        String protocol = uriValue.getScheme();

        if (!protocol.equals("file")) {
          _modifiableURI = false;
        } else {
          // Use just the path here in case we
          // are passed a URI that has a fragment.
          // If we had file:/C%7C/foo.txt#bar
          // then bar is the fragment.  Unfortunately,
          // new File(file:/C%7C/foo.txt#bar) will fail,
          // so we add the path.
          String path = uriValue.getPath();
          if (path != null) {
            File file = new File(path);

            try {
              if (path.indexOf("%20") == -1) {
                _modifiableURI = file.canWrite();
              } else {
                // FIXME: we need a better way to check if
                // a URL is writable.

                // Sigh.  If the filename has spaces in it,
                // then the URL will have %20s.  However,
                // the file does not have %20s.
                // See
                // https://chess.eecs.berkeley.edu/bugzilla/show_bug.cgi?id=153
                path = StringUtilities.substitute(path, "%20", " ");
                file = new File(path);
                _modifiableURI = file.canWrite();
              }
            } catch (java.security.AccessControlException accessControl) {
              // If we are running in a sandbox, then canWrite()
              // may throw an AccessControlException.
              _modifiableURI = false;
            }
          }
        }
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
示例#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
  /**
   * 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);
  }
示例#8
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;
   }
 }
示例#9
0
  /**
   * React to a change in an attribute. If the attribute is <i>name</i>, then change the name of the
   * container to match.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not acceptable to this container (not thrown
   *     in this base class).
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == name) {
      Nameable container = getContainer();

      try {
        container.setName(name.getExpression());
      } catch (NameDuplicationException e) {
        throw new IllegalActionException(
            this, e, "Cannot change the name of the container to match.");
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
示例#10
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);
    }
  }
示例#11
0
  // /////////////////////////////////////////////////////////////////
  // // private methods ////
  private void _setValue(Token value) throws IllegalActionException {
    Attribute variable = getModifiedVariable();

    if (variable instanceof Variable) {
      ((Variable) variable).setToken(value);

      // NOTE: If we don't call validate(), then the
      // change will not propagate to dependents.
      ((Variable) variable).validate();
    } else if (variable instanceof Settable) {
      ((Settable) variable).setExpression(value.toString());

      // NOTE: If we don't call validate(), then the
      // change will not propagate to dependents.
      ((Settable) variable).validate();
    } else {
      throw new IllegalActionException(
          SetVariable.this,
          "Cannot set the value of the variable " + "named: " + variableName.getExpression());
    }
  }
示例#12
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");
  }