01: package org.drools.rule.builder.dialect.java;
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.HashMap;
20: import java.util.Map;
21:
22: import org.mvel.Macro;
23: import org.mvel.MacroProcessor;
24:
25: public class KnowledgeHelperFixer {
26: private static final Map macros;
27:
28: static {
29: macros = new HashMap(5);
30:
31: macros.put("insert", new Macro() {
32: public String doMacro() {
33: return "drools.insert";
34: }
35: });
36:
37: macros.put("insertLogical", new Macro() {
38: public String doMacro() {
39: return "drools.insertLogical";
40: }
41: });
42:
43: macros.put("modifyRetract", new Macro() {
44: public String doMacro() {
45: return "drools.modifyRetract";
46: }
47: });
48:
49: macros.put("modifyInsert", new Macro() {
50: public String doMacro() {
51: return "drools.modifyInsert";
52: }
53: });
54:
55: macros.put("update", new Macro() {
56: public String doMacro() {
57: return "drools.update";
58: }
59: });
60:
61: macros.put("retract", new Macro() {
62: public String doMacro() {
63: return "drools.retract";
64: }
65: });
66: }
67:
68: public String fix(final String raw) {
69: if (raw == null || "".equals(raw.trim())) {
70: return raw;
71: }
72:
73: MacroProcessor macroProcessor = new MacroProcessor();
74: macroProcessor.setMacros(macros);
75: return macroProcessor.parse(raw);
76: }
77: }
|