[jboss-svn-commits] JBL Code SVN: r13131 - labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 5 20:15:48 EDT 2007
Author: pombredanne
Date: 2007-07-05 20:15:48 -0400 (Thu, 05 Jul 2007)
New Revision: 13131
Modified:
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELExprAnalyzer.java
Log:
Fix calls to ExpressionCompiler to use the new MVEL ParserContext
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2007-07-06 00:11:35 UTC (rev 13130)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2007-07-06 00:15:48 UTC (rev 13131)
@@ -16,6 +16,7 @@
import org.mvel.ExpressionCompiler;
import org.mvel.Macro;
import org.mvel.MacroProcessor;
+import org.mvel.ParserContext;
import org.mvel.ast.WithNode;
import org.mvel.integration.Interceptor;
import org.mvel.integration.VariableResolverFactory;
@@ -34,34 +35,34 @@
this.interceptors.put( "Modify", new ModifyInterceptor() );
macros = new HashMap(4);
-
+
macros.put( "insert",
new Macro() {
public String doMacro() {
return "drools.insert";
}
- } );
-
+ } );
+
macros.put( "modify",
new Macro() {
public String doMacro() {
return "@Modify with";
}
} );
-
+
macros.put( "update",
new Macro() {
public String doMacro() {
return "drools.update";
}
} );
-
+
macros.put( "retract",
new Macro() {
public String doMacro() {
return "drools.retract";
}
- } );
+ } );
}
public void build(final RuleBuildContext context) {
@@ -72,23 +73,33 @@
final DroolsMVELFactory factory = new DroolsMVELFactory( context.getDeclarationResolver().getDeclarations(),
null,
context.getPkg().getGlobals() );
- factory.setNextFactory( ((MVELDialect) context.getDialect()).getClassImportResolverFactory() );
+ MVELDialect dialect = (MVELDialect) context.getDialect();
+ factory.setNextFactory( (dialect).getClassImportResolverFactory() );
+
MacroProcessor macroProcessor = new MacroProcessor();
macroProcessor.setMacros( macros );
-
-
+
+
String pkg = "";
if (context.getPkg()!=null && context.getPkg().getName()!=null && context.getPkg().getName().length()>0) {
pkg = context.getPkg().getName()+".";
}
-
- String sourceFile = pkg+context.getRuleDescr().getClassName();
-
- final Serializable expr = compileExpression( macroProcessor.parse( delimitExpressions( (String) context.getRuleDescr().getConsequence() )),
- ((MVELDialect) context.getDialect()).getClassImportResolverFactory().getImportedClasses(), this.interceptors , sourceFile);
-
+ String sourceFile = pkg + context.getRuleDescr().getClassName();
+
+ ParserContext parserContext = new ParserContext();
+ parserContext.setImports(dialect.getClassImportResolverFactory().getImportedClasses());
+
+ parserContext.setInterceptors(this.interceptors);
+ parserContext.setSourceFile(sourceFile);
+ parserContext.setDebugSymbols( true );
+
+ ExpressionCompiler parser = new ExpressionCompiler(macroProcessor.parse( delimitExpressions( (String) context.getRuleDescr().getConsequence() )));
+ CompiledExpression cExpr = parser.compile();
+
+ final Serializable expr = cExpr;
+
context.getRule().setConsequence( new MVELConsequence( expr,
factory ) );
} catch ( final Exception e ) {
@@ -103,7 +114,7 @@
* Allows newlines to demarcate expressions, as per MVEL command line.
* If expression spans multiple lines (ie inside an unbalanced bracket) then
* it is left alone.
- * Uses character based iteration which is at least an order of magnitude faster then a single
+ * Uses character based iteration which is at least an order of magnitude faster then a single
* simple regex.
*/
public String delimitExpressions(String s) {
@@ -175,7 +186,7 @@
VariableResolverFactory factory) {
Object object = ((WithNode) node). getNestedStatement().getValue( null,
factory );
-
+
DroolsMVELKnowledgeHelper resolver = ( DroolsMVELKnowledgeHelper ) factory.getVariableResolver( "drools" );
KnowledgeHelper helper = ( KnowledgeHelper ) resolver.getValue();
helper.modifyRetract( object );
@@ -192,16 +203,4 @@
}
}
-
- public static Serializable compileExpression(String expression, Map imports,
- Map interceptors, String sourceName) {
- ExpressionCompiler parser = new ExpressionCompiler(expression);
- parser.setImportedClasses(imports);
- parser.setInterceptors(interceptors);
- parser.setSourceFile(sourceName);
- parser.setDebugSymbols( true );
- CompiledExpression cExpr = parser.compile();
- return cExpr;
- }
-
}
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELExprAnalyzer.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELExprAnalyzer.java 2007-07-06 00:11:35 UTC (rev 13130)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELExprAnalyzer.java 2007-07-06 00:15:48 UTC (rev 13131)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 JBoss Inc
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,13 +24,14 @@
import org.antlr.runtime.RecognitionException;
import org.mvel.ExpressionCompiler;
+import org.mvel.ParserContext;
/**
* Expression analyzer.
- *
+ *
*/
public class MVELExprAnalyzer {
-
+
public MVELExprAnalyzer() {
// intentionally left blank.
}
@@ -41,35 +42,36 @@
/**
* Analyze an expression.
- *
+ *
* @param expr
* The expression to analyze.
* @param availDecls
* Total set of declarations available.
- *
+ *
* @return The <code>Set</code> of declarations used by the expression.
- * @throws RecognitionException
+ * @throws RecognitionException
* If an error occurs in the parser.
*/
public MVELAnalysisResult analyzeExpression(final String expr,
final Set[] availableIdentifiers) throws RecognitionException {
ExpressionCompiler compiler = new ExpressionCompiler( expr);
- compiler.compile();
-
- return analyze( compiler.getInputs(),
+ compiler.compile();
+ ParserContext context = compiler.getParserContextState();
+ Set inputs = context.getInputs().keySet();
+ return analyze( inputs,
availableIdentifiers );
}
/**
* Analyze an expression.
- *
+ *
* @param availDecls
* Total set of declarations available.
* @param ast
* The AST for the expression.
- *
+ *
* @return The <code>Set</code> of declarations used by the expression.
- *
+ *
* @throws RecognitionException
* If an error occurs in the parser.
*/
@@ -98,6 +100,6 @@
result.setBoundIdentifiers( used );
result.setNotBoundedIdentifiers( new ArrayList( notBound ) );
- return result;
+ return result;
}
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list