[jboss-svn-commits] JBL Code SVN: r9781 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/compiler and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 26 19:11:33 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-02-26 19:11:32 -0500 (Mon, 26 Feb 2007)
New Revision: 9781

Added:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/DeclarationTypeFixer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/FunctionBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaExprAnalyzer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/KnowledgeHelperFixer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/PackageStore.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/RuleBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/PredicateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ReturnValueBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java
Removed:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/EvalBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/DeclarationTypeFixer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/JavaExprAnalyzer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/KnowledgeHelperFixer.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/PackageStore.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaAccumulateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaConsequenceBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaEvalBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaPredicateBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaReturnValueBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELEvalBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELFromBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/dialect/mvel/MVELEvalBuilderTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java
Log:
JBRULES-708 MVEL Integration
-More interface/implementation seperation for dialects

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	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -39,6 +39,9 @@
 import org.codehaus.jfdi.interpreter.TypeResolver;
 import org.drools.RuntimeDroolsException;
 import org.drools.base.ClassFieldExtractorCache;
+import org.drools.dialect.java.FunctionBuilder;
+import org.drools.dialect.java.PackageStore;
+import org.drools.dialect.java.RuleBuilder;
 import org.drools.facttemplates.FactTemplate;
 import org.drools.facttemplates.FactTemplateImpl;
 import org.drools.facttemplates.FieldTemplate;
@@ -55,9 +58,6 @@
 import org.drools.rule.LineMappings;
 import org.drools.rule.Package;
 import org.drools.rule.Rule;
-import org.drools.semantics.java.FunctionBuilder;
-import org.drools.semantics.java.PackageStore;
-import org.drools.semantics.java.RuleBuilder;
 import org.drools.spi.FunctionResolver;
 import org.drools.xml.XmlPackageReader;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/DeclarationTypeFixer.java (from rev 9748, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/DeclarationTypeFixer.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/DeclarationTypeFixer.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/DeclarationTypeFixer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,24 @@
+/**
+ * 
+ */
+package org.drools.dialect.java;
+
+import org.drools.rule.Declaration;
+
+/**
+ * @author fburlet
+ * @author gdupriez
+ *
+ */
+public class DeclarationTypeFixer {
+    
+    public String fix(Declaration declaration) {
+        Class classType = declaration.getExtractor().getExtractToClass();
+        if (classType.isArray()) {
+            return classType.getComponentType().getName().concat("[]");
+        } else {
+            // Does this replacement usefull in the declaration type ??
+            return classType.getName().replace('$', '.');
+        }
+    }
+}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/FunctionBuilder.java (from rev 9753, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/FunctionBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/FunctionBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,118 @@
+package org.drools.dialect.java;
+
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
+import org.codehaus.jfdi.interpreter.TypeResolver;
+import org.drools.RuntimeDroolsException;
+import org.drools.lang.descr.FunctionDescr;
+import org.drools.rule.LineMappings;
+import org.drools.rule.Package;
+import org.drools.spi.DeclarationScopeResolver;
+
+public class FunctionBuilder {
+    private static final StringTemplateGroup functionGroup = new StringTemplateGroup( new InputStreamReader( FunctionBuilder.class.getResourceAsStream( "javaFunction.stg" ) ),
+                                                                                      AngleBracketTemplateLexer.class );
+
+    public FunctionBuilder() {
+
+    }
+
+    public String build(final Package pkg,
+                        final FunctionDescr functionDescr,
+                        final TypeResolver typeResolver,
+                        final Map lineMappings) {
+        final StringTemplate st = FunctionBuilder.functionGroup.getInstanceOf( "function" );
+
+        st.setAttribute( "package",
+                         pkg.getName() );
+
+        st.setAttribute( "imports",
+                         pkg.getImports() );
+
+        st.setAttribute( "className",
+                         ucFirst( functionDescr.getName() ) );
+        st.setAttribute( "methodName",
+                         functionDescr.getName() );
+
+        st.setAttribute( "returnType",
+                         functionDescr.getReturnType() );
+
+        st.setAttribute( "parameterTypes",
+                         functionDescr.getParameterTypes() );
+
+        st.setAttribute( "parameterNames",
+                         functionDescr.getParameterNames() );
+
+        Map params = new HashMap();
+        List names = functionDescr.getParameterNames();
+        List types = functionDescr.getParameterTypes();
+        try {
+            for ( int i = 0, size = names.size(); i < size; i++ ) {
+                params.put( names.get( i ), typeResolver.resolveType( (String) types.get( i ) ) );
+            }
+        } catch ( ClassNotFoundException e ) {
+            // todo : must be a better way so we don't have to try/catch each resolveType call
+            throw new RuntimeDroolsException( e );                
+        }                   
+        
+        st.setAttribute( "text",
+                         functionDescr.getText() );
+        
+        String text = st.toString();
+        
+        BufferedReader reader = new BufferedReader( new StringReader ( text ) );
+        String line = null;
+        String lineStartsWith = "    public static " + functionDescr.getReturnType( ) + " " + functionDescr.getName();
+        int offset = 0;
+        try {
+            while ( ( line = reader.readLine() ) != null ) {
+                offset++;
+                if ( line.startsWith( lineStartsWith ) ) {
+                    break;
+                }
+            }
+            functionDescr.setOffset( offset );
+        } catch ( IOException e ) {
+            // won't ever happen, it's just reading over a string.
+            throw new RuntimeDroolsException( "Error determining start offset with function" );
+        }
+        
+        String name = pkg.getName() + "." + ucFirst( functionDescr.getName() );
+        LineMappings mapping = new LineMappings( name );
+        mapping.setStartLine( functionDescr.getLine() );
+        mapping.setOffset( functionDescr.getOffset() );      
+        lineMappings.put( name, lineMappings );
+
+        return text;
+
+    }
+
+    private String ucFirst(final String name) {
+        return name.toUpperCase().charAt( 0 ) + name.substring( 1 );
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaAccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaAccumulateBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaAccumulateBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -27,11 +27,11 @@
 import org.drools.rule.Column;
 import org.drools.rule.ConditionalElement;
 import org.drools.rule.Declaration;
-import org.drools.semantics.java.builder.AccumulateBuilder;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.ColumnBuilder;
-import org.drools.semantics.java.builder.ConditionalElementBuilder;
+import org.drools.rule.builder.AccumulateBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.ColumnBuilder;
+import org.drools.rule.builder.ConditionalElementBuilder;
 
 /**
  * @author etirelli

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaConsequenceBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaConsequenceBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaConsequenceBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -23,9 +23,9 @@
 import org.drools.RuntimeDroolsException;
 import org.drools.lang.descr.RuleDescr;
 import org.drools.rule.Declaration;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.ConsequenceBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.ConsequenceBuilder;
 
 /**
  * @author etirelli

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaEvalBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaEvalBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaEvalBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -24,10 +24,10 @@
 import org.drools.rule.ConditionalElement;
 import org.drools.rule.Declaration;
 import org.drools.rule.EvalCondition;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.ColumnBuilder;
-import org.drools.semantics.java.builder.ConditionalElementBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.ColumnBuilder;
+import org.drools.rule.builder.ConditionalElementBuilder;
 
 /**
  * @author etirelli

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaExprAnalyzer.java (from rev 9748, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/JavaExprAnalyzer.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaExprAnalyzer.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaExprAnalyzer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,137 @@
+package org.drools.dialect.java;
+
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.TokenStream;
+import org.drools.semantics.java.parser.JavaParserLexer;
+import org.drools.semantics.java.parser.JavaParserParser;
+
+/**
+ * Expression analyzer.
+ * 
+ * @author <a href="mailto:bob at eng.werken.com">bob mcwhirter </a>
+ */
+public class JavaExprAnalyzer {
+    // ------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------
+
+    /**
+     * Construct.
+     */
+    public JavaExprAnalyzer() {
+        // intentionally left blank.
+    }
+
+    // ------------------------------------------------------------
+    // Instance methods
+    // ------------------------------------------------------------
+
+    /**
+     * 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 
+     *             If an error occurs in the parser.
+     */
+    public List[] analyzeExpression(final String expr,
+                                    final Set[] availableIdentifiers) throws RecognitionException {
+        final CharStream charStream = new ANTLRStringStream( expr );
+        final JavaParserLexer lexer = new JavaParserLexer( charStream );
+        final TokenStream tokenStream = new CommonTokenStream( lexer );
+        final JavaParserParser parser = new JavaParserParser( tokenStream );
+
+        parser.logicalOrExpression();
+
+        return analyze( parser.getIdentifiers(),
+                        availableIdentifiers );
+    }
+
+    public List[] analyzeBlock(final String expr,
+                               final Set[] availableIdentifiers) throws RecognitionException {
+        final CharStream charStream = new ANTLRStringStream( "{" + expr + "}" );
+        final JavaParserLexer lexer = new JavaParserLexer( charStream );
+        final TokenStream tokenStream = new CommonTokenStream( lexer );
+        final JavaParserParser parser = new JavaParserParser( tokenStream );
+
+        parser.compoundStatement();
+
+        return analyze( parser.getIdentifiers(),
+                        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.
+     */
+    private List[] analyze(final List identifiers,
+                           final Set[] availableIdentifiers) throws RecognitionException {
+        final List[] used = new List[availableIdentifiers.length];
+        for ( int i = 0, length = used.length; i < length; i++ ) {
+            used[i] = new ArrayList();
+        }
+
+        for ( int i = 0, length = availableIdentifiers.length; i < length; i++ ) {
+            final Set set = availableIdentifiers[i];
+            for ( final Iterator it = set.iterator(); it.hasNext(); ) {
+                final String eachDecl = (String) it.next();
+                if ( identifiers.contains( eachDecl ) ) {
+                    used[i].add( eachDecl );
+                }
+            }
+        }
+
+        return used;
+        //--------------------------------------------------------        
+        //        List decls = new ArrayList();
+        //        
+        //        for ( Iterator declIter = availDecls.iterator(); declIter.hasNext(); )
+        //        {
+        //            String eachDecl = (String) declIter.next();
+        //
+        //            if ( identifiers.contains( eachDecl ) )
+        //            {
+        //                decls.add( eachDecl );
+        //            }
+        //        }
+        //
+        //        return decls;        
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaPredicateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaPredicateBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaPredicateBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -6,9 +6,9 @@
 import org.drools.lang.descr.PredicateDescr;
 import org.drools.rule.Declaration;
 import org.drools.rule.PredicateConstraint;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.PredicateBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.PredicateBuilder;
 
 public class JavaPredicateBuilder
     implements

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaReturnValueBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaReturnValueBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/JavaReturnValueBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -6,8 +6,8 @@
 import org.drools.lang.descr.ReturnValueRestrictionDescr;
 import org.drools.rule.Declaration;
 import org.drools.rule.ReturnValueRestriction;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
 
 public class JavaReturnValueBuilder {
     public void build(final BuildContext context,

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/KnowledgeHelperFixer.java (from rev 9748, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/KnowledgeHelperFixer.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/KnowledgeHelperFixer.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/KnowledgeHelperFixer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,199 @@
+package org.drools.dialect.java;
+
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class KnowledgeHelperFixer {
+
+    static String  KNOWLEDGE_HELPER_PFX = "";                               //could also be: "drools\\." for "classic" mode.
+    static Pattern MODIFY               = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "modify\\s*\\(([^)]+)\\)(.*)",
+                                                           Pattern.DOTALL );
+    static Pattern ASSERT               = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "assert\\s*\\((.*)\\)(.*)",
+                                                           Pattern.DOTALL );
+    static Pattern ASSERT_LOGICAL       = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "assertLogical\\s*\\((.*)\\)(.*)",
+                                                           Pattern.DOTALL );
+    static Pattern RETRACT              = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "retract\\s*\\(([^)]+)\\)(.*)",
+                                                           Pattern.DOTALL );
+
+    /**
+     * This takes a raw consequence, and fixes up the KnowledegeHelper references 
+     * to be what SMF requires.
+     *
+     * eg: modify( myObject ); --> drools.modify( myObjectHandle, myObject );
+     * refer to the Replacer implementation classes below for the specific replacement patterns.
+     * 
+     * (can adjust the PREFIX if needed).
+     * 
+     * Uses some non-tail recursion to ensure that all parts are "expanded". 
+     */
+    public String fix(final String raw) {
+        String result = fix( raw,
+                             ModifyReplacer.INSTANCE );
+        result = fix( result,
+                      AssertReplacer.INSTANCE );
+        result = fix( result,
+                      AssertLogicalReplacer.INSTANCE );
+        result = fix( result,
+                      RetractReplacer.INSTANCE );
+        return result;
+    }
+
+    /**
+     * Recursively apply the pattern, replace the guts of what is matched.
+     */
+    public String fix(final String raw,
+                      final Replacer replacer) {
+        if ( raw == null ) {
+            return null;
+        }
+        final Matcher matcher = replacer.getPattern().matcher( raw );
+
+        if ( matcher.matches() ) {
+            String pre = matcher.group( 1 );
+            if ( matcher.group( 1 ) != null ) {
+                pre = fix( pre,
+                           replacer );
+            }
+            final String obj = matcher.group( 2 ).trim();
+            String post = matcher.group( 3 );
+            if ( post != null ) {
+                post = fix( post,
+                            replacer );
+            }
+
+            final String replacement = escapeDollarSigns( replacer,
+                                                    obj );
+            return pre + matcher.replaceAll( replacement ) + post;
+
+        } else {
+            return raw;
+        }
+    }
+
+    /** 
+     * This is needed to escape "$" so that matches doesn't try and pull out groups that don't exist.
+     * "$" may just be used in variable name etc... 
+     */
+    private String escapeDollarSigns(final Replacer replacer,
+                                     final String obj) {
+        return KnowledgeHelperFixer.replace( replacer.getReplacement( obj ),
+                             "$",
+                             "\\$",
+                             256 );
+    }
+
+    static interface Replacer {
+        Pattern getPattern();
+
+        String getReplacement(String guts);
+    }
+
+    static class AssertReplacer
+        implements
+        Replacer {
+
+        static Replacer INSTANCE = new AssertReplacer();
+
+        public Pattern getPattern() {
+            return KnowledgeHelperFixer.ASSERT;
+        }
+
+        public String getReplacement(final String guts) {
+            return "drools.assertObject(" + guts + ")";
+        }
+
+    }
+
+    static class AssertLogicalReplacer
+        implements
+        Replacer {
+
+        static Replacer INSTANCE = new AssertLogicalReplacer();
+
+        public Pattern getPattern() {
+            return KnowledgeHelperFixer.ASSERT_LOGICAL;
+        }
+
+        public String getReplacement(final String guts) {
+            return "drools.assertLogicalObject(" + guts + ")";
+        }
+
+    }
+
+    static class ModifyReplacer
+        implements
+        Replacer {
+
+        static Replacer INSTANCE = new ModifyReplacer();
+
+        public Pattern getPattern() {
+            return KnowledgeHelperFixer.MODIFY;
+        }
+
+        public String getReplacement(final String guts) {
+            return "drools.modifyObject(" + guts.trim() + "__Handle__, " + guts + ")";
+        }
+
+    }
+
+    static class RetractReplacer
+        implements
+        Replacer {
+
+        static Replacer INSTANCE = new RetractReplacer();
+
+        public Pattern getPattern() {
+            return KnowledgeHelperFixer.RETRACT;
+        }
+
+        public String getReplacement(final String guts) {
+            return "drools.retractObject(" + guts.trim() + "__Handle__)";
+        }
+
+    }
+
+    /**
+     * Simple non regex replacer. 
+     * jakarta commons provided the inspiration for this.
+     */
+    static String replace(final String text,
+                          final String repl,
+                          final String with,
+                          int max) {
+        if ( text == null || repl == null || repl.equals( "" ) || with == null || max == 0 ) {
+            return text;
+        }
+
+        final StringBuffer buf = new StringBuffer( text.length() );
+        int start = 0, end = 0;
+        while ( (end = text.indexOf( repl,
+                                     start )) != -1 ) {
+            buf.append( text.substring( start,
+                                        end ) ).append( with );
+            start = end + repl.length();
+
+            if ( --max == 0 ) {
+                break;
+            }
+        }
+        buf.append( text.substring( start ) );
+        return buf.toString();
+    }
+
+}
\ No newline at end of file

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/PackageStore.java (from rev 9748, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/PackageStore.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/PackageStore.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/PackageStore.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,65 @@
+package org.drools.dialect.java;
+
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.commons.jci.stores.ResourceStore;
+import org.drools.rule.PackageCompilationData;
+
+public class PackageStore
+    implements
+    ResourceStore {
+    private PackageCompilationData packageCompilationData;
+
+    public PackageStore() {
+    }
+
+    public PackageStore(final PackageCompilationData packageCompiationData) {
+        this.packageCompilationData = packageCompiationData;
+    }
+
+    public void setPackageCompilationData(final PackageCompilationData packageCompiationData) {
+        this.packageCompilationData = packageCompiationData;
+    }
+
+    public void write(final String resourceName,
+                      final byte[] clazzData) {
+        try {
+            this.packageCompilationData.write( resourceName,
+                                               clazzData );
+        } catch ( final Exception e ) {
+
+        }
+    }
+
+    public byte[] read(final String resourceName) {
+        byte[] clazz = null;
+        try {
+            clazz = this.packageCompilationData.read( resourceName );
+        } catch ( final Exception e ) {
+
+        }
+        return clazz;
+    }
+
+    public void remove(final String resourceName) {
+        try {
+            this.packageCompilationData.remove( resourceName );
+        } catch ( final Exception e ) {
+
+        }
+    }
+}
\ No newline at end of file

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/RuleBuilder.java (from rev 9779, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/RuleBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/java/RuleBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,250 @@
+package org.drools.dialect.java;
+
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.codehaus.jfdi.interpreter.TypeResolver;
+import org.drools.RuntimeDroolsException;
+import org.drools.base.ClassFieldExtractorCache;
+import org.drools.base.evaluators.DateFactory;
+import org.drools.dialect.mvel.MVELFromBuilder;
+import org.drools.lang.descr.AccumulateDescr;
+import org.drools.lang.descr.AndDescr;
+import org.drools.lang.descr.AttributeDescr;
+import org.drools.lang.descr.CollectDescr;
+import org.drools.lang.descr.EvalDescr;
+import org.drools.lang.descr.ExistsDescr;
+import org.drools.lang.descr.ForallDescr;
+import org.drools.lang.descr.FromDescr;
+import org.drools.lang.descr.NotDescr;
+import org.drools.lang.descr.OrDescr;
+import org.drools.lang.descr.QueryDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.GroupElement;
+import org.drools.rule.Package;
+import org.drools.rule.Rule;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.CollectBuilder;
+import org.drools.rule.builder.ColumnBuilder;
+import org.drools.rule.builder.ConditionalElementBuilder;
+import org.drools.rule.builder.ConsequenceBuilder;
+import org.drools.rule.builder.ForallBuilder;
+import org.drools.rule.builder.GroupElementBuilder;
+import org.drools.rule.builder.RuleClassBuilder;
+
+/**
+ * This builds the rule structure from an AST.
+ * Generates semantic code where necessary if semantics are used.
+ * This is an internal API.
+ */
+public class RuleBuilder {
+
+    // the current build context
+    private BuildContext       context;
+
+    // the current build utils
+    private BuildUtils         utils;
+
+    // a map of registered builders
+    private Map                builders;
+
+    // the builder for columns
+    private ColumnBuilder      columnBuilder;
+
+    // the builder for the consequence
+    private ConsequenceBuilder consequenceBuilder;
+    
+    // the builder for the rule class
+    private RuleClassBuilder   classBuilder;
+
+    // Constructor
+    public RuleBuilder(final TypeResolver typeResolver,
+                       final ClassFieldExtractorCache cache) {
+
+        // statically adding all builders to the map
+        // but in the future we can move that to a configuration
+        // if we want to
+        this.builders = new HashMap();
+        builders.put( EvalDescr.class,
+                      new JavaEvalBuilder() );
+        builders.put( FromDescr.class,
+                      new MVELFromBuilder() );
+        builders.put( CollectDescr.class,
+                      new CollectBuilder() );
+        builders.put( AccumulateDescr.class,
+                      new JavaAccumulateBuilder() );
+        builders.put( ForallDescr.class,
+                      new ForallBuilder() );
+        GroupElementBuilder gebuilder = new GroupElementBuilder();
+        builders.put( AndDescr.class,
+                      gebuilder);
+        builders.put( OrDescr.class,
+                      gebuilder);
+        builders.put( NotDescr.class,
+                      gebuilder);
+        builders.put( ExistsDescr.class,
+                      gebuilder);
+        
+        
+        this.utils = new BuildUtils( new KnowledgeHelperFixer(),
+                                     new DeclarationTypeFixer(),
+                                     new JavaExprAnalyzer(),
+                                     typeResolver,
+                                     cache,
+                                     builders );
+
+        this.columnBuilder = new ColumnBuilder();
+
+        this.consequenceBuilder = new JavaConsequenceBuilder();
+        
+        this.classBuilder = new RuleClassBuilder();
+    }
+
+    public Map getInvokers() {
+        return (this.context == null) ? null : this.context.getInvokers();
+    }
+
+    public Map getDescrLookups() {
+        return (this.context == null) ? null : this.context.getDescrLookups();
+    }
+
+    public String getRuleClass() {
+        return (this.context == null) ? null : this.context.getRuleClass();
+    }
+
+    public Map getInvokerLookups() {
+        return (this.context == null) ? null : this.context.getInvokerLookups();
+    }
+
+    public List getErrors() {
+        return (this.context == null) ? null : this.context.getErrors();
+    }
+
+    public Rule getRule() {
+        if ( this.context == null ) {
+            return null;
+        }
+        if ( !this.context.getErrors().isEmpty() ) {
+            this.context.getRule().setSemanticallyValid( false );
+        }
+        return this.context.getRule();
+    }
+
+    public Package getPackage() {
+        return this.context.getPkg();
+    }
+
+    /**
+     * Build the give rule into the 
+     * @param pkg
+     * @param ruleDescr
+     * @return
+     */
+    public synchronized Rule build(final Package pkg,
+                                   final RuleDescr ruleDescr) {
+        this.context = new BuildContext( pkg,
+                                         ruleDescr );
+
+        // Assign attributes
+        setAttributes( this.context.getRule(),
+                       ruleDescr.getAttributes() );
+
+        ConditionalElementBuilder builder = utils.getBuilder( ruleDescr.getLhs().getClass() );
+        if( builder != null ) {
+            GroupElement ce = (GroupElement) builder.build( this.context, this.utils, this.columnBuilder, ruleDescr.getLhs() );
+            this.context.getRule().setLhs( ce );
+        } else {
+            throw new RuntimeDroolsException("BUG: builder not found for descriptor class "+ruleDescr.getLhs().getClass() );
+        }
+
+        // Build the consequence and generate it's invoker/s
+        // generate the main rule from the previously generated s.
+        if ( !(ruleDescr instanceof QueryDescr) ) {
+            // do not build the consequence if we have a query
+            this.consequenceBuilder.buildConsequence( this.context,
+                                                      this.utils,
+                                                      ruleDescr );
+        }
+        this.classBuilder.buildRule( this.context, this.utils, ruleDescr );
+
+        return this.context.getRule();
+    }
+
+
+    /**
+     * Sets rule Attributes
+     * 
+     * @param rule
+     * @param attributes
+     */
+    void setAttributes(final Rule rule,
+                               final List attributes) {
+        
+        for ( final Iterator it = attributes.iterator(); it.hasNext(); ) {
+            final AttributeDescr attributeDescr = (AttributeDescr) it.next();
+            final String name = attributeDescr.getName();
+            if ( name.equals( "salience" ) ) {
+                rule.setSalience( Integer.parseInt( attributeDescr.getValue() ) );
+            } else if ( name.equals( "no-loop" ) ) {
+                if ( attributeDescr.getValue() == null ) {
+                    rule.setNoLoop( true );
+                } else {
+                    rule.setNoLoop( Boolean.valueOf( attributeDescr.getValue() ).booleanValue() );
+                }
+            } else if ( name.equals( "auto-focus" ) ) {
+                if ( attributeDescr.getValue() == null ) {
+                    rule.setAutoFocus( true );
+                } else {
+                    rule.setAutoFocus( Boolean.valueOf( attributeDescr.getValue() ).booleanValue() );
+                }
+            } else if ( name.equals( "agenda-group" ) ) {
+                rule.setAgendaGroup( attributeDescr.getValue() );
+            } else if ( name.equals( "activation-group" ) ) {
+                rule.setActivationGroup( attributeDescr.getValue() );
+            } else if ( name.equals( "ruleflow-group" ) ) {
+                rule.setRuleFlowGroup( attributeDescr.getValue() );
+            } else if ( name.equals( "duration" ) ) {
+                rule.setDuration( Long.parseLong( attributeDescr.getValue() ) );
+                rule.setAgendaGroup( "" );
+            } else if (name.equals( "enabled" )){
+                if (attributeDescr.getValue() == null) {
+                    rule.setEnabled( true );
+                } else {
+                    rule.setEnabled( Boolean.valueOf( attributeDescr.getValue() ).booleanValue());
+                }
+            } else if (name.equals( "date-effective" )) {                
+                Calendar cal = Calendar.getInstance();
+                cal.setTime( DateFactory.parseDate( attributeDescr.getValue() ) );
+                rule.setDateEffective( cal );
+            } else if (name.equals( "date-expires" )) {     
+                Calendar cal = Calendar.getInstance();
+                cal.setTime( DateFactory.parseDate( attributeDescr.getValue() ) );
+                rule.setDateExpires( cal );
+                
+            } else if ( name.equals( "language" ) ) {
+                //@todo: we don't currently  support multiple languages
+            }
+        }
+    }
+
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELEvalBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELEvalBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELEvalBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -27,10 +27,10 @@
 import org.drools.rule.ConditionalElement;
 import org.drools.rule.Declaration;
 import org.drools.rule.EvalCondition;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.ColumnBuilder;
-import org.drools.semantics.java.builder.ConditionalElementBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.ColumnBuilder;
+import org.drools.rule.builder.ConditionalElementBuilder;
 import org.drools.spi.DeclarationScopeResolver;
 import org.mvel.MVEL;
 

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELFromBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELFromBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/dialect/mvel/MVELFromBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -27,11 +27,11 @@
 import org.drools.rule.Column;
 import org.drools.rule.ConditionalElement;
 import org.drools.rule.From;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.ColumnBuilder;
-import org.drools.semantics.java.builder.ConditionalElementBuilder;
-import org.drools.semantics.java.builder.FromBuilder;
+import org.drools.rule.builder.BuildContext;
+import org.drools.rule.builder.BuildUtils;
+import org.drools.rule.builder.ColumnBuilder;
+import org.drools.rule.builder.ConditionalElementBuilder;
+import org.drools.rule.builder.FromBuilder;
 import org.drools.spi.DataProvider;
 import org.mvel.CompiledExpression;
 import org.mvel.ExpressionParser;

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder (from rev 9748, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder)

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/AccumulateBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,158 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.drools.base.ClassObjectType;
-import org.drools.lang.descr.AccumulateDescr;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.rule.Accumulate;
-import org.drools.rule.Column;
-import org.drools.rule.ConditionalElement;
-import org.drools.rule.Declaration;
-
-/**
- * @author etirelli
- *
- */
-public class AccumulateBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /* (non-Javadoc)
-     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
-     */
-    public ConditionalElement build(BuildContext context,
-                                    BuildUtils utils,
-                                    ColumnBuilder columnBuilder,
-                                    BaseDescr descr) {
-
-        AccumulateDescr accumDescr = (AccumulateDescr) descr;
-
-        Column sourceColumn = columnBuilder.build( context,
-                                                   utils,
-                                                   accumDescr.getSourceColumn() );
-
-        if ( sourceColumn == null ) {
-            return null;
-        }
-
-        Column resultColumn = columnBuilder.build( context,
-                                                   utils,
-                                                   accumDescr.getResultColumn() );
-
-        final String className = "accumulate" + context.getNextId();
-        accumDescr.setClassMethodName( className );
-
-        final List[] usedIdentifiers1 = utils.getUsedIdentifiers( context,
-                                                                  accumDescr,
-                                                                  accumDescr.getInitCode() );
-        final List[] usedIdentifiers2 = utils.getUsedIdentifiers( context,
-                                                                  accumDescr,
-                                                                  accumDescr.getActionCode() );
-        final List[] usedIdentifiers3 = utils.getUsedIdentifiers( context,
-                                                                  accumDescr,
-                                                                  accumDescr.getResultCode() );
-
-        final List requiredDeclarations = new ArrayList( usedIdentifiers1[0] );
-        requiredDeclarations.addAll( usedIdentifiers2[0] );
-        requiredDeclarations.addAll( usedIdentifiers3[0] );
-
-        final List requiredGlobals = new ArrayList( usedIdentifiers1[1] );
-        requiredGlobals.addAll( usedIdentifiers2[1] );
-        requiredGlobals.addAll( usedIdentifiers3[1] );
-
-        final Declaration[] declarations = new Declaration[requiredDeclarations.size()];
-        for ( int i = 0, size = requiredDeclarations.size(); i < size; i++ ) {
-            declarations[i] = (Declaration) context.getDeclarationResolver().getDeclaration( (String) requiredDeclarations.get( i ) );
-        }
-        final Declaration[] sourceDeclArr = (Declaration[]) sourceColumn.getOuterDeclarations().values().toArray( new Declaration[0] );
-
-        final String[] globals = (String[]) requiredGlobals.toArray( new String[requiredGlobals.size()] );
-
-        StringTemplate st = utils.getRuleGroup().getInstanceOf( "accumulateMethod" );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           globals );
-
-        st.setAttribute( "innerDeclarations",
-                         sourceDeclArr );
-        st.setAttribute( "methodName",
-                         className );
-
-        final String initCode = utils.getFunctionFixer().fix( accumDescr.getInitCode() );
-        final String actionCode = utils.getFunctionFixer().fix( accumDescr.getActionCode() );
-        final String resultCode = utils.getFunctionFixer().fix( accumDescr.getResultCode() );
-        st.setAttribute( "initCode",
-                         initCode );
-        st.setAttribute( "actionCode",
-                         actionCode );
-        st.setAttribute( "resultCode",
-                         resultCode );
-
-        String resultType = null;
-        // TODO: Need to change this... 
-        if ( resultColumn.getObjectType() instanceof ClassObjectType ) {
-            resultType = ((ClassObjectType) resultColumn.getObjectType()).getClassType().getName();
-        } else {
-            resultType = resultColumn.getObjectType().getValueType().getClassType().getName();
-        }
-
-        st.setAttribute( "resultType",
-                         resultType );
-
-        context.getMethods().add( st.toString() );
-
-        st = utils.getInvokerGroup().getInstanceOf( "accumulateInvoker" );
-
-        st.setAttribute( "package",
-                         context.getPkg().getName() );
-        st.setAttribute( "ruleClassName",
-                         utils.ucFirst( context.getRuleDescr().getClassName() ) );
-        st.setAttribute( "invokerClassName",
-                         context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker" );
-        st.setAttribute( "methodName",
-                         className );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           (String[]) requiredGlobals.toArray( new String[requiredGlobals.size()] ) );
-
-        st.setAttribute( "hashCode",
-                         actionCode.hashCode() );
-
-        Accumulate accumulate = new Accumulate( sourceColumn,
-                                                resultColumn,
-                                                declarations,
-                                                sourceDeclArr );
-        final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker";
-        context.getInvokers().put( invokerClassName,
-                                   st.toString() );
-        context.getInvokerLookups().put( invokerClassName,
-                                         accumulate );
-        context.getDescrLookups().put( invokerClassName,
-                                       accumDescr );
-        return accumulate;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/AccumulateBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/AccumulateBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,16 @@
+package org.drools.rule.builder;
+
+import org.drools.lang.descr.BaseDescr;
+import org.drools.rule.ConditionalElement;
+
+public interface AccumulateBuilder {
+
+    /* (non-Javadoc)
+     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
+     */
+    public ConditionalElement build(BuildContext context,
+                                    BuildUtils utils,
+                                    ColumnBuilder columnBuilder,
+                                    BaseDescr descr);
+
+}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/BuildContext.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,235 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-
-import org.drools.lang.descr.QueryDescr;
-import org.drools.lang.descr.RuleDescr;
-import org.drools.rule.Package;
-import org.drools.rule.Query;
-import org.drools.rule.Rule;
-import org.drools.spi.DeclarationScopeResolver;
-
-/**
- * A context for the current build
- * 
- * @author etirelli
- */
-public class BuildContext {
-
-    // current package
-    private Package            pkg;
-
-    // current rule
-    private Rule               rule;
-    
-    // a stack for the rule building used
-    // for declarations resolution
-    private Stack              buildStack;
-
-    // current Rule descriptor
-    private RuleDescr          ruleDescr;
-
-    // the class name for the rule
-    private String             ruleClass;
-
-    // available declarationResolver 
-    private DeclarationScopeResolver declarationResolver;
-
-    // errors found when building the current context
-    private List               errors;
-
-    // list of generated methods
-    private List               methods;
-
-    // map<String invokerClassName, String invokerCode> of generated invokers
-    private Map                invokers;
-
-    // map<String invokerClassName, ConditionalElement ce> of generated invoker lookups
-    private Map                invokerLookups;
-
-    // map<String invokerClassName, BaseDescr descr> of descriptor lookups
-    private Map                descrLookups;
-
-    // a simple counter for generated names
-    private int                counter;
-
-    // a simple counter for columns
-    private int                columnId = -1;
-
-    /**
-     * Default constructor
-     */
-    public BuildContext(final Package pkg,
-                        final RuleDescr ruleDescr) {
-        this.pkg = pkg;
-
-        this.methods = new ArrayList();
-        this.invokers = new HashMap();
-        this.invokerLookups = new HashMap();
-        this.descrLookups = new HashMap();
-        this.errors = new ArrayList();
-        this.buildStack = new Stack();
-        this.declarationResolver = new DeclarationScopeResolver( new Map[]{this.pkg.getGlobals()}, this.buildStack );
-        this.ruleDescr = ruleDescr;
-
-        if ( ruleDescr instanceof QueryDescr ) {
-            this.rule = new Query( ruleDescr.getName() );
-        } else {
-            this.rule = new Rule( ruleDescr.getName() );
-        }
-
-    }
-
-    /**
-     * Returns the list of errors found while building the current context
-     * @return
-     */
-    public List getErrors() {
-        return errors;
-    }
-
-    /**
-     * Returns the current package being built
-     * @return
-     */
-    public Package getPkg() {
-        return pkg;
-    }
-
-    /**
-     * Returns the current Rule being built
-     * @return
-     */
-    public Rule getRule() {
-        return rule;
-    }
-
-    /**
-     * Returns the current RuleDescriptor
-     * @return
-     */
-    public RuleDescr getRuleDescr() {
-        return ruleDescr;
-    }
-
-    /**
-     * Returns the available declarationResolver instance
-     * @return
-     */
-    public DeclarationScopeResolver getDeclarationResolver() {
-        return declarationResolver;
-    }
-
-    /**
-     * Sets the available declarationResolver instance
-     * @param declarationResolver
-     */
-    public void setDeclarationResolver(DeclarationScopeResolver variables) {
-        this.declarationResolver = variables;
-    }
-
-    /**
-     * Returns the Map<String invokerClassName, BaseDescr descr> of descriptor lookups
-     * @return
-     */
-    public Map getDescrLookups() {
-        return descrLookups;
-    }
-
-    public void setDescrLookups(Map descrLookups) {
-        this.descrLookups = descrLookups;
-    }
-
-    /**
-     * Returns the Map<String invokerClassName, ConditionalElement ce> of generated invoker lookups
-     * @return
-     */
-    public Map getInvokerLookups() {
-        return invokerLookups;
-    }
-
-    public void setInvokerLookups(Map invokerLookups) {
-        this.invokerLookups = invokerLookups;
-    }
-
-    /**
-     * Returns the Map<String invokerClassName, String invokerCode> of generated invokers
-     * @return
-     */
-    public Map getInvokers() {
-        return invokers;
-    }
-
-    public void setInvokers(Map invokers) {
-        this.invokers = invokers;
-    }
-
-    /**
-     * Returns the list of generated methods
-     * @return
-     */
-    public List getMethods() {
-        return methods;
-    }
-
-    public void setMethods(List methods) {
-        this.methods = methods;
-    }
-
-    /**
-     * Returns current counter value for generated method names
-     * @return
-     */
-    public int getCurrentId() {
-        return counter;
-    }
-
-    public int getNextId() {
-        return counter++;
-    }
-
-    public int getColumnId() {
-        return columnId;
-    }
-
-    public int getNextColumnId() {
-        return ++columnId;
-    }
-
-    public void setColumnId(int columnId) {
-        this.columnId = columnId;
-    }
-
-    public String getRuleClass() {
-        return ruleClass;
-    }
-
-    public void setRuleClass(String ruleClass) {
-        this.ruleClass = ruleClass;
-    }
-
-    public Stack getBuildStack() {
-        return buildStack;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/BuildContext.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildContext.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.drools.lang.descr.QueryDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.Package;
+import org.drools.rule.Query;
+import org.drools.rule.Rule;
+import org.drools.spi.DeclarationScopeResolver;
+
+/**
+ * A context for the current build
+ * 
+ * @author etirelli
+ */
+public class BuildContext {
+
+    // current package
+    private Package            pkg;
+
+    // current rule
+    private Rule               rule;
+    
+    // a stack for the rule building used
+    // for declarations resolution
+    private Stack              buildStack;
+
+    // current Rule descriptor
+    private RuleDescr          ruleDescr;
+
+    // the class name for the rule
+    private String             ruleClass;
+
+    // available declarationResolver 
+    private DeclarationScopeResolver declarationResolver;
+
+    // errors found when building the current context
+    private List               errors;
+
+    // list of generated methods
+    private List               methods;
+
+    // map<String invokerClassName, String invokerCode> of generated invokers
+    private Map                invokers;
+
+    // map<String invokerClassName, ConditionalElement ce> of generated invoker lookups
+    private Map                invokerLookups;
+
+    // map<String invokerClassName, BaseDescr descr> of descriptor lookups
+    private Map                descrLookups;
+
+    // a simple counter for generated names
+    private int                counter;
+
+    // a simple counter for columns
+    private int                columnId = -1;
+
+    /**
+     * Default constructor
+     */
+    public BuildContext(final Package pkg,
+                        final RuleDescr ruleDescr) {
+        this.pkg = pkg;
+
+        this.methods = new ArrayList();
+        this.invokers = new HashMap();
+        this.invokerLookups = new HashMap();
+        this.descrLookups = new HashMap();
+        this.errors = new ArrayList();
+        this.buildStack = new Stack();
+        this.declarationResolver = new DeclarationScopeResolver( new Map[]{this.pkg.getGlobals()}, this.buildStack );
+        this.ruleDescr = ruleDescr;
+
+        if ( ruleDescr instanceof QueryDescr ) {
+            this.rule = new Query( ruleDescr.getName() );
+        } else {
+            this.rule = new Rule( ruleDescr.getName() );
+        }
+
+    }
+
+    /**
+     * Returns the list of errors found while building the current context
+     * @return
+     */
+    public List getErrors() {
+        return errors;
+    }
+
+    /**
+     * Returns the current package being built
+     * @return
+     */
+    public Package getPkg() {
+        return pkg;
+    }
+
+    /**
+     * Returns the current Rule being built
+     * @return
+     */
+    public Rule getRule() {
+        return rule;
+    }
+
+    /**
+     * Returns the current RuleDescriptor
+     * @return
+     */
+    public RuleDescr getRuleDescr() {
+        return ruleDescr;
+    }
+
+    /**
+     * Returns the available declarationResolver instance
+     * @return
+     */
+    public DeclarationScopeResolver getDeclarationResolver() {
+        return declarationResolver;
+    }
+
+    /**
+     * Sets the available declarationResolver instance
+     * @param declarationResolver
+     */
+    public void setDeclarationResolver(DeclarationScopeResolver variables) {
+        this.declarationResolver = variables;
+    }
+
+    /**
+     * Returns the Map<String invokerClassName, BaseDescr descr> of descriptor lookups
+     * @return
+     */
+    public Map getDescrLookups() {
+        return descrLookups;
+    }
+
+    public void setDescrLookups(Map descrLookups) {
+        this.descrLookups = descrLookups;
+    }
+
+    /**
+     * Returns the Map<String invokerClassName, ConditionalElement ce> of generated invoker lookups
+     * @return
+     */
+    public Map getInvokerLookups() {
+        return invokerLookups;
+    }
+
+    public void setInvokerLookups(Map invokerLookups) {
+        this.invokerLookups = invokerLookups;
+    }
+
+    /**
+     * Returns the Map<String invokerClassName, String invokerCode> of generated invokers
+     * @return
+     */
+    public Map getInvokers() {
+        return invokers;
+    }
+
+    public void setInvokers(Map invokers) {
+        this.invokers = invokers;
+    }
+
+    /**
+     * Returns the list of generated methods
+     * @return
+     */
+    public List getMethods() {
+        return methods;
+    }
+
+    public void setMethods(List methods) {
+        this.methods = methods;
+    }
+
+    /**
+     * Returns current counter value for generated method names
+     * @return
+     */
+    public int getCurrentId() {
+        return counter;
+    }
+
+    public int getNextId() {
+        return counter++;
+    }
+
+    public int getColumnId() {
+        return columnId;
+    }
+
+    public int getNextColumnId() {
+        return ++columnId;
+    }
+
+    public void setColumnId(int columnId) {
+        this.columnId = columnId;
+    }
+
+    public String getRuleClass() {
+        return ruleClass;
+    }
+
+    public void setRuleClass(String ruleClass) {
+        this.ruleClass = ruleClass;
+    }
+
+    public Stack getBuildStack() {
+        return buildStack;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/BuildUtils.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,234 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.antlr.stringtemplate.StringTemplateGroup;
-import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
-import org.codehaus.jfdi.interpreter.TypeResolver;
-import org.drools.base.ClassFieldExtractorCache;
-import org.drools.compiler.RuleError;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.rule.Declaration;
-import org.drools.semantics.java.DeclarationTypeFixer;
-import org.drools.semantics.java.FunctionFixer;
-import org.drools.semantics.java.JavaExprAnalyzer;
-import org.drools.semantics.java.KnowledgeHelperFixer;
-import org.drools.semantics.java.RuleBuilder;
-
-/**
- * A holder class for utility functions
- * 
- * @author etirelli
- */
-public class BuildUtils {
-
-    // the string template groups
-    private final StringTemplateGroup      ruleGroup    = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaRule.stg" ) ),
-                                                                                   AngleBracketTemplateLexer.class );
-
-    private final StringTemplateGroup      invokerGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaInvokers.stg" ) ),
-                                                                                   AngleBracketTemplateLexer.class );
-
-    private final KnowledgeHelperFixer     knowledgeHelperFixer;
-
-    private final FunctionFixer            functionFixer;
-    
-    private final DeclarationTypeFixer     typeFixer;
-
-    private final JavaExprAnalyzer         analyzer;
-
-    private final TypeResolver             typeResolver;
-
-    private final ClassFieldExtractorCache classFieldExtractorCache;
-    
-    private final Map                      builders;
-
-    public BuildUtils(final FunctionFixer functionFixer,
-                      final KnowledgeHelperFixer knowledgeHelperFixer,
-                      final DeclarationTypeFixer typeFixer,
-                      final JavaExprAnalyzer analyzer,
-                      final TypeResolver typeResolver,
-                      final ClassFieldExtractorCache classFieldExtractorCache,
-                      final Map builders ) {
-        this.functionFixer = functionFixer;
-        this.knowledgeHelperFixer = knowledgeHelperFixer;
-        this.typeFixer = typeFixer;
-        this.analyzer = analyzer;
-        this.typeResolver = typeResolver;
-        this.classFieldExtractorCache = classFieldExtractorCache;
-        this.builders = builders;
-    }
-
-    public List[] getUsedIdentifiers(final BuildContext context,
-                                     final BaseDescr descr,
-                                     final String text) {
-        List[] usedIdentifiers = null;
-        try {
-            usedIdentifiers = this.analyzer.analyzeExpression( text,
-                                                               new Set[]{context.getDeclarationResolver().getDeclarations().keySet(), context.getPkg().getGlobals().keySet()} );
-        } catch ( final Exception e ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    descr,
-                                                    null,
-                                                    "Unable to determine the used declarations" ) );
-        }
-        return usedIdentifiers;
-    }
-
-    public List[] getUsedCIdentifiers(final BuildContext context,
-                                      final BaseDescr descr,
-                                      final String text) {
-        List[] usedIdentifiers = null;
-        try {
-            usedIdentifiers = this.analyzer.analyzeBlock( text,
-                                                          new Set[]{context.getDeclarationResolver().getDeclarations().keySet(), context.getPkg().getGlobals().keySet()} );
-        } catch ( final Exception e ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    descr,
-                                                    null,
-                                                    "Unable to determine the used declarations" ) );
-        }
-        return usedIdentifiers;
-    }
-
-    /**
-     * Sets usual string template attributes:
-     * 
-     * <li> list of declarations and declaration types</li>
-     * <li> list of globals and global types</li>
-     *
-     * @param context the current build context
-     * @param st the string template whose attributes will be set 
-     * @param declarations array of declarations to set
-     * @param globals array of globals to set
-     */
-    public void setStringTemplateAttributes(final BuildContext context,
-                                            final StringTemplate st,
-                                            final Declaration[] declarations,
-                                            final String[] globals) {
-        final String[] declarationTypes = new String[declarations.length];
-        for ( int i = 0, size = declarations.length; i < size; i++ ) {
-            declarationTypes[i] = this.typeFixer.fix( declarations[i] ); 
-        }
-
-        final List globalTypes = new ArrayList( globals.length );
-        for ( int i = 0, length = globals.length; i < length; i++ ) {
-            globalTypes.add( ((Class) context.getPkg().getGlobals().get( globals[i] )).getName().replace( '$',
-                                                                                                          '.' ) );
-        }
-
-        st.setAttribute( "declarations",
-                         declarations );
-        st.setAttribute( "declarationTypes",
-                         declarationTypes );
-
-        st.setAttribute( "globals",
-                         globals );
-        st.setAttribute( "globalTypes",
-                         globalTypes );
-    }
-
-    /**
-     * Upper case the first letter of "name"
-     * 
-     * @param name
-     * @return
-     */
-    public String ucFirst(final String name) {
-        return name.toUpperCase().charAt( 0 ) + name.substring( 1 );
-    }
-
-    /**
-     * Returns the string template group of invokers
-     * @return
-     */
-    public StringTemplateGroup getInvokerGroup() {
-        return invokerGroup;
-    }
-
-    /**
-     * Returns the string template group of actual rule templates
-     * @return
-     */
-    public StringTemplateGroup getRuleGroup() {
-        return ruleGroup;
-    }
-
-    /**
-     * Returns the Knowledge Helper Fixer
-     * @return
-     */
-    public KnowledgeHelperFixer getKnowledgeHelperFixer() {
-        return knowledgeHelperFixer;
-    }
-
-    /**
-     * Returns the function fixer instance
-     * @return
-     */
-    public FunctionFixer getFunctionFixer() {
-        return functionFixer;
-    }
-
-    /**
-     * Returns the current type resolver instance
-     * @return
-     */
-    public TypeResolver getTypeResolver() {
-        return this.typeResolver;
-    }
-
-    /**
-     * Returns the cache of field extractors
-     * @return
-     */
-    public ClassFieldExtractorCache getClassFieldExtractorCache() {
-        return classFieldExtractorCache;
-    }
-
-    /**
-     * Returns a map<Class, ConditionalElementBuilder> of builders
-     * @return
-     */
-    public Map getBuilders() {
-        return builders;
-    }
-
-    /**
-     * Returns the builder for the given descriptor class
-     * @param descr
-     * @return
-     */
-    public ConditionalElementBuilder getBuilder(Class descr) {
-        return (ConditionalElementBuilder) builders.get( descr );
-    }
-
-    /**
-     * @return the typeFixer
-     */
-    public DeclarationTypeFixer getTypeFixer() {
-        return typeFixer;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/BuildUtils.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/BuildUtils.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
+import org.codehaus.jfdi.interpreter.TypeResolver;
+import org.drools.base.ClassFieldExtractorCache;
+import org.drools.compiler.RuleError;
+import org.drools.dialect.java.DeclarationTypeFixer;
+import org.drools.dialect.java.JavaExprAnalyzer;
+import org.drools.dialect.java.KnowledgeHelperFixer;
+import org.drools.dialect.java.RuleBuilder;
+import org.drools.lang.descr.BaseDescr;
+import org.drools.rule.Declaration;
+
+/**
+ * A holder class for utility functions
+ * 
+ * @author etirelli
+ */
+public class BuildUtils {
+
+    // the string template groups
+    private final StringTemplateGroup      ruleGroup    = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaRule.stg" ) ),
+                                                                                   AngleBracketTemplateLexer.class );
+
+    private final StringTemplateGroup      invokerGroup = new StringTemplateGroup( new InputStreamReader( RuleBuilder.class.getResourceAsStream( "javaInvokers.stg" ) ),
+                                                                                   AngleBracketTemplateLexer.class );
+
+    private final KnowledgeHelperFixer     knowledgeHelperFixer;
+  
+    private final DeclarationTypeFixer     typeFixer;
+
+    private final JavaExprAnalyzer         analyzer;
+
+    private final TypeResolver             typeResolver;
+
+    private final ClassFieldExtractorCache classFieldExtractorCache;
+    
+    private final Map                      builders;
+
+    public BuildUtils(final KnowledgeHelperFixer knowledgeHelperFixer,
+                      final DeclarationTypeFixer typeFixer,
+                      final JavaExprAnalyzer analyzer,
+                      final TypeResolver typeResolver,
+                      final ClassFieldExtractorCache classFieldExtractorCache,
+                      final Map builders ) {
+        this.knowledgeHelperFixer = knowledgeHelperFixer;
+        this.typeFixer = typeFixer;
+        this.analyzer = analyzer;
+        this.typeResolver = typeResolver;
+        this.classFieldExtractorCache = classFieldExtractorCache;
+        this.builders = builders;
+    }
+
+    public List[] getUsedIdentifiers(final BuildContext context,
+                                     final BaseDescr descr,
+                                     final String text) {
+        List[] usedIdentifiers = null;
+        try {
+            usedIdentifiers = this.analyzer.analyzeExpression( text,
+                                                               new Set[]{context.getDeclarationResolver().getDeclarations().keySet(), context.getPkg().getGlobals().keySet()} );
+        } catch ( final Exception e ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    descr,
+                                                    null,
+                                                    "Unable to determine the used declarations" ) );
+        }
+        return usedIdentifiers;
+    }
+
+    public List[] getUsedCIdentifiers(final BuildContext context,
+                                      final BaseDescr descr,
+                                      final String text) {
+        List[] usedIdentifiers = null;
+        try {
+            usedIdentifiers = this.analyzer.analyzeBlock( text,
+                                                          new Set[]{context.getDeclarationResolver().getDeclarations().keySet(), context.getPkg().getGlobals().keySet()} );
+        } catch ( final Exception e ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    descr,
+                                                    null,
+                                                    "Unable to determine the used declarations" ) );
+        }
+        return usedIdentifiers;
+    }
+
+    /**
+     * Sets usual string template attributes:
+     * 
+     * <li> list of declarations and declaration types</li>
+     * <li> list of globals and global types</li>
+     *
+     * @param context the current build context
+     * @param st the string template whose attributes will be set 
+     * @param declarations array of declarations to set
+     * @param globals array of globals to set
+     */
+    public void setStringTemplateAttributes(final BuildContext context,
+                                            final StringTemplate st,
+                                            final Declaration[] declarations,
+                                            final String[] globals) {
+        final String[] declarationTypes = new String[declarations.length];
+        for ( int i = 0, size = declarations.length; i < size; i++ ) {
+            declarationTypes[i] = this.typeFixer.fix( declarations[i] ); 
+        }
+
+        final List globalTypes = new ArrayList( globals.length );
+        for ( int i = 0, length = globals.length; i < length; i++ ) {
+            globalTypes.add( ((Class) context.getPkg().getGlobals().get( globals[i] )).getName().replace( '$',
+                                                                                                          '.' ) );
+        }
+
+        st.setAttribute( "declarations",
+                         declarations );
+        st.setAttribute( "declarationTypes",
+                         declarationTypes );
+
+        st.setAttribute( "globals",
+                         globals );
+        st.setAttribute( "globalTypes",
+                         globalTypes );
+    }
+
+    /**
+     * Upper case the first letter of "name"
+     * 
+     * @param name
+     * @return
+     */
+    public String ucFirst(final String name) {
+        return name.toUpperCase().charAt( 0 ) + name.substring( 1 );
+    }
+
+    /**
+     * Returns the string template group of invokers
+     * @return
+     */
+    public StringTemplateGroup getInvokerGroup() {
+        return invokerGroup;
+    }
+
+    /**
+     * Returns the string template group of actual rule templates
+     * @return
+     */
+    public StringTemplateGroup getRuleGroup() {
+        return ruleGroup;
+    }
+
+    /**
+     * Returns the Knowledge Helper Fixer
+     * @return
+     */
+    public KnowledgeHelperFixer getKnowledgeHelperFixer() {
+        return knowledgeHelperFixer;
+    }
+
+    /**
+     * Returns the current type resolver instance
+     * @return
+     */
+    public TypeResolver getTypeResolver() {
+        return this.typeResolver;
+    }
+
+    /**
+     * Returns the cache of field extractors
+     * @return
+     */
+    public ClassFieldExtractorCache getClassFieldExtractorCache() {
+        return classFieldExtractorCache;
+    }
+
+    /**
+     * Returns a map<Class, ConditionalElementBuilder> of builders
+     * @return
+     */
+    public Map getBuilders() {
+        return builders;
+    }
+
+    /**
+     * Returns the builder for the given descriptor class
+     * @param descr
+     * @return
+     */
+    public ConditionalElementBuilder getBuilder(Class descr) {
+        return (ConditionalElementBuilder) builders.get( descr );
+    }
+
+    /**
+     * @return the typeFixer
+     */
+    public DeclarationTypeFixer getTypeFixer() {
+        return typeFixer;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/CollectBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,59 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.CollectDescr;
-import org.drools.rule.Collect;
-import org.drools.rule.Column;
-import org.drools.rule.ConditionalElement;
-
-/**
- * @author etirelli
- *
- */
-public class CollectBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /* (non-Javadoc)
-     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
-     */
-    public ConditionalElement build(BuildContext context,
-                                    BuildUtils utils,
-                                    ColumnBuilder columnBuilder,
-                                    BaseDescr descr) {
-        
-        CollectDescr collectDescr = (CollectDescr) descr;
-        
-        Column sourceColumn = columnBuilder.build( context, utils, collectDescr.getSourceColumn() );
-
-        if ( sourceColumn == null ) {
-            return null;
-        }
-
-        Column resultColumn = columnBuilder.build( context, utils, collectDescr.getResultColumn() );
-
-        final String className = "collect" + context.getNextId();
-        collectDescr.setClassMethodName( className );
-
-        Collect collect = new Collect( sourceColumn,
-                                       resultColumn );
-        return collect;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/CollectBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/CollectBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.CollectDescr;
+import org.drools.rule.Collect;
+import org.drools.rule.Column;
+import org.drools.rule.ConditionalElement;
+
+/**
+ * @author etirelli
+ *
+ */
+public class CollectBuilder
+    implements
+    ConditionalElementBuilder {
+
+    /* (non-Javadoc)
+     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
+     */
+    public ConditionalElement build(BuildContext context,
+                                    BuildUtils utils,
+                                    ColumnBuilder columnBuilder,
+                                    BaseDescr descr) {
+        
+        CollectDescr collectDescr = (CollectDescr) descr;
+        
+        Column sourceColumn = columnBuilder.build( context, utils, collectDescr.getSourceColumn() );
+
+        if ( sourceColumn == null ) {
+            return null;
+        }
+
+        Column resultColumn = columnBuilder.build( context, utils, collectDescr.getResultColumn() );
+
+        final String className = "collect" + context.getNextId();
+        collectDescr.setClassMethodName( className );
+
+        Collect collect = new Collect( sourceColumn,
+                                       resultColumn );
+        return collect;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ColumnBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,706 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.drools.RuntimeDroolsException;
-import org.drools.base.ClassObjectType;
-import org.drools.base.FieldFactory;
-import org.drools.base.ShadowProxyFactory;
-import org.drools.base.ValueType;
-import org.drools.base.evaluators.Operator;
-import org.drools.compiler.RuleError;
-import org.drools.facttemplates.FactTemplate;
-import org.drools.facttemplates.FactTemplateFieldExtractor;
-import org.drools.facttemplates.FactTemplateObjectType;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.ColumnDescr;
-import org.drools.lang.descr.FieldBindingDescr;
-import org.drools.lang.descr.FieldConstraintDescr;
-import org.drools.lang.descr.LiteralRestrictionDescr;
-import org.drools.lang.descr.PredicateDescr;
-import org.drools.lang.descr.RestrictionConnectiveDescr;
-import org.drools.lang.descr.RestrictionDescr;
-import org.drools.lang.descr.ReturnValueRestrictionDescr;
-import org.drools.lang.descr.VariableRestrictionDescr;
-import org.drools.rule.AndCompositeRestriction;
-import org.drools.rule.Column;
-import org.drools.rule.Declaration;
-import org.drools.rule.LiteralConstraint;
-import org.drools.rule.LiteralRestriction;
-import org.drools.rule.MultiRestrictionFieldConstraint;
-import org.drools.rule.OrCompositeRestriction;
-import org.drools.rule.PredicateConstraint;
-import org.drools.rule.ReturnValueConstraint;
-import org.drools.rule.ReturnValueRestriction;
-import org.drools.rule.VariableConstraint;
-import org.drools.rule.VariableRestriction;
-import org.drools.spi.Evaluator;
-import org.drools.spi.FieldExtractor;
-import org.drools.spi.FieldValue;
-import org.drools.spi.ObjectType;
-import org.drools.spi.Restriction;
-
-/**
- * A builder for columns
- * 
- * @author etirelli
- */
-public class ColumnBuilder {
-
-    /**
-     * Build a column for the given descriptor in the current 
-     * context and using the given utils object
-     * 
-     * @param context
-     * @param utils
-     * @param columnDescr
-     * @return
-     */
-    public Column build(final BuildContext context,
-                        final BuildUtils utils,
-                        final ColumnDescr columnDescr) {
-
-        if ( columnDescr.getObjectType() == null || columnDescr.getObjectType().equals( "" ) ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    columnDescr,
-                                                    null,
-                                                    "ObjectType not correctly defined" ) );
-            return null;
-        }
-
-        ObjectType objectType = null;
-
-        final FactTemplate factTemplate = context.getPkg().getFactTemplate( columnDescr.getObjectType() );
-
-        if ( factTemplate != null ) {
-            objectType = new FactTemplateObjectType( factTemplate );
-        } else {
-            try {
-                Class userProvidedClass = utils.getTypeResolver().resolveType( columnDescr.getObjectType() );
-                String shadowProxyName = ShadowProxyFactory.getProxyClassNameForClass( userProvidedClass );
-                Class shadowClass = null;
-                try {
-                    // if already loaded
-                    shadowClass = context.getPkg().getPackageCompilationData().getClassLoader().loadClass( shadowProxyName );
-                } catch ( ClassNotFoundException cnfe ) {
-                    // otherwise, create and load
-                    byte[] proxyBytes = ShadowProxyFactory.getProxyBytes( userProvidedClass );
-                    if ( proxyBytes != null ) {
-                        context.getPkg().getPackageCompilationData().write( shadowProxyName,
-                                                                            proxyBytes );
-                        shadowClass = context.getPkg().getPackageCompilationData().getClassLoader().loadClass( shadowProxyName );
-                    }
-
-                }
-                objectType = new ClassObjectType( userProvidedClass,
-                                                  shadowClass );
-            } catch ( final ClassNotFoundException e ) {
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        columnDescr,
-                                                        null,
-                                                        "Unable to resolve ObjectType '" + columnDescr.getObjectType() + "'" ) );
-                return null;
-            }
-        }
-
-        Column column;
-        if ( columnDescr.getIdentifier() != null && !columnDescr.getIdentifier().equals( "" ) ) {
-            
-            if ( context.getDeclarationResolver().isDuplicated( columnDescr.getIdentifier() ) ) {
-                // This declaration already  exists, so throw an Exception
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        columnDescr,
-                                                        null,
-                                                        "Duplicate declaration for variable '" + columnDescr.getIdentifier() + "' in the rule '" + context.getRule().getName() + "'" ) );
-            }
-
-            column = new Column( context.getNextColumnId(),
-                                 0, // offset is 0 by default
-                                 objectType,
-                                 columnDescr.getIdentifier() );
-        } else {
-            column = new Column( context.getNextColumnId(),
-                                 0, // offset is 0 by default
-                                 objectType,
-                                 null );
-        }
-        // adding the newly created column to the build stack
-        // this is necessary in case of local declaration usage
-        context.getBuildStack().push( column );
-
-        for ( final Iterator it = columnDescr.getDescrs().iterator(); it.hasNext(); ) {
-            final Object object = it.next();
-            if ( object instanceof FieldBindingDescr ) {
-                build( context,
-                       utils,
-                       column,
-                       (FieldBindingDescr) object );
-            } else if ( object instanceof FieldConstraintDescr ) {
-                build( context,
-                       utils,
-                       column,
-                       (FieldConstraintDescr) object );
-            } else if ( object instanceof PredicateDescr ) {
-                build( context,
-                       utils,
-                       column,
-                       (PredicateDescr) object );
-            }
-        }
-        // poping the column
-        context.getBuildStack().pop();
-        return column;
-    }
-
-    private void build(final BuildContext context,
-                       final BuildUtils utils,
-                       final Column column,
-                       final FieldConstraintDescr fieldConstraintDescr) {
-
-        final FieldExtractor extractor = getFieldExtractor( context,
-                                                            utils,
-                                                            fieldConstraintDescr,
-                                                            column.getObjectType(),
-                                                            fieldConstraintDescr.getFieldName() );
-        if ( extractor == null ) {
-            // @todo log error
-            return;
-        }
-
-        if ( fieldConstraintDescr.getRestrictions().size() == 1 ) {
-            final Object object = fieldConstraintDescr.getRestrictions().get( 0 );
-
-            final Restriction restriction = buildRestriction( context,
-                                                              utils,
-                                                              column,
-                                                              extractor,
-                                                              fieldConstraintDescr,
-                                                              (RestrictionDescr) object );
-            if ( restriction == null ) {
-                // @todo log errors
-                return;
-            }
-
-            if ( object instanceof LiteralRestrictionDescr ) {
-                column.addConstraint( new LiteralConstraint( extractor,
-                                                             (LiteralRestriction) restriction ) );
-            } else if ( object instanceof VariableRestrictionDescr ) {
-                column.addConstraint( new VariableConstraint( extractor,
-                                                              (VariableRestriction) restriction ) );
-            } else if ( object instanceof ReturnValueRestrictionDescr ) {
-                column.addConstraint( new ReturnValueConstraint( extractor,
-                                                                 (ReturnValueRestriction) restriction ) );
-            }
-
-            return;
-        }
-
-        final List orList = new ArrayList();
-        List andList = null;
-
-        RestrictionDescr currentRestriction = null;
-        RestrictionDescr previousRestriction = null;
-
-        List currentList = null;
-        List previousList = null;
-
-        for ( final Iterator it = fieldConstraintDescr.getRestrictions().iterator(); it.hasNext(); ) {
-            final Object object = it.next();
-
-            // Process an and/or connective 
-            if ( object instanceof RestrictionConnectiveDescr ) {
-
-                // is the connective an 'and'?
-                if ( ((RestrictionConnectiveDescr) object).getConnective() == RestrictionConnectiveDescr.AND ) {
-                    // if andList is null, then we know its the first
-                    if ( andList == null ) {
-                        andList = new ArrayList();
-                    }
-                    previousList = currentList;
-                    currentList = andList;
-                } else {
-                    previousList = currentList;
-                    currentList = orList;
-                }
-            } else {
-                Restriction restriction = null;
-                if ( currentList != null ) {
-                    // Are we are at the first operator? if so treat differently
-                    if ( previousList == null ) {
-                        restriction = buildRestriction( context,
-                                                        utils,
-                                                        column,
-                                                        extractor,
-                                                        fieldConstraintDescr,
-                                                        previousRestriction );
-                        if ( currentList == andList ) {
-                            andList.add( restriction );
-                        } else {
-                            orList.add( restriction );
-                        }
-                    } else {
-                        restriction = buildRestriction( context,
-                                                        utils,
-                                                        column,
-                                                        extractor,
-                                                        fieldConstraintDescr,
-                                                        previousRestriction );
-
-                        if ( previousList == andList && currentList == orList ) {
-                            andList.add( restriction );
-                            if ( andList.size() == 1 ) {
-                                // Can't have an 'and' connective with one child, so add directly to the or list
-                                orList.add( andList.get( 0 ) );
-                            } else {
-                                final Restriction restrictions = new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) );
-                                orList.add( restrictions );
-                            }
-                            andList = null;
-                        } else if ( previousList == andList && currentList == andList ) {
-                            andList.add( restriction );
-                        } else if ( previousList == orList && currentList == andList ) {
-                            andList.add( restriction );
-                        } else if ( previousList == orList && currentList == orList ) {
-                            orList.add( restriction );
-                        }
-                    }
-                }
-            }
-            previousRestriction = currentRestriction;
-            currentRestriction = (RestrictionDescr) object;
-        }
-
-        final Restriction restriction = buildRestriction( context,
-                                                          utils,
-                                                          column,
-                                                          extractor,
-                                                          fieldConstraintDescr,
-                                                          currentRestriction );
-        currentList.add( restriction );
-
-        Restriction restrictions = null;
-        if ( currentList == andList && !orList.isEmpty() ) {
-            // Check if it finished with an and, and process it
-            if ( andList != null ) {
-                if ( andList.size() == 1 ) {
-                    // Can't have an 'and' connective with one child, so add directly to the or list
-                    orList.add( andList.get( 0 ) );
-                } else {
-                    orList.add( new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) ) );
-                }
-                andList = null;
-            }
-        }
-
-        if ( !orList.isEmpty() ) {
-            restrictions = new OrCompositeRestriction( (Restriction[]) orList.toArray( new Restriction[orList.size()] ) );
-        } else if ( andList != null && !andList.isEmpty() ) {
-            restrictions = new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) );
-        } else {
-            // @todo throw error
-        }
-
-        column.addConstraint( new MultiRestrictionFieldConstraint( extractor,
-                                                                   restrictions ) );
-    }
-
-    private void build(final BuildContext context,
-                       final BuildUtils utils,
-                       final Column column,
-                       final FieldBindingDescr fieldBindingDescr) {
-
-        if ( context.getDeclarationResolver().isDuplicated( fieldBindingDescr.getIdentifier() ) ) {
-            // This declaration already  exists, so throw an Exception
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    fieldBindingDescr,
-                                                    null,
-                                                    "Duplicate declaration for variable '" + fieldBindingDescr.getIdentifier() + "' in the rule '" + context.getRule().getName() + "'" ) );
-            return;
-        }
-
-        final FieldExtractor extractor = getFieldExtractor( context,
-                                                            utils,
-                                                            fieldBindingDescr,
-                                                            column.getObjectType(),
-                                                            fieldBindingDescr.getFieldName() );
-        if ( extractor == null ) {
-            return;
-        }
-
-        column.addDeclaration( fieldBindingDescr.getIdentifier(),
-                               extractor );
-    }
-
-    private void build(final BuildContext context,
-                       final BuildUtils utils,
-                       final Column column,
-                       final PredicateDescr predicateDescr) {
-        // generate 
-        // generate Invoker
-        final String className = "predicate" + context.getNextId();
-        predicateDescr.setClassMethodName( className );
-
-        final List[] usedIdentifiers = utils.getUsedIdentifiers( context,
-                                                                 predicateDescr,
-                                                                 predicateDescr.getText() );
-
-        final List tupleDeclarations = new ArrayList();
-        final List factDeclarations = new ArrayList();
-        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            Declaration decl = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
-            if ( decl.getColumn() == column ) {
-                factDeclarations.add( decl );
-            } else {
-                tupleDeclarations.add( decl );
-            }
-        }
-        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
-        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
-
-        final PredicateConstraint predicateConstraint = new PredicateConstraint( previousDeclarations,
-                                                                                 localDeclarations );
-        column.addConstraint( predicateConstraint );
-
-        StringTemplate st = utils.getRuleGroup().getInstanceOf( "predicateMethod" );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           previousDeclarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        final String[] localDeclarationTypes = new String[localDeclarations.length];
-        for ( int i = 0, size = localDeclarations.length; i < size; i++ ) {
-            localDeclarationTypes[i] = utils.getTypeFixer().fix( localDeclarations[i] );
-        }
-
-        st.setAttribute( "localDeclarations",
-                         localDeclarations );
-        st.setAttribute( "localDeclarationTypes",
-                         localDeclarationTypes );
-
-        st.setAttribute( "methodName",
-                         className );
-
-        final String predicateText = utils.getFunctionFixer().fix( predicateDescr.getText(),
-                                                                   context.getDeclarationResolver() );
-        st.setAttribute( "text",
-                         predicateText );
-
-        context.getMethods().add( st.toString() );
-
-        st = utils.getInvokerGroup().getInstanceOf( "predicateInvoker" );
-
-        st.setAttribute( "package",
-                         context.getPkg().getName() );
-        st.setAttribute( "ruleClassName",
-                         utils.ucFirst( context.getRuleDescr().getClassName() ) );
-        st.setAttribute( "invokerClassName",
-                         context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker" );
-        st.setAttribute( "methodName",
-                         className );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           previousDeclarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        st.setAttribute( "localDeclarations",
-                         localDeclarations );
-        st.setAttribute( "localDeclarationTypes",
-                         localDeclarationTypes );
-
-        st.setAttribute( "hashCode",
-                         predicateText.hashCode() );
-
-        final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker";
-        context.getInvokers().put( invokerClassName,
-                                   st.toString() );
-        context.getInvokerLookups().put( invokerClassName,
-                                         predicateConstraint );
-        context.getDescrLookups().put( invokerClassName,
-                                       predicateDescr );
-    }
-
-    private Restriction buildRestriction(final BuildContext context,
-                                         final BuildUtils utils,
-                                         final Column column,
-                                         final FieldExtractor extractor,
-                                         final FieldConstraintDescr fieldConstraintDescr,
-                                         final RestrictionDescr restrictionDescr) {
-        Restriction restriction = null;
-        if ( restrictionDescr instanceof LiteralRestrictionDescr ) {
-            restriction = buildRestriction( context,
-                                            utils,
-                                            extractor,
-                                            fieldConstraintDescr,
-                                            (LiteralRestrictionDescr) restrictionDescr );
-        } else if ( restrictionDescr instanceof VariableRestrictionDescr ) {
-            restriction = buildRestriction( context,
-                                            extractor,
-                                            fieldConstraintDescr,
-                                            (VariableRestrictionDescr) restrictionDescr );
-        } else if ( restrictionDescr instanceof ReturnValueRestrictionDescr ) {
-            restriction = buildRestriction( context,
-                                            utils,
-                                            column,
-                                            extractor,
-                                            fieldConstraintDescr,
-                                            (ReturnValueRestrictionDescr) restrictionDescr );
-
-        }
-
-        return restriction;
-    }
-
-    private VariableRestriction buildRestriction(final BuildContext context,
-                                                 final FieldExtractor extractor,
-                                                 final FieldConstraintDescr fieldConstraintDescr,
-                                                 final VariableRestrictionDescr variableRestrictionDescr) {
-        if ( variableRestrictionDescr.getIdentifier() == null || variableRestrictionDescr.getIdentifier().equals( "" ) ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    variableRestrictionDescr,
-                                                    null,
-                                                    "Identifier not defined for binding field '" + fieldConstraintDescr.getFieldName() + "'" ) );
-            return null;
-        }
-
-        final Declaration declaration = (Declaration) context.getDeclarationResolver().getDeclaration( variableRestrictionDescr.getIdentifier() );
-
-        if ( declaration == null ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    variableRestrictionDescr,
-                                                    null,
-                                                    "Unable to return Declaration for identifier '" + variableRestrictionDescr.getIdentifier() + "'" ) );
-            return null;
-        }
-
-        final Evaluator evaluator = getEvaluator( context,
-                                                  variableRestrictionDescr,
-                                                  extractor.getValueType(),
-                                                  variableRestrictionDescr.getEvaluator() );
-        if ( evaluator == null ) {
-            return null;
-        }
-
-        return new VariableRestriction( extractor,
-                                        declaration,
-                                        evaluator );
-    }
-
-    private LiteralRestriction buildRestriction(final BuildContext context,
-                                                final BuildUtils utils,
-                                                final FieldExtractor extractor,
-                                                final FieldConstraintDescr fieldConstraintDescr,
-                                                final LiteralRestrictionDescr literalRestrictionDescr) {
-        FieldValue field = null;
-        if ( literalRestrictionDescr.isStaticFieldValue() ) {
-            final int lastDot = literalRestrictionDescr.getText().lastIndexOf( '.' );
-            final String className = literalRestrictionDescr.getText().substring( 0,
-                                                                                  lastDot );
-            final String fieldName = literalRestrictionDescr.getText().substring( lastDot + 1 );
-            try {
-                final Class staticClass = utils.getTypeResolver().resolveType( className );
-                field = FieldFactory.getFieldValue( staticClass.getField( fieldName ).get( null ).toString(),
-                                                    extractor.getValueType() );
-            } catch ( final ClassNotFoundException e ) {
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        literalRestrictionDescr,
-                                                        e,
-                                                        e.getMessage() ) );
-            } catch ( final Exception e ) {
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        literalRestrictionDescr,
-                                                        e,
-                                                        "Unable to create a Field value of type  '" + extractor.getValueType() + "' and value '" + literalRestrictionDescr.getText() + "'" ) );
-            }
-
-        } else {
-            try {
-                field = FieldFactory.getFieldValue( literalRestrictionDescr.getText(),
-                                                    extractor.getValueType() );
-            } catch ( final Exception e ) {
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        literalRestrictionDescr,
-                                                        e,
-                                                        "Unable to create a Field value of type  '" + extractor.getValueType() + "' and value '" + literalRestrictionDescr.getText() + "'" ) );
-            }
-        }
-
-        final Evaluator evaluator = getEvaluator( context,
-                                                  literalRestrictionDescr,
-                                                  extractor.getValueType(),
-                                                  literalRestrictionDescr.getEvaluator() );
-        if ( evaluator == null ) {
-            return null;
-        }
-
-        return new LiteralRestriction( field,
-                                       evaluator,
-                                       extractor );
-    }
-
-    private ReturnValueRestriction buildRestriction(final BuildContext context,
-                                                    final BuildUtils utils,
-                                                    final Column column,
-                                                    final FieldExtractor extractor,
-                                                    final FieldConstraintDescr fieldConstraintDescr,
-                                                    final ReturnValueRestrictionDescr returnValueRestrictionDescr) {
-        final String className = "returnValue" + context.getNextId();
-        returnValueRestrictionDescr.setClassMethodName( className );
-
-        final List[] usedIdentifiers = utils.getUsedIdentifiers( context,
-                                                                 returnValueRestrictionDescr,
-                                                                 returnValueRestrictionDescr.getText() );
-
-        final List tupleDeclarations = new ArrayList();
-        final List factDeclarations = new ArrayList();
-        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            Declaration declaration = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
-            if ( declaration.getColumn() == column ) {
-                factDeclarations.add( declaration );
-            } else {
-                tupleDeclarations.add( declaration );
-            }
-        }
-
-        final Evaluator evaluator = getEvaluator( context,
-                                                  returnValueRestrictionDescr,
-                                                  extractor.getValueType(),
-                                                  returnValueRestrictionDescr.getEvaluator() );
-        if ( evaluator == null ) {
-            return null;
-        }
-
-        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
-        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
-        final ReturnValueRestriction returnValueRestriction = new ReturnValueRestriction( extractor,
-                                                                                          previousDeclarations,
-                                                                                          localDeclarations,
-                                                                                          evaluator );
-
-        StringTemplate st = utils.getRuleGroup().getInstanceOf( "returnValueMethod" );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           previousDeclarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        final String[] localDeclarationTypes = new String[localDeclarations.length];
-        for ( int i = 0, size = localDeclarations.length; i < size; i++ ) {
-            localDeclarationTypes[i] = utils.getTypeFixer().fix( localDeclarations[i] );
-        }
-
-        st.setAttribute( "localDeclarations",
-                         localDeclarations );
-        st.setAttribute( "localDeclarationTypes",
-                         localDeclarationTypes );
-
-        st.setAttribute( "methodName",
-                         className );
-
-        final String returnValueText = utils.getFunctionFixer().fix( returnValueRestrictionDescr.getText(),
-                                                                     context.getDeclarationResolver() );
-        st.setAttribute( "text",
-                         returnValueText );
-
-        context.getMethods().add( st.toString() );
-
-        st = utils.getInvokerGroup().getInstanceOf( "returnValueInvoker" );
-
-        st.setAttribute( "package",
-                         context.getPkg().getName() );
-        st.setAttribute( "ruleClassName",
-                         utils.ucFirst( context.getRuleDescr().getClassName() ) );
-        st.setAttribute( "invokerClassName",
-                         context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker" );
-        st.setAttribute( "methodName",
-                         className );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           previousDeclarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        st.setAttribute( "localDeclarations",
-                         localDeclarations );
-        st.setAttribute( "localDeclarationTypes",
-                         localDeclarationTypes );
-
-        st.setAttribute( "hashCode",
-                         returnValueText.hashCode() );
-
-        final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker";
-        context.getInvokers().put( invokerClassName,
-                                   st.toString() );
-        context.getInvokerLookups().put( invokerClassName,
-                                         returnValueRestriction );
-        context.getDescrLookups().put( invokerClassName,
-                                       returnValueRestrictionDescr );
-
-        return returnValueRestriction;
-    }
-
-    private FieldExtractor getFieldExtractor(final BuildContext context,
-                                             final BuildUtils utils,
-                                             final BaseDescr descr,
-                                             final ObjectType objectType,
-                                             final String fieldName) {
-        FieldExtractor extractor = null;
-
-        if ( objectType.getValueType() == ValueType.FACTTEMPLATE_TYPE ) {
-            //@todo use extractor cache            
-            final FactTemplate factTemplate = ((FactTemplateObjectType) objectType).getFactTemplate();
-            extractor = new FactTemplateFieldExtractor( factTemplate,
-                                                        factTemplate.getFieldTemplateIndex( fieldName ) );
-        } else {
-            try {
-                extractor = utils.getClassFieldExtractorCache().getExtractor( ((ClassObjectType) objectType).getClassType(),
-                                                                              fieldName );
-            } catch ( final RuntimeDroolsException e ) {
-                context.getErrors().add( new RuleError( context.getRule(),
-                                                        descr,
-                                                        e,
-                                                        "Unable to create Field Extractor for '" + fieldName + "'" ) );
-            }
-        }
-
-        return extractor;
-    }
-
-    private Evaluator getEvaluator(final BuildContext context,
-                                   final BaseDescr descr,
-                                   final ValueType valueType,
-                                   final String evaluatorString) {
-
-        final Evaluator evaluator = valueType.getEvaluator( Operator.determineOperator( evaluatorString ) );
-
-        if ( evaluator == null ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    descr,
-                                                    null,
-                                                    "Unable to determine the Evaluator for  '" + valueType + "' and '" + evaluatorString + "'" ) );
-        }
-
-        return evaluator;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ColumnBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ColumnBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,603 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.drools.RuntimeDroolsException;
+import org.drools.base.ClassObjectType;
+import org.drools.base.FieldFactory;
+import org.drools.base.ShadowProxyFactory;
+import org.drools.base.ValueType;
+import org.drools.base.evaluators.Operator;
+import org.drools.compiler.RuleError;
+import org.drools.dialect.java.JavaPredicateBuilder;
+import org.drools.dialect.java.JavaReturnValueBuilder;
+import org.drools.facttemplates.FactTemplate;
+import org.drools.facttemplates.FactTemplateFieldExtractor;
+import org.drools.facttemplates.FactTemplateObjectType;
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.ColumnDescr;
+import org.drools.lang.descr.FieldBindingDescr;
+import org.drools.lang.descr.FieldConstraintDescr;
+import org.drools.lang.descr.LiteralRestrictionDescr;
+import org.drools.lang.descr.PredicateDescr;
+import org.drools.lang.descr.RestrictionConnectiveDescr;
+import org.drools.lang.descr.RestrictionDescr;
+import org.drools.lang.descr.ReturnValueRestrictionDescr;
+import org.drools.lang.descr.VariableRestrictionDescr;
+import org.drools.rule.AndCompositeRestriction;
+import org.drools.rule.Column;
+import org.drools.rule.Declaration;
+import org.drools.rule.LiteralConstraint;
+import org.drools.rule.LiteralRestriction;
+import org.drools.rule.MultiRestrictionFieldConstraint;
+import org.drools.rule.OrCompositeRestriction;
+import org.drools.rule.PredicateConstraint;
+import org.drools.rule.ReturnValueConstraint;
+import org.drools.rule.ReturnValueRestriction;
+import org.drools.rule.VariableConstraint;
+import org.drools.rule.VariableRestriction;
+import org.drools.spi.Evaluator;
+import org.drools.spi.FieldExtractor;
+import org.drools.spi.FieldValue;
+import org.drools.spi.ObjectType;
+import org.drools.spi.Restriction;
+
+/**
+ * A builder for columns
+ * 
+ * @author etirelli
+ */
+public class ColumnBuilder {
+
+    /**
+     * Build a column for the given descriptor in the current 
+     * context and using the given utils object
+     * 
+     * @param context
+     * @param utils
+     * @param columnDescr
+     * @return
+     */
+    public Column build(final BuildContext context,
+                        final BuildUtils utils,
+                        final ColumnDescr columnDescr) {
+
+        if ( columnDescr.getObjectType() == null || columnDescr.getObjectType().equals( "" ) ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    columnDescr,
+                                                    null,
+                                                    "ObjectType not correctly defined" ) );
+            return null;
+        }
+
+        ObjectType objectType = null;
+
+        final FactTemplate factTemplate = context.getPkg().getFactTemplate( columnDescr.getObjectType() );
+
+        if ( factTemplate != null ) {
+            objectType = new FactTemplateObjectType( factTemplate );
+        } else {
+            try {
+                Class userProvidedClass = utils.getTypeResolver().resolveType( columnDescr.getObjectType() );
+                String shadowProxyName = ShadowProxyFactory.getProxyClassNameForClass( userProvidedClass );
+                Class shadowClass = null;
+                try {
+                    // if already loaded
+                    shadowClass = context.getPkg().getPackageCompilationData().getClassLoader().loadClass( shadowProxyName );
+                } catch ( ClassNotFoundException cnfe ) {
+                    // otherwise, create and load
+                    byte[] proxyBytes = ShadowProxyFactory.getProxyBytes( userProvidedClass );
+                    if ( proxyBytes != null ) {
+                        context.getPkg().getPackageCompilationData().write( shadowProxyName,
+                                                                            proxyBytes );
+                        shadowClass = context.getPkg().getPackageCompilationData().getClassLoader().loadClass( shadowProxyName );
+                    }
+
+                }
+                objectType = new ClassObjectType( userProvidedClass,
+                                                  shadowClass );
+            } catch ( final ClassNotFoundException e ) {
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        columnDescr,
+                                                        null,
+                                                        "Unable to resolve ObjectType '" + columnDescr.getObjectType() + "'" ) );
+                return null;
+            }
+        }
+
+        Column column;
+        if ( columnDescr.getIdentifier() != null && !columnDescr.getIdentifier().equals( "" ) ) {
+
+            if ( context.getDeclarationResolver().isDuplicated( columnDescr.getIdentifier() ) ) {
+                // This declaration already  exists, so throw an Exception
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        columnDescr,
+                                                        null,
+                                                        "Duplicate declaration for variable '" + columnDescr.getIdentifier() + "' in the rule '" + context.getRule().getName() + "'" ) );
+            }
+
+            column = new Column( context.getNextColumnId(),
+                                 0, // offset is 0 by default
+                                 objectType,
+                                 columnDescr.getIdentifier() );
+        } else {
+            column = new Column( context.getNextColumnId(),
+                                 0, // offset is 0 by default
+                                 objectType,
+                                 null );
+        }
+        // adding the newly created column to the build stack
+        // this is necessary in case of local declaration usage
+        context.getBuildStack().push( column );
+
+        for ( final Iterator it = columnDescr.getDescrs().iterator(); it.hasNext(); ) {
+            final Object object = it.next();
+            if ( object instanceof FieldBindingDescr ) {
+                build( context,
+                       utils,
+                       column,
+                       (FieldBindingDescr) object );
+            } else if ( object instanceof FieldConstraintDescr ) {
+                build( context,
+                       utils,
+                       column,
+                       (FieldConstraintDescr) object );
+            } else if ( object instanceof PredicateDescr ) {
+                build( context,
+                       utils,
+                       column,
+                       (PredicateDescr) object );
+            }
+        }
+        // poping the column
+        context.getBuildStack().pop();
+        return column;
+    }
+
+    private void build(final BuildContext context,
+                       final BuildUtils utils,
+                       final Column column,
+                       final FieldConstraintDescr fieldConstraintDescr) {
+
+        final FieldExtractor extractor = getFieldExtractor( context,
+                                                            utils,
+                                                            fieldConstraintDescr,
+                                                            column.getObjectType(),
+                                                            fieldConstraintDescr.getFieldName() );
+        if ( extractor == null ) {
+            // @todo log error
+            return;
+        }
+
+        if ( fieldConstraintDescr.getRestrictions().size() == 1 ) {
+            final Object object = fieldConstraintDescr.getRestrictions().get( 0 );
+
+            final Restriction restriction = buildRestriction( context,
+                                                              utils,
+                                                              column,
+                                                              extractor,
+                                                              fieldConstraintDescr,
+                                                              (RestrictionDescr) object );
+            if ( restriction == null ) {
+                // @todo log errors
+                return;
+            }
+
+            if ( object instanceof LiteralRestrictionDescr ) {
+                column.addConstraint( new LiteralConstraint( extractor,
+                                                             (LiteralRestriction) restriction ) );
+            } else if ( object instanceof VariableRestrictionDescr ) {
+                column.addConstraint( new VariableConstraint( extractor,
+                                                              (VariableRestriction) restriction ) );
+            } else if ( object instanceof ReturnValueRestrictionDescr ) {
+                column.addConstraint( new ReturnValueConstraint( extractor,
+                                                                 (ReturnValueRestriction) restriction ) );
+            }
+
+            return;
+        }
+
+        final List orList = new ArrayList();
+        List andList = null;
+
+        RestrictionDescr currentRestriction = null;
+        RestrictionDescr previousRestriction = null;
+
+        List currentList = null;
+        List previousList = null;
+
+        for ( final Iterator it = fieldConstraintDescr.getRestrictions().iterator(); it.hasNext(); ) {
+            final Object object = it.next();
+
+            // Process an and/or connective 
+            if ( object instanceof RestrictionConnectiveDescr ) {
+
+                // is the connective an 'and'?
+                if ( ((RestrictionConnectiveDescr) object).getConnective() == RestrictionConnectiveDescr.AND ) {
+                    // if andList is null, then we know its the first
+                    if ( andList == null ) {
+                        andList = new ArrayList();
+                    }
+                    previousList = currentList;
+                    currentList = andList;
+                } else {
+                    previousList = currentList;
+                    currentList = orList;
+                }
+            } else {
+                Restriction restriction = null;
+                if ( currentList != null ) {
+                    // Are we are at the first operator? if so treat differently
+                    if ( previousList == null ) {
+                        restriction = buildRestriction( context,
+                                                        utils,
+                                                        column,
+                                                        extractor,
+                                                        fieldConstraintDescr,
+                                                        previousRestriction );
+                        if ( currentList == andList ) {
+                            andList.add( restriction );
+                        } else {
+                            orList.add( restriction );
+                        }
+                    } else {
+                        restriction = buildRestriction( context,
+                                                        utils,
+                                                        column,
+                                                        extractor,
+                                                        fieldConstraintDescr,
+                                                        previousRestriction );
+
+                        if ( previousList == andList && currentList == orList ) {
+                            andList.add( restriction );
+                            if ( andList.size() == 1 ) {
+                                // Can't have an 'and' connective with one child, so add directly to the or list
+                                orList.add( andList.get( 0 ) );
+                            } else {
+                                final Restriction restrictions = new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) );
+                                orList.add( restrictions );
+                            }
+                            andList = null;
+                        } else if ( previousList == andList && currentList == andList ) {
+                            andList.add( restriction );
+                        } else if ( previousList == orList && currentList == andList ) {
+                            andList.add( restriction );
+                        } else if ( previousList == orList && currentList == orList ) {
+                            orList.add( restriction );
+                        }
+                    }
+                }
+            }
+            previousRestriction = currentRestriction;
+            currentRestriction = (RestrictionDescr) object;
+        }
+
+        final Restriction restriction = buildRestriction( context,
+                                                          utils,
+                                                          column,
+                                                          extractor,
+                                                          fieldConstraintDescr,
+                                                          currentRestriction );
+        currentList.add( restriction );
+
+        Restriction restrictions = null;
+        if ( currentList == andList && !orList.isEmpty() ) {
+            // Check if it finished with an and, and process it
+            if ( andList != null ) {
+                if ( andList.size() == 1 ) {
+                    // Can't have an 'and' connective with one child, so add directly to the or list
+                    orList.add( andList.get( 0 ) );
+                } else {
+                    orList.add( new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) ) );
+                }
+                andList = null;
+            }
+        }
+
+        if ( !orList.isEmpty() ) {
+            restrictions = new OrCompositeRestriction( (Restriction[]) orList.toArray( new Restriction[orList.size()] ) );
+        } else if ( andList != null && !andList.isEmpty() ) {
+            restrictions = new AndCompositeRestriction( (Restriction[]) andList.toArray( new Restriction[andList.size()] ) );
+        } else {
+            // @todo throw error
+        }
+
+        column.addConstraint( new MultiRestrictionFieldConstraint( extractor,
+                                                                   restrictions ) );
+    }
+
+    private void build(final BuildContext context,
+                       final BuildUtils utils,
+                       final Column column,
+                       final FieldBindingDescr fieldBindingDescr) {
+
+        if ( context.getDeclarationResolver().isDuplicated( fieldBindingDescr.getIdentifier() ) ) {
+            // This declaration already  exists, so throw an Exception
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    fieldBindingDescr,
+                                                    null,
+                                                    "Duplicate declaration for variable '" + fieldBindingDescr.getIdentifier() + "' in the rule '" + context.getRule().getName() + "'" ) );
+            return;
+        }
+
+        final FieldExtractor extractor = getFieldExtractor( context,
+                                                            utils,
+                                                            fieldBindingDescr,
+                                                            column.getObjectType(),
+                                                            fieldBindingDescr.getFieldName() );
+        if ( extractor == null ) {
+            return;
+        }
+
+        column.addDeclaration( fieldBindingDescr.getIdentifier(),
+                               extractor );
+    }
+
+    private void build(final BuildContext context,
+                       final BuildUtils utils,
+                       final Column column,
+                       final PredicateDescr predicateDescr) {
+        final List[] usedIdentifiers = utils.getUsedIdentifiers( context,
+                                                                 predicateDescr,
+                                                                 predicateDescr.getText() );
+
+        final List tupleDeclarations = new ArrayList();
+        final List factDeclarations = new ArrayList();
+        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
+            Declaration decl = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
+            if ( decl.getColumn() == column ) {
+                factDeclarations.add( decl );
+            } else {
+                tupleDeclarations.add( decl );
+            }
+        }
+        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
+        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
+
+        final PredicateConstraint predicateConstraint = new PredicateConstraint( previousDeclarations,
+                                                                                 localDeclarations );
+        column.addConstraint( predicateConstraint );
+
+        JavaPredicateBuilder builder = new JavaPredicateBuilder();
+
+        builder.build( context,
+                       utils,
+                       usedIdentifiers,
+                       previousDeclarations,
+                       localDeclarations,
+                       predicateConstraint,
+                       predicateDescr );
+
+    }
+
+    private Restriction buildRestriction(final BuildContext context,
+                                         final BuildUtils utils,
+                                         final Column column,
+                                         final FieldExtractor extractor,
+                                         final FieldConstraintDescr fieldConstraintDescr,
+                                         final RestrictionDescr restrictionDescr) {
+        Restriction restriction = null;
+        if ( restrictionDescr instanceof LiteralRestrictionDescr ) {
+            restriction = buildRestriction( context,
+                                            utils,
+                                            extractor,
+                                            fieldConstraintDescr,
+                                            (LiteralRestrictionDescr) restrictionDescr );
+        } else if ( restrictionDescr instanceof VariableRestrictionDescr ) {
+            restriction = buildRestriction( context,
+                                            extractor,
+                                            fieldConstraintDescr,
+                                            (VariableRestrictionDescr) restrictionDescr );
+        } else if ( restrictionDescr instanceof ReturnValueRestrictionDescr ) {
+            restriction = buildRestriction( context,
+                                            utils,
+                                            column,
+                                            extractor,
+                                            fieldConstraintDescr,
+                                            (ReturnValueRestrictionDescr) restrictionDescr );
+
+        }
+
+        return restriction;
+    }
+
+    private VariableRestriction buildRestriction(final BuildContext context,
+                                                 final FieldExtractor extractor,
+                                                 final FieldConstraintDescr fieldConstraintDescr,
+                                                 final VariableRestrictionDescr variableRestrictionDescr) {
+        if ( variableRestrictionDescr.getIdentifier() == null || variableRestrictionDescr.getIdentifier().equals( "" ) ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    variableRestrictionDescr,
+                                                    null,
+                                                    "Identifier not defined for binding field '" + fieldConstraintDescr.getFieldName() + "'" ) );
+            return null;
+        }
+
+        final Declaration declaration = (Declaration) context.getDeclarationResolver().getDeclaration( variableRestrictionDescr.getIdentifier() );
+
+        if ( declaration == null ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    variableRestrictionDescr,
+                                                    null,
+                                                    "Unable to return Declaration for identifier '" + variableRestrictionDescr.getIdentifier() + "'" ) );
+            return null;
+        }
+
+        final Evaluator evaluator = getEvaluator( context,
+                                                  variableRestrictionDescr,
+                                                  extractor.getValueType(),
+                                                  variableRestrictionDescr.getEvaluator() );
+        if ( evaluator == null ) {
+            return null;
+        }
+
+        return new VariableRestriction( extractor,
+                                        declaration,
+                                        evaluator );
+    }
+
+    private LiteralRestriction buildRestriction(final BuildContext context,
+                                                final BuildUtils utils,
+                                                final FieldExtractor extractor,
+                                                final FieldConstraintDescr fieldConstraintDescr,
+                                                final LiteralRestrictionDescr literalRestrictionDescr) {
+        FieldValue field = null;
+        if ( literalRestrictionDescr.isStaticFieldValue() ) {
+            final int lastDot = literalRestrictionDescr.getText().lastIndexOf( '.' );
+            final String className = literalRestrictionDescr.getText().substring( 0,
+                                                                                  lastDot );
+            final String fieldName = literalRestrictionDescr.getText().substring( lastDot + 1 );
+            try {
+                final Class staticClass = utils.getTypeResolver().resolveType( className );
+                field = FieldFactory.getFieldValue( staticClass.getField( fieldName ).get( null ).toString(),
+                                                    extractor.getValueType() );
+            } catch ( final ClassNotFoundException e ) {
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        literalRestrictionDescr,
+                                                        e,
+                                                        e.getMessage() ) );
+            } catch ( final Exception e ) {
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        literalRestrictionDescr,
+                                                        e,
+                                                        "Unable to create a Field value of type  '" + extractor.getValueType() + "' and value '" + literalRestrictionDescr.getText() + "'" ) );
+            }
+
+        } else {
+            try {
+                field = FieldFactory.getFieldValue( literalRestrictionDescr.getText(),
+                                                    extractor.getValueType() );
+            } catch ( final Exception e ) {
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        literalRestrictionDescr,
+                                                        e,
+                                                        "Unable to create a Field value of type  '" + extractor.getValueType() + "' and value '" + literalRestrictionDescr.getText() + "'" ) );
+            }
+        }
+
+        final Evaluator evaluator = getEvaluator( context,
+                                                  literalRestrictionDescr,
+                                                  extractor.getValueType(),
+                                                  literalRestrictionDescr.getEvaluator() );
+        if ( evaluator == null ) {
+            return null;
+        }
+
+        return new LiteralRestriction( field,
+                                       evaluator,
+                                       extractor );
+    }
+
+    private ReturnValueRestriction buildRestriction(final BuildContext context,
+                                                    final BuildUtils utils,
+                                                    final Column column,
+                                                    final FieldExtractor extractor,
+                                                    final FieldConstraintDescr fieldConstraintDescr,
+                                                    final ReturnValueRestrictionDescr returnValueRestrictionDescr) {
+        final List[] usedIdentifiers = utils.getUsedIdentifiers( context,
+                                                                 returnValueRestrictionDescr,
+                                                                 returnValueRestrictionDescr.getText() );
+
+        final List tupleDeclarations = new ArrayList();
+        final List factDeclarations = new ArrayList();
+        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
+            Declaration declaration = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
+            if ( declaration.getColumn() == column ) {
+                factDeclarations.add( declaration );
+            } else {
+                tupleDeclarations.add( declaration );
+            }
+        }
+
+        final Evaluator evaluator = getEvaluator( context,
+                                                  returnValueRestrictionDescr,
+                                                  extractor.getValueType(),
+                                                  returnValueRestrictionDescr.getEvaluator() );
+        if ( evaluator == null ) {
+            return null;
+        }
+
+        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
+        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
+        final ReturnValueRestriction returnValueRestriction = new ReturnValueRestriction( extractor,
+                                                                                          previousDeclarations,
+                                                                                          localDeclarations,
+                                                                                          evaluator );
+
+        JavaReturnValueBuilder builder = new JavaReturnValueBuilder();
+
+        builder.build( context,
+                       utils,
+                       usedIdentifiers,
+                       previousDeclarations,
+                       localDeclarations,
+                       returnValueRestriction,
+                       returnValueRestrictionDescr );
+
+        return returnValueRestriction;
+    }
+
+    private FieldExtractor getFieldExtractor(final BuildContext context,
+                                             final BuildUtils utils,
+                                             final BaseDescr descr,
+                                             final ObjectType objectType,
+                                             final String fieldName) {
+        FieldExtractor extractor = null;
+
+        if ( objectType.getValueType() == ValueType.FACTTEMPLATE_TYPE ) {
+            //@todo use extractor cache            
+            final FactTemplate factTemplate = ((FactTemplateObjectType) objectType).getFactTemplate();
+            extractor = new FactTemplateFieldExtractor( factTemplate,
+                                                        factTemplate.getFieldTemplateIndex( fieldName ) );
+        } else {
+            try {
+                extractor = utils.getClassFieldExtractorCache().getExtractor( ((ClassObjectType) objectType).getClassType(),
+                                                                              fieldName );
+            } catch ( final RuntimeDroolsException e ) {
+                context.getErrors().add( new RuleError( context.getRule(),
+                                                        descr,
+                                                        e,
+                                                        "Unable to create Field Extractor for '" + fieldName + "'" ) );
+            }
+        }
+
+        return extractor;
+    }
+
+    private Evaluator getEvaluator(final BuildContext context,
+                                   final BaseDescr descr,
+                                   final ValueType valueType,
+                                   final String evaluatorString) {
+
+        final Evaluator evaluator = valueType.getEvaluator( Operator.determineOperator( evaluatorString ) );
+
+        if ( evaluator == null ) {
+            context.getErrors().add( new RuleError( context.getRule(),
+                                                    descr,
+                                                    null,
+                                                    "Unable to determine the Evaluator for  '" + valueType + "' and '" + evaluatorString + "'" ) );
+        }
+
+        return evaluator;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ConditionalElementBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,35 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import org.drools.lang.descr.BaseDescr;
-import org.drools.rule.ConditionalElement;
-
-/**
- * An interface to define classes capable of building
- * specific conditional elements.
- * 
- * @author etirelli
- */
-public interface ConditionalElementBuilder {
-
-    public ConditionalElement build(final BuildContext context,
-                                    final BuildUtils utils, 
-                                    final ColumnBuilder columnBuilder,
-                                    final BaseDescr descr);
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ConditionalElementBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConditionalElementBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import org.drools.lang.descr.BaseDescr;
+import org.drools.rule.ConditionalElement;
+
+/**
+ * An interface to define classes capable of building
+ * specific conditional elements.
+ * 
+ * @author etirelli
+ */
+public interface ConditionalElementBuilder {
+
+    public ConditionalElement build(final BuildContext context,
+                                    final BuildUtils utils, 
+                                    final ColumnBuilder columnBuilder,
+                                    final BaseDescr descr);
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ConsequenceBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,114 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.drools.RuntimeDroolsException;
-import org.drools.lang.descr.RuleDescr;
-import org.drools.rule.Declaration;
-
-/**
- * @author etirelli
- *
- */
-public class ConsequenceBuilder {
-
-    public void buildConsequence(final BuildContext context,
-                                 final BuildUtils utils,
-                                 final RuleDescr ruleDescr) {
-        
-        // pushing consequence LHS into the stack for variable resolution
-        context.getBuildStack().push( context.getRule().getLhs() );
-        
-        // generate 
-        // generate Invoker
-        final String className = "consequence";
-
-        StringTemplate st = utils.getRuleGroup().getInstanceOf( "consequenceMethod" );
-
-        st.setAttribute( "methodName",
-                         className );
-
-        final List[] usedIdentifiers = utils.getUsedCIdentifiers( context,
-                                                                  ruleDescr,
-                                                                  ruleDescr.getConsequence() );
-
-        final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
-        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            declarations[i] = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
-        }
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-        st.setAttribute( "text",
-                         utils.getFunctionFixer().fix( utils.getKnowledgeHelperFixer().fix( ruleDescr.getConsequence() ),
-                                                       context.getDeclarationResolver() ) );
-
-        context.getMethods().add( st.toString() );
-
-        st = utils.getInvokerGroup().getInstanceOf( "consequenceInvoker" );
-
-        st.setAttribute( "package",
-                         context.getPkg().getName() );
-        st.setAttribute( "ruleClassName",
-                         utils.ucFirst( context.getRuleDescr().getClassName() ) );
-        st.setAttribute( "invokerClassName",
-                         ruleDescr.getClassName() + utils.ucFirst( className ) + "Invoker" );
-        st.setAttribute( "methodName",
-                         className );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        // Must use the rule declarations, so we use the same order as used in the generated invoker
-        final List list = Arrays.asList( context.getRule().getDeclarations() );
-
-        final int[] indexes = new int[declarations.length];
-        for ( int i = 0, length = declarations.length; i < length; i++ ) {
-            indexes[i] = list.indexOf( declarations[i] );
-            if ( indexes[i] == -1 ) {
-                // some defensive code, this should never happen
-                throw new RuntimeDroolsException( "Unable to find declaration in list while generating the consequence invoker" );
-            }
-        }
-
-        st.setAttribute( "indexes",
-                         indexes );
-
-        st.setAttribute( "text",
-                         ruleDescr.getConsequence() );
-
-        final String invokerClassName = context.getPkg().getName() + "." + ruleDescr.getClassName() + utils.ucFirst( className ) + "Invoker";
-        context.getInvokers().put( invokerClassName,
-                                   st.toString() );
-        context.getInvokerLookups().put( invokerClassName,
-                                         context.getRule() );
-        context.getDescrLookups().put( invokerClassName,
-                                       ruleDescr );
-        
-        // popping Rule.getLHS() from the build stack
-        context.getBuildStack().pop();
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ConsequenceBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ConsequenceBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,11 @@
+package org.drools.rule.builder;
+
+import org.drools.lang.descr.RuleDescr;
+
+public interface ConsequenceBuilder {
+
+    public void buildConsequence(final BuildContext context,
+                                 final BuildUtils utils,
+                                 final RuleDescr ruleDescr);
+
+}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/EvalBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/EvalBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/EvalBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,114 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.List;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.EvalDescr;
-import org.drools.rule.ConditionalElement;
-import org.drools.rule.Declaration;
-import org.drools.rule.EvalCondition;
-
-/**
- * @author etirelli
- *
- */
-public class EvalBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /**
-     * Builds and returns an Eval Conditional Element
-     * 
-     * @param context The current build context
-     * @param utils The current build utils instance
-     * @param columnBuilder not used by EvalBuilder
-     * @param descr The Eval Descriptor to build the eval conditional element from
-     * 
-     * @return the Eval Conditional Element
-     */
-    public ConditionalElement build(final BuildContext context,
-                                    final BuildUtils utils,
-                                    final ColumnBuilder columnBuilder,
-                                    final BaseDescr descr) {
-        // it must be an EvalDescr
-        EvalDescr evalDescr = (EvalDescr) descr;
-
-        final String className = "eval" + context.getNextId();
-        
-        evalDescr.setClassMethodName( className );
-
-        final List[] usedIdentifiers = utils.getUsedIdentifiers( context,
-                                                                 evalDescr,
-                                                                 evalDescr.getText() );
-
-        final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
-        for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            declarations[i] = (Declaration) context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) );
-        }
-
-        final EvalCondition eval = new EvalCondition( declarations );
-
-        StringTemplate st = utils.getRuleGroup().getInstanceOf( "evalMethod" );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        st.setAttribute( "methodName",
-                         className );
-
-        final String evalText = utils.getFunctionFixer().fix( evalDescr.getText(),
-                                                              context.getDeclarationResolver() );
-        st.setAttribute( "text",
-                         evalText );
-
-        context.getMethods().add( st.toString() );
-
-        st = utils.getInvokerGroup().getInstanceOf( "evalInvoker" );
-
-        st.setAttribute( "package",
-                         context.getPkg().getName() );
-        st.setAttribute( "ruleClassName",
-                         utils.ucFirst( context.getRuleDescr().getClassName() ) );
-        st.setAttribute( "invokerClassName",
-                         context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker" );
-        st.setAttribute( "methodName",
-                         className );
-
-        utils.setStringTemplateAttributes( context,
-                                           st,
-                                           declarations,
-                                           (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ) );
-
-        st.setAttribute( "hashCode",
-                         evalText.hashCode() );
-
-        final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + utils.ucFirst( className ) + "Invoker";
-        context.getInvokers().put( invokerClassName,
-                                   st.toString() );
-        context.getInvokerLookups().put( invokerClassName,
-                                         eval );
-        context.getDescrLookups().put( invokerClassName,
-                                       evalDescr );
-        return eval;
-    }
-
-}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ForallBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,68 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.Iterator;
-
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.ColumnDescr;
-import org.drools.lang.descr.ForallDescr;
-import org.drools.rule.Column;
-import org.drools.rule.ConditionalElement;
-import org.drools.rule.Forall;
-
-/**
- * @author etirelli
- *
- */
-public class ForallBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /* (non-Javadoc)
-     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
-     */
-    public ConditionalElement build(BuildContext context,
-                                    BuildUtils utils,
-                                    ColumnBuilder columnBuilder,
-                                    BaseDescr descr) {
-        ForallDescr forallDescr = (ForallDescr) descr;
-        
-        Column baseColumn = columnBuilder.build( context, utils, forallDescr.getBaseColumn() );
-
-        if ( baseColumn == null ) {
-            return null;
-        }
-
-        Forall forall = new Forall( baseColumn );
-        
-        // adding the newly created forall CE to the build stack
-        // this is necessary in case of local declaration usage
-        context.getBuildStack().push( forall );
-        
-        for( Iterator it = forallDescr.getRemainingColumns().iterator(); it.hasNext(); ) {
-            Column anotherColumn = columnBuilder.build( context, utils, (ColumnDescr) it.next() );
-            forall.addRemainingColumn( anotherColumn );
-        }
-        
-        // poping the forall
-        context.getBuildStack().pop();
-        
-        return forall;
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ForallBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ForallBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.util.Iterator;
+
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.ColumnDescr;
+import org.drools.lang.descr.ForallDescr;
+import org.drools.rule.Column;
+import org.drools.rule.ConditionalElement;
+import org.drools.rule.Forall;
+
+/**
+ * @author etirelli
+ *
+ */
+public class ForallBuilder
+    implements
+    ConditionalElementBuilder {
+
+    /* (non-Javadoc)
+     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
+     */
+    public ConditionalElement build(BuildContext context,
+                                    BuildUtils utils,
+                                    ColumnBuilder columnBuilder,
+                                    BaseDescr descr) {
+        ForallDescr forallDescr = (ForallDescr) descr;
+        
+        Column baseColumn = columnBuilder.build( context, utils, forallDescr.getBaseColumn() );
+
+        if ( baseColumn == null ) {
+            return null;
+        }
+
+        Forall forall = new Forall( baseColumn );
+        
+        // adding the newly created forall CE to the build stack
+        // this is necessary in case of local declaration usage
+        context.getBuildStack().push( forall );
+        
+        for( Iterator it = forallDescr.getRemainingColumns().iterator(); it.hasNext(); ) {
+            Column anotherColumn = columnBuilder.build( context, utils, (ColumnDescr) it.next() );
+            forall.addRemainingColumn( anotherColumn );
+        }
+        
+        // poping the forall
+        context.getBuildStack().pop();
+        
+        return forall;
+    }
+
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/FromBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,86 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.io.Serializable;
-
-import org.drools.base.DroolsMVELFactory;
-import org.drools.base.dataproviders.MVELDataProvider;
-import org.drools.compiler.RuleError;
-import org.drools.lang.descr.AccessorDescr;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.FromDescr;
-import org.drools.rule.Column;
-import org.drools.rule.ConditionalElement;
-import org.drools.rule.From;
-import org.drools.spi.DataProvider;
-import org.mvel.CompiledExpression;
-import org.mvel.ExpressionParser;
-import org.mvel.MVEL;
-
-/**
- * A builder for "from" conditional element
- * 
- * @author etirelli
- */
-public class FromBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /**
-     * @inheritDoc
-     */
-    public ConditionalElement build(final BuildContext context,
-                                    final BuildUtils utils,
-                                    final ColumnBuilder columnBuilder,
-                                    final BaseDescr descr) {
-        FromDescr fromDescr = (FromDescr) descr;
-
-        final Column column = columnBuilder.build( context,
-                                                   utils,
-                                                   fromDescr.getReturnedColumn() );
-
-        if ( column == null ) {
-            return null;
-        }
-
-        AccessorDescr accessor = (AccessorDescr) fromDescr.getDataSource();
-        DataProvider dataProvider = null;
-        try {
-//            JFDIParser parser = createParser( utils,
-//                                              accessor.toString() );
-            DroolsMVELFactory factory = new DroolsMVELFactory( );
-            factory.setDeclarationMap( context.getDeclarationResolver().getDeclarations() );
-            factory.setGlobalsMap( context.getPkg().getGlobals() );
-            
-            //parser.setValueHandlerFactory( factory );
-            Serializable compiled = MVEL.compileExpression( accessor.toString() );
-
-            dataProvider = new MVELDataProvider( compiled,
-                                                 factory );
-        } catch ( final Exception e ) {
-            context.getErrors().add( new RuleError( context.getRule(),
-                                                    fromDescr,
-                                                    null,
-                                                    "Unable to build expression for 'from' node '" + accessor.toString() + "'" ) );
-            return null;
-        }
-
-        return new From( column,
-                         dataProvider );
-    }
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/FromBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/FromBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,16 @@
+package org.drools.rule.builder;
+
+import org.drools.lang.descr.BaseDescr;
+import org.drools.rule.ConditionalElement;
+
+public interface FromBuilder {
+
+    /**
+     * @inheritDoc
+     */
+    public ConditionalElement build(final BuildContext context,
+                                    final BuildUtils utils,
+                                    final ColumnBuilder columnBuilder,
+                                    final BaseDescr descr);
+
+}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/GroupElementBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,105 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.Iterator;
-
-import org.drools.RuntimeDroolsException;
-import org.drools.lang.descr.AndDescr;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.ColumnDescr;
-import org.drools.lang.descr.ConditionalElementDescr;
-import org.drools.lang.descr.ExistsDescr;
-import org.drools.lang.descr.NotDescr;
-import org.drools.lang.descr.OrDescr;
-import org.drools.rule.Column;
-import org.drools.rule.ConditionalElement;
-import org.drools.rule.GroupElement;
-import org.drools.rule.GroupElementFactory;
-
-/**
- * @author etirelli
- *
- */
-public class GroupElementBuilder
-    implements
-    ConditionalElementBuilder {
-
-    /* (non-Javadoc)
-     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
-     */
-    public ConditionalElement build(BuildContext context,
-                                    BuildUtils utils,
-                                    ColumnBuilder columnBuilder,
-                                    BaseDescr descr) {
-        ConditionalElementDescr cedescr = (ConditionalElementDescr) descr;
-
-        final GroupElement ge = this.newGroupElementFor( cedescr.getClass() );
-        context.getBuildStack().push( ge );
-
-        // iterate over child descriptors
-        for ( Iterator it = cedescr.getDescrs().iterator(); it.hasNext(); ) {
-            // gets child to build
-            BaseDescr child = (BaseDescr) it.next();
-
-            // gets corresponding builder
-            ConditionalElementBuilder cebuilder = utils.getBuilder( child.getClass() );
-
-            if ( cebuilder != null ) {
-                ConditionalElement ce = cebuilder.build( context,
-                                                         utils,
-                                                         columnBuilder,
-                                                         (BaseDescr) child );
-                if( ce != null ) {
-                    ge.addChild( ce );
-                }
-            } else if ( child instanceof ColumnDescr ) {
-                final Column column = columnBuilder.build( context,
-                                                           utils,
-                                                           (ColumnDescr) child );
-                // in case there is a problem with the column building,
-                // builder will return null. Ex: ClassNotFound for the column type
-                if( column != null ) {
-                    ge.addChild( column );
-                }
-
-            } else {
-                throw new RuntimeDroolsException("BUG: no builder found for descriptor class "+child.getClass() );
-            }
-
-        }
-
-        context.getBuildStack().pop();
-        
-        return ge;
-    }
-
-    private GroupElement newGroupElementFor(Class descr) {
-        if ( AndDescr.class.isAssignableFrom( descr ) ) {
-            return GroupElementFactory.newAndInstance();
-        } else if ( OrDescr.class.isAssignableFrom( descr ) ) {
-            return GroupElementFactory.newOrInstance();
-        } else if ( NotDescr.class.isAssignableFrom( descr ) ) {
-            return GroupElementFactory.newNotInstance();
-        } else if ( ExistsDescr.class.isAssignableFrom( descr ) ) {
-            return GroupElementFactory.newExistsInstance();
-        } else {
-            throw new RuntimeDroolsException( "BUG: Not able to create a group element for descriptor: " + descr.getName() );
-        }
-    }
-
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/GroupElementBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/GroupElementBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.util.Iterator;
+
+import org.drools.RuntimeDroolsException;
+import org.drools.lang.descr.AndDescr;
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.ColumnDescr;
+import org.drools.lang.descr.ConditionalElementDescr;
+import org.drools.lang.descr.ExistsDescr;
+import org.drools.lang.descr.NotDescr;
+import org.drools.lang.descr.OrDescr;
+import org.drools.rule.Column;
+import org.drools.rule.ConditionalElement;
+import org.drools.rule.GroupElement;
+import org.drools.rule.GroupElementFactory;
+
+/**
+ * @author etirelli
+ *
+ */
+public class GroupElementBuilder
+    implements
+    ConditionalElementBuilder {
+
+    /* (non-Javadoc)
+     * @see org.drools.semantics.java.builder.ConditionalElementBuilder#build(org.drools.semantics.java.builder.BuildContext, org.drools.semantics.java.builder.BuildUtils, org.drools.semantics.java.builder.ColumnBuilder, org.drools.lang.descr.BaseDescr)
+     */
+    public ConditionalElement build(BuildContext context,
+                                    BuildUtils utils,
+                                    ColumnBuilder columnBuilder,
+                                    BaseDescr descr) {
+        ConditionalElementDescr cedescr = (ConditionalElementDescr) descr;
+
+        final GroupElement ge = this.newGroupElementFor( cedescr.getClass() );
+        context.getBuildStack().push( ge );
+
+        // iterate over child descriptors
+        for ( Iterator it = cedescr.getDescrs().iterator(); it.hasNext(); ) {
+            // gets child to build
+            BaseDescr child = (BaseDescr) it.next();
+
+            // gets corresponding builder
+            ConditionalElementBuilder cebuilder = utils.getBuilder( child.getClass() );
+
+            if ( cebuilder != null ) {
+                ConditionalElement ce = cebuilder.build( context,
+                                                         utils,
+                                                         columnBuilder,
+                                                         (BaseDescr) child );
+                if( ce != null ) {
+                    ge.addChild( ce );
+                }
+            } else if ( child instanceof ColumnDescr ) {
+                final Column column = columnBuilder.build( context,
+                                                           utils,
+                                                           (ColumnDescr) child );
+                // in case there is a problem with the column building,
+                // builder will return null. Ex: ClassNotFound for the column type
+                if( column != null ) {
+                    ge.addChild( column );
+                }
+
+            } else {
+                throw new RuntimeDroolsException("BUG: no builder found for descriptor class "+child.getClass() );
+            }
+
+        }
+
+        context.getBuildStack().pop();
+        
+        return ge;
+    }
+
+    private GroupElement newGroupElementFor(Class descr) {
+        if ( AndDescr.class.isAssignableFrom( descr ) ) {
+            return GroupElementFactory.newAndInstance();
+        } else if ( OrDescr.class.isAssignableFrom( descr ) ) {
+            return GroupElementFactory.newOrInstance();
+        } else if ( NotDescr.class.isAssignableFrom( descr ) ) {
+            return GroupElementFactory.newNotInstance();
+        } else if ( ExistsDescr.class.isAssignableFrom( descr ) ) {
+            return GroupElementFactory.newExistsInstance();
+        } else {
+            throw new RuntimeDroolsException( "BUG: Not able to create a group element for descriptor: " + descr.getName() );
+        }
+    }
+
+}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/PredicateBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/PredicateBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/PredicateBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/PredicateBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,17 @@
+package org.drools.rule.builder;
+
+import java.util.List;
+
+import org.drools.lang.descr.PredicateDescr;
+import org.drools.rule.Declaration;
+import org.drools.rule.PredicateConstraint;
+
+public interface PredicateBuilder {
+    public void build(final BuildContext context,
+                      final BuildUtils utils,
+                      final List[] usedIdentifiers,
+                      final Declaration[] previousDeclarations,
+                      final Declaration[] localDeclarations,
+                      final PredicateConstraint predicateConstraint,
+                      final PredicateDescr predicateDescr);
+}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ReturnValueBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/ReturnValueBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ReturnValueBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/ReturnValueBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,17 @@
+package org.drools.rule.builder;
+
+import java.util.List;
+
+import org.drools.lang.descr.ReturnValueRestrictionDescr;
+import org.drools.rule.Declaration;
+import org.drools.rule.ReturnValueRestriction;
+
+public interface ReturnValueBuilder {
+    public void build(final BuildContext context,
+                      final BuildUtils utils,
+                      final List[] usedIdentifiers,
+                      final Declaration[] previousDeclarations,
+                      final Declaration[] localDeclarations,
+                      final ReturnValueRestriction returnValueRestriction,
+                      final ReturnValueRestrictionDescr returnValueRestrictionDescr);
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/RuleClassBuilder.java	2007-02-25 22:53:26 UTC (rev 9748)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,62 +0,0 @@
-/*
- * Copyright 2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.semantics.java.builder;
-
-import java.util.Iterator;
-
-import org.drools.lang.descr.RuleDescr;
-
-/**
- * @author etirelli
- *
- */
-public class RuleClassBuilder {
-
-    public void buildRule(final BuildContext context,
-                           final BuildUtils utils,
-                           final RuleDescr ruleDescr) {
-        // If there is no compiled code, return
-        if ( context.getMethods().isEmpty() ) {
-            context.setRuleClass( null );
-            return;
-        }
-        final String lineSeparator = System.getProperty( "line.separator" );
-
-        final StringBuffer buffer = new StringBuffer();
-        buffer.append( "package " + context.getPkg().getName() + ";" + lineSeparator );
-
-        for ( final Iterator it = context.getPkg().getImports().iterator(); it.hasNext(); ) {
-            buffer.append( "import " + it.next() + ";" + lineSeparator );
-        }
-
-        buffer.append( "public class " + utils.ucFirst( ruleDescr.getClassName() ) + " {" + lineSeparator );
-        buffer.append( "    private static final long serialVersionUID  = 320L;" + lineSeparator );
-
-        for ( int i = 0, size = context.getMethods().size() - 1; i < size; i++ ) {
-            buffer.append( context.getMethods().get( i ) + lineSeparator );
-        }
-
-        final String[] lines = buffer.toString().split( lineSeparator );
-
-        ruleDescr.setConsequenceOffset( lines.length + 1 );
-
-        buffer.append( context.getMethods().get( context.getMethods().size() - 1 ) + lineSeparator );
-        buffer.append( "}" );
-
-        context.setRuleClass( buffer.toString() );
-    }
-}

Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java (from rev 9780, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/builder/RuleClassBuilder.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/RuleClassBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.rule.builder;
+
+import java.util.Iterator;
+
+import org.drools.lang.descr.RuleDescr;
+
+/**
+ * @author etirelli
+ *
+ */
+public class RuleClassBuilder {
+
+    public void buildRule(final BuildContext context,
+                           final BuildUtils utils,
+                           final RuleDescr ruleDescr) {
+        // If there is no compiled code, return
+        if ( context.getMethods().isEmpty() ) {
+            context.setRuleClass( null );
+            return;
+        }
+        final String lineSeparator = System.getProperty( "line.separator" );
+
+        final StringBuffer buffer = new StringBuffer();
+        buffer.append( "package " + context.getPkg().getName() + ";" + lineSeparator );
+
+        for ( final Iterator it = context.getPkg().getImports().iterator(); it.hasNext(); ) {
+            buffer.append( "import " + it.next() + ";" + lineSeparator );
+        }
+        
+        for ( final Iterator it = context.getPkg().getStaticImports().iterator(); it.hasNext(); ) {
+            buffer.append( "import static " + it.next() + ";" + lineSeparator );
+        }        
+
+        buffer.append( "public class " + utils.ucFirst( ruleDescr.getClassName() ) + " {" + lineSeparator );
+        buffer.append( "    private static final long serialVersionUID  = 320L;" + lineSeparator );
+
+        for ( int i = 0, size = context.getMethods().size() - 1; i < size; i++ ) {
+            buffer.append( context.getMethods().get( i ) + lineSeparator );
+        }
+
+        final String[] lines = buffer.toString().split( lineSeparator );
+
+        ruleDescr.setConsequenceOffset( lines.length + 1 );
+
+        buffer.append( context.getMethods().get( context.getMethods().size() - 1 ) + lineSeparator );
+        buffer.append( "}" );
+
+        context.setRuleClass( buffer.toString() );
+    }
+}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/DeclarationTypeFixer.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/DeclarationTypeFixer.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/DeclarationTypeFixer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,24 +0,0 @@
-/**
- * 
- */
-package org.drools.semantics.java;
-
-import org.drools.rule.Declaration;
-
-/**
- * @author fburlet
- * @author gdupriez
- *
- */
-public class DeclarationTypeFixer {
-    
-    public String fix(Declaration declaration) {
-        Class classType = declaration.getExtractor().getExtractToClass();
-        if (classType.isArray()) {
-            return classType.getComponentType().getName().concat("[]");
-        } else {
-            // Does this replacement usefull in the declaration type ??
-            return classType.getName().replace('$', '.');
-        }
-    }
-}

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/FunctionBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,118 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.antlr.stringtemplate.StringTemplate;
-import org.antlr.stringtemplate.StringTemplateGroup;
-import org.antlr.stringtemplate.language.AngleBracketTemplateLexer;
-import org.codehaus.jfdi.interpreter.TypeResolver;
-import org.drools.RuntimeDroolsException;
-import org.drools.lang.descr.FunctionDescr;
-import org.drools.rule.LineMappings;
-import org.drools.rule.Package;
-import org.drools.spi.DeclarationScopeResolver;
-
-public class FunctionBuilder {
-    private static final StringTemplateGroup functionGroup = new StringTemplateGroup( new InputStreamReader( FunctionBuilder.class.getResourceAsStream( "javaFunction.stg" ) ),
-                                                                                      AngleBracketTemplateLexer.class );
-
-    public FunctionBuilder() {
-
-    }
-
-    public String build(final Package pkg,
-                        final FunctionDescr functionDescr,
-                        final TypeResolver typeResolver,
-                        final Map lineMappings) {
-        final StringTemplate st = FunctionBuilder.functionGroup.getInstanceOf( "function" );
-
-        st.setAttribute( "package",
-                         pkg.getName() );
-
-        st.setAttribute( "imports",
-                         pkg.getImports() );
-
-        st.setAttribute( "className",
-                         ucFirst( functionDescr.getName() ) );
-        st.setAttribute( "methodName",
-                         functionDescr.getName() );
-
-        st.setAttribute( "returnType",
-                         functionDescr.getReturnType() );
-
-        st.setAttribute( "parameterTypes",
-                         functionDescr.getParameterTypes() );
-
-        st.setAttribute( "parameterNames",
-                         functionDescr.getParameterNames() );
-
-        Map params = new HashMap();
-        List names = functionDescr.getParameterNames();
-        List types = functionDescr.getParameterTypes();
-        try {
-            for ( int i = 0, size = names.size(); i < size; i++ ) {
-                params.put( names.get( i ), typeResolver.resolveType( (String) types.get( i ) ) );
-            }
-        } catch ( ClassNotFoundException e ) {
-            // todo : must be a better way so we don't have to try/catch each resolveType call
-            throw new RuntimeDroolsException( e );                
-        }                   
-        
-        st.setAttribute( "text",
-                         functionDescr.getText() );
-        
-        String text = st.toString();
-        
-        BufferedReader reader = new BufferedReader( new StringReader ( text ) );
-        String line = null;
-        String lineStartsWith = "    public static " + functionDescr.getReturnType( ) + " " + functionDescr.getName();
-        int offset = 0;
-        try {
-            while ( ( line = reader.readLine() ) != null ) {
-                offset++;
-                if ( line.startsWith( lineStartsWith ) ) {
-                    break;
-                }
-            }
-            functionDescr.setOffset( offset );
-        } catch ( IOException e ) {
-            // won't ever happen, it's just reading over a string.
-            throw new RuntimeDroolsException( "Error determining start offset with function" );
-        }
-        
-        String name = pkg.getName() + "." + ucFirst( functionDescr.getName() );
-        LineMappings mapping = new LineMappings( name );
-        mapping.setStartLine( functionDescr.getLine() );
-        mapping.setOffset( functionDescr.getOffset() );      
-        lineMappings.put( name, lineMappings );
-
-        return text;
-
-    }
-
-    private String ucFirst(final String name) {
-        return name.toUpperCase().charAt( 0 ) + name.substring( 1 );
-    }
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/JavaExprAnalyzer.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/JavaExprAnalyzer.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/JavaExprAnalyzer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,137 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.CharStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RecognitionException;
-import org.antlr.runtime.TokenStream;
-import org.drools.semantics.java.parser.JavaParserLexer;
-import org.drools.semantics.java.parser.JavaParserParser;
-
-/**
- * Expression analyzer.
- * 
- * @author <a href="mailto:bob at eng.werken.com">bob mcwhirter </a>
- */
-public class JavaExprAnalyzer {
-    // ------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------
-
-    /**
-     * Construct.
-     */
-    public JavaExprAnalyzer() {
-        // intentionally left blank.
-    }
-
-    // ------------------------------------------------------------
-    // Instance methods
-    // ------------------------------------------------------------
-
-    /**
-     * 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 
-     *             If an error occurs in the parser.
-     */
-    public List[] analyzeExpression(final String expr,
-                                    final Set[] availableIdentifiers) throws RecognitionException {
-        final CharStream charStream = new ANTLRStringStream( expr );
-        final JavaParserLexer lexer = new JavaParserLexer( charStream );
-        final TokenStream tokenStream = new CommonTokenStream( lexer );
-        final JavaParserParser parser = new JavaParserParser( tokenStream );
-
-        parser.logicalOrExpression();
-
-        return analyze( parser.getIdentifiers(),
-                        availableIdentifiers );
-    }
-
-    public List[] analyzeBlock(final String expr,
-                               final Set[] availableIdentifiers) throws RecognitionException {
-        final CharStream charStream = new ANTLRStringStream( "{" + expr + "}" );
-        final JavaParserLexer lexer = new JavaParserLexer( charStream );
-        final TokenStream tokenStream = new CommonTokenStream( lexer );
-        final JavaParserParser parser = new JavaParserParser( tokenStream );
-
-        parser.compoundStatement();
-
-        return analyze( parser.getIdentifiers(),
-                        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.
-     */
-    private List[] analyze(final List identifiers,
-                           final Set[] availableIdentifiers) throws RecognitionException {
-        final List[] used = new List[availableIdentifiers.length];
-        for ( int i = 0, length = used.length; i < length; i++ ) {
-            used[i] = new ArrayList();
-        }
-
-        for ( int i = 0, length = availableIdentifiers.length; i < length; i++ ) {
-            final Set set = availableIdentifiers[i];
-            for ( final Iterator it = set.iterator(); it.hasNext(); ) {
-                final String eachDecl = (String) it.next();
-                if ( identifiers.contains( eachDecl ) ) {
-                    used[i].add( eachDecl );
-                }
-            }
-        }
-
-        return used;
-        //--------------------------------------------------------        
-        //        List decls = new ArrayList();
-        //        
-        //        for ( Iterator declIter = availDecls.iterator(); declIter.hasNext(); )
-        //        {
-        //            String eachDecl = (String) declIter.next();
-        //
-        //            if ( identifiers.contains( eachDecl ) )
-        //            {
-        //                decls.add( eachDecl );
-        //            }
-        //        }
-        //
-        //        return decls;        
-    }
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/KnowledgeHelperFixer.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/KnowledgeHelperFixer.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/KnowledgeHelperFixer.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,199 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class KnowledgeHelperFixer {
-
-    static String  KNOWLEDGE_HELPER_PFX = "";                               //could also be: "drools\\." for "classic" mode.
-    static Pattern MODIFY               = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "modify\\s*\\(([^)]+)\\)(.*)",
-                                                           Pattern.DOTALL );
-    static Pattern ASSERT               = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "assert\\s*\\((.*)\\)(.*)",
-                                                           Pattern.DOTALL );
-    static Pattern ASSERT_LOGICAL       = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "assertLogical\\s*\\((.*)\\)(.*)",
-                                                           Pattern.DOTALL );
-    static Pattern RETRACT              = Pattern.compile( "(.*)\\b" + KnowledgeHelperFixer.KNOWLEDGE_HELPER_PFX + "retract\\s*\\(([^)]+)\\)(.*)",
-                                                           Pattern.DOTALL );
-
-    /**
-     * This takes a raw consequence, and fixes up the KnowledegeHelper references 
-     * to be what SMF requires.
-     *
-     * eg: modify( myObject ); --> drools.modify( myObjectHandle, myObject );
-     * refer to the Replacer implementation classes below for the specific replacement patterns.
-     * 
-     * (can adjust the PREFIX if needed).
-     * 
-     * Uses some non-tail recursion to ensure that all parts are "expanded". 
-     */
-    public String fix(final String raw) {
-        String result = fix( raw,
-                             ModifyReplacer.INSTANCE );
-        result = fix( result,
-                      AssertReplacer.INSTANCE );
-        result = fix( result,
-                      AssertLogicalReplacer.INSTANCE );
-        result = fix( result,
-                      RetractReplacer.INSTANCE );
-        return result;
-    }
-
-    /**
-     * Recursively apply the pattern, replace the guts of what is matched.
-     */
-    public String fix(final String raw,
-                      final Replacer replacer) {
-        if ( raw == null ) {
-            return null;
-        }
-        final Matcher matcher = replacer.getPattern().matcher( raw );
-
-        if ( matcher.matches() ) {
-            String pre = matcher.group( 1 );
-            if ( matcher.group( 1 ) != null ) {
-                pre = fix( pre,
-                           replacer );
-            }
-            final String obj = matcher.group( 2 ).trim();
-            String post = matcher.group( 3 );
-            if ( post != null ) {
-                post = fix( post,
-                            replacer );
-            }
-
-            final String replacement = escapeDollarSigns( replacer,
-                                                    obj );
-            return pre + matcher.replaceAll( replacement ) + post;
-
-        } else {
-            return raw;
-        }
-    }
-
-    /** 
-     * This is needed to escape "$" so that matches doesn't try and pull out groups that don't exist.
-     * "$" may just be used in variable name etc... 
-     */
-    private String escapeDollarSigns(final Replacer replacer,
-                                     final String obj) {
-        return KnowledgeHelperFixer.replace( replacer.getReplacement( obj ),
-                             "$",
-                             "\\$",
-                             256 );
-    }
-
-    static interface Replacer {
-        Pattern getPattern();
-
-        String getReplacement(String guts);
-    }
-
-    static class AssertReplacer
-        implements
-        Replacer {
-
-        static Replacer INSTANCE = new AssertReplacer();
-
-        public Pattern getPattern() {
-            return KnowledgeHelperFixer.ASSERT;
-        }
-
-        public String getReplacement(final String guts) {
-            return "drools.assertObject(" + guts + ")";
-        }
-
-    }
-
-    static class AssertLogicalReplacer
-        implements
-        Replacer {
-
-        static Replacer INSTANCE = new AssertLogicalReplacer();
-
-        public Pattern getPattern() {
-            return KnowledgeHelperFixer.ASSERT_LOGICAL;
-        }
-
-        public String getReplacement(final String guts) {
-            return "drools.assertLogicalObject(" + guts + ")";
-        }
-
-    }
-
-    static class ModifyReplacer
-        implements
-        Replacer {
-
-        static Replacer INSTANCE = new ModifyReplacer();
-
-        public Pattern getPattern() {
-            return KnowledgeHelperFixer.MODIFY;
-        }
-
-        public String getReplacement(final String guts) {
-            return "drools.modifyObject(" + guts.trim() + "__Handle__, " + guts + ")";
-        }
-
-    }
-
-    static class RetractReplacer
-        implements
-        Replacer {
-
-        static Replacer INSTANCE = new RetractReplacer();
-
-        public Pattern getPattern() {
-            return KnowledgeHelperFixer.RETRACT;
-        }
-
-        public String getReplacement(final String guts) {
-            return "drools.retractObject(" + guts.trim() + "__Handle__)";
-        }
-
-    }
-
-    /**
-     * Simple non regex replacer. 
-     * jakarta commons provided the inspiration for this.
-     */
-    static String replace(final String text,
-                          final String repl,
-                          final String with,
-                          int max) {
-        if ( text == null || repl == null || repl.equals( "" ) || with == null || max == 0 ) {
-            return text;
-        }
-
-        final StringBuffer buf = new StringBuffer( text.length() );
-        int start = 0, end = 0;
-        while ( (end = text.indexOf( repl,
-                                     start )) != -1 ) {
-            buf.append( text.substring( start,
-                                        end ) ).append( with );
-            start = end + repl.length();
-
-            if ( --max == 0 ) {
-                break;
-            }
-        }
-        buf.append( text.substring( start ) );
-        return buf.toString();
-    }
-
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/PackageStore.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/PackageStore.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/PackageStore.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,65 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.commons.jci.stores.ResourceStore;
-import org.drools.rule.PackageCompilationData;
-
-public class PackageStore
-    implements
-    ResourceStore {
-    private PackageCompilationData packageCompilationData;
-
-    public PackageStore() {
-    }
-
-    public PackageStore(final PackageCompilationData packageCompiationData) {
-        this.packageCompilationData = packageCompiationData;
-    }
-
-    public void setPackageCompilationData(final PackageCompilationData packageCompiationData) {
-        this.packageCompilationData = packageCompiationData;
-    }
-
-    public void write(final String resourceName,
-                      final byte[] clazzData) {
-        try {
-            this.packageCompilationData.write( resourceName,
-                                               clazzData );
-        } catch ( final Exception e ) {
-
-        }
-    }
-
-    public byte[] read(final String resourceName) {
-        byte[] clazz = null;
-        try {
-            clazz = this.packageCompilationData.read( resourceName );
-        } catch ( final Exception e ) {
-
-        }
-        return clazz;
-    }
-
-    public void remove(final String resourceName) {
-        try {
-            this.packageCompilationData.remove( resourceName );
-        } catch ( final Exception e ) {
-
-        }
-    }
-}
\ No newline at end of file

Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -1,253 +0,0 @@
-package org.drools.semantics.java;
-
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.codehaus.jfdi.interpreter.TypeResolver;
-import org.drools.RuntimeDroolsException;
-import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.evaluators.DateFactory;
-import org.drools.dialect.java.JavaAccumulateBuilder;
-import org.drools.dialect.java.JavaConsequenceBuilder;
-import org.drools.dialect.java.JavaEvalBuilder;
-import org.drools.dialect.mvel.MVELFromBuilder;
-import org.drools.lang.descr.AccumulateDescr;
-import org.drools.lang.descr.AndDescr;
-import org.drools.lang.descr.AttributeDescr;
-import org.drools.lang.descr.CollectDescr;
-import org.drools.lang.descr.EvalDescr;
-import org.drools.lang.descr.ExistsDescr;
-import org.drools.lang.descr.ForallDescr;
-import org.drools.lang.descr.FromDescr;
-import org.drools.lang.descr.NotDescr;
-import org.drools.lang.descr.OrDescr;
-import org.drools.lang.descr.QueryDescr;
-import org.drools.lang.descr.RuleDescr;
-import org.drools.rule.GroupElement;
-import org.drools.rule.Package;
-import org.drools.rule.Rule;
-import org.drools.semantics.java.builder.ForallBuilder;
-import org.drools.semantics.java.builder.BuildContext;
-import org.drools.semantics.java.builder.BuildUtils;
-import org.drools.semantics.java.builder.CollectBuilder;
-import org.drools.semantics.java.builder.ColumnBuilder;
-import org.drools.semantics.java.builder.ConditionalElementBuilder;
-import org.drools.semantics.java.builder.ConsequenceBuilder;
-import org.drools.semantics.java.builder.GroupElementBuilder;
-import org.drools.semantics.java.builder.RuleClassBuilder;
-
-/**
- * This builds the rule structure from an AST.
- * Generates semantic code where necessary if semantics are used.
- * This is an internal API.
- */
-public class RuleBuilder {
-
-    // the current build context
-    private BuildContext       context;
-
-    // the current build utils
-    private BuildUtils         utils;
-
-    // a map of registered builders
-    private Map                builders;
-
-    // the builder for columns
-    private ColumnBuilder      columnBuilder;
-
-    // the builder for the consequence
-    private ConsequenceBuilder consequenceBuilder;
-    
-    // the builder for the rule class
-    private RuleClassBuilder   classBuilder;
-
-    // Constructor
-    public RuleBuilder(final TypeResolver typeResolver,
-                       final ClassFieldExtractorCache cache) {
-
-        // statically adding all builders to the map
-        // but in the future we can move that to a configuration
-        // if we want to
-        this.builders = new HashMap();
-        builders.put( EvalDescr.class,
-                      new JavaEvalBuilder() );
-        builders.put( FromDescr.class,
-                      new MVELFromBuilder() );
-        builders.put( CollectDescr.class,
-                      new CollectBuilder() );
-        builders.put( AccumulateDescr.class,
-                      new JavaAccumulateBuilder() );
-        builders.put( ForallDescr.class,
-                      new ForallBuilder() );
-        GroupElementBuilder gebuilder = new GroupElementBuilder();
-        builders.put( AndDescr.class,
-                      gebuilder);
-        builders.put( OrDescr.class,
-                      gebuilder);
-        builders.put( NotDescr.class,
-                      gebuilder);
-        builders.put( ExistsDescr.class,
-                      gebuilder);
-        
-        
-        this.utils = new BuildUtils( new KnowledgeHelperFixer(),
-                                     new DeclarationTypeFixer(),
-                                     new JavaExprAnalyzer(),
-                                     typeResolver,
-                                     cache,
-                                     builders );
-
-        this.columnBuilder = new ColumnBuilder();
-
-        this.consequenceBuilder = new JavaConsequenceBuilder();
-        
-        this.classBuilder = new RuleClassBuilder();
-    }
-
-    public Map getInvokers() {
-        return (this.context == null) ? null : this.context.getInvokers();
-    }
-
-    public Map getDescrLookups() {
-        return (this.context == null) ? null : this.context.getDescrLookups();
-    }
-
-    public String getRuleClass() {
-        return (this.context == null) ? null : this.context.getRuleClass();
-    }
-
-    public Map getInvokerLookups() {
-        return (this.context == null) ? null : this.context.getInvokerLookups();
-    }
-
-    public List getErrors() {
-        return (this.context == null) ? null : this.context.getErrors();
-    }
-
-    public Rule getRule() {
-        if ( this.context == null ) {
-            return null;
-        }
-        if ( !this.context.getErrors().isEmpty() ) {
-            this.context.getRule().setSemanticallyValid( false );
-        }
-        return this.context.getRule();
-    }
-
-    public Package getPackage() {
-        return this.context.getPkg();
-    }
-
-    /**
-     * Build the give rule into the 
-     * @param pkg
-     * @param ruleDescr
-     * @return
-     */
-    public synchronized Rule build(final Package pkg,
-                                   final RuleDescr ruleDescr) {
-        this.context = new BuildContext( pkg,
-                                         ruleDescr );
-
-        // Assign attributes
-        setAttributes( this.context.getRule(),
-                       ruleDescr.getAttributes() );
-
-        ConditionalElementBuilder builder = utils.getBuilder( ruleDescr.getLhs().getClass() );
-        if( builder != null ) {
-            GroupElement ce = (GroupElement) builder.build( this.context, this.utils, this.columnBuilder, ruleDescr.getLhs() );
-            this.context.getRule().setLhs( ce );
-        } else {
-            throw new RuntimeDroolsException("BUG: builder not found for descriptor class "+ruleDescr.getLhs().getClass() );
-        }
-
-        // Build the consequence and generate it's invoker/s
-        // generate the main rule from the previously generated s.
-        if ( !(ruleDescr instanceof QueryDescr) ) {
-            // do not build the consequence if we have a query
-            this.consequenceBuilder.buildConsequence( this.context,
-                                                      this.utils,
-                                                      ruleDescr );
-        }
-        this.classBuilder.buildRule( this.context, this.utils, ruleDescr );
-
-        return this.context.getRule();
-    }
-
-
-    /**
-     * Sets rule Attributes
-     * 
-     * @param rule
-     * @param attributes
-     */
-    void setAttributes(final Rule rule,
-                               final List attributes) {
-        
-        for ( final Iterator it = attributes.iterator(); it.hasNext(); ) {
-            final AttributeDescr attributeDescr = (AttributeDescr) it.next();
-            final String name = attributeDescr.getName();
-            if ( name.equals( "salience" ) ) {
-                rule.setSalience( Integer.parseInt( attributeDescr.getValue() ) );
-            } else if ( name.equals( "no-loop" ) ) {
-                if ( attributeDescr.getValue() == null ) {
-                    rule.setNoLoop( true );
-                } else {
-                    rule.setNoLoop( Boolean.valueOf( attributeDescr.getValue() ).booleanValue() );
-                }
-            } else if ( name.equals( "auto-focus" ) ) {
-                if ( attributeDescr.getValue() == null ) {
-                    rule.setAutoFocus( true );
-                } else {
-                    rule.setAutoFocus( Boolean.valueOf( attributeDescr.getValue() ).booleanValue() );
-                }
-            } else if ( name.equals( "agenda-group" ) ) {
-                rule.setAgendaGroup( attributeDescr.getValue() );
-            } else if ( name.equals( "activation-group" ) ) {
-                rule.setActivationGroup( attributeDescr.getValue() );
-            } else if ( name.equals( "ruleflow-group" ) ) {
-                rule.setRuleFlowGroup( attributeDescr.getValue() );
-            } else if ( name.equals( "duration" ) ) {
-                rule.setDuration( Long.parseLong( attributeDescr.getValue() ) );
-                rule.setAgendaGroup( "" );
-            } else if (name.equals( "enabled" )){
-                if (attributeDescr.getValue() == null) {
-                    rule.setEnabled( true );
-                } else {
-                    rule.setEnabled( Boolean.valueOf( attributeDescr.getValue() ).booleanValue());
-                }
-            } else if (name.equals( "date-effective" )) {                
-                Calendar cal = Calendar.getInstance();
-                cal.setTime( DateFactory.parseDate( attributeDescr.getValue() ) );
-                rule.setDateEffective( cal );
-            } else if (name.equals( "date-expires" )) {     
-                Calendar cal = Calendar.getInstance();
-                cal.setTime( DateFactory.parseDate( attributeDescr.getValue() ) );
-                rule.setDateExpires( cal );
-                
-            } else if ( name.equals( "language" ) ) {
-                //@todo: we don't currently  support multiple languages
-            }
-        }
-    }
-
-}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/dialect/mvel/MVELEvalBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/dialect/mvel/MVELEvalBuilderTest.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/dialect/mvel/MVELEvalBuilderTest.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -19,7 +19,7 @@
 import org.drools.rule.Declaration;
 import org.drools.rule.EvalCondition;
 import org.drools.rule.Package;
-import org.drools.semantics.java.builder.BuildContext;
+import org.drools.rule.builder.BuildContext;
 import org.drools.spi.DeclarationScopeResolver;
 import org.drools.spi.FieldExtractor;
 

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/AccumulateTemplateTest.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -13,6 +13,7 @@
 import org.drools.Person;
 import org.drools.base.ClassFieldExtractor;
 import org.drools.base.ClassObjectType;
+import org.drools.dialect.java.RuleBuilder;
 import org.drools.rule.Declaration;
 import org.drools.spi.ColumnExtractor;
 

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/KnowledgeHelperFixerTest.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import org.drools.dialect.java.KnowledgeHelperFixer;
+
 import junit.framework.TestCase;
 
 public class KnowledgeHelperFixerTest extends TestCase {

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java	2007-02-27 00:06:47 UTC (rev 9780)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/semantics/java/RuleBuilderTest.java	2007-02-27 00:11:32 UTC (rev 9781)
@@ -29,6 +29,7 @@
 import org.codehaus.jfdi.interpreter.TypeResolver;
 import org.drools.base.ClassFieldExtractorCache;
 import org.drools.compiler.DrlParser;
+import org.drools.dialect.java.RuleBuilder;
 import org.drools.lang.descr.AttributeDescr;
 import org.drools.lang.descr.PackageDescr;
 import org.drools.lang.descr.RuleDescr;
@@ -58,7 +59,7 @@
     }
 
     /**
-     * Test method for {@link org.drools.semantics.java.RuleBuilder#build(org.drools.rule.Package, org.drools.lang.descr.RuleDescr)}.
+     * Test method for {@link org.drools.dialect.java.RuleBuilder#build(org.drools.rule.Package, org.drools.lang.descr.RuleDescr)}.
      */
     public void testBuild() {
         try {




More information about the jboss-svn-commits mailing list