01: package org.drools.lang.descr;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: public class OrDescr extends BaseDescr implements
23: ConditionalElementDescr {
24: /**
25: *
26: */
27: private static final long serialVersionUID = 400L;
28: private List descrs = new ArrayList();
29:
30: public OrDescr() {
31: }
32:
33: public void insertBeforeLast(final Class clazz,
34: final BaseDescr baseDescr) {
35: if (clazz.isInstance(baseDescr)) {
36: for (int i = this .descrs.size() - 1; i >= 0; i--) {
37: if (this .descrs.get(i) instanceof FieldConstraintDescr) {
38: insertDescr(i - 1, baseDescr);
39: return;
40: }
41: }
42: }
43: }
44:
45: public void insertDescr(int index, final BaseDescr baseDescr) {
46: this .descrs.add(index, baseDescr);
47: }
48:
49: public void addDescr(final BaseDescr baseDescr) {
50: this .descrs.add(baseDescr);
51: }
52:
53: public List getDescrs() {
54: return this .descrs;
55: }
56:
57: public void addOrMerge(final BaseDescr baseDescr) {
58: if (baseDescr instanceof OrDescr) {
59: this .descrs.addAll(((OrDescr) baseDescr).getDescrs());
60: } else {
61: this.descrs.add(baseDescr);
62: }
63: }
64:
65: }
|