/** Create mapping pairs of objects of the embedding morphisms. */ private void mapKernel2MultiObject(final MultiRule multiRule) { final OrdinaryMorphism embLeft = multiRule.getEmbeddingLeft(); final Enumeration<GraphObject> domLeft = embLeft.getDomain(); while (domLeft.hasMoreElements()) { final GraphObject kern = domLeft.nextElement(); multiRule.mapKernel2MultiObject(kern, embLeft.getImage(kern)); } // final Enumeration<GraphObject> enLeft = multiRule.getLeft().getElements(); // while (enLeft.hasMoreElements()) { // final GraphObject obj = enLeft.nextElement(); // if (embLeft.getInverseImage(obj).hasMoreElements()){ // multiRule.mapKernel2MultiObject(embLeft.getInverseImage(obj).nextElement(), obj); // } // } final OrdinaryMorphism embRight = multiRule.getEmbeddingRight(); final Enumeration<GraphObject> domRight = embRight.getDomain(); while (domRight.hasMoreElements()) { final GraphObject kern = domRight.nextElement(); multiRule.mapKernel2MultiObject(kern, embRight.getImage(kern)); } // final Enumeration<GraphObject> enRight = multiRule.getRight().getElements(); // while (enRight.hasMoreElements()) { // final GraphObject obj = enRight.nextElement(); // if (embRight.getInverseImage(obj).hasMoreElements()) { // multiRule.mapKernel2MultiObject(embRight.getInverseImage(obj).nextElement(), obj); // } // } }
/** * 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(); }
/** * Replicate remove rule mapping of the kernel rule. * * @param go graph object of the kernel rule * @param left true if graph object belongs to the LHS of the kernel rule, otherwise false */ public void propagateRemoveRuleMappingToMultiRule(final GraphObject go, boolean left) { for (int i = 0; i < this.multiRules.size(); i++) { final MultiRule multiRule = (MultiRule) this.multiRules.get(i); if (left) { GraphObject objL = multiRule.getEmbeddingLeft().getImage(go); if (objL != null) multiRule.removeMapping(go); } else { GraphObject objR = multiRule.getEmbeddingRight().getImage(go); if (objR != null && this.getInverseImage(objR).hasMoreElements()) multiRule.removeMapping(this.getInverseImage(go).nextElement()); } } }
/** * Replicate new rule mapping of the kernel rule. * * @param leftgo graph object of the LHS of the kernel rule * @param rightgo graph object of the RHS of the kernel rule * @throws BadMappingException */ public void propagateAddRuleMappingToMultiRule( final GraphObject leftgo, final GraphObject rightgo) throws BadMappingException { for (int i = 0; i < this.multiRules.size(); i++) { final MultiRule multiRule = (MultiRule) this.multiRules.get(i); try { GraphObject objL = multiRule.getEmbeddingLeft().getImage(leftgo); GraphObject objR = multiRule.getEmbeddingRight().getImage(rightgo); if (objL != null && objR != null) multiRule.addMapping(objL, objR); } catch (BadMappingException ex) { System.out.println( "RuleScheme.propagateCreatedMappingToMultiRule: " + ex.getLocalizedMessage()); throw ex; } } }
/** * 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(); } }