[jboss-svn-commits] JBL Code SVN: r9811 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: base/dataproviders and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 27 11:42:26 EST 2007


Author: mark.proctor at jboss.com
Date: 2007-02-27 11:42:25 -0500 (Tue, 27 Feb 2007)
New Revision: 9811

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELDeclarationVariable.java
   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/DroolsMVELGlobalVariable.java
Removed:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELDeclarationVariable.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELGlobalVariable.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MVELDataProvider.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELEvalExpression.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELPredicateExpression.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
Log:
JBRULES-708 MVEL Integration
-More interface/implementation seperation for dialects

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELDeclarationVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELDeclarationVariable.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELDeclarationVariable.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -1,39 +0,0 @@
-package org.drools.base;
-
-import org.drools.rule.Declaration;
-import org.mvel.integration.VariableResolver;
-
-public class DroolsMVELDeclarationVariable
-    implements
-    VariableResolver {
-    
-    private Declaration declaration;
-    private DroolsMVELFactory factory;
-       
-    public DroolsMVELDeclarationVariable(Declaration declaration,
-    		DroolsMVELFactory factory ) {
-        this.declaration = declaration;
-        this.factory =  factory;
-    }        
-    
-    public String getName() {
-        return this.declaration.getIdentifier();
-    }
-
-    public Class getKnownType() {
-        return declaration.getExtractor().getExtractToClass();
-    }
-
-    public Object getValue() {
-        return declaration.getValue( this.factory.getValue( this.declaration ));
-    }
-
-    public void setValue(Object value) {
-        throw new UnsupportedOperationException( "External Variable identifer='" + getName() + "' type='" + getKnownType()+ "' is final, it cannot be set" );
-    }
-    
-    public int getFlags()  {
-    	return 0;
-    }    
-
-}

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELFactory.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELFactory.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -1,116 +0,0 @@
-package org.drools.base;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.drools.WorkingMemory;
-import org.drools.rule.Declaration;
-import org.drools.spi.Tuple;
-import org.mvel.integration.VariableResolver;
-import org.mvel.integration.VariableResolverFactory;
-
-public class DroolsMVELFactory implements VariableResolverFactory {    
-    private Tuple tuple;
-    private Map declarations;
-    private Map globals;
-    
-    private Map resolvers;
-    //private
-    private WorkingMemory workingMemory;
-    
-    public DroolsMVELFactory() {
-    	this.resolvers = Collections.EMPTY_MAP;
-    }
-    
-    public void setDeclarationMap(Map declarations) {
-        this.declarations = declarations;
-    }
-    
-    public void setGlobalsMap(Map globals) {
-        this.globals = globals;
-    }
-    
-    public void setContext(Tuple tuple, WorkingMemory workingMemory) {
-        this.tuple = tuple;
-        this.workingMemory = workingMemory;
-    }
-    
-    public Object getValue(Declaration declaration) {
-        return tuple.get( declaration ).getObject();
-    }
-    
-    public Object getValue(String identifier) {
-        return this.workingMemory.getGlobal( identifier );
-    }
-
-	public VariableResolver createVariable(String name, Object value) {
-		throw new UnsupportedOperationException( "Variables cannot be created here" );
-	}
-
-	public VariableResolverFactory getNextFactory() {
-		return null;
-	}
-
-	public VariableResolverFactory setNextFactory(VariableResolverFactory resolverFactory) {
-		throw new UnsupportedOperationException( "Chained factories are not support for DroolsMVELFactory" );
-	}    	
-	
-	public VariableResolver getVariableResolver(String name) {	 	  
-		return ( VariableResolver ) this.resolvers.get( name );
-	}
-
-	public boolean isResolveable(String name) {
-		 //return this.declarations.containsKey( name ) || this.globals.containsKey( name );
-		  if ( this.resolvers == Collections.EMPTY_MAP) {
-			  this.resolvers = new HashMap();
-		  }
-		  
-		  VariableResolver resolver = (VariableResolver) this.resolvers.get( name );
-		  
-		  if ( resolver != null )  {
-			  return true;
-		  }
-		  
-	      if ( this.declarations.containsKey( name )) {
-	    	  resolver = new DroolsMVELDeclarationVariable( (Declaration) this.declarations.get( name ), this );
-	      } else {
-	    	  resolver = new DroolsMVELGlobalVariable( name, (Class) this.globals.get( name ), this );
-	      }
-	      
-	      if ( resolver != null ) {
-	    	  this.resolvers.put( name,  resolver );
-	    	  return true;
-	      } else {
-	    	  return false;
-	      }	      	
-	}
-
-	public boolean isTarget(String name) {
-		return this.resolvers.containsKey( name  );
-	}    
-    
-//    public ValueHandler createExternalVariable(String identifier) {        
-//        registerExternalVariable( identifier );
-//        ValueHandler variable;
-//        if ( this.declarations.containsKey( identifier )) {
-//            variable = new DroolsMVELDeclarationVariable( (Declaration) this.declarations.get( identifier ), this );
-//        } else {
-//            variable = new DroolsMVELGlobalVariable( identifier, (Class) this.globals.get( identifier ), this );
-//        }
-//        return variable;
-//    	return null;
-//    }
-//
-//    public boolean isValidVariable(String identifier) {        
-//        return this.declarations.containsKey( identifier );
-//    }   
-//    
-//    public Declaration[] getRequiredDeclarations()  {
-//        List list = new ArrayList();
-//        for (int i  = 0, length  = this.requiredVariables.length; i < length; i++) {
-//            list.add( this.declarations.get( this.requiredVariables[i] ) );
-//        }
-//        return (Declaration[]) list.toArray( new Declaration[list.size()  ]  );
-//    }
-}

Deleted: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELGlobalVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELGlobalVariable.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELGlobalVariable.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -1,41 +0,0 @@
-package org.drools.base;
-
-import org.mvel.integration.VariableResolver;
-
-public class DroolsMVELGlobalVariable
-    implements
-    VariableResolver {
-    
-    private String name;
-    private Class knownType;
-    private DroolsMVELFactory factory;
-       
-    public DroolsMVELGlobalVariable(String identifier,
-                                    Class knownType,
-                                    DroolsMVELFactory factory ) {
-        this.name = identifier;
-        this.factory =  factory;
-        this.knownType = knownType;
-    }
-    
-    public String getName() {
-        return this.name;
-    }
-
-    public Class getKnownType() {
-        return this.knownType;
-    }
-
-    public Object getValue() {
-        return this.factory.getValue( this.name );
-    }
-
-    public void setValue(Object value) {
-        throw new UnsupportedOperationException( "External Variable identifer='" + getName() + "' type='" + getKnownType() + "' is final, it cannot be set" );
-    }
-    
-    public int getFlags()  {
-    	return 0;
-    }        
-
-}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MVELDataProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MVELDataProvider.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/dataproviders/MVELDataProvider.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -6,7 +6,7 @@
 import java.util.Iterator;
 
 import org.drools.WorkingMemory;
-import org.drools.base.DroolsMVELFactory;
+import org.drools.base.mvel.DroolsMVELFactory;
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Declaration;
 import org.drools.spi.DataProvider;

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELDeclarationVariable.java (from rev 9748, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELDeclarationVariable.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELDeclarationVariable.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELDeclarationVariable.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -0,0 +1,39 @@
+package org.drools.base.mvel;
+
+import org.drools.rule.Declaration;
+import org.mvel.integration.VariableResolver;
+
+public class DroolsMVELDeclarationVariable
+    implements
+    VariableResolver {
+    
+    private Declaration declaration;
+    private DroolsMVELFactory factory;
+       
+    public DroolsMVELDeclarationVariable(Declaration declaration,
+    		DroolsMVELFactory factory ) {
+        this.declaration = declaration;
+        this.factory =  factory;
+    }        
+    
+    public String getName() {
+        return this.declaration.getIdentifier();
+    }
+
+    public Class getKnownType() {
+        return declaration.getExtractor().getExtractToClass();
+    }
+
+    public Object getValue() {
+        return declaration.getValue( this.factory.getValue( this.declaration ));
+    }
+
+    public void setValue(Object value) {
+        throw new UnsupportedOperationException( "External Variable identifer='" + getName() + "' type='" + getKnownType()+ "' is final, it cannot be set" );
+    }
+    
+    public int getFlags()  {
+    	return 0;
+    }    
+
+}

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java (from rev 9748, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELFactory.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -0,0 +1,116 @@
+package org.drools.base.mvel;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.WorkingMemory;
+import org.drools.rule.Declaration;
+import org.drools.spi.Tuple;
+import org.mvel.integration.VariableResolver;
+import org.mvel.integration.VariableResolverFactory;
+
+public class DroolsMVELFactory implements VariableResolverFactory {    
+    private Tuple tuple;
+    private Map declarations;
+    private Map globals;
+    
+    private Map resolvers;
+    //private
+    private WorkingMemory workingMemory;
+    
+    public DroolsMVELFactory() {
+    	this.resolvers = Collections.EMPTY_MAP;
+    }
+    
+    public void setDeclarationMap(Map declarations) {
+        this.declarations = declarations;
+    }
+    
+    public void setGlobalsMap(Map globals) {
+        this.globals = globals;
+    }
+    
+    public void setContext(Tuple tuple, WorkingMemory workingMemory) {
+        this.tuple = tuple;
+        this.workingMemory = workingMemory;
+    }
+    
+    public Object getValue(Declaration declaration) {
+        return tuple.get( declaration ).getObject();
+    }
+    
+    public Object getValue(String identifier) {
+        return this.workingMemory.getGlobal( identifier );
+    }
+
+	public VariableResolver createVariable(String name, Object value) {
+		throw new UnsupportedOperationException( "Variables cannot be created here" );
+	}
+
+	public VariableResolverFactory getNextFactory() {
+		return null;
+	}
+
+	public VariableResolverFactory setNextFactory(VariableResolverFactory resolverFactory) {
+		throw new UnsupportedOperationException( "Chained factories are not support for DroolsMVELFactory" );
+	}    	
+	
+	public VariableResolver getVariableResolver(String name) {	 	  
+		return ( VariableResolver ) this.resolvers.get( name );
+	}
+
+	public boolean isResolveable(String name) {
+		 //return this.declarations.containsKey( name ) || this.globals.containsKey( name );
+		  if ( this.resolvers == Collections.EMPTY_MAP) {
+			  this.resolvers = new HashMap();
+		  }
+		  
+		  VariableResolver resolver = (VariableResolver) this.resolvers.get( name );
+		  
+		  if ( resolver != null )  {
+			  return true;
+		  }
+		  
+	      if ( this.declarations.containsKey( name )) {
+	    	  resolver = new DroolsMVELDeclarationVariable( (Declaration) this.declarations.get( name ), this );
+	      } else {
+	    	  resolver = new DroolsMVELGlobalVariable( name, (Class) this.globals.get( name ), this );
+	      }
+	      
+	      if ( resolver != null ) {
+	    	  this.resolvers.put( name,  resolver );
+	    	  return true;
+	      } else {
+	    	  return false;
+	      }	      	
+	}
+
+	public boolean isTarget(String name) {
+		return this.resolvers.containsKey( name  );
+	}    
+    
+//    public ValueHandler createExternalVariable(String identifier) {        
+//        registerExternalVariable( identifier );
+//        ValueHandler variable;
+//        if ( this.declarations.containsKey( identifier )) {
+//            variable = new DroolsMVELDeclarationVariable( (Declaration) this.declarations.get( identifier ), this );
+//        } else {
+//            variable = new DroolsMVELGlobalVariable( identifier, (Class) this.globals.get( identifier ), this );
+//        }
+//        return variable;
+//    	return null;
+//    }
+//
+//    public boolean isValidVariable(String identifier) {        
+//        return this.declarations.containsKey( identifier );
+//    }   
+//    
+//    public Declaration[] getRequiredDeclarations()  {
+//        List list = new ArrayList();
+//        for (int i  = 0, length  = this.requiredVariables.length; i < length; i++) {
+//            list.add( this.declarations.get( this.requiredVariables[i] ) );
+//        }
+//        return (Declaration[]) list.toArray( new Declaration[list.size()  ]  );
+//    }
+}

Copied: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELGlobalVariable.java (from rev 9748, labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/DroolsMVELGlobalVariable.java)
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELGlobalVariable.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELGlobalVariable.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -0,0 +1,41 @@
+package org.drools.base.mvel;
+
+import org.mvel.integration.VariableResolver;
+
+public class DroolsMVELGlobalVariable
+    implements
+    VariableResolver {
+    
+    private String name;
+    private Class knownType;
+    private DroolsMVELFactory factory;
+       
+    public DroolsMVELGlobalVariable(String identifier,
+                                    Class knownType,
+                                    DroolsMVELFactory factory ) {
+        this.name = identifier;
+        this.factory =  factory;
+        this.knownType = knownType;
+    }
+    
+    public String getName() {
+        return this.name;
+    }
+
+    public Class getKnownType() {
+        return this.knownType;
+    }
+
+    public Object getValue() {
+        return this.factory.getValue( this.name );
+    }
+
+    public void setValue(Object value) {
+        throw new UnsupportedOperationException( "External Variable identifer='" + getName() + "' type='" + getKnownType() + "' is final, it cannot be set" );
+    }
+    
+    public int getFlags()  {
+    	return 0;
+    }        
+
+}

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELEvalExpression.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELEvalExpression.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELEvalExpression.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -3,7 +3,6 @@
 import java.io.Serializable;
 
 import org.drools.WorkingMemory;
-import org.drools.base.DroolsMVELFactory;
 import org.drools.rule.Declaration;
 import org.drools.spi.EvalExpression;
 import org.drools.spi.Tuple;
@@ -12,12 +11,12 @@
 public class MVELEvalExpression
     implements
     EvalExpression {
-    
-    private static final long          serialVersionUID = 320L;
-    
-    private final Serializable expr;
+
+    private static final long       serialVersionUID = 320L;
+
+    private final Serializable      expr;
     private final DroolsMVELFactory factory;
-    
+
     public MVELEvalExpression(final Serializable expr,
                               final DroolsMVELFactory factory) {
         this.expr = expr;
@@ -26,10 +25,12 @@
 
     public boolean evaluate(Tuple tuple,
                             Declaration[] requiredDeclarations,
-                            WorkingMemory workingMemory) throws Exception {                
-        factory.setContext( tuple, workingMemory );   
-        Boolean result = ( Boolean ) MVEL.executeExpression(this.expr, factory);        
-        return result.booleanValue(); 
+                            WorkingMemory workingMemory) throws Exception {
+        factory.setContext( tuple,
+                            workingMemory );
+        Boolean result = (Boolean) MVEL.executeExpression( this.expr,
+                                                           factory );
+        return result.booleanValue();
     }
 
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELPredicateExpression.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELPredicateExpression.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELPredicateExpression.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -3,7 +3,6 @@
 import java.io.Serializable;
 
 import org.drools.WorkingMemory;
-import org.drools.base.DroolsMVELFactory;
 import org.drools.rule.Declaration;
 import org.drools.spi.PredicateExpression;
 import org.drools.spi.Tuple;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2007-02-27 16:02:57 UTC (rev 9810)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2007-02-27 16:42:25 UTC (rev 9811)
@@ -178,6 +178,7 @@
                                              localDeclarations,
                                              ctx.workingMemory );
         } catch ( Exception e ) {
+            e.printStackTrace();
             throw new RuntimeDroolsException( "Exception executing predicate " + this.expression,
                                               e );
         }




More information about the jboss-svn-commits mailing list