/**
   * 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);
  }
  /**
   * 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();
    }

    String attributeName = ((StringToken) _attributeName.getToken()).stringValue();
    String attributeClass;
    if (isAttributeClassEnabled()) {
      attributeClass = _attributeClass;
    } else {
      Attribute oldAttribute = hostObject.getAttribute(attributeName);
      if (oldAttribute == null) {
        throw new IllegalActionException(
            "Unable to determine the class"
                + " of attribute "
                + _attributeName
                + " for entity "
                + hostObject
                + ".");
      }
      attributeClass = oldAttribute.getClassName();
    }

    ParserScope scope = NamedObjVariable.getNamedObjVariable(hostObject, true).getParserScope();
    GTParameter.Evaluator evaluator = new GTParameter.Evaluator(pattern, matchResult);
    String expression;
    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());
        }
      }
      expression = buffer.toString();
    } else if (!(_valueParseTree.isConstant()
        && _valueParseTree.getToken() instanceof StringToken)) {
      ASTPtRootNode newRoot = _evaluate(_valueParseTree, evaluator, scope);
      expression = _parseTreeWriter.parseTreeToExpression(newRoot);
    } else {
      expression = _attributeValue.get();
    }
    String moml =
        "<property name=\""
            + attributeName
            + "\" class=\""
            + attributeClass
            + "\" value=\""
            + StringUtilities.escapeForXML(expression)
            + "\"/>";
    return new MoMLChangeRequest(this, hostObject, moml, null);
  }