public static void transform(GraGra grammar, GraTraEventListener l) {
    if (grammar == null) return;

    System.out.println(grammar.getGraTraOptions().toString());
    createGraTraInstance(grammar);

    gratra.addGraTraListener(l);
    gratra.setGraGra(grammar);
    gratra.setHostGraph(grammar.getGraph());
    gratra.enableWriteLogFile(writeLogFile);

    MorphCompletionStrategy strategy = CompletionStrategySelector.getDefault();
    // strategy = new Completion_NAC(new Completion_InjCSP());

    if (grammar.getGraTraOptions().isEmpty()) {
      grammar.setGraTraOptions(strategy);
      gratra.setCompletionStrategy(strategy);
    } else {
      if (grammar.getGraTraOptions().contains("showGraphAfterStep"))
        grammar.getGraTraOptions().remove("showGraphAfterStep");
      gratra.setGraTraOptions(grammar.getGraTraOptions());
      System.out.println("Options:  " + grammar.getGraTraOptions());
      System.out.println();
    }

    grammar.destroyAllMatches();

    if (priority) ((PriorityGraTraImpl) gratra).transform();
    else if (layered) ((LayeredGraTraImpl) gratra).transform();
    else if (ruleSequence) ((RuleSequencesGraTraImpl) gratra).transform();
    else ((DefaultGraTraImpl) gratra).transform();
  }
  public void transform() {
    this.stopping = false;

    if (!this.grammar.getListOfRules().isEmpty() && this.currentRuleSet.isEmpty()) setRuleSet();

    if (this.writeLogFile) {
      String dirName = this.grammar.getDirName();
      String fileName = this.grammar.getFileName();
      if ((fileName == null) || fileName.equals("")) fileName = this.grammar.getName();
      openTransformProtocol(dirName, fileName);
      String version = "Version:  AGG " + Version.getID() + "\n";
      writeTransformProtocol(version);
      String s0 = "Graph transformation by rule priority of : " + this.grammar.getName();
      String s1 = "at graph : " + this.grammar.getGraph().getName();
      String s2 = getRuleNames(this.currentRuleSet);
      writeTransformProtocol(s0);
      writeTransformProtocol(s1);
      writeTransformProtocol(s2);
      writeTransformProtocol("\n");
    }
    // first check the rules, the graph
    if (!this.grammarChecked) {
      Pair<Object, String> pair = this.grammar.isReadyToTransform(true);
      if (pair != null) {
        Object test = pair.first;
        if (test != null) {
          String s0 = pair.second + "\nTransformation is stopped.";

          if (test instanceof Type)
            ((GraTra) this).fireGraTra(new GraTraEvent(this, GraTraEvent.ATTR_TYPE_FAILED, s0));
          else if (test instanceof Rule)
            ((GraTra) this).fireGraTra(new GraTraEvent(this, GraTraEvent.RULE_FAILED, s0));
          else if (test instanceof AtomConstraint)
            ((GraTra) this).fireGraTra(new GraTraEvent(this, GraTraEvent.ATOMIC_GC_FAILED, s0));
          transformFailed(s0);
          return;
        }
      } else if (!this.grammar.isGraphReadyForTransform()) {
        String s0 =
            "Graph of the grammar is not fine."
                + "\nPlease check attribute settings of the objects. \nTransformation is stopped.";
        ((GraTra) this).fireGraTra(new GraTraEvent(this, GraTraEvent.GRAPH_FAILED, s0));
        transformFailed(s0);
        return;
      } else if (!this.checkGraphConsistency()) {
        String s =
            "Graph consistency failed."
                + "\nPlease check the host graph against the graph constraints."
                + "\nTransformation is stopped.";
        ((GraTra) this).fireGraTra(new GraTraEvent(this, GraTraEvent.GRAPH_FAILED, s));
        transformFailed(s);
        return;
      }
      this.grammarChecked = true;
    }

    // stop start time
    long startTime = System.currentTimeMillis();
    //		time0 = startTime;

    Vector<Rule> ruleSet = getEnabledRules(this.currentRuleSet);
    transform(ruleSet);

    if (this.options.hasOption(GraTraOptions.CONSISTENCY_CHECK_AFTER_GRAPH_TRAFO)) {
      this.checkGraphConsistency();
    }

    // stop time
    System.out.println(
        "Used time for graph transformation:  " + (System.currentTimeMillis() - startTime) + "ms");

    if (this.writeLogFile) {
      writeUsedTimeToProtocol("Used time for graph transformation: ", startTime);
      writeTransformProtocol("\nGraph transformation finished");
      closeTransformProtocol();
    }

    fireGraTra(new GraTraEvent(this, GraTraEvent.TRANSFORM_FINISHED, this.errorMsg));
  }