01: package org.drools.brms.client.modeldriven.brl;
02:
03: /**
04: * This is a field constraint that may span multiple fields.
05: *
06: * @author Michael Neale
07: */
08: public class CompositeFieldConstraint implements FieldConstraint {
09:
10: /**
11: * Means that any of the children can resolve to be true.
12: */
13: public static final String COMPOSITE_TYPE_OR = "||";
14:
15: /**
16: * Means that ALL of the children constraints must resolve to be true.
17: */
18: public static final String COMPOSITE_TYPE_AND = "&&";
19:
20: /**
21: * The type of composite that it is.
22: */
23: public String compositeJunctionType = null;
24:
25: /**
26: * This is the child field constraints of the composite.
27: * They may be single constraints, or composite themselves.
28: * If this composite is it at the "top level" - then
29: * there is no need to look at the compositeType property
30: * (as they are all children that are "anded" together anyway in the fact
31: * pattern that contains it).
32: */
33: public FieldConstraint[] constraints = null;
34:
35: public void addConstraint(final FieldConstraint constraint) {
36: if (this .constraints == null) {
37: this .constraints = new FieldConstraint[1];
38: this .constraints[0] = constraint;
39: } else {
40: final FieldConstraint[] newList = new FieldConstraint[this .constraints.length + 1];
41: for (int i = 0; i < this .constraints.length; i++) {
42: newList[i] = this .constraints[i];
43: }
44: newList[this .constraints.length] = constraint;
45: this .constraints = newList;
46: }
47: }
48:
49: public void removeConstraint(final int idx) {
50: //Unfortunately, this is kinda duplicate code with other methods,
51: //but with typed arrays, and GWT, its not really possible to do anything "better"
52: //at this point in time.
53: final FieldConstraint[] newList = new FieldConstraint[this .constraints.length - 1];
54: int newIdx = 0;
55: for (int i = 0; i < this.constraints.length; i++) {
56:
57: if (i != idx) {
58: newList[newIdx] = this.constraints[i];
59: newIdx++;
60: }
61:
62: }
63: this.constraints = newList;
64:
65: }
66:
67: }
|