[jboss-svn-commits] JBL Code SVN: r17470 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Dec 31 09:35:00 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-12-31 09:35:00 -0500 (Mon, 31 Dec 2007)
New Revision: 17470

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
Log:
JBRULES-1397 org.mvel.CompileException: variable already defined within scope
-localvariables  is now always created, or cleared, on setcontext.
-createVariables for typed and untyped local variables is now simplified.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	2007-12-31 14:26:04 UTC (rev 17469)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	2007-12-31 14:35:00 UTC (rev 17470)
@@ -163,7 +163,15 @@
         this.knowledgeHelper = knowledgeHelper;
         this.object = object;
         this.workingMemory = workingMemory;
-        this.localVariables = variables;
+        if ( variables == null ) {
+            if ( this.localVariables == null ) {
+                this.localVariables = new HashMap();
+            } else {
+                this.localVariables.clear();
+            }            
+        } else {
+            this.localVariables = variables;
+        }
     }
 
     public KnowledgeHelper getKnowledgeHelper() {
@@ -192,41 +200,29 @@
     public VariableResolver createVariable(String name,
                                            Object value) {
         VariableResolver vr = getVariableResolver( name );
-        if ( vr != null ) {
-            if ( this.localVariables == null ) {
-                this.localVariables = new HashMap();
-            }
-            vr.setValue( value );
-            return vr;
-        } else {
-            if ( this.localVariables == null ) {
-                this.localVariables = new HashMap();
-            }
+        if ( vr == null ) {
             addResolver( name,
                          vr = new LocalVariableResolver( this,
                                                          name ) );
-            vr.setValue( value );
-            return vr;
         }
+        
+        vr.setValue( value );
+        return vr;        
     }
 
     public VariableResolver createVariable(String name,
                                            Object value,
                                            Class type) {
         VariableResolver vr = getVariableResolver( name );
-        if ( vr != null && vr.getType() != null ) {
-            throw new CompileException( "variable already defined within scope: " + vr.getType() + " " + name );
-        } else {
-            if ( this.localVariables == null ) {
-                this.localVariables = new HashMap();
-            }
+        if ( vr == null ) {
             addResolver( name,
                          vr = new LocalVariableResolver( this,
                                                          name,
                                                          type ) );
-            vr.setValue( value );
-            return vr;
-        }
+        }        
+        
+        vr.setValue( value );
+        return vr;
     }
 
     public boolean isResolveable(String name) {
@@ -253,12 +249,7 @@
                                                        (Class) this.globals.get( name ),
                                                        this ) );
             return true;
-        } else if ( this.variableResolvers != null && this.variableResolvers.containsKey( name ) ) {
-            addResolver( name,
-                         new LocalVariableResolver( this,
-                                                    name ) );
-            return true;
-        } else if ( nextFactory != null ) {
+        }  else if ( nextFactory != null ) {
             return nextFactory.isResolveable( name );
         }
 




More information about the jboss-svn-commits mailing list