Esempio n. 1
0
  public GraGra load(String fName) {
    if (fName.endsWith(".ggx")) {
      h = new XMLHelper();
      if (h.read_from_xml(fName)) {

        // create a gragra
        GraGra gra = new GraGra(false);
        h.getTopObject(gra);
        gra.setFileName(fName);
        return gra;
      }
      return null;
    }
    return null;
  }
Esempio n. 2
0
 public static void save(GraGra gra, String outFileName) {
   if (outFileName.equals("")) outputFileName = gra.getName() + "_out.ggx";
   else if (outFileName.equals("_out.ggx"))
     outputFileName = fileName.substring(0, fileName.length() - 4) + "_out.ggx";
   else if (outFileName.indexOf(".ggx") == -1) outputFileName = outFileName.concat(".ggx");
   else if (outFileName.equals(fileName))
     outputFileName = fileName.substring(0, fileName.length() - 4) + "_out.ggx";
   else {
     outputFileName = outFileName;
   }
   if (outputFileName.endsWith(".ggx")) {
     XMLHelper xmlh = new XMLHelper();
     xmlh.addTopObject(gra);
     xmlh.save_to_xml(outputFileName);
   }
 }
Esempio n. 3
0
  /**
   * Load the rule scheme.
   *
   * @param h AGG XML helper
   */
  public void XreadObject(XMLHelper h) {
    if (h.isTag("RuleScheme", this)) {
      Object attr_str = "";

      //			setSchemeName(h.readAttr("name"));

      attr_str = h.readAttr("atLeastOneMultiMatch");
      if (!"".equals(attr_str)) {
        this.atLeastOneMultiMatch = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("checkConflict");
      if (!"".equals(attr_str)) {
        this.checkDeleteUseConflict = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("disjointMultis");
      if (!"".equals(attr_str)) {
        this.disjointMultis = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("enabled");
      if (!"".equals(attr_str)) {
        this.enabled = Boolean.valueOf((String) attr_str).booleanValue();
      }

      attr_str = h.readAttr("index");
      if (!"".equals(attr_str)) {
        this.itsIndex = Integer.valueOf((String) attr_str).intValue();
      }

      attr_str = h.readAttr("name");
      if (!"".equals(attr_str)) {
        setSchemeName((String) attr_str);
      }

      attr_str = h.readAttr("parallelKernel");
      if (!"".equals(attr_str)) {
        this.parallelKernel = Boolean.valueOf((String) attr_str).booleanValue();
      }

      if (h.readSubTag("Kernel")) {
        h.getObject("", this.kernelRule, true);
        h.close();
        this.kernelRule.getLeft().setKind(GraphKind.LHS);
        this.kernelRule.getRight().setKind(GraphKind.RHS);
        this.kernelRule.setRuleScheme(this);
      }

      while (h.readSubTag("Multi")) {
        MultiRule mr = createEmptyMultiRule();
        h.getObject("", mr, true);

        if (h.readSubTag("EmbeddingLeft")) {
          mr.getEmbeddingLeft().readMorphism(h);
          h.close();
        }

        if (h.readSubTag("EmbeddingRight")) {
          mr.getEmbeddingRight().readMorphism(h);
          h.close();
        }
        h.close();

        mr.getLeft().setKind(GraphKind.LHS);
        mr.getRight().setKind(GraphKind.RHS);

        mr.setRuleScheme(this);
        mr.applyEmbeddedRuleMapping(this.kernelRule);
        mapKernel2MultiObject(mr);

        this.kernelRule.getLeft().addObserver(mr);
        this.kernelRule.getRight().addObserver(mr);
      }

      this.kernelRule.setChanged(false);

      //			if (h.readSubTag("Amalgamated")) {
      //				this.amalgamRule = new AmalgamatedRule(this.getTypeSet());
      //				h.getObject("", amalgamRule, true);
      //				h.close();
      //				this.amalgamRule.setRuleScheme(this);
      //
      //				if (h.readSubTag("MatchOf")) {
      //					Object obj = h.getObject("Rule", null, false);
      //					if (obj instanceof Rule) {
      //						Rule r = (Rule) obj;
      //						Match m = createMatch(r);
      //						h.getObject("Match", m, true);
      //						if (m.getSize() > 0)
      //							m.setPartialMorphismCompletion(true);
      //					}
      //					h.close();
      //				}
      //			}

      // read layer
      if (h.readSubTag("TaggedValue")) {
        int v = 0;
        String t = h.readAttr("Tag");
        // read new attribute
        int v2 = h.readIAttr("TagValue");
        if (v2 > 0) v = v2;
        if (t.equals("layer")) this.layer = v;
        h.close();
      }

      // read priority
      if (h.readSubTag("TaggedValue")) {
        int v = 0;
        String t = h.readAttr("Tag");
        // read new attribute
        int v2 = h.readIAttr("TagValue");
        if (v2 > 0) v = v2;
        if (t.equals("priority")) this.priority = v;
        h.close();
      }
      h.close();
    }
  }
Esempio n. 4
0
  /**
   * Save the rule scheme.
   *
   * @param h AGG XML helper
   */
  public void XwriteObject(XMLHelper h) {
    h.openNewElem("RuleScheme", this);
    h.addAttr("name", this.schemeName);
    if (!this.enabled) h.addAttr("enabled", "false");

    h.addAttr("disjointMultis", String.valueOf(this.disjointMultis));
    h.addAttr("parallelKernel", String.valueOf(this.parallelKernel));
    h.addAttr("checkConflict", String.valueOf(this.checkDeleteUseConflict));
    h.addAttr("atLeastOneMultiMatch", String.valueOf(this.atLeastOneMultiMatch));
    h.addAttr("index", this.itsIndex);

    h.openSubTag("Kernel");
    h.addObject("", this.kernelRule, true);
    h.close();

    for (int i = 0; i < this.multiRules.size(); i++) {
      h.openSubTag("Multi");
      final MultiRule r = (MultiRule) this.multiRules.get(i);
      h.addObject("", r, true);

      h.openSubTag("EmbeddingLeft");
      r.getEmbeddingLeft().writeMorphism(h);
      h.close();

      h.openSubTag("EmbeddingRight");
      r.getEmbeddingRight().writeMorphism(h);
      h.close();

      h.close();
    }

    if (this.amalgamRule != null) {
      h.openSubTag("Amalgamated");
      h.addObject("", this.amalgamRule, true);
      h.close();

      //			if (this.amalgamRule.getMatch() != null) {
      //				this.amalgamRule.getMatch().setName("MatchOf_" + this.amalgamRule.getName());
      //				h.openSubTag("MatchOf");
      //				h.addObject("Rule", this.amalgamRule, false);
      //				h.addObject("", this.amalgamRule.getMatch(), true);
      //				h.close();
      //			}
    }

    // TaggedValue layer
    h.openSubTag("TaggedValue");
    h.addAttr("Tag", "layer");
    h.addAttr("TagValue", this.layer);
    h.close();

    // TaggedValue priority
    h.openSubTag("TaggedValue");
    h.addAttr("Tag", "priority");
    h.addAttr("TagValue", this.priority);
    h.close();

    h.close();
  }
  /**
   * Reads the contents of a xml file to restore this object.
   *
   * @param h A helper object for loading.
   */
  public void XreadObject(XMLHelper h) {
    if (h.isTag("CriticalPairs", this)) {
      // System.out.println("LayerExcludePairContainer.XreadObject ...");
      Rule r1 = null;
      Rule r2 = null;
      boolean b = false;
      Vector<
              Pair<
                  Pair<OrdinaryMorphism, OrdinaryMorphism>,
                  Pair<OrdinaryMorphism, OrdinaryMorphism>>>
          allOverlappings = null;
      Vector<String> tagnames = new Vector<String>(1);
      Vector<String> tagnames2 = new Vector<String>(1);

      this.grammar = BaseFactory.theFactory().createGraGra();
      h.getObject("", this.grammar, true);

      tagnames.add("conflictContainer");
      tagnames.add("conflictsContainer");
      tagnames.add("excludeContainer");

      tagnames2.add("dependencyContainer");
      tagnames2.add("dependenciesContainer");

      this.switchDependency = false;

      if (h.readSubTag(tagnames2)) {
        this.conflictKind = CriticalPair.TRIGGER_DEPENDENCY;
        if (h.readAttr("kind").equals("trigger_switch_dependency")) {
          this.switchDependency = true;
          this.conflictKind = CriticalPair.TRIGGER_SWITCH_DEPENDENCY;
        }
      } else if (h.readSubTag(tagnames)) {
        this.conflictKind = CriticalPair.CONFLICT;
      }

      if (this.conflictKind == CriticalPair.TRIGGER_DEPENDENCY
          || this.conflictKind == CriticalPair.TRIGGER_SWITCH_DEPENDENCY
          || this.conflictKind == CriticalPair.CONFLICT) {
        Enumeration<?> r1s = h.getEnumeration("", null, true, "Rule");
        if (!r1s.hasMoreElements()) r1s = h.getEnumeration("", null, true, "Regel");
        while (r1s.hasMoreElements()) {
          h.peekElement(r1s.nextElement());
          /*
           * da ein referenziertes object geholt werden soll. muss nur
           * angegeben werden wie der Membername heisst.
           */
          r1 = (Rule) h.getObject("R1", null, false);
          Enumeration<?> r2s = h.getEnumeration("", null, true, "Rule");
          if (!r2s.hasMoreElements()) r2s = h.getEnumeration("", null, true, "Regel");
          while (r2s.hasMoreElements()) {
            h.peekElement(r2s.nextElement());
            r2 = (Rule) h.getObject("R2", null, false);
            String bool = h.readAttr("bool");
            allOverlappings = null;
            b = false;
            if (bool.equals("true")) {
              b = true;
              allOverlappings =
                  new Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>();
              Enumeration<?> overlappings = h.getEnumeration("", null, true, "Overlapping_Pair");
              while (overlappings.hasMoreElements()) {
                h.peekElement(overlappings.nextElement());
                Graph g = (Graph) h.getObject("", new Graph(), true);

                while (h.readSubTag("Critical")) {
                  GraphObject o = (GraphObject) h.getObject("object", null, false);
                  if (o != null) o.setCritical(true);
                  h.close();
                }
                /*
                 * OrdinaryMorphism first =
                 * BaseFactory.theFactory().createMorphism(r1.getRight(),g);
                 * first.readMorphism(h); OrdinaryMorphism
                 * second =
                 * BaseFactory.theFactory().createMorphism(r2.getLeft(),g);
                 * second.readMorphism(h);
                 * allOverlappings.addElement(new
                 * Pair(first,second));
                 */

                Pair<
                        Pair<OrdinaryMorphism, OrdinaryMorphism>,
                        Pair<OrdinaryMorphism, OrdinaryMorphism>>
                    p = readOverlappingMorphisms(h, r1, r2, g);
                allOverlappings.addElement(p);

                h.close();
              }
            }
            addQuadruple(this.excludeContainer, r1, r2, b, allOverlappings);
            h.close();
          }
          h.close();
        }
        h.close();
        // System.out.println("excludeContainer
        // "+excludeContainer+"\n");
      } /* Ende readSubTag("excludeContainer") */
      if (h.readSubTag("conflictFreeContainer")) {
        Enumeration<?> r1s = h.getEnumeration("", null, true, "Rule");
        if (!r1s.hasMoreElements()) r1s = h.getEnumeration("", null, true, "Regel");
        while (r1s.hasMoreElements()) {
          h.peekElement(r1s.nextElement());
          /*
           * da ein referenziertes object geholt werden soll. muss nur
           * angegeben werden wie der Membername heisst.
           */
          r1 = (Rule) h.getObject("R1", null, false);
          Enumeration<?> r2s = h.getEnumeration("", null, true, "Rule");
          if (!r2s.hasMoreElements()) r2s = h.getEnumeration("", null, true, "Regel");
          while (r2s.hasMoreElements()) {
            h.peekElement(r2s.nextElement());
            r2 = (Rule) h.getObject("R2", null, false);
            String bool = h.readAttr("bool");
            b = false;
            if (bool.equals("true")) b = true;
            addQuadruple(this.conflictFreeContainer, r1, r2, b, null);

            if (!r1.isEnabled()) // test disabled rule
            this.getEntry(r1, r2).state = Entry.DISABLED;
            else if (r1.getLayer() != r2.getLayer()) // test rule
              // layer
              this.getEntry(r1, r2).state = Entry.NOT_RELATED;

            h.close();
          }
          h.close();
        }
        h.close();
        // System.out.println("conflictFreeContainer
        // "+conflictFreeContainer+"\n");
      }
    }
    // isComputed = true;
    h.close();
  }
  /**
   * Writes the contents of this object to a file in a xml format.
   *
   * @param h A helper object for storing.
   */
  public void XwriteObject(XMLHelper h) {
    h.openNewElem("CriticalPairs", this);
    h.addObject("GraGra", getGrammar(), true);
    h.openSubTag("dependenciesContainer");

    String kind = "trigger_dependency";
    if (this.switchDependency) kind = "trigger_switch_dependency";
    h.addAttr("kind", kind);

    // Inhalt von excludeContainer schreiben (save)
    for (Enumeration<Rule> keys = this.excludeContainer.keys(); keys.hasMoreElements(); ) {
      Rule r1 = keys.nextElement();
      h.openSubTag("Rule");
      h.addObject("R1", r1, false);

      Hashtable<
              Rule,
              Pair<
                  Boolean,
                  Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>>>
          secondPart = this.excludeContainer.get(r1);
      for (Enumeration<Rule> k2 = secondPart.keys(); k2.hasMoreElements(); ) {
        Rule r2 = k2.nextElement();
        h.openSubTag("Rule");
        h.addObject("R2", r2, false);
        Pair<
                Boolean,
                Vector<
                    Pair<
                        Pair<OrdinaryMorphism, OrdinaryMorphism>,
                        Pair<OrdinaryMorphism, OrdinaryMorphism>>>>
            p = secondPart.get(r2);
        Boolean b = p.first;
        h.addAttr("bool", b.toString());
        if (b.booleanValue()) {
          Vector<
                  Pair<
                      Pair<OrdinaryMorphism, OrdinaryMorphism>,
                      Pair<OrdinaryMorphism, OrdinaryMorphism>>>
              v = p.second;
          for (int i = 0; i < v.size(); i++) {
            Pair<Pair<OrdinaryMorphism, OrdinaryMorphism>, Pair<OrdinaryMorphism, OrdinaryMorphism>>
                p2i = v.elementAt(i);
            Pair<OrdinaryMorphism, OrdinaryMorphism> p2 = p2i.first;
            h.openSubTag("Overlapping_Pair");
            OrdinaryMorphism first = p2.first;
            Graph overlapping = first.getImage();
            /*
             * durch das true macht der String am Anfang keinen Sinn
             */
            h.addObject("", overlapping, true);

            Iterator<?> e = overlapping.getNodesSet().iterator();
            while (e.hasNext()) {
              GraphObject o = (GraphObject) e.next();
              if (o.isCritical()) {
                h.openSubTag("Critical");
                h.addObject("object", o, false);
                h.close();
              }
            }
            e = overlapping.getArcsSet().iterator();
            while (e.hasNext()) {
              GraphObject o = (GraphObject) e.next();
              if (o.isCritical()) {
                h.openSubTag("Critical");
                h.addObject("object", o, false);
                h.close();
              }
            }

            /*
             * first.writeMorphism(h);
             * ((OrdinaryMorphism)p2.second).writeMorphism(h);
             */

            writeOverlapMorphisms(h, r1, r2, p2i);

            h.close();
          }
        }
        h.close();
      }

      h.close();
    }
    h.close();
    h.openSubTag("conflictFreeContainer");
    for (Enumeration<Rule> keys = this.excludeContainer.keys(); keys.hasMoreElements(); ) {
      Rule r1 = keys.nextElement();
      h.openSubTag("Rule");
      h.addObject("R1", r1, false);

      Hashtable<
              Rule,
              Pair<
                  Boolean,
                  Vector<
                      Pair<
                          Pair<OrdinaryMorphism, OrdinaryMorphism>,
                          Pair<OrdinaryMorphism, OrdinaryMorphism>>>>>
          secondPart = this.conflictFreeContainer.get(r1);
      for (Enumeration<Rule> k2 = secondPart.keys(); k2.hasMoreElements(); ) {
        Rule r2 = k2.nextElement();
        h.openSubTag("Rule");
        h.addObject("R2", r2, false);
        Boolean b = secondPart.get(r2).first;
        h.addAttr("bool", b.toString());
        h.close();
      }

      h.close();
    }
    h.close();
    h.close();
  }