Package org.drools.guvnor.client.modeldriven.brl

Examples of org.drools.guvnor.client.modeldriven.brl.RuleModel


    for (int i = 0; i < dt.data.length; i++) {
      String[] row = dt.data[i];
      String num = row[0];
      String desc = row[1];

      RuleModel rm = new RuleModel();
      rm.name = getName(dt.tableName, num);

      doMetadata(dt.getMetadataCols(), row, rm);
      doAttribs(dt.getMetadataCols().size(), dt.attributeCols, row, rm);
      doConditions(dt.getMetadataCols().size() + dt.attributeCols.size(), dt.conditionCols, row, rm);
View Full Code Here


    public void addPackageFromBrl(final Resource resource) throws DroolsParserException,
                                                          IOException {
        this.resource = resource;

        String brl = loadBrlFile( resource.getReader() );
        RuleModel model = BRXMLPersistence.getInstance().unmarshal( brl );
        String drl = BRDRLPersistence.getInstance().marshal( model );
        final DrlParser parser = new DrlParser();
        DefaultExpander expander = getDslExpander();

        try {
View Full Code Here

    public void addPackageFromBrl(final Resource resource)
      throws DroolsParserException, IOException {
    this.resource = resource;

        String brl = loadBrlFile(resource.getReader());
    RuleModel model = BRXMLPersistence.getInstance().unmarshal(brl);
    String drl = BRDRLPersistence.getInstance().marshal(model);
        final DrlParser parser = new DrlParser();
        DefaultExpander expander = getDslExpander();

        try {
View Full Code Here

    for (int i = 0; i < dt.data.length; i++) {
      String[] row = dt.data[i];
      String num = row[0];
      String desc = row[1];

      RuleModel rm = new RuleModel();
      rm.name = getName(dt.tableName, num);

      doMetadata(dt.getMetadataCols(), row, rm);
      doAttribs(dt.getMetadataCols().size(), dt.attributeCols, row, rm);
      doConditions(dt.getMetadataCols().size() + dt.attributeCols.size(), dt.conditionCols, row, rm);
View Full Code Here

import com.thoughtworks.xstream.XStream;

public class RuleModelTest extends TestCase {

  public void testAddItemLhs() {
    final RuleModel model = new RuleModel();
    final FactPattern x = new FactPattern();
    model.addLhsItem(x);
    assertEquals(1, model.lhs.length);

    final FactPattern y = new FactPattern();
    model.addLhsItem(y);

    assertEquals(2, model.lhs.length);
    assertEquals(x, model.lhs[0]);
    assertEquals(y, model.lhs[1]);
View Full Code Here

    assertEquals(y, model.lhs[1]);

  }

  public void testAddItemRhs() {
    final RuleModel model = new RuleModel();
    final IAction a0 = new ActionSetField();
    final IAction a1 = new ActionSetField();

    model.addRhsItem(a0);

    assertEquals(1, model.rhs.length);
    model.addRhsItem(a1);

    assertEquals(2, model.rhs.length);

    assertEquals(a0, model.rhs[0]);
    assertEquals(a1, model.rhs[1]);
View Full Code Here

    assertEquals(a0, model.rhs[0]);
    assertEquals(a1, model.rhs[1]);
  }

  public void testAllVariableBindings() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[2];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "boundFact";

    SingleFieldConstraint sfc = new SingleFieldConstraint("q");
    x.addConstraint(sfc);
    sfc.fieldBinding = "field1";

    SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
    x.addConstraint(sfc2);
    sfc2.fieldBinding = "field2";

    model.lhs[1] = new CompositeFactPattern();

    List vars = model.getAllVariables();
    assertEquals(3, vars.size());
    assertEquals("boundFact", vars.get(0));
    assertEquals("field1", vars.get(1));
    assertEquals("field2", vars.get(2));

    assertTrue(model.isVariableNameUsed("field2"));

  }
View Full Code Here

    assertTrue(model.isVariableNameUsed("field2"));

  }

  public void testAttributes() {
    final RuleModel m = new RuleModel();
    final RuleAttribute at = new RuleAttribute("salience", "42");
    m.addAttribute(at);
    assertEquals(1, m.attributes.length);
    assertEquals(at, m.attributes[0]);

    final RuleAttribute at2 = new RuleAttribute("agenda-group", "x");
    m.addAttribute(at2);
    assertEquals(2, m.attributes.length);
    assertEquals(at2, m.attributes[1]);

    m.removeAttribute(0);
    assertEquals(1, m.attributes.length);
    assertEquals(at2, m.attributes[0]);
  }
View Full Code Here

    assertEquals(1, m.attributes.length);
    assertEquals(at2, m.attributes[0]);
  }

  public void testBindingList() {
    final RuleModel model = new RuleModel();

    model.lhs = new IPattern[3];
    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "x";

    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.boundName = "y";

    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;

    final List b = model.getBoundFacts();
    assertEquals(2, b.size());

    assertEquals("x", b.get(0));
    assertEquals("y", b.get(1));
View Full Code Here

    assertEquals("y", b.get(1));

  }

  public void testBoundFactFinder() {
    final RuleModel model = new RuleModel();

    assertNull(model.getBoundFact("x"));
    model.lhs = new IPattern[3];

    final FactPattern x = new FactPattern("Car");
    model.lhs[0] = x;
    x.boundName = "x";

    assertNotNull(model.getBoundFact("x"));
    assertEquals(x, model.getBoundFact("x"));

    final FactPattern y = new FactPattern("Car");
    model.lhs[1] = y;
    y.boundName = "y";

    final FactPattern other = new FactPattern("House");
    model.lhs[2] = other;

    assertEquals(y, model.getBoundFact("y"));
    assertEquals(x, model.getBoundFact("x"));

    model.rhs = new IAction[1];
    final ActionSetField set = new ActionSetField();
    set.variable = "x";
    model.rhs[0] = set;

    assertTrue(model.isBoundFactUsed("x"));
    assertFalse(model.isBoundFactUsed("y"));

    assertEquals(3, model.lhs.length);
    assertFalse(model.removeLhsItem(0));
    assertEquals(3, model.lhs.length);

    final ActionRetractFact fact = new ActionRetractFact("q");
    model.rhs[0] = fact;
    assertTrue(model.isBoundFactUsed("q"));
    assertFalse(model.isBoundFactUsed("x"));

    final XStream xt = new XStream();
    xt.alias("rule", RuleModel.class);
    xt.alias("fact", FactPattern.class);
    xt.alias("retract", ActionRetractFact.class);
View Full Code Here

TOP

Related Classes of org.drools.guvnor.client.modeldriven.brl.RuleModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.