コード例 #1
0
 private void transformFailed(String text) {
   System.out.println(text);
   writeTransformProtocol(text);
   writeTransformProtocol("\nGraph transformation failed");
   // fireGraTra(new GraTraEvent(this,GraTraEvent.TRANSFORM_FAILED,
   // this.errorMsg));
   fireGraTra(new GraTraEvent(this, GraTraEvent.TRANSFORM_FINISHED, this.errorMsg));
   closeTransformProtocol();
 }
コード例 #2
0
 private boolean applyRule(Rule r) {
   boolean applied = false;
   while (apply(r)) {
     applied = true;
     break;
   }
   String s0 = r.getName() + " \t applied:  " + applied;
   System.out.println(s0);
   writeTransformProtocol(s0);
   String s1 = "";
   if (!applied) {
     s1 = s1 + getErrorMsg();
     writeTransformProtocol(s1);
   }
   return applied;
 }
コード例 #3
0
 public void transform(List<Rule> ruleSet) {
   //		allRulesEnabled = true;
   this.currentRuleSet.clear();
   this.currentRuleSet.addAll(ruleSet);
   boolean result = apply();
   if (!result && !this.priorityGraTra)
     writeTransformProtocol("Graph transformation failed. No rule priority used.");
 }
コード例 #4
0
  private void openTransformProtocol(String dirName, String fileName) {
    String dName = dirName;
    String fName = "PriorityGraTra.log";
    // System.out.println("PriorityGraTraImpl.openTransformProtocol:
    // dirName: "+dirName);
    // System.out.println("PriorityGraTraImpl.openTransformProtocol:
    // fileName: "+fileName);
    if ((fileName != null) && !fileName.equals("")) {
      if (fileName.endsWith(".ggx"))
        fName = fileName.substring(0, fileName.length() - 4) + "_GraTra.log";
      else fName = fileName + "_GraTra.log";
    }
    // System.out.println(fName);

    if ((dName != null) && !dName.equals("")) {
      this.f = new File(dirName);
      if (this.f.exists()) {
        if (this.f.isFile()) {
          if (this.f.getParent() != null) dName = this.f.getParent() + File.separator;
          else dName = "." + File.separator;
        } else if (this.f.isDirectory()) {
          // System.out.println(dirName);
          dName = this.f.getPath() + File.separator;
        } else dName = "." + File.separator;
      } else dName = "." + File.separator;
      this.f = new File(dirName + fName);
    } else this.f = new File(fName);

    try {
      this.os = new FileOutputStream(this.f);
      this.protocolFileName = this.f.getName();
    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
    }

    writeTransformProtocol((new Date()).toString());
  }
コード例 #5
0
  private void writeUsedTimeToProtocol(String text, long beginTime) {
    writeTransformProtocol(text + +(System.currentTimeMillis() - beginTime) + "ms");

    //		time0 = System.currentTimeMillis();
  }
コード例 #6
0
  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));
  }