[jboss-svn-commits] JBL Code SVN: r18997 - in labs/jbossrules/branches/ming-serialization: drools-compiler/src/test/java/org/drools/integrationtests and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Mar 14 17:25:21 EDT 2008


Author: tirelli
Date: 2008-03-14 17:25:21 -0400 (Fri, 14 Mar 2008)
New Revision: 18997

Modified:
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java
   labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java
   labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
Log:
fixing tests

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java	2008-03-14 20:52:20 UTC (rev 18996)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/PatternBuilder.java	2008-03-14 21:25:21 UTC (rev 18997)
@@ -26,6 +26,7 @@
 import org.drools.base.FieldFactory;
 import org.drools.base.ValueType;
 import org.drools.base.evaluators.EvaluatorDefinition;
+import org.drools.base.field.ObjectFieldImpl;
 import org.drools.compiler.Dialect;
 import org.drools.compiler.DescrBuildError;
 import org.drools.facttemplates.FactTemplate;
@@ -768,6 +769,11 @@
             final Class staticClass = context.getDialect().getTypeResolver().resolveType( className );
             field = FieldFactory.getFieldValue( staticClass.getField( fieldName ).get( null ),
                                                 extractor.getValueType() );
+            if( field.isObjectField() ) {
+                ((ObjectFieldImpl) field).setEnum( true );
+                ((ObjectFieldImpl) field).setEnumName( staticClass.getName() );
+                ((ObjectFieldImpl) field).setFieldName( fieldName );
+            }
         } catch ( final ClassNotFoundException e ) {
             // nothing to do, as it is not a class name with static field
         } catch ( final Exception e ) {

Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2008-03-14 20:52:20 UTC (rev 18996)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java	2008-03-14 21:25:21 UTC (rev 18997)
@@ -134,7 +134,7 @@
 
         RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-//        ruleBase    = SerializationHelper.serializeObject(ruleBase);
+        ruleBase    = SerializationHelper.serializeObject(ruleBase);
         WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final Cheese cheese = new Cheese( "stilton",
                                           15 );
@@ -142,7 +142,7 @@
         List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
-//        workingMemory   = SerializationHelper.serializeObject(workingMemory);
+        workingMemory   = SerializationHelper.serializeObject(workingMemory);
         workingMemory.fireAllRules();
 
         list    = (List)workingMemory.getGlobal("list");
@@ -166,10 +166,10 @@
 
         RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-//        ruleBase    = SerializationHelper.serializeObject(ruleBase);
-        final WorkingMemory workingMemory = ruleBase.newStatefulSession();
+        ruleBase    = SerializationHelper.serializeObject(ruleBase);
+        WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
-        final List list = new ArrayList();
+        List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
 
@@ -183,6 +183,8 @@
         cheesery2.setMaturity( Maturity.YOUNG );
         workingMemory.insert( cheesery2 );
 
+//        workingMemory   = SerializationHelper.serializeObject(workingMemory);
+//        list = (List) workingMemory.getGlobal( "list" );
         workingMemory.fireAllRules();
 
         assertEquals( 2,
@@ -201,7 +203,7 @@
 
         RuleBase ruleBase = getRuleBase();
         ruleBase.addPackage( pkg );
-//        ruleBase    = SerializationHelper.serializeObject(ruleBase);
+        ruleBase    = SerializationHelper.serializeObject(ruleBase);
         final WorkingMemory workingMemory = ruleBase.newStatefulSession();
         final List result = new ArrayList();
         workingMemory.setGlobal( "result",

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java	2008-03-14 20:52:20 UTC (rev 18996)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java	2008-03-14 21:25:21 UTC (rev 18997)
@@ -16,33 +16,80 @@
  * limitations under the License.
  */
 
-import java.util.Collection;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Collection;
 
 import org.drools.RuntimeDroolsException;
 import org.drools.spi.FieldValue;
 
 public class ObjectFieldImpl
     implements
-    FieldValue, Externalizable {
+    FieldValue,
+    Externalizable {
 
     private static final long serialVersionUID = 400L;
-    private Object      value;
+    private Object            value;
 
-    private boolean     isCollection;
-    private boolean     isNumber;
-    private boolean     isBoolean;
-    private boolean     isCharacter;
-    private boolean     isString;
+    // the isEnum attribute is used to support jdk 1.4 type safe enums, and so
+    // has a different behavior of the other booleans in this class
+    private boolean           isEnum;
+    private String            enumName;
+    private String            fieldName;
 
+    private transient boolean isCollection;
+    private transient boolean isNumber;
+    private transient boolean isBoolean;
+    private transient boolean isCharacter;
+    private transient boolean isString;
+
     public ObjectFieldImpl() {
-        this(null);
+        this( null );
     }
+
     public ObjectFieldImpl(final Object value) {
         this.value = value;
+        this.isEnum = value instanceof Enum;
+        setBooleans();
+    }
+
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        isEnum = in.readBoolean();
+        enumName = (String) in.readObject();
+        fieldName = (String) in.readObject();
+        if ( !isEnum || enumName == null || fieldName == null ) {
+            value = in.readObject();
+        } else {
+            resolveEnumValue();
+        }
+        setBooleans();
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeBoolean( isEnum );
+        out.writeObject( enumName );
+        out.writeObject( fieldName );
+        if ( !isEnum || enumName == null || fieldName == null ) {
+            out.writeObject( value );
+        }
+    }
+
+    private void resolveEnumValue() {
+        try {
+            final Class<?> staticClass = Class.forName( enumName );
+            value = staticClass.getField( fieldName ).get( null );
+        } catch ( final Exception e ) {
+            throw new RuntimeDroolsException("Error deserializing enum value "+enumName+"."+fieldName+" : "+e.getMessage());
+        }
+    }
+
+    /**
+     * @param value
+     */
+    private void setBooleans() {
         this.isCollection = value instanceof Collection;
         this.isNumber = value instanceof Number;
         this.isBoolean = value instanceof Boolean;
@@ -50,24 +97,6 @@
         this.isString = value instanceof String;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        value       = in.readObject();
-        isCollection = in.readBoolean();
-        isNumber    = in.readBoolean();
-        isBoolean   = in.readBoolean();
-        isCharacter = in.readBoolean();
-        isString    = in.readBoolean();
-    }
-
-    public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(value);
-        out.writeBoolean(isCollection);
-        out.writeBoolean(isNumber);
-        out.writeBoolean(isBoolean);
-        out.writeBoolean(isCharacter);
-        out.writeBoolean(isString);
-    }
-
     public Object getValue() {
         return this.value;
     }
@@ -79,7 +108,7 @@
     public boolean getBooleanValue() {
         if ( isBoolean ) {
             return ((Boolean) this.value).booleanValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Boolean.valueOf( (String) this.value ).booleanValue();
         }
         throw new RuntimeDroolsException( "Conversion to boolean not supported for type: " + this.value.getClass() );
@@ -88,7 +117,7 @@
     public byte getByteValue() {
         if ( isNumber ) {
             return ((Number) this.value).byteValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Byte.valueOf( (String) this.value ).byteValue();
         }
         throw new RuntimeDroolsException( "Conversion to byte not supported for type: " + this.value.getClass() );
@@ -97,8 +126,8 @@
     public char getCharValue() {
         if ( isCharacter ) {
             return ((Character) this.value).charValue();
-        } else if( isString && ((String) this.value).length() == 1 ) {
-            return ( (String) this.value ).charAt( 0 );
+        } else if ( isString && ((String) this.value).length() == 1 ) {
+            return ((String) this.value).charAt( 0 );
         }
         throw new RuntimeDroolsException( "Conversion to char not supported for type: " + this.value.getClass() );
     }
@@ -106,7 +135,7 @@
     public double getDoubleValue() {
         if ( isNumber ) {
             return ((Number) this.value).doubleValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Double.valueOf( (String) this.value ).doubleValue();
         }
         throw new RuntimeDroolsException( "Conversion to double not supported for type: " + this.value.getClass() );
@@ -115,7 +144,7 @@
     public float getFloatValue() {
         if ( isNumber ) {
             return ((Number) this.value).floatValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Float.valueOf( (String) this.value ).floatValue();
         }
         throw new RuntimeDroolsException( "Conversion to float not supported for type: " + this.value.getClass() );
@@ -124,7 +153,7 @@
     public int getIntValue() {
         if ( isNumber ) {
             return ((Number) this.value).intValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Integer.valueOf( (String) this.value ).intValue();
         }
         throw new RuntimeDroolsException( "Conversion to int not supported for type: " + this.value.getClass() );
@@ -133,7 +162,7 @@
     public long getLongValue() {
         if ( isNumber ) {
             return ((Number) this.value).longValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Long.valueOf( (String) this.value ).longValue();
         }
         throw new RuntimeDroolsException( "Conversion to long not supported for type: " + this.value.getClass() );
@@ -142,7 +171,7 @@
     public short getShortValue() {
         if ( isNumber ) {
             return ((Number) this.value).shortValue();
-        } else if( isString ) {
+        } else if ( isString ) {
             return Short.valueOf( (String) this.value ).shortValue();
         }
         throw new RuntimeDroolsException( "Conversion to short not supported for type: " + this.value.getClass() );
@@ -195,4 +224,29 @@
     public boolean isStringField() {
         return this.isString;
     }
+
+    public boolean isEnum() {
+        return isEnum;
+    }
+
+    public void setEnum(boolean isEnum) {
+        this.isEnum = isEnum;
+    }
+
+    public String getEnumName() {
+        return enumName;
+    }
+
+    public void setEnumName(String enumName) {
+        this.enumName = enumName;
+    }
+
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2008-03-14 20:52:20 UTC (rev 18996)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/reteoo/EvalConditionNode.java	2008-03-14 21:25:21 UTC (rev 18997)
@@ -102,6 +102,8 @@
         condition   = (EvalCondition)in.readObject();
         tupleSource = (TupleSource)in.readObject();
         tupleMemoryEnabled  = in.readBoolean();
+        previousTupleSinkNode   = (TupleSinkNode)in.readObject();
+        nextTupleSinkNode       = (TupleSinkNode)in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
@@ -109,6 +111,8 @@
         out.writeObject(condition);
         out.writeObject(tupleSource);
         out.writeBoolean(tupleMemoryEnabled);
+        out.writeObject(previousTupleSinkNode);
+        out.writeObject(nextTupleSinkNode);
     }
     /**
      * Attaches this node into the network.




More information about the jboss-svn-commits mailing list