01: package org.drools;
02:
03: import org.drools.util.UUIDGenerator;
04:
05: /*
06: * Copyright 2005 JBoss Inc
07: *
08: * Licensed under the Apache License, Version 2.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: */
20:
21: /**
22: * This is a utility to create rule bases based on the type of engine you wish to use.
23: *
24: */
25: public class RuleBaseFactory {
26:
27: private static final RuleBaseFactory INSTANCE = new RuleBaseFactory();
28:
29: private RuleBaseFactory() {
30: }
31:
32: public static RuleBaseFactory getInstance() {
33: return RuleBaseFactory.INSTANCE;
34: }
35:
36: /** Create a new default rule base (RETEOO type engine) */
37: public static RuleBase newRuleBase() {
38: return RuleBaseFactory.newRuleBase(RuleBase.RETEOO, null);
39: }
40:
41: public static RuleBase newRuleBase(
42: final RuleBaseConfiguration config) {
43: return RuleBaseFactory.newRuleBase(RuleBase.RETEOO, config);
44: }
45:
46: public static RuleBase newRuleBase(final int type) {
47: return RuleBaseFactory.newRuleBase(type, null);
48: }
49:
50: /** Create a new RuleBase of the appropriate type */
51: public static RuleBase newRuleBase(final int type,
52: final RuleBaseConfiguration config) {
53: switch (type) {
54: case RuleBase.RETEOO:
55: return new org.drools.reteoo.ReteooRuleBase(
56: UUIDGenerator.getInstance()
57: .generateRandomBasedUUID().toString(),
58: config);
59: default:
60: throw new IllegalArgumentException("Unknown engine type: "
61: + type);
62:
63: }
64: }
65:
66: }
|