[jboss-svn-commits] JBL Code SVN: r20816 - in labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools: rule/builder/dialect/mvel and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jun 26 13:59:33 EDT 2008
Author: mark.proctor at jboss.com
Date: 2008-06-26 13:59:33 -0400 (Thu, 26 Jun 2008)
New Revision: 20816
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
Log:
JBRULES-720 Clips Parser
-We now set the ContextClassLoader for MVEL, so it can see Drools specific classes.
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-06-26 16:17:29 UTC (rev 20815)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-06-26 17:59:33 UTC (rev 20816)
@@ -500,6 +500,9 @@
PackageRegistry pkgRegistry = new PackageRegistry( this,
pkg );
+
+ // add default import for this namespace
+ pkgRegistry.addImport( packageDescr.getNamespace() + ".*" );
this.pkgRegistryMap.put( packageDescr.getName(),
pkgRegistry );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-06-26 16:17:29 UTC (rev 20815)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-06-26 17:59:33 UTC (rev 20816)
@@ -329,8 +329,7 @@
public void addFunction(FunctionDescr functionDescr,
TypeResolver typeResolver) {
- ExpressionCompiler compiler = new ExpressionCompiler( (String) functionDescr.getContent() );
- Serializable s1 = compiler.compile();
+ Serializable s1 = compile( (String) functionDescr.getContent(), null, null, null, null,null );
Map<String, org.mvel.ast.Function> map = CompilerTools.extractAllDeclaredFunctions( (CompiledExpression) s1 );
MVELDialectRuntimeData data = (MVELDialectRuntimeData) this.packageRegistry.getDialectRuntimeRegistry().getDialectData( getId() );
for ( org.mvel.ast.Function function : map.values() ) {
@@ -497,8 +496,15 @@
}
synchronized ( COMPILER_LOCK ) {
+ ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader( pkg.getPackageScopeClassLoader() );
+
AbstractParser.setLanguageLevel( languageLevel );
- return compiler.compile( parserContext );
+ Serializable expr = compiler.compile( parserContext );
+
+ Thread.currentThread().setContextClassLoader( tempClassLoader );
+
+ return expr;
}
}
@@ -522,46 +528,48 @@
parserContext.setInterceptors( interceptors );
}
- List list[] = analysis.getBoundIdentifiers();
-
- // @TODO yuck, we don't want conditions for configuration :(
- if ( context instanceof RuleBuildContext ) {
- //FIXME: analysis can be null, throws an NPE
- DeclarationScopeResolver resolver = ((RuleBuildContext) context).getDeclarationResolver();
- for ( Iterator it = list[0].iterator(); it.hasNext(); ) {
+ if ( analysis != null ) {
+ List list[] = analysis.getBoundIdentifiers();
+
+ // @TODO yuck, we don't want conditions for configuration :(
+ if ( context instanceof RuleBuildContext ) {
+ //FIXME: analysis can be null, throws an NPE
+ DeclarationScopeResolver resolver = ((RuleBuildContext) context).getDeclarationResolver();
+ for ( Iterator it = list[0].iterator(); it.hasNext(); ) {
+ String identifier = (String) it.next();
+ Class cls = resolver.getDeclaration( identifier ).getExtractor().getExtractToClass();
+ parserContext.addInput( identifier,
+ cls );
+ }
+ }
+
+ Map globalTypes = context.getPkg().getGlobals();
+ for ( Iterator it = list[1].iterator(); it.hasNext(); ) {
String identifier = (String) it.next();
- Class cls = resolver.getDeclaration( identifier ).getExtractor().getExtractToClass();
parserContext.addInput( identifier,
- cls );
+ (Class) globalTypes.get( identifier ) );
}
- }
-
- Map globalTypes = context.getPkg().getGlobals();
- for ( Iterator it = list[1].iterator(); it.hasNext(); ) {
- String identifier = (String) it.next();
- parserContext.addInput( identifier,
- (Class) globalTypes.get( identifier ) );
- }
-
- if ( otherInputVariables != null ) {
- for ( Iterator it = otherInputVariables.entrySet().iterator(); it.hasNext(); ) {
- Entry entry = (Entry) it.next();
- parserContext.addInput( (String) entry.getKey(),
- (Class) entry.getValue() );
+
+ if ( otherInputVariables != null ) {
+ for ( Iterator it = otherInputVariables.entrySet().iterator(); it.hasNext(); ) {
+ Entry entry = (Entry) it.next();
+ parserContext.addInput( (String) entry.getKey(),
+ (Class) entry.getValue() );
+ }
}
- }
-
- if ( outerDeclarations != null ) {
- for ( Iterator it = outerDeclarations.entrySet().iterator(); it.hasNext(); ) {
- Entry entry = (Entry) it.next();
- parserContext.addInput( (String) entry.getKey(),
- ((Declaration) entry.getValue()).getExtractor().getExtractToClass() );
+
+ if ( outerDeclarations != null ) {
+ for ( Iterator it = outerDeclarations.entrySet().iterator(); it.hasNext(); ) {
+ Entry entry = (Entry) it.next();
+ parserContext.addInput( (String) entry.getKey(),
+ ((Declaration) entry.getValue()).getExtractor().getExtractToClass() );
+ }
}
+
+ parserContext.addInput( "drools",
+ KnowledgeHelper.class );
}
- parserContext.addInput( "drools",
- KnowledgeHelper.class );
-
return parserContext;
}
More information about the jboss-svn-commits
mailing list