01: package org.drools.conflict;
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 org.drools.spi.Activation;
20: import org.drools.spi.ConflictResolver;
21:
22: /**
23: * Strategy for resolving conflicts amongst multiple rules.
24: *
25: * <p>
26: * Since a fact or set of facts may activate multiple rules, a
27: * <code>ConflictResolutionStrategy</code> is used to provide priority
28: * ordering of conflicting rules.
29: * </p>
30: *
31: * @see Activation
32: * @see org.drools.spi.Tuple
33: * @see org.drools.rule.Rule
34: *
35: * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris </a>
36: */
37: public class CompositeConflictResolver extends AbstractConflictResolver {
38: /**
39: *
40: */
41: private static final long serialVersionUID = 400L;
42: private final ConflictResolver[] components;
43:
44: public CompositeConflictResolver(final ConflictResolver[] components) {
45: this .components = components;
46: }
47:
48: /**
49: * @see AbstractConflictResolver
50: */
51: public final int compare(final Activation lhs, final Activation rhs) {
52: int result = 0;
53:
54: for (int i = 0; result == 0 && i < this.components.length; ++i) {
55: result = this.components[i].compare(lhs, rhs);
56: }
57:
58: return result;
59: }
60: }
|