Пример #1
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()
              + ".");
    }
  }
Пример #2
0
  /**
   * Move this object up by one in the list of relations of the container. If this object is already
   * first, do nothing. Increment the version of the workspace.
   *
   * @return The index of the specified object prior to moving it, or -1 if it is not moved.
   * @exception IllegalActionException If this object has no container.
   */
  public int moveUp() throws IllegalActionException {
    CompositeEntity container = (CompositeEntity) getContainer();

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

    try {
      _workspace.getWriteAccess();

      int result = container._containedRelations.moveUp(this);

      // Propagate.
      Iterator derivedObjects = getDerivedList().iterator();

      while (derivedObjects.hasNext()) {
        NamedObj derived = (NamedObj) derivedObjects.next();
        container = (CompositeEntity) derived.getContainer();
        container._containedRelations.moveUp(derived);
      }

      return result;
    } finally {
      _workspace.doneWriting();
    }
  }
Пример #3
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;
  }
Пример #4
0
  /**
   * Return the container entity for the specified ASTPtRootNode.
   *
   * @param node The specified ASTPtRootNode.
   * @return The container entity for the specified ASTPtRootNode.
   */
  public Entity getContainerEntity(ASTPtRootNode node) {
    Attribute attribute = _solver.getAttribute(node);
    NamedObj container = attribute.getContainer();

    while (!(container instanceof Entity)) {
      container = container.getContainer();
    }
    return (Entity) container;
  }
Пример #5
0
 /**
  * Find an attribute in the object or its container (if searchContainers is true) in the given
  * class.
  *
  * @param object The object to which the attribute longs.
  * @param attributeClass The attribute class.
  * @param searchContainers Whether containers of the object are searched.
  * @return The attribute if found, or null otherwise.
  */
 public static Attribute findMatchingAttribute(
     Object object, Class<? extends Attribute> attributeClass, boolean searchContainers) {
   if (object instanceof NamedObj) {
     NamedObj namedObj = (NamedObj) object;
     List<?> list = namedObj.attributeList(attributeClass);
     if (!list.isEmpty()) {
       return (Attribute) list.get(0);
     } else if (searchContainers) {
       return findMatchingAttribute(namedObj.getContainer(), attributeClass, searchContainers);
     }
   }
   return null;
 }
Пример #6
0
    /**
     * Create an editor for configuring the specified object with the specified parent window.
     *
     * @param object The object to configure.
     * @param parent The parent window, or null if there is none.
     */
    public void createEditor(NamedObj object, Frame parent) {
      try {
        Configuration configuration = ((TableauFrame) parent).getConfiguration();

        NamedObj _container = (NamedObj) object.getContainer();
        TextEffigy codeEffigy =
            TextEffigy.newTextEffigy(configuration.getDirectory(), generateCode());
        codeEffigy.setModified(true);
        configuration.createPrimaryTableau(codeEffigy);
      } catch (Exception ex) {
        throw new InternalErrorException(
            object, ex, "Cannot generate code. Perhaps outside Vergil?");
      }
    }
Пример #7
0
 /**
  * Return the change request to delete the given object.
  *
  * @param originator The originator of the change request.
  * @param object The object to be deleted.
  * @return The change request.
  */
 public static MoMLChangeRequest getDeletionChangeRequest(Object originator, NamedObj object) {
   String moml;
   if (object instanceof Attribute) {
     moml = "<deleteProperty name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Entity) {
     moml = "<deleteEntity name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Port) {
     moml = "<deletePort name=\"" + object.getName() + "\"/>";
   } else if (object instanceof Relation) {
     moml = "<deleteRelation name=\"" + object.getName() + "\"/>";
   } else {
     return null;
   }
   return new MoMLChangeRequest(originator, object.getContainer(), moml);
 }
Пример #8
0
  /**
   * Get the change request to update the object in the host model.
   *
   * @param pattern The pattern of the transformation rule.
   * @param replacement The replacement of the transformation rule.
   * @param matchResult The match result.
   * @param patternObject The object in the pattern, or null.
   * @param replacementObject The object in the replacement that corresponds to the object in the
   *     pattern.
   * @param hostObject The object in the host model corresponding to the object in the replacement.
   * @return The change request.
   * @exception IllegalActionException If error occurs in generating the change request.
   */
  @Override
  public ChangeRequest getChangeRequest(
      Pattern pattern,
      Replacement replacement,
      MatchResult matchResult,
      NamedObj patternObject,
      NamedObj replacementObject,
      NamedObj hostObject)
      throws IllegalActionException {
    if (_valueParseTree == null) {
      _reparse();
    }

    ParserScope scope = NamedObjVariable.getNamedObjVariable(hostObject, true).getParserScope();
    GTParameter.Evaluator evaluator = new GTParameter.Evaluator(pattern, matchResult);

    String name;
    if (_valueParseTree instanceof ASTPtSumNode) {
      StringBuffer buffer = new StringBuffer();
      for (int i = 0; i < _valueParseTree.jjtGetNumChildren(); i++) {
        ASTPtRootNode child = (ASTPtRootNode) _valueParseTree.jjtGetChild(i);
        if (!(child.isConstant() && child.getToken() instanceof StringToken)) {
          ASTPtLeafNode newNode = _evaluate(child, evaluator, scope);
          buffer.append(_parseTreeWriter.parseTreeToExpression(newNode));
        } else {
          buffer.append(((StringToken) child.getToken()).stringValue());
        }
      }
      name = buffer.toString();
    } else if (!(_valueParseTree.isConstant()
        && _valueParseTree.getToken() instanceof StringToken)) {
      ASTPtRootNode newRoot = _evaluate(_valueParseTree, evaluator, scope);
      name = _parseTreeWriter.parseTreeToExpression(newRoot);
    } else {
      name = _name.get();
    }

    NamedObj parent = hostObject.getContainer();
    String moml =
        "<entity name=\"" + hostObject.getName() + "\"><rename name=\"" + name + "\"/></entity>";
    return new MoMLChangeRequest(this, parent, moml, null);
  }
Пример #9
0
  /**
   * Remove the decorated attributes.
   *
   * @param target The decorated attribute to remove
   */
  public void removeDecoratedAttributes(NamedObj target) {
    if (_debugging) {
      _debug("create decorated attributes to be called for Giotto quantityManager");
    }
    for (Actor actor :
        (List<Actor>) ((TypedCompositeActor) target.getContainer()).deepEntityList()) {
      NamedObj temp = (NamedObj) actor;
      if (_debugging) {
        _debug("temp has name " + temp.getDisplayName());
      }

      List<Parameter> paramList = temp.attributeList();

      for (Parameter param : paramList) {
        if (param.getDisplayName().equals("WCET")) {
          param.setPersistent(false);
        }
      }
    }
  }
Пример #10
0
  /**
   * Given an object in the replacement, return the corresponding object in the pattern if any, or
   * null otherwise.
   *
   * @param replacementObject The object in the replacement.
   * @return The object in the pattern, or null if not found.
   */
  public static NamedObj getCorrespondingPatternObject(NamedObj replacementObject) {
    if (replacementObject instanceof Replacement) {
      return ((TransformationRule) replacementObject.getContainer()).getPattern();
    }

    PatternObjectAttribute attribute;
    try {
      attribute = getPatternObjectAttribute(replacementObject, false);
    } catch (KernelException e) {
      attribute = null;
    }
    if (attribute == null) {
      return null;
    }

    CompositeActorMatcher container = getContainingPatternOrReplacement(replacementObject);
    if (container == null) {
      return null;
    }

    String patternObjectName = attribute.getExpression();
    if (patternObjectName.equals("")) {
      return null;
    }

    TransformationRule transformer = (TransformationRule) container.getContainer();
    Pattern pattern = transformer.getPattern();
    if (replacementObject instanceof Attribute) {
      return pattern.getAttribute(patternObjectName);
    } else if (replacementObject instanceof Entity) {
      return pattern.getEntity(patternObjectName);
    } else if (replacementObject instanceof Relation) {
      return pattern.getRelation(patternObjectName);
    } else {
      return null;
    }
  }
  /**
   * Override the base class so that if the port is being removed from the current container, then
   * it is also removed from the controller and from each of the refinements.
   *
   * @param container The proposed container.
   * @exception IllegalActionException If the proposed container is not a ComponentEntity, doesn't
   *     implement Actor, or has no name, or the port and container are not in the same workspace.
   *     Or it's not null
   * @exception NameDuplicationException If the container already has a port with the name of this
   *     port.
   */
  public void setContainer(Entity container)
      throws IllegalActionException, NameDuplicationException {
    NamedObj oldContainer = getContainer();

    if (container == oldContainer) {
      // Nothing to do.
      return;
    }

    boolean disableStatus = _mirrorDisable;

    try {
      _workspace.getWriteAccess();

      if (_mirrorDisable || (getContainer() == null)) {
        // process request for the sibling
        if (_hasSibling && isOutput() && (getContainer() != null)) {
          TransitionRefinement transContainer = (TransitionRefinement) oldContainer;
          TransitionRefinementPort sibling =
              (TransitionRefinementPort) transContainer.getPort(getName() + "_in");

          sibling._mirrorDisable = true;
          sibling.setContainer(container);
          sibling._mirrorDisable = false;
        }

        // Have already called the super class.
        // This time, process the request.
        super.setContainer(container);
      } else {
        // if this is the input port of a pair of siblings,
        // then forward request to the output port of the pair
        _mirrorDisable = true;

        boolean success = false;
        String portName = getName();

        if (_hasSibling && isInput() && !isOutput()) {
          // we are the input sibling, extract "real" port name
          portName = getName().substring(0, getName().length() - 3);
        }

        if (oldContainer != null) {
          Nameable modal = oldContainer.getContainer();

          if (modal instanceof ModalModel) {
            Port port = ((ModalModel) modal).getPort(portName);

            if (port != null) {
              port.setContainer(null);
              success = true;
            }
          }
        }

        if (!success) {
          super.setContainer(container);
        }
      }
    } finally {
      _mirrorDisable = disableStatus;
      _workspace.doneWriting();
    }
  }
Пример #12
0
  /**
   * Queue a change request to alter the value of the attribute attached to the specified entry, if
   * there is one. This method is called whenever an entry has been changed. If no attribute is
   * attached to the specified entry, then do nothing.
   *
   * @param name The name of the entry that has changed.
   */
  public void changed(final String name) {
    // Check if the entry that changed is in the mapping.
    if (_attributes.containsKey(name)) {
      final Settable attribute = (Settable) (_attributes.get(name));

      if (attribute == null) {
        // No associated attribute.
        return;
      }

      ChangeRequest request;

      if (attribute instanceof PasswordAttribute) {
        // Passwords have to be handled specially because the password
        // is not represented in a string.
        request =
            new ChangeRequest(this, name) {
              protected void _execute() throws IllegalActionException {
                char[] password = getCharArrayValue(name);
                ((PasswordAttribute) attribute).setPassword(password);
                attribute.validate();

                Iterator<?> derived = ((PasswordAttribute) attribute).getDerivedList().iterator();

                while (derived.hasNext()) {
                  PasswordAttribute derivedPassword = (PasswordAttribute) derived.next();
                  derivedPassword.setPassword(password);
                }
              }
            };
      } else if (attribute instanceof NamedObj) {
        // NOTE: We must use a MoMLChangeRequest so that changes
        // propagate to any objects that have been instantiating
        // using this one as a class.  This is only an issue if
        // attribute is a NamedObj.
        NamedObj castAttribute = (NamedObj) attribute;

        String stringValue = getStringValue(name);

        // If the attribute is a DoubleRangeParameter, then we
        // have to translate the integer value returned by the
        // JSlider into a double.
        if (attribute instanceof DoubleRangeParameter) {
          try {
            int newValue = Integer.parseInt(stringValue);
            int precision =
                ((IntToken) ((DoubleRangeParameter) attribute).precision.getToken()).intValue();
            double max =
                ((DoubleToken) ((DoubleRangeParameter) attribute).max.getToken()).doubleValue();
            double min =
                ((DoubleToken) ((DoubleRangeParameter) attribute).min.getToken()).doubleValue();
            double newValueAsDouble = min + (((max - min) * newValue) / precision);
            stringValue = "" + newValueAsDouble;
          } catch (IllegalActionException e) {
            throw new InternalErrorException(e);
          }
        }

        // The context for the MoML should be the first container
        // above this attribute in the hierarchy that defers its
        // MoML definition, or the immediate parent if there is none.
        NamedObj parent = castAttribute.getContainer();
        String moml =
            "<property name=\""
                + castAttribute.getName()
                + "\" value=\""
                + StringUtilities.escapeForXML(stringValue)
                + "\"/>";
        request =
            new MoMLChangeRequest(
                this, // originator
                parent, // context
                moml, // MoML code
                null) { // base
              protected void _execute() throws Exception {
                synchronized (PtolemyQuery.this) {
                  try {
                    _ignoreChangeNotifications = true;
                    super._execute();
                  } finally {
                    _ignoreChangeNotifications = false;
                  }
                }
              }
            };
      } else {
        // If the attribute is not a NamedObj, then we
        // set its value directly.
        request =
            new ChangeRequest(this, name) {
              protected void _execute() throws IllegalActionException {
                attribute.setExpression(getStringValue(name));

                attribute.validate();

                /* NOTE: Earlier version:
                // Here, we need to handle instances of Variable
                // specially.  This is too bad...
                if (attribute instanceof Variable) {

                // Will this ever happen?  A
                // Variable that is not a NamedObj???
                // Retrieve the token to force
                // evaluation, so as to check the
                // validity of the new value.

                ((Variable)attribute).getToken();
                }
                */
              }
            };
      }

      // NOTE: This object is never removed as a listener from
      // the change request.  This is OK because this query will
      // be closed at some point, and all references to it will
      // disappear, and thus both it and the change request should
      // become accessible to the garbage collector.  However, I
      // don't quite trust Java to do this right, since it's not
      // completely clear that it releases resources when windows
      // are closed.  It would be better if this listener were
      // a weak reference.
      // NOTE: This appears to be unnecessary, since we register
      // as a change listener on the handler.  This results in
      // two notifications.  EAL 9/15/02.
      request.addChangeListener(this);

      if (_handler == null) {
        request.execute();
      } else {
        if (request instanceof MoMLChangeRequest) {
          ((MoMLChangeRequest) request).setUndoable(true);
        }

        // Remove the error handler so that this class handles
        // the error through the notification.  Save the previous
        // error handler to restore after this request has been
        // processes.
        _savedErrorHandler = MoMLParser.getErrorHandler();
        MoMLParser.setErrorHandler(null);
        _handler.requestChange(request);
      }
    }
  }