Пример #1
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;
    }
  }