[jboss-svn-commits] JBL Code SVN: r10518 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/clp/functions and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Mar 24 15:50:18 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-03-24 15:50:18 -0400 (Sat, 24 Mar 2007)
New Revision: 10518
Added:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/CreateListFunction.java
Removed:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanLiteralValue.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleLiteralValue.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongLiteralValue.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectLiteralValue.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BaseValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPFactory.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPGlobalVariable.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLexer.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLocalDeclarationVariable.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPParser.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPPreviousDeclarationVariable.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Deffunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ExecutionContext.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Function.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionCaller.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionDelegator.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LispForm.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ListValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LocalVariableValue.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/TempTokenVariable.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/VariableValueHandler.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/AddFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/BindFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/IfFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/LessThanFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/ModifyFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/MultiplyFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/WhileFunction.java
labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/CLP.g
labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/functions.conf
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/AddFunctionTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/BlockExecutionTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ClpParserTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/CompiledParserTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/DeffunctionTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ModifyFunctionTest.java
Log:
JBRULES-720 Clips Parser
-Working on creaet$, not yet finished
-In the middle of a broken refactor
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BaseValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BaseValueHandler.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BaseValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -55,9 +55,9 @@
String name = getClass().getName();
name = name.substring( name.lastIndexOf( "." ) + 1 );
try {
- return "[" + name + "value = '" + getValue(null) + "']";
+ return "[" + name + " value = '" + getValue(null) + "']";
} catch (Exception e) {
- return "[" + name + "value = N/A]";
+ return "[" + name + " value = N/A]";
}
}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanLiteralValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanLiteralValue.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanLiteralValue.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,82 +0,0 @@
-package org.drools.clp;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-public class BooleanLiteralValue extends BaseValueHandler {
- private boolean booleanValue;
-
- public BooleanLiteralValue(String booleanValue) {
- this.booleanValue = Boolean.valueOf( booleanValue ).booleanValue();
- }
-
- public BooleanLiteralValue(boolean booleanValue) {
- this.booleanValue = booleanValue;
- }
-
- public void setValue(ExecutionContext context, Object value) {
- throw new RuntimeException( "LiteralValues cannot be set");
- }
-
- public Object getValue(ExecutionContext context) {
- return new Boolean( this.booleanValue );
- }
-
- public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to BitDecimal" );
- }
-
- public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to BitInteger" );
- }
-
- public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
- return this.booleanValue;
- }
-
- public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to double" );
- }
-
- public float getFloatValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to float" );
- }
-
- public int getIntValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to int" );
- }
-
- public long getLongValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to long" );
- }
-
- public short getShortValue(ExecutionContext context) throws NumberFormatException {
- throw new RuntimeException( "Boolean format exception, cannot be cast to short" );
- }
-
- public String getStringValue(ExecutionContext context) {
- return Boolean.toString( this.booleanValue );
- }
-
- public String toString() {
- return "[BooleanLiteralValue value='" + this.booleanValue + "']";
- }
-
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + (booleanValue ? 1231 : 1237);
- return result;
- }
-
- public boolean equals(Object obj) {
- if ( this == obj ) return true;
- if ( obj == null ) return false;
- if ( !(obj instanceof BooleanLiteralValue) ) return false;
- final BooleanLiteralValue other = (BooleanLiteralValue) obj;
- if ( booleanValue != other.booleanValue ) return false;
- return true;
- }
-
-
-}
Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanValueHandler.java (from rev 10465, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanLiteralValue.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanValueHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/BooleanValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -0,0 +1,88 @@
+package org.drools.clp;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.drools.base.SimpleValueType;
+
+public class BooleanValueHandler implements ValueHandler {
+ private boolean booleanValue;
+
+ public BooleanValueHandler(String booleanValue) {
+ this.booleanValue = Boolean.valueOf( booleanValue ).booleanValue();
+ }
+
+ public BooleanValueHandler(boolean booleanValue) {
+ this.booleanValue = booleanValue;
+ }
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.BOOLEAN;
+ }
+
+ public void setValue(ExecutionContext context, Object value) {
+ throw new RuntimeException( "LiteralValues cannot be set");
+ }
+
+ public Object getValue(ExecutionContext context) {
+ return new Boolean( this.booleanValue );
+ }
+
+ public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to BitDecimal" );
+ }
+
+ public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to BitInteger" );
+ }
+
+ public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
+ return this.booleanValue;
+ }
+
+ public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to double" );
+ }
+
+ public float getFloatValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to float" );
+ }
+
+ public int getIntValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to int" );
+ }
+
+ public long getLongValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to long" );
+ }
+
+ public short getShortValue(ExecutionContext context) throws NumberFormatException {
+ throw new RuntimeException( "Boolean format exception, cannot be cast to short" );
+ }
+
+ public String getStringValue(ExecutionContext context) {
+ return Boolean.toString( this.booleanValue );
+ }
+
+ public String toString() {
+ return "[BooleanLiteralValue value='" + this.booleanValue + "']";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + (booleanValue ? 1231 : 1237);
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( !(obj instanceof BooleanValueHandler) ) return false;
+ final BooleanValueHandler other = (BooleanValueHandler) obj;
+ if ( booleanValue != other.booleanValue ) return false;
+ return true;
+ }
+
+
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPFactory.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPFactory.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -5,11 +5,12 @@
import java.util.Map;
import org.drools.WorkingMemory;
+import org.drools.base.ValueType;
import org.drools.rule.Declaration;
import org.drools.spi.Tuple;
import org.mvel.integration.VariableResolver;
-public class CLPFactory {
+public class CLPFactory {
private Tuple tuple;
private Object object;
private Map localDeclarations;
@@ -25,8 +26,8 @@
}
public CLPFactory(Map previousDeclarations,
- Map localDeclarations,
- Map globals) {
+ Map localDeclarations,
+ Map globals) {
}
@@ -42,7 +43,6 @@
this.globals = globals;
}
-
public Object getObject() {
return this.object;
}
@@ -68,9 +68,9 @@
throw new UnsupportedOperationException( "Variables cannot be created here" );
}
-// public ValueHandler getVariableResolver(String name) {
-// return (ValueHandler) this.resolvers.get( name );
-// }
+ // public ValueHandler getVariableResolver(String name) {
+ // return (ValueHandler) this.resolvers.get( name );
+ // }
public ValueHandler getVariableResolver(String name) {
//return this.declarations.containsKey( name ) || this.globals.containsKey( name );
@@ -84,14 +84,16 @@
return null;
}
- if ( this.previousDeclarations != null && this.previousDeclarations.containsKey( name ) ) {
+ if ( this.previousDeclarations != null && this.previousDeclarations.containsKey( name ) ) {
resolver = new CLPPreviousDeclarationVariable( (Declaration) this.previousDeclarations.get( name ) );
} else if ( this.localDeclarations != null && this.localDeclarations.containsKey( name ) ) {
- resolver = new CLPLocalDeclarationVariable( (Declaration) this.localDeclarations.get( name ) );
+ resolver = new CLPLocalDeclarationVariable( (Declaration) this.localDeclarations.get( name ) );
} else {
+ Class clazz = (Class) this.globals.get( name );
resolver = new CLPGlobalVariable( name,
- (Class) this.globals.get( name ),
- this );
+ clazz,
+ ValueType.determineValueType( clazz ).getSimpleType(),
+ this );
}
if ( resolver != null ) {
@@ -103,9 +105,9 @@
}
}
-// public boolean isTarget(String name) {
-// return this.resolvers.containsKey( name );
-// }
+ // public boolean isTarget(String name) {
+ // return this.resolvers.containsKey( name );
+ // }
// public ValueHandler createExternalVariable(String identifier) {
// registerExternalVariable( identifier );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPGlobalVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPGlobalVariable.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPGlobalVariable.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -5,10 +5,12 @@
private String identifier;
private Class knownType;
+ private int simpleType;
private CLPFactory factory;
public CLPGlobalVariable(String identifier,
Class knownType,
+ int simpleType,
CLPFactory factory ) {
this.identifier = identifier;
this.factory = factory;
@@ -18,6 +20,10 @@
public String getIdentifier() {
return this.identifier;
}
+
+ public int getValueType(ExecutionContext context) {
+ return this.simpleType;
+ }
public Class getKnownType() {
return this.knownType;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLexer.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLexer.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLexer.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -3,12 +3,17 @@
package org.drools.clp;
-import org.antlr.runtime.*;
-import java.util.Stack;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
import java.util.HashMap;
+
+import org.antlr.runtime.BaseRecognizer;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.DFA;
+import org.antlr.runtime.EarlyExitException;
+import org.antlr.runtime.Lexer;
+import org.antlr.runtime.MismatchedSetException;
+import org.antlr.runtime.NoViableAltException;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
public class CLPLexer extends Lexer {
public static final int EXISTS=14;
public static final int LEFT_PAREN=4;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLocalDeclarationVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLocalDeclarationVariable.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPLocalDeclarationVariable.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -3,7 +3,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import org.drools.base.ValueType;
import org.drools.rule.Declaration;
public class CLPLocalDeclarationVariable implements VariableValueHandler {
@@ -21,8 +20,8 @@
return declaration.getExtractor().getExtractToClass();
}
- public ValueType getValueType() {
- return this.declaration.getValueType();
+ public int getValueType(ExecutionContext context) {
+ return this.declaration.getValueType().getSimpleType();
}
public void setValue(ExecutionContext context,
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPParser.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPParser.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPParser.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,20 +1,42 @@
// $ANTLR 3.0b7 C:\\dev\\jbossrules\\trunk\\drools-compiler\\src\\main\\resources\\org\\drools\\clp\\CLP.g 2007-03-24 14:22:23
package org.drools.clp;
- import java.util.List;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.HashMap;
- import java.util.StringTokenizer;
- import org.drools.lang.descr.*;
- import org.drools.compiler.SwitchingCommonTokenStream;
+ import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.antlr.runtime.BitSet;
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.EarlyExitException;
+import org.antlr.runtime.FailedPredicateException;
+import org.antlr.runtime.MismatchedNotSetException;
+import org.antlr.runtime.MismatchedSetException;
+import org.antlr.runtime.MismatchedTokenException;
+import org.antlr.runtime.MismatchedTreeNodeException;
+import org.antlr.runtime.NoViableAltException;
+import org.antlr.runtime.Parser;
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.TokenStream;
+import org.drools.lang.descr.AndDescr;
+import org.drools.lang.descr.AttributeDescr;
+import org.drools.lang.descr.ColumnDescr;
+import org.drools.lang.descr.ConditionalElementDescr;
+import org.drools.lang.descr.DescrFactory;
+import org.drools.lang.descr.EvalDescr;
+import org.drools.lang.descr.ExistsDescr;
+import org.drools.lang.descr.FieldBindingDescr;
+import org.drools.lang.descr.FieldConstraintDescr;
+import org.drools.lang.descr.LiteralRestrictionDescr;
+import org.drools.lang.descr.NotDescr;
+import org.drools.lang.descr.OrDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.PredicateDescr;
+import org.drools.lang.descr.RestrictionConnectiveDescr;
+import org.drools.lang.descr.ReturnValueRestrictionDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.drools.lang.descr.VariableRestrictionDescr;
-import org.antlr.runtime.*;
-import java.util.Stack;
-import java.util.List;
-import java.util.ArrayList;
-
public class CLPParser extends Parser {
public static final String[] tokenNames = new String[] {
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "LEFT_PAREN", "DEFRULE", "NAME", "STRING", "RIGHT_PAREN", "SALIENCE", "INT", "AND", "OR", "NOT", "EXISTS", "TEST", "VAR", "ASSIGN_OP", "AMPERSAND", "PIPE", "TILDE", "COLON", "EQUALS", "FLOAT", "BOOL", "NULL", "EOL", "WS", "DECLARE", "EscapeSequence", "HexDigit", "UnicodeEscape", "OctalEscape", "SYMBOL", "SH_STYLE_SINGLE_LINE_COMMENT", "C_STYLE_SINGLE_LINE_COMMENT", "LEFT_SQUARE", "RIGHT_SQUARE", "LEFT_CURLY", "RIGHT_CURLY", "MULTI_LINE_COMMENT", "'=>'"
@@ -1533,7 +1555,7 @@
{
t=(Token)input.LT(1);
match(input,STRING,FOLLOW_STRING_in_lisp_atom1133);
- value = new ObjectLiteralValue( getString( t ) );
+ value = new ObjectValueHandler( getString( t ) );
}
break;
@@ -1542,7 +1564,7 @@
{
t=(Token)input.LT(1);
match(input,NAME,FOLLOW_NAME_in_lisp_atom1148);
- value = new ObjectLiteralValue( t.getText() );
+ value = new ObjectValueHandler( t.getText() );
}
break;
@@ -1551,7 +1573,7 @@
{
t=(Token)input.LT(1);
match(input,FLOAT,FOLLOW_FLOAT_in_lisp_atom1163);
- value = new DoubleLiteralValue( t.getText() );
+ value = new DoubleValueHandler( t.getText() );
}
break;
@@ -1560,7 +1582,7 @@
{
t=(Token)input.LT(1);
match(input,INT,FOLLOW_INT_in_lisp_atom1175);
- value = new LongLiteralValue( t.getText() );
+ value = new LongValueHandler( t.getText() );
}
break;
@@ -1569,7 +1591,7 @@
{
t=(Token)input.LT(1);
match(input,BOOL,FOLLOW_BOOL_in_lisp_atom1191);
- value = new BooleanLiteralValue( t.getText() );
+ value = new BooleanValueHandler( t.getText() );
}
break;
@@ -1578,7 +1600,7 @@
{
t=(Token)input.LT(1);
match(input,NULL,FOLLOW_NULL_in_lisp_atom1209);
- value = ObjectLiteralValue.NULL;
+ value = ObjectValueHandler.NULL;
}
break;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPPreviousDeclarationVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPPreviousDeclarationVariable.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/CLPPreviousDeclarationVariable.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -3,7 +3,6 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import org.drools.base.ValueType;
import org.drools.common.InternalFactHandle;
import org.drools.rule.Declaration;
@@ -23,8 +22,8 @@
return declaration.getExtractor().getExtractToClass();
}
- public ValueType getValueType() {
- return this.declaration.getValueType();
+ public int getValueType(ExecutionContext context) {
+ return this.declaration.getValueType().getSimpleType();
}
public void setValue(ExecutionContext context,
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Deffunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Deffunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Deffunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -55,7 +55,7 @@
public void initCallback(ExecutionBuildContext context) {
}
- public Object execute(ValueHandler[] args,
+ public ValueHandler execute(ValueHandler[] args,
ExecutionContext context) {
ExecutionContext newContext = initContext( args,
context );
@@ -65,7 +65,7 @@
for ( int i = 0, length = this.functions.length; i < length; i++ ) {
returnValue = this.functions[i].getValue( newContext );
}
- return returnValue;
+ return new ObjectValueHandler( returnValue );
}
private ExecutionContext initContext(ValueHandler[] args,
@@ -74,8 +74,10 @@
context.getTuple(),
args.length );
for ( int i = 0, length = args.length; i < length; i++ ) {
+ // We know that each argument is a local variable, so we can cast and access the underlying value handler,
+ // as we don't want the variable fully resolved at this stage, just mapped.
newContext.setLocalVariable( i,
- args[i].getValue( context ) );
+ ((LocalVariableValue) args[i]).getRawValue( context ) );
}
return newContext;
}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleLiteralValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleLiteralValue.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleLiteralValue.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,84 +0,0 @@
-package org.drools.clp;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-public class DoubleLiteralValue extends BaseValueHandler {
- private double doubleValue;
-
- public DoubleLiteralValue(String doubleValue) {
- this.doubleValue = Double.valueOf( doubleValue ).doubleValue();
- }
-
- public DoubleLiteralValue(double doubleValue) {
- this.doubleValue = doubleValue;
- }
-
- public void setValue(ExecutionContext context, Object value) {
- throw new RuntimeException( "LiteralValues cannot be set");
- }
-
- public Object getValue(ExecutionContext context) {
- return new Double( this.doubleValue );
- }
-
- public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
- return new BigDecimal( this.doubleValue );
- }
-
- public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
- return BigInteger.valueOf( (long) this.doubleValue );
- }
-
- public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
- return ( this.doubleValue == 0 ) ? false : true;
- }
-
- public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
- return this.doubleValue;
- }
-
- public float getFloatValue(ExecutionContext context) throws NumberFormatException {
- return (float) this.doubleValue;
- }
-
- public int getIntValue(ExecutionContext context) throws NumberFormatException {
- return (int) this.doubleValue;
- }
-
- public long getLongValue(ExecutionContext context) throws NumberFormatException {
- return (long) this.doubleValue;
- }
-
- public short getShortValue(ExecutionContext context) throws NumberFormatException {
- return (short) this.doubleValue;
- }
-
- public String getStringValue(ExecutionContext context) {
- return Double.toString( this.doubleValue );
- }
-
- public String toString() {
- return "[DoubleLiteralValue value='" + this.doubleValue + "']";
- }
-
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits( doubleValue );
- result = PRIME * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- public boolean equals(Object obj) {
- if ( this == obj ) return true;
- if ( obj == null ) return false;
- if ( !(obj instanceof DoubleLiteralValue) ) return false;
- final DoubleLiteralValue other = (DoubleLiteralValue) obj;
- if ( Double.doubleToLongBits( doubleValue ) != Double.doubleToLongBits( other.doubleValue ) ) return false;
- return true;
- }
-
-
-}
Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleValueHandler.java (from rev 10465, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleLiteralValue.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleValueHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/DoubleValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -0,0 +1,90 @@
+package org.drools.clp;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.drools.base.SimpleValueType;
+
+public class DoubleValueHandler implements ValueHandler {
+ private double doubleValue;
+
+ public DoubleValueHandler(String doubleValue) {
+ this.doubleValue = Double.valueOf( doubleValue ).doubleValue();
+ }
+
+ public DoubleValueHandler(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.DECIMAL;
+ }
+
+ public void setValue(ExecutionContext context, Object value) {
+ throw new RuntimeException( "LiteralValues cannot be set");
+ }
+
+ public Object getValue(ExecutionContext context) {
+ return new Double( this.doubleValue );
+ }
+
+ public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
+ return new BigDecimal( this.doubleValue );
+ }
+
+ public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
+ return BigInteger.valueOf( (long) this.doubleValue );
+ }
+
+ public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
+ return ( this.doubleValue == 0 ) ? false : true;
+ }
+
+ public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
+ return this.doubleValue;
+ }
+
+ public float getFloatValue(ExecutionContext context) throws NumberFormatException {
+ return (float) this.doubleValue;
+ }
+
+ public int getIntValue(ExecutionContext context) throws NumberFormatException {
+ return (int) this.doubleValue;
+ }
+
+ public long getLongValue(ExecutionContext context) throws NumberFormatException {
+ return (long) this.doubleValue;
+ }
+
+ public short getShortValue(ExecutionContext context) throws NumberFormatException {
+ return (short) this.doubleValue;
+ }
+
+ public String getStringValue(ExecutionContext context) {
+ return Double.toString( this.doubleValue );
+ }
+
+ public String toString() {
+ return "[DoubleLiteralValue value='" + this.doubleValue + "']";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ long temp;
+ temp = Double.doubleToLongBits( doubleValue );
+ result = PRIME * result + (int) (temp ^ (temp >>> 32));
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( !(obj instanceof DoubleValueHandler) ) return false;
+ final DoubleValueHandler other = (DoubleValueHandler) obj;
+ if ( Double.doubleToLongBits( doubleValue ) != Double.doubleToLongBits( other.doubleValue ) ) return false;
+ return true;
+ }
+
+
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ExecutionContext.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ExecutionContext.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ExecutionContext.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -7,7 +7,7 @@
private InternalWorkingMemory workingMemory;
private ReteTuple tuple;
private Object object;
- private Object[] localVariables;
+ private ValueHandler[] localVariables;
public ExecutionContext(InternalWorkingMemory workingMemory,
ReteTuple tuple,
@@ -25,7 +25,7 @@
this.workingMemory = workingMemory;
this.tuple = tuple;
this.object = object;
- this.localVariables = new Object[localVariableSize];
+ this.localVariables = new ValueHandler[localVariableSize];
}
public ReteTuple getTuple() {
@@ -40,13 +40,13 @@
return this.object;
}
- public Object getLocalVariable(int index) {
+ public ValueHandler getLocalVariable(int index) {
return localVariables[index];
}
public void setLocalVariable(int index,
- Object object) {
- this.localVariables[index] = object;
+ ValueHandler valueHandler) {
+ this.localVariables[index] = valueHandler;
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Function.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Function.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/Function.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -2,7 +2,7 @@
public interface Function { //extends ValueHandler {
- public Object execute(ValueHandler[] args, ExecutionContext context);
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context);
public String getName();
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionCaller.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionCaller.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionCaller.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,75 +1,137 @@
package org.drools.clp;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Map;
-public class FunctionCaller extends BaseValueHandler {
- private Function function;
-
+import org.drools.base.SimpleValueType;
+
+public class FunctionCaller
+ implements
+ ValueHandler {
+ private Function function;
+
protected ValueHandler[] parameters;
-
+
public FunctionCaller() {
this( null );
}
-
+
public FunctionCaller(Function function) {
this.function = function;
}
-
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.FUNCTION;
+ }
+
public void setFunction(Function function) {
this.function = function;
}
-
+
public Function getFunction() {
return this.function;
}
-
+
public String getName() {
- return ( this.function == null ) ? null : this.function.getName();
- }
-
+ return (this.function == null) ? null : this.function.getName();
+ }
+
public LispList createList(int index) {
return this.function.createList( index );
}
-
+
public void addParameter(ValueHandler valueHandler) {
- if (this.parameters == null) {
- this.parameters = new ValueHandler[] { valueHandler};
+ if ( this.parameters == null ) {
+ this.parameters = new ValueHandler[]{valueHandler};
} else {
- ValueHandler[] temp = new ValueHandler[ parameters.length + 1 ];
- System.arraycopy( this.parameters, 0, temp, 0, this.parameters.length );
- temp[ temp.length - 1] = valueHandler;
- this.parameters = temp;
- }
+ ValueHandler[] temp = new ValueHandler[parameters.length + 1];
+ System.arraycopy( this.parameters,
+ 0,
+ temp,
+ 0,
+ this.parameters.length );
+ temp[temp.length - 1] = valueHandler;
+ this.parameters = temp;
+ }
}
-
+
public ValueHandler[] getParameters() {
return this.parameters;
- }
-
- public Object getValue(ExecutionContext context) {
- return function.execute( parameters, context );
}
+ private ValueHandler resolveFunction(FunctionCaller caller,
+ ExecutionContext context) {
+ ValueHandler result = caller.getFunction().execute( caller.getParameters(),
+ context );
+ if ( result instanceof FunctionCaller ) {
+ result = resolveFunction( (FunctionCaller) result,
+ context );
+ }
+ return result;
+ }
+
+ public Object getValue(ExecutionContext context) {
+ return resolveFunction( this,
+ context ).getValue( context );
+ }
+
public void setValue(ExecutionContext context,
Object object) {
- throw new RuntimeException( "You cannot set the value on a Function" );
+ throw new RuntimeException( "You cannot set the value on a Function" );
}
-
- public void replaceTempTokens(Map variables) {
- for ( int i = 0, length = this.parameters.length; i < length; i++ ) {
- if ( this.parameters[i] instanceof TempTokenVariable ) {
- TempTokenVariable var = ( TempTokenVariable ) this.parameters[i];
- this.parameters[i] = ( ValueHandler ) variables.get( var.getIdentifier() );
- } else if ( this.parameters[i] instanceof FunctionCaller ) {
- ((FunctionCaller)parameters[i]).replaceTempTokens( variables );
- } else if ( this.parameters[i] instanceof ListValueHandler ) {
- ((ListValueHandler)parameters[i]).replaceTempTokens( variables );
- }
- }
- }
- public String toString() {
- return "[FunctionCaller " + this.function + "]";
- }
-
+ public void replaceTempTokens(Map variables) {
+ for ( int i = 0, length = this.parameters.length; i < length; i++ ) {
+ if ( this.parameters[i] instanceof TempTokenVariable ) {
+ TempTokenVariable var = (TempTokenVariable) this.parameters[i];
+ this.parameters[i] = (ValueHandler) variables.get( var.getIdentifier() );
+ } else if ( this.parameters[i] instanceof FunctionCaller ) {
+ ((FunctionCaller) parameters[i]).replaceTempTokens( variables );
+ } else if ( this.parameters[i] instanceof ListValueHandler ) {
+ ((ListValueHandler) parameters[i]).replaceTempTokens( variables );
+ }
+ }
+ }
+
+ public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getBigDecimalValue( context );
+ }
+
+ public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getBigIntegerValue( context );
+ }
+
+ public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
+ return resolveFunction( this, context ).getBooleanValue( context );
+ }
+
+ public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getDoubleValue( context );
+ }
+
+ public float getFloatValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getFloatValue( context );
+ }
+
+ public int getIntValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getIntValue( context );
+ }
+
+ public long getLongValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getLongValue( context );
+ }
+
+ public short getShortValue(ExecutionContext context) throws NumberFormatException {
+ return resolveFunction( this, context ).getShortValue( context );
+ }
+
+ public String getStringValue(ExecutionContext context) {
+ return resolveFunction( this, context ).getStringValue( context );
+ }
+
+ public String toString() {
+ return "[FunctionCaller " + this.function + "]";
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionDelegator.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionDelegator.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/FunctionDelegator.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -17,6 +17,10 @@
public void setFunction(Function function) {
this.function = function;
}
+
+ public Function getFunction() {
+ return this.function;
+ }
public ValueHandler addParameterCallback(int index,
ValueHandler valueHandler,
@@ -30,7 +34,7 @@
this.function.initCallback( context );
}
- public Object execute(ValueHandler[] args,
+ public ValueHandler execute(ValueHandler[] args,
ExecutionContext context) {
return function.execute( args,
context );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LispForm.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LispForm.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LispForm.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -19,15 +19,25 @@
// we know this is a string literal, so can use null for the context
if ( this.caller == null ) {
this.caller = new FunctionCaller( this.context.getFunctionRegistry().getFunction( valueHandler.getStringValue( null ) ) );
- this.caller.getFunction().initCallback( context );
+
+ //We can only call initCallback on known functions
+ FunctionDelegator delegator = ( FunctionDelegator ) this.caller.getFunction();
+ if ( delegator.getFunction() != null ) {
+ delegator.getFunction().initCallback( context );
+ }
+
} else {
- int length;
- if ( this.caller == null || this.caller.getParameters() == null ) {
- length = 0;
- } else {
- length = ( this.caller == null ) ? 0 : this.caller.getParameters().length;
+ // we can only execute callbacks on known functions
+ FunctionDelegator delegator = ( FunctionDelegator ) this.caller.getFunction();
+ if ( delegator.getFunction() != null ) {
+ int length;
+ if ( this.caller == null || this.caller.getParameters() == null ) {
+ length = 0;
+ } else {
+ length = ( this.caller == null ) ? 0 : this.caller.getParameters().length;
+ }
+ valueHandler = delegator.getFunction().addParameterCallback( length, valueHandler, context );
}
- valueHandler = this.caller.getFunction().addParameterCallback( length, valueHandler, context );
this.caller.addParameter( valueHandler );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ListValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ListValueHandler.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ListValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -4,9 +4,19 @@
import java.math.BigInteger;
import java.util.Map;
+import org.drools.base.SimpleValueType;
+
public class ListValueHandler implements ValueHandler {
private ValueHandler[] list;
+ public ListValueHandler() {
+
+ }
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.LIST;
+ }
+
public void add(ValueHandler valueHandler) {
if (this.list == null) {
this.list = new ValueHandler[] { valueHandler};
@@ -78,8 +88,16 @@
((ListValueHandler)list[i]).replaceTempTokens( variables );
}
}
- }
+ }
+ public int size() {
+ return (this.list == null) ? 0 : this.list.length;
+ }
+
+ public boolean isEmpty() {
+ return (this.list == null) ? true : this.list.length > 0;
+ }
+
public String toString() {
StringBuffer b = new StringBuffer();
b.append( "[ListValueHandler " );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LocalVariableValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LocalVariableValue.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LocalVariableValue.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,6 +1,5 @@
package org.drools.clp;
-import org.drools.base.ValueType;
public class LocalVariableValue extends BaseValueHandler implements VariableValueHandler {
private static final long serialVersionUID = 320L;
@@ -29,17 +28,24 @@
return this.identifier;
}
- public ValueType getValueType() {
- return null;
+ public int getValueType(ExecutionContext context) {
+ return context.getLocalVariable( this.index ).getValueType( context );
}
public Object getValue(ExecutionContext context) {
+ Object object = context.getLocalVariable( this.index ).getValue( context );
+ //if ( object instanceof )
+ return object;
+ }
+
+ public ValueHandler getRawValue(ExecutionContext context) {
+ // this is a hack as some parts of the system need the ValueHandler and not the Value
return context.getLocalVariable( this.index );
}
public void setValue(ExecutionContext context,
Object object) {
- context.setLocalVariable( this.index, object );
+ context.setLocalVariable( this.index, (ValueHandler) object );
}
public String toString() {
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongLiteralValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongLiteralValue.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongLiteralValue.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,82 +0,0 @@
-package org.drools.clp;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-public class LongLiteralValue extends BaseValueHandler {
- private long longValue;
-
- public LongLiteralValue(String longValue) {
- this.longValue = Long.valueOf( longValue ).longValue();
- }
-
- public LongLiteralValue(long longValue) {
- this.longValue = longValue;
- }
-
- public void setValue(ExecutionContext context, Object value) {
- throw new RuntimeException( "LiteralValues cannot be set");
- }
-
- public Object getValue(ExecutionContext context) {
- return new Long( this.longValue );
- }
-
- public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
- return new BigDecimal( this.longValue );
- }
-
- public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
- return BigInteger.valueOf( this.longValue );
- }
-
- public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
- return ( this.longValue == 0 ) ? false : true;
- }
-
- public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
- return this.longValue;
- }
-
- public float getFloatValue(ExecutionContext context) throws NumberFormatException {
- return this.longValue;
- }
-
- public int getIntValue(ExecutionContext context) throws NumberFormatException {
- return (int) this.longValue;
- }
-
- public long getLongValue(ExecutionContext context) throws NumberFormatException {
- return this.longValue;
- }
-
- public short getShortValue(ExecutionContext context) throws NumberFormatException {
- return (short) this.longValue;
- }
-
- public String getStringValue(ExecutionContext context) {
- return Long.toString( this.longValue );
- }
-
- public String toString() {
- return "[LongLiteralValue value='" + this.longValue + "']";
- }
-
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + (int) (longValue ^ (longValue >>> 32));
- return result;
- }
-
- public boolean equals(Object obj) {
- if ( this == obj ) return true;
- if ( obj == null ) return false;
- if ( ! ( obj instanceof LongLiteralValue ) ) return false;
- final LongLiteralValue other = (LongLiteralValue) obj;
- if ( longValue != other.longValue ) return false;
- return true;
- }
-
-
-}
Copied: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongValueHandler.java (from rev 10465, labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongLiteralValue.java)
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongValueHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/LongValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -0,0 +1,88 @@
+package org.drools.clp;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.drools.base.SimpleValueType;
+
+public class LongValueHandler implements ValueHandler {
+ private long longValue;
+
+ public LongValueHandler(String longValue) {
+ this.longValue = Long.valueOf( longValue ).longValue();
+ }
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.INTEGER;
+ }
+
+ public LongValueHandler(long longValue) {
+ this.longValue = longValue;
+ }
+
+ public void setValue(ExecutionContext context, Object value) {
+ throw new RuntimeException( "LiteralValues cannot be set");
+ }
+
+ public Object getValue(ExecutionContext context) {
+ return new Long( this.longValue );
+ }
+
+ public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
+ return new BigDecimal( this.longValue );
+ }
+
+ public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
+ return BigInteger.valueOf( this.longValue );
+ }
+
+ public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
+ return ( this.longValue == 0 ) ? false : true;
+ }
+
+ public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
+ return this.longValue;
+ }
+
+ public float getFloatValue(ExecutionContext context) throws NumberFormatException {
+ return this.longValue;
+ }
+
+ public int getIntValue(ExecutionContext context) throws NumberFormatException {
+ return (int) this.longValue;
+ }
+
+ public long getLongValue(ExecutionContext context) throws NumberFormatException {
+ return this.longValue;
+ }
+
+ public short getShortValue(ExecutionContext context) throws NumberFormatException {
+ return (short) this.longValue;
+ }
+
+ public String getStringValue(ExecutionContext context) {
+ return Long.toString( this.longValue );
+ }
+
+ public String toString() {
+ return "[LongLiteralValue value='" + this.longValue + "']";
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + (int) (longValue ^ (longValue >>> 32));
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( ! ( obj instanceof LongValueHandler ) ) return false;
+ final LongValueHandler other = (LongValueHandler) obj;
+ if ( longValue != other.longValue ) return false;
+ return true;
+ }
+
+
+}
Deleted: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectLiteralValue.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectLiteralValue.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectLiteralValue.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,59 +0,0 @@
-package org.drools.clp;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-public class ObjectLiteralValue extends BaseValueHandler {
- public static final ObjectLiteralValue NULL = new ObjectLiteralValue( "null" );
-
- private Object objectValue;
-
- public ObjectLiteralValue(Object objectValue) {
- this.objectValue = objectValue;
- }
-
- public void setValue(ExecutionContext context, Object value) {
- throw new RuntimeException( "LiteralValues cannot be set");
- }
-
- public Object getValue(ExecutionContext context) {
- return this.objectValue;
- }
-
- public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
- return (BigDecimal) getValue(context);
- }
-
- public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
- return (BigInteger) getValue(context);
- }
-
- public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
- return ((Boolean) getValue(context)).booleanValue();
- }
-
- public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
- return ((Double) getValue(context)).doubleValue();
- }
-
- public float getFloatValue(ExecutionContext context) throws NumberFormatException {
- return ((Float) getValue(context)).floatValue();
- }
-
- public int getIntValue(ExecutionContext context) throws NumberFormatException {
- return ((Integer) getValue(context)).intValue();
- }
-
- public long getLongValue(ExecutionContext context) throws NumberFormatException {
- return ((Long) getValue(context)).longValue();
- }
-
- public short getShortValue(ExecutionContext context) throws NumberFormatException {
- return ((Short) getValue(context)).shortValue();
- }
-
- public String getStringValue(ExecutionContext context) {
- return (String) getValue(context);
- }
-
-}
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectValueHandler.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ObjectValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -0,0 +1,62 @@
+package org.drools.clp;
+
+import org.drools.base.SimpleValueType;
+
+public class ObjectValueHandler extends BaseValueHandler {
+ public static final ObjectValueHandler NULL = new ObjectValueHandler( "null" );
+
+ private Object objectValue;
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.OBJECT;
+ }
+
+ public ObjectValueHandler(Object objectValue) {
+ this.objectValue = objectValue;
+ }
+
+ public void setValue(ExecutionContext context, Object value) {
+ throw new RuntimeException( "LiteralValues cannot be set");
+ }
+
+ public Object getValue(ExecutionContext context) {
+ return this.objectValue;
+ }
+ /*
+ public BigDecimal getBigDecimalValue(ExecutionContext context) throws NumberFormatException {
+ return (BigDecimal) getValue(context);
+ }
+
+ public BigInteger getBigIntegerValue(ExecutionContext context) throws NumberFormatException {
+ return (BigInteger) getValue(context);
+ }
+
+ public boolean getBooleanValue(ExecutionContext context) throws ClassCastException {
+ return ((Boolean) getValue(context)).booleanValue();
+ }
+
+ public double getDoubleValue(ExecutionContext context) throws NumberFormatException {
+ return ((Double) getValue(context)).doubleValue();
+ }
+
+ public float getFloatValue(ExecutionContext context) throws NumberFormatException {
+ return ((Float) getValue(context)).floatValue();
+ }
+
+ public int getIntValue(ExecutionContext context) throws NumberFormatException {
+ return ((Integer) getValue(context)).intValue();
+ }
+
+ public long getLongValue(ExecutionContext context) throws NumberFormatException {
+ return ((Long) getValue(context)).longValue();
+ }
+
+ public short getShortValue(ExecutionContext context) throws NumberFormatException {
+ return ((Short) getValue(context)).shortValue();
+ }
+
+ public String getStringValue(ExecutionContext context) {
+ return (String) getValue(context);
+ } */
+
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/TempTokenVariable.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/TempTokenVariable.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/TempTokenVariable.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,6 +1,8 @@
package org.drools.clp;
+import org.drools.base.SimpleValueType;
+
public class TempTokenVariable extends BaseValueHandler implements VariableValueHandler {
private String identifier;
@@ -12,6 +14,10 @@
public String getIdentifier() {
return this.identifier;
}
+
+ public int getValueType(ExecutionContext context) {
+ return SimpleValueType.UNKNOWN;
+ }
public Object getValue(ExecutionContext context) {
throw new UnsupportedOperationException( "TempTokenVariable Variable identifer='" + getIdentifier() + " cannot be read" );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ValueHandler.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/ValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -4,7 +4,10 @@
import java.math.BigInteger;
public interface ValueHandler {
-
+ public boolean isResolved();
+
+ public int getValueType(ExecutionContext context);
+
public void setValue(ExecutionContext context,
Object object);
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/VariableValueHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/VariableValueHandler.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/VariableValueHandler.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,6 +1,6 @@
package org.drools.clp;
public interface VariableValueHandler extends ValueHandler {
- public String getIdentifier();
+ public String getIdentifier();
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/AddFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/AddFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/AddFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -6,6 +6,7 @@
import org.drools.clp.Function;
import org.drools.clp.LispForm;
import org.drools.clp.LispList;
+import org.drools.clp.ObjectValueHandler;
import org.drools.clp.ValueHandler;
public class AddFunction extends BaseFunction implements Function {
@@ -15,12 +16,12 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
BigDecimal bdval = new BigDecimal(0);
for ( int i = 0, length = args.length; i < length; i++ ) {
bdval = bdval.add( args[i].getBigDecimalValue( context ) );
}
- return new BigDecimal( bdval.intValue() );
+ return new ObjectValueHandler( new BigDecimal( bdval.intValue() ) );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/BindFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/BindFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/BindFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -3,6 +3,7 @@
import org.drools.clp.ExecutionBuildContext;
import org.drools.clp.ExecutionContext;
import org.drools.clp.Function;
+import org.drools.clp.FunctionCaller;
import org.drools.clp.LispForm;
import org.drools.clp.LispList;
import org.drools.clp.TempTokenVariable;
@@ -27,8 +28,16 @@
return valueHandler;
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
- args[0].setValue( context, args[1].getValue( context ) );
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
+ args[0].setValue( context, args[1].getValue( context ));
+// Object object = args[1].getValue( context );
+// if ( object instanceof FunctionCaller || object instanceof VariableValueHandler) {
+// // this is if the paramter is a variable or a function, so we must resolve further
+// args[0].setValue( context, ( ( ValueHandler ) object).getValue( context ));
+// } else {
+// // thi sis if the parameter
+// args[0].setValue( context, object);
+// }
return args[0];
}
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/CreateListFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/CreateListFunction.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/CreateListFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -0,0 +1,42 @@
+package org.drools.clp.functions;
+
+import org.drools.clp.ExecutionContext;
+import org.drools.clp.Function;
+import org.drools.clp.FunctionCaller;
+import org.drools.clp.ListValueHandler;
+import org.drools.clp.ValueHandler;
+
+public class CreateListFunction extends BaseFunction implements Function {
+ private static final String name = "create$";
+
+ public CreateListFunction() {
+
+ }
+
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
+ ListValueHandler list = new ListValueHandler();
+ addElements(list, args, context);
+ return list;
+ }
+
+ public void addElements(ListValueHandler list, ListValueHandler nested, ExecutionContext context) {
+ addElements(list, nested.getList(), context);
+ }
+
+ public void addElements(ListValueHandler list, ValueHandler[] args, ExecutionContext context) {
+ for ( int i = 0, length = args.length; i < length; i++ ) {
+ if ( args[i] instanceof ListValueHandler) {
+ addElements(list, ( ListValueHandler ) args[i], context);
+ } else if ( args[i] instanceof FunctionCaller && ((FunctionCaller)args[i]).getName().equals( "create$" ) ){
+ addElements(list, (ListValueHandler)args[i].getValue( context ), context );
+ } else {
+ list.add( args[i] );
+ }
+ }
+ }
+
+
+ public String getName() {
+ return name;
+ }
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/IfFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/IfFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/IfFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,9 +1,11 @@
package org.drools.clp.functions;
+import org.drools.clp.BooleanValueHandler;
import org.drools.clp.ExecutionContext;
import org.drools.clp.Function;
import org.drools.clp.LispForm;
import org.drools.clp.LispList;
+import org.drools.clp.ObjectValueHandler;
import org.drools.clp.ValueHandler;
public class IfFunction extends BaseFunction implements Function {
@@ -13,14 +15,14 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
boolean result = args[0].getBooleanValue( context );
if ( result ) {
- return args[2].getValue( context );
+ return new ObjectValueHandler( args[2].getValue( context ) );
} else if ( args[3] != null && args[4] != null ) {
- return args[4].getValue( context );
+ return new ObjectValueHandler( args[4].getValue( context ) );
} else {
- return new Boolean( result );
+ return new BooleanValueHandler( result );
}
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/LessThanFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/LessThanFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/LessThanFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,5 +1,6 @@
package org.drools.clp.functions;
+import org.drools.clp.BooleanValueHandler;
import org.drools.clp.ExecutionContext;
import org.drools.clp.Function;
import org.drools.clp.LispForm;
@@ -13,8 +14,8 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
- return new Boolean( args[0].getBigDecimalValue( context ).compareTo( args[1].getBigDecimalValue( context ) ) < 0 );
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
+ return new BooleanValueHandler( args[0].getBigDecimalValue( context ).compareTo( args[1].getBigDecimalValue( context ) ) < 0 );
}
public String getName() {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/ModifyFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/ModifyFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/ModifyFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -14,7 +14,7 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
Object object = args[0].getValue( context );
for ( int i = 1, length = args.length; i < length; i++ ) {
ValueHandler[] list = (ValueHandler[]) args[i].getValue( context );
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/MultiplyFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/MultiplyFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/MultiplyFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -6,6 +6,7 @@
import org.drools.clp.Function;
import org.drools.clp.LispForm;
import org.drools.clp.LispList;
+import org.drools.clp.ObjectValueHandler;
import org.drools.clp.ValueHandler;
public class MultiplyFunction extends BaseFunction implements Function {
@@ -15,12 +16,12 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
BigDecimal bdval = new BigDecimal(0);
for ( int i = 0, length = args.length; i < length; i++ ) {
bdval = bdval.multiply( args[i].getBigDecimalValue( context ) );
}
- return bdval;
+ return new ObjectValueHandler( bdval );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/WhileFunction.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/WhileFunction.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/clp/functions/WhileFunction.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -4,6 +4,7 @@
import org.drools.clp.Function;
import org.drools.clp.LispForm;
import org.drools.clp.LispList;
+import org.drools.clp.ObjectValueHandler;
import org.drools.clp.ValueHandler;
public class WhileFunction extends BaseFunction implements Function {
@@ -13,7 +14,7 @@
}
- public Object execute(ValueHandler[] args, ExecutionContext context) {
+ public ValueHandler execute(ValueHandler[] args, ExecutionContext context) {
Object result = null;
ValueHandler doHandler = args[ args.length - 1 ];
@@ -22,7 +23,7 @@
result = doHandler.getValue( context );
}
- return result;
+ return new ObjectValueHandler( result );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/CLP.g
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/CLP.g 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/CLP.g 2007-03-24 19:50:18 UTC (rev 10518)
@@ -527,7 +527,7 @@
}
:
( t=VAR { value = context.getVariableValueHandler(t.getText() ); }
- | t=STRING { value = new ObjectLiteralValue( getString( t ) ); }
+ | t=STRING { value = new ObjectLiteralValue( getString( t ) ); }
| t=NAME { value = new ObjectLiteralValue( t.getText() ); }
| t=FLOAT { value = new DoubleLiteralValue( t.getText() ); }
| t=INT { value = new LongLiteralValue( t.getText() ); }
Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/functions.conf
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/functions.conf 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/clp/functions.conf 2007-03-24 19:50:18 UTC (rev 10518)
@@ -1,3 +1,4 @@
+org.drools.clp.functions.CreateListFunction
org.drools.clp.functions.AddFunction
org.drools.clp.functions.IfFunction
org.drools.clp.functions.WhileFunction
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/AddFunctionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/AddFunctionTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/AddFunctionTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -20,21 +20,21 @@
public class AddFunctionTest extends TestCase {
public void testAdd() {
- ValueHandler val1 = new ObjectLiteralValue( new BigDecimal( 10 ) );
- ValueHandler val2 = new ObjectLiteralValue( new BigDecimal( 10 ) );
+ ValueHandler val1 = new ObjectValueHandler( new BigDecimal( 10 ) );
+ ValueHandler val2 = new ObjectValueHandler( new BigDecimal( 10 ) );
ValueHandler[] params = new ValueHandler[]{val1, val2};
AddFunction add = new AddFunction();
assertEquals( new BigDecimal( 20 ),
add.execute( params,
- null ) );
+ null ).getValue( null ) );
}
public void testNestedAdd() {
- ValueHandler val1 = new ObjectLiteralValue( new BigDecimal( 10 ) );
- ValueHandler val2 = new ObjectLiteralValue( new BigDecimal( 10 ) );
- ValueHandler val3 = new ObjectLiteralValue( new BigDecimal( 10 ) );
+ ValueHandler val1 = new ObjectValueHandler( new BigDecimal( 10 ) );
+ ValueHandler val2 = new ObjectValueHandler( new BigDecimal( 10 ) );
+ ValueHandler val3 = new ObjectValueHandler( new BigDecimal( 10 ) );
FunctionCaller functionValue = new FunctionCaller( new AddFunction() );
functionValue.addParameter( val1 );
@@ -46,7 +46,7 @@
assertEquals( new BigDecimal( 30 ),
add.execute( params,
- null ) );
+ null ).getValue( null ) );
}
public void testNestedAddWithVars() {
@@ -91,7 +91,7 @@
new BigDecimal( 10 ),
1 );
context.setLocalVariable( 0,
- new BigDecimal( 10 ) );
+ new ObjectValueHandler( new BigDecimal( 10 ) ) );
FunctionCaller functionValue = new FunctionCaller( new AddFunction() );
functionValue.addParameter( val1 );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/BlockExecutionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/BlockExecutionTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/BlockExecutionTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -22,8 +22,8 @@
ExecutionBuildContext build = new ExecutionBuildContext(engine, this.registry );
FunctionCaller addCaller = new FunctionCaller( new AddFunction() );
- addCaller.addParameter( new ObjectLiteralValue( new BigDecimal( 20) ) );
- addCaller.addParameter( new LongLiteralValue( "11" ) );
+ addCaller.addParameter( new ObjectValueHandler( new BigDecimal( 20) ) );
+ addCaller.addParameter( new LongValueHandler( "11" ) );
FunctionCaller bindCaller = new FunctionCaller( new BindFunction() );
bindCaller.addParameter( build.createLocalVariable( "?x" ) );
@@ -37,13 +37,13 @@
modifyCaller.addParameter( build.getVariableValueHandler( "?p" ) );
ListValueHandler list = new ListValueHandler();
- list.add( new ObjectLiteralValue( "age") );
+ list.add( new ObjectValueHandler( "age") );
list.add( build.getVariableValueHandler( "?x" ) );
modifyCaller.addParameter( list );
ExecutionContext context = new ExecutionContext(null, null, 2);
Person p = new Person("mark");
- context.setLocalVariable( 1, p );
+ context.setLocalVariable( 1, new ObjectValueHandler( p ) );
engine.addFunction( modifyCaller );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ClpParserTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ClpParserTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ClpParserTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -47,8 +47,8 @@
FunctionCaller fc = ( FunctionCaller ) parse( "(< 1 2)" ).lisp_list( context, new LispForm(context) );
assertEquals( "<", fc.getName() );
- assertEquals( new LongLiteralValue( 1 ), fc.getParameters()[0] );
- assertEquals( new LongLiteralValue( 2 ), fc.getParameters()[1] );
+ assertEquals( new LongValueHandler( 1 ), fc.getParameters()[0] );
+ assertEquals( new LongValueHandler( 2 ), fc.getParameters()[1] );
}
public void testPatternsRule() throws Exception {
@@ -117,15 +117,15 @@
CLPReturnValue clprv = ( CLPReturnValue ) retDescr.getContent();
FunctionCaller fc = clprv.getFunctions()[0];
assertEquals( "+", fc.getName() );
- assertEquals( new LongLiteralValue( 2 ), fc.getParameters()[0] );
- assertEquals( new LongLiteralValue( 3 ), fc.getParameters()[1] );
+ assertEquals( new LongValueHandler( 2 ), fc.getParameters()[0] );
+ assertEquals( new LongValueHandler( 3 ), fc.getParameters()[1] );
PredicateDescr predicateDescr = (PredicateDescr) colList.get( 1 );
CLPPredicate clpp = ( CLPPredicate ) predicateDescr.getContent();
fc = clpp.getFunctions()[0];
assertEquals( "<", fc.getName() );
- assertEquals( new LongLiteralValue( 1 ), fc.getParameters()[0] );
- assertEquals( new LongLiteralValue( 2 ), fc.getParameters()[1] );
+ assertEquals( new LongValueHandler( 1 ), fc.getParameters()[0] );
+ assertEquals( new LongValueHandler( 2 ), fc.getParameters()[1] );
// Parse the second column
col = (ColumnDescr) lhsList.get( 1 );
@@ -315,8 +315,8 @@
CLPEval clpe = ( CLPEval ) evalDescr.getContent();
FunctionCaller f = clpe.getFunctions()[0];
assertEquals( "<", f.getName() );
- assertEquals( new DoubleLiteralValue( 9.0 ), f.getParameters()[0] );
- assertEquals( new DoubleLiteralValue( 1.3 ), f.getParameters()[1] );
+ assertEquals( new DoubleValueHandler( 9.0 ), f.getParameters()[0] );
+ assertEquals( new DoubleValueHandler( 1.3 ), f.getParameters()[1] );
}
public void testRuleHeader() throws Exception {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/CompiledParserTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/CompiledParserTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/CompiledParserTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -19,15 +19,13 @@
public class CompiledParserTest extends TestCase {
private CLPParser parser;
- public void test1() throws Exception {
+ public void testBindAndModify() throws Exception {
BlockExecutionEngine engine = ( BlockExecutionEngine ) parse("(bind ?x (+ 20 11) ) (modify ?p (age ?x) )").rhs();
ExecutionContext context = new ExecutionContext(null, null, 2);
-
- Person p = new Person("mark");
+
Map vars = new HashMap();
-
- //vars.put( "?x", new LocalVariableValue( "?x", 0 ) );
- vars.put( "?p", new ObjectLiteralValue( p ) );
+ Person p = new Person("mark");
+ vars.put( "?p", new ObjectValueHandler( p ) );
engine.replaceTempTokens( vars );
engine.execute( context );
@@ -35,6 +33,41 @@
assertEquals( 31, p.getAge() );
}
+ public void testSimpleCreate$() throws Exception {
+ BlockExecutionEngine engine = ( BlockExecutionEngine ) parse("(bind ?x (create$ 1 2 3) )").rhs();
+ ExecutionContext context = new ExecutionContext(null, null, 1);
+ engine.execute( context );
+
+ ListValueHandler list = ( ListValueHandler ) context.getLocalVariable( 0 ).getValue( context );
+
+ assertEquals( 3, list.size() );
+
+ assertEquals( 1, list.getList()[0].getIntValue( context ) );
+ assertEquals( 2, list.getList()[1].getIntValue( context ) );
+ assertEquals( 3, list.getList()[2].getIntValue( context ) );
+ }
+
+ public void testNestedCreate$() throws Exception {
+ BlockExecutionEngine engine = ( BlockExecutionEngine ) parse("(bind ?x (create$ 1 2 3) ) (bind ?y (create$ 1 ?x (create$ a b ?x c) 3) )").rhs();
+ ExecutionContext context = new ExecutionContext(null, null, 2);
+ engine.execute( context );
+
+ // check ?x
+ ListValueHandler list = ( ListValueHandler ) context.getLocalVariable( 0 ).getValue( context );;
+ assertEquals( 3, list.size() );
+ assertEquals( 1, list.getList()[0].getIntValue( context ) );
+ assertEquals( 2, list.getList()[1].getIntValue( context ) );
+ assertEquals( 3, list.getList()[2].getIntValue( context ) );
+
+ // check ?y
+ list = ( ListValueHandler ) context.getLocalVariable( 1 ).getValue( context );;
+ assertEquals( 11, list.size() );
+
+// assertEquals( 1, list.getList()[0].getIntValue( context ) );
+// assertEquals( 2, list.getList()[1].getIntValue( context ) );
+// assertEquals( 3, list.getList()[2].getIntValue( context ) );
+ }
+
public void testIf() throws Exception {
BlockExecutionEngine engine = ( BlockExecutionEngine ) parse("(if (< ?x ?y ) then (modify ?p (age 15) ) else (modify ?p (age 5)))").rhs();
ExecutionContext context = new ExecutionContext(null, null, 2);
@@ -42,17 +75,17 @@
Person p = new Person("mark");
Map vars = new HashMap();
- vars.put( "?x", new LongLiteralValue( 10 ) );
+ vars.put( "?x", new LongValueHandler( 10 ) );
vars.put( "?y", new LocalVariableValue( "?y", 0 ) );
- vars.put( "?p", new ObjectLiteralValue( p ) );
+ vars.put( "?p", new ObjectValueHandler( p ) );
engine.replaceTempTokens( vars );
- context.setLocalVariable( 0, new Long( 20 ) );
+ context.setLocalVariable( 0, new LongValueHandler( 20 ) );
engine.execute( context );
assertEquals( 15, p.getAge() );
- context.setLocalVariable( 0, new Long( 7 ) );
+ context.setLocalVariable( 0, new LongValueHandler( 7 ) );
engine.execute( context );
assertEquals( 5, p.getAge() );
}
@@ -67,11 +100,11 @@
vars.put( "?y", new LocalVariableValue( "?y", 1 ) );
engine.replaceTempTokens( vars );
- context.setLocalVariable( 0, new Long( 0 ) );
- context.setLocalVariable( 1, new Long( 10 ) );
+ context.setLocalVariable( 0, new LongValueHandler( 0 ) );
+ context.setLocalVariable( 1, new LongValueHandler( 10 ) );
engine.execute( context );
- assertEquals( new BigDecimal(10), context.getLocalVariable( 0 ) );
+ assertEquals( new BigDecimal(10), context.getLocalVariable( 0 ).getValue( context ) );
}
private CLPParser parse(final String text) throws Exception {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/DeffunctionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/DeffunctionTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/DeffunctionTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -25,12 +25,12 @@
ExecutionContext context = new ExecutionContext(null, null, 2);
ValueHandler q = new LocalVariableValue("q", 0);
- context.setLocalVariable( 0, new Integer( 10 ) );
+ q.setValue( context, new LongValueHandler( 10 ) );
ValueHandler w = new LocalVariableValue("w", 1);
- context.setLocalVariable( 1, new Integer( 7 ) );
+ w.setValue( context, new LongValueHandler( 7 ) );
- assertEquals( new BigDecimal( 17 ), function.execute( new ValueHandler[] { q, w }, context ) );
+ assertEquals( new BigDecimal( 17 ), function.execute( new ValueHandler[] { q, w }, context ).getValue( context ) );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ModifyFunctionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ModifyFunctionTest.java 2007-03-24 17:29:03 UTC (rev 10517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/clp/ModifyFunctionTest.java 2007-03-24 19:50:18 UTC (rev 10518)
@@ -11,14 +11,14 @@
Person p = new Person("mark");
ExecutionContext context = new ExecutionContext(null, null, 1);
- context.setLocalVariable( 0, p );
+ //context.setLocalVariable( 0, p );
LocalVariableValue var = new LocalVariableValue("p", 0);
- var.setValue( context, p );
+ var.setValue( context, new ObjectValueHandler( p ) );
ListValueHandler list = new ListValueHandler();
- list.add( new ObjectLiteralValue( "name") );
- list.add( new ObjectLiteralValue( "bob") );
+ list.add( new ObjectValueHandler( "name") );
+ list.add( new ObjectValueHandler( "bob") );
function.execute( new ValueHandler[] { var, list }, context );
More information about the jboss-svn-commits
mailing list