[jboss-svn-commits] JBL Code SVN: r17407 - in labs/jbossrules/branches/serialization: drools-core/src/main/java/org/drools/common and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 26 07:05:03 EST 2007


Author: haruki_zaemon
Date: 2007-12-26 07:05:02 -0500 (Wed, 26 Dec 2007)
New Revision: 17407

Modified:
   labs/jbossrules/branches/serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsSerializable.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/EvalCondition.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
   labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
Log:
Make more stuff serializable.

Modified: labs/jbossrules/branches/serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
===================================================================
--- labs/jbossrules/branches/serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2007-12-26 12:05:02 UTC (rev 17407)
@@ -54,10 +54,8 @@
 returnValueInvoker() ::=<<
 package @{package};
 
-public class @{invokerClassName} implements org.drools.spi.ReturnValueExpression, org.drools.spi.CompiledInvoker
+public class @{invokerClassName} implements org.drools.spi.ReturnValueExpression, org.drools.spi.CompiledInvoker, org.drools.common.DroolsSerializable
 {
-    private static final long serialVersionUID  = 400L;
-
     public org.drools.spi.FieldValue evaluate(java.lang.Object object,
                             org.drools.spi.Tuple tuple,
                             org.drools.rule.Declaration[] previousDeclarations,
@@ -90,13 +88,20 @@
     @includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
 
     @includeByRef{equals()}
+
+    public void droolsWriteObject(org.drools.common.DroolsObjectOutputStream out) throws java.io.IOException {
+    }
+
+    public Object droolsReadObject(org.drools.common.DroolsObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
+        return this;
+    }
 }
 >>=::
 
 predicateInvoker() ::=<<
 package @{package};
 
-public class @{invokerClassName} implements org.drools.spi.PredicateExpression, org.drools.spi.CompiledInvoker
+public class @{invokerClassName} implements org.drools.spi.PredicateExpression, org.drools.spi.CompiledInvoker, org.drools.common.DroolsSerializable
 {
     private static final long serialVersionUID  = 400L;
 
@@ -127,13 +132,20 @@
     @includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
 
     @includeByRef{equals()}
+
+    public void droolsWriteObject(org.drools.common.DroolsObjectOutputStream out) throws java.io.IOException {
+    }
+
+    public Object droolsReadObject(org.drools.common.DroolsObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
+        return this;
+    }
 }
 >>=::
 
 evalInvoker() ::=<<
 package @{package};
 
-public class @{invokerClassName} implements org.drools.spi.EvalExpression, org.drools.spi.CompiledInvoker
+public class @{invokerClassName} implements org.drools.spi.EvalExpression, org.drools.spi.CompiledInvoker, org.drools.common.DroolsSerializable
 {
     private static final long serialVersionUID  = 400L;
 
@@ -158,6 +170,13 @@
     @includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
 
     @includeByRef{equals()}
+
+    public void droolsWriteObject(org.drools.common.DroolsObjectOutputStream out) throws java.io.IOException {
+    }
+
+    public Object droolsReadObject(org.drools.common.DroolsObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
+        return this;
+    }
 }
 >>=::
 

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -237,7 +237,7 @@
         DroolsSerializable serializable = (DroolsSerializable) instantiator.newInstance();
         registerObject(handle, serializable);
         Object replacement = serializable.droolsReadObject(this);
-        if (replacement != null) {
+        if (replacement != serializable) {
             serializable = (DroolsSerializable) replacement;
             registerObject(handle, serializable);
         }

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsObjectOutputStream.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -62,6 +62,7 @@
     private void writeObject(Object object, Class clazz, int handle) throws IOException {
         if (DroolsSerializable.class.isAssignableFrom(clazz)) {
             writeSerializable((DroolsSerializable) object, clazz, handle);
+        // FIXME haruki_zaemon Uncomment this to support externalizable
 //        } else if (Externalizable.class.isAssignableFrom(clazz)) {
 //            writeExternalizable((Externalizable) object, clazz, handle);
         } else if (clazz == String.class) {

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsSerializable.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsSerializable.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/common/DroolsSerializable.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -3,6 +3,7 @@
 import java.io.IOException;
 import java.io.Serializable;
 
+// FIXME haruki_zaemon This shouldn't be serializable but is for now until we sort out the existing tests that need it
 public interface DroolsSerializable extends Serializable {
     void droolsWriteObject(DroolsObjectOutputStream out) throws IOException;
 

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/EvalCondition.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/EvalCondition.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/EvalCondition.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,24 +19,28 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.io.IOException;
 
 import org.drools.RuntimeDroolsException;
 import org.drools.WorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.spi.EvalExpression;
 import org.drools.spi.Tuple;
 
-public class EvalCondition extends ConditionalElement {
+public class EvalCondition extends ConditionalElement implements DroolsSerializable {
     /**
-     * 
+     *
      */
     private static final long          serialVersionUID = 400L;
 
+    private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
+
     private EvalExpression             expression;
 
-    private final Declaration[]        requiredDeclarations;
+    private Declaration[]        requiredDeclarations;
 
-    private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
-
     public EvalCondition(final Declaration[] requiredDeclarations) {
         this( null,
               requiredDeclarations );
@@ -134,4 +138,14 @@
         return Collections.EMPTY_LIST;
     }
 
-};
\ No newline at end of file
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(expression);
+        out.writeObject(requiredDeclarations);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        expression = (EvalExpression) in.readObject();
+        requiredDeclarations = (Declaration[]) in.readObject();
+        return this;
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,14 @@
  */
 
 import java.util.Arrays;
+import java.io.IOException;
 
 import org.drools.RuntimeDroolsException;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
@@ -30,35 +34,36 @@
 
 /**
  * A predicate can be written as a top level constraint or be nested
- * inside inside a field constraint (and as so, must implement the 
+ * inside inside a field constraint (and as so, must implement the
  * Restriction interface).
- * 
+ *
  * @author etirelli
  */
 public class PredicateConstraint
     implements
     BetaNodeFieldConstraint,
     AlphaNodeFieldConstraint,
-    Restriction {
+    Restriction,
+    DroolsSerializable {
 
     /**
-     * 
+     *
      */
     private static final long          serialVersionUID   = 400L;
 
+    private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
+    private static final String[]      EMPTY_GLOBALS      = new String[0];
+
     private PredicateExpression        expression;
 
-    private final Declaration[]        requiredDeclarations;
+    private Declaration[]        requiredDeclarations;
 
-    private final Declaration[]        previousDeclarations;
+    private Declaration[]        previousDeclarations;
 
-    private final Declaration[]        localDeclarations;
+    private Declaration[]        localDeclarations;
 
-    private final String[]             requiredGlobals;
+    private String[]             requiredGlobals;
 
-    private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
-    private static final String[]      EMPTY_GLOBALS      = new String[0];
-
     public PredicateConstraint(final PredicateExpression evaluator) {
         this( evaluator,
               null,
@@ -281,6 +286,23 @@
                                         this.requiredGlobals );
     }
 
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(expression);
+        out.writeObject(requiredDeclarations);
+        out.writeObject(previousDeclarations);
+        out.writeObject(localDeclarations);
+        out.writeObject(requiredGlobals);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        expression = (PredicateExpression) in.readObject();
+        requiredDeclarations = (Declaration[]) in.readObject();
+        previousDeclarations = (Declaration[]) in.readObject();
+        localDeclarations = (Declaration[]) in.readObject();
+        requiredGlobals = (String[]) in.readObject();
+        return this;
+    }
+
     public static class PredicateContextEntry
         implements
         ContextEntry {

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,6 +19,9 @@
 import org.drools.RuntimeDroolsException;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.ReturnValueRestriction.ReturnValueContextEntry;
 import org.drools.spi.AlphaNodeFieldConstraint;
@@ -27,18 +30,21 @@
 import org.drools.spi.FieldExtractor;
 import org.drools.spi.ReturnValueExpression;
 
+import java.io.IOException;
+
 public class ReturnValueConstraint
     implements
     BetaNodeFieldConstraint,
-    AlphaNodeFieldConstraint {
+    AlphaNodeFieldConstraint,
+    DroolsSerializable {
 
     /**
-     * 
+     *
      */
     private static final long            serialVersionUID = 400L;
 
-    private final FieldExtractor         fieldExtractor;
-    private final ReturnValueRestriction restriction;
+    private FieldExtractor         fieldExtractor;
+    private ReturnValueRestriction restriction;
 
     public ReturnValueConstraint(final FieldExtractor fieldExtractor,
                                  final ReturnValueRestriction restriction) {
@@ -55,7 +61,7 @@
         this.restriction.replaceDeclaration( oldDecl,
                                              newDecl );
     }
-    
+
     public void setReturnValueExpression(final ReturnValueExpression expression) {
         this.restriction.setReturnValueExpression( expression );
     }
@@ -138,9 +144,19 @@
                                               e );
         }
     }
-    
+
     public Object clone() {
         return new ReturnValueConstraint( this.fieldExtractor, (ReturnValueRestriction) this.restriction.clone() );
     }
 
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(fieldExtractor);
+        out.writeObject(restriction);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        fieldExtractor = (FieldExtractor) in.readObject();
+        restriction = (ReturnValueRestriction) in.readObject();
+        return this;
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,11 +17,15 @@
  */
 
 import java.util.Arrays;
+import java.io.IOException;
 
 import org.drools.RuntimeDroolsException;
 import org.drools.WorkingMemory;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Evaluator;
 import org.drools.spi.Extractor;
@@ -32,28 +36,29 @@
 
 public class ReturnValueRestriction
     implements
-    Restriction {
+    Restriction,
+    DroolsSerializable {
 
     private static final long             serialVersionUID = 400L;
 
+    private static final Declaration[]    noRequiredDeclarations = new Declaration[]{};
+
+    private static final String[]         noRequiredGlobals = new String[]{};
+
     private ReturnValueExpression         expression;
 
-    private final Declaration[]           requiredDeclarations;
-    
-    private final String[]                requiredGlobals;
+    private Declaration[]           requiredDeclarations;
 
-    private final Declaration[]           previousDeclarations;
+    private String[]                requiredGlobals;
 
-    private final Declaration[]           localDeclarations;
+    private Declaration[]           previousDeclarations;
 
-    private final Evaluator               evaluator;
+    private Declaration[]           localDeclarations;
 
-    private static final Declaration[]    noRequiredDeclarations = new Declaration[]{};
+    private Evaluator               evaluator;
 
-    private static final String[]         noRequiredGlobals = new String[]{};
+    private ReturnValueContextEntry contextEntry;
 
-    private final ReturnValueContextEntry contextEntry;
-
     public ReturnValueRestriction(final FieldExtractor fieldExtractor,
                                   final Declaration[] previousDeclarations,
                                   final Declaration[] localDeclarations,
@@ -86,7 +91,7 @@
         } else {
             this.localDeclarations = ReturnValueRestriction.noRequiredDeclarations;
         }
-        
+
         if ( requiredGlobals != null ) {
             this.requiredGlobals = requiredGlobals;
         } else {
@@ -122,11 +127,11 @@
     public Declaration[] getLocalDeclarations() {
         return this.localDeclarations;
     }
-    
+
     public String[] getRequiredGlobals() {
         return this.requiredGlobals;
     }
-    
+
     public void replaceDeclaration(Declaration oldDecl,
                                    Declaration newDecl) {
         for( int i = 0; i < this.requiredDeclarations.length; i++) {
@@ -258,18 +263,18 @@
     public ContextEntry getContextEntry() {
         return this.contextEntry;
     }
-    
+
     public Object clone() {
         Declaration[] previous = new Declaration[ this.previousDeclarations.length ];
         for( int i = 0; i < previous.length; i++ ) {
             previous[i] = (Declaration) this.previousDeclarations[i].clone();
         }
-        
+
         Declaration[] local = new Declaration[ this.localDeclarations.length ];
         for( int i = 0; i < local.length; i++ ) {
             local[i] = (Declaration) this.localDeclarations[i].clone();
         }
-        
+
         return new ReturnValueRestriction( this.contextEntry.fieldExtractor,
                                            previous,
                                            local,
@@ -277,8 +282,30 @@
                                            this.evaluator );
     }
 
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(expression);
+        out.writeObject(requiredDeclarations);
+        out.writeObject(requiredGlobals);
+        out.writeObject(previousDeclarations);
+        out.writeObject(localDeclarations);
+        out.writeObject(evaluator);
+        out.writeObject(contextEntry);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        expression = (ReturnValueExpression) in.readObject();
+        requiredDeclarations = (Declaration[]) in.readObject();
+        requiredGlobals = (String[]) in.readObject();
+        previousDeclarations = (Declaration[]) in.readObject();
+        localDeclarations = (Declaration[]) in.readObject();
+        evaluator = (Evaluator) in.readObject();
+        contextEntry = (ReturnValueContextEntry) in.readObject();
+        return this;
+    }
+
     public static class ReturnValueContextEntry
         implements
+        DroolsSerializable,
         ContextEntry {
 
         private static final long    serialVersionUID = 400L;
@@ -358,6 +385,27 @@
         public InternalWorkingMemory getWorkingMemory() {
             return this.workingMemory;
         }
+
+        public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+            out.writeObject(fieldExtractor);
+            out.writeObject(handle);
+            out.writeObject(leftTuple);
+            out.writeObject(workingMemory);
+            out.writeObject(previousDeclarations);
+            out.writeObject(localDeclarations);
+            out.writeObject(entry);
+        }
+
+        public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+            fieldExtractor = (FieldExtractor) in.readObject();
+            handle = (InternalFactHandle) in.readObject();
+            leftTuple = (ReteTuple) in.readObject();
+            workingMemory = (InternalWorkingMemory) in.readObject();
+            previousDeclarations = (Declaration[]) in.readObject();
+            localDeclarations = (Declaration[]) in.readObject();
+            entry = (ContextEntry) in.readObject();
+            return this;
+        }
     }
 
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableConstraint.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableConstraint.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableConstraint.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,21 +18,27 @@
 
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.spi.Evaluator;
 import org.drools.spi.FieldExtractor;
 
+import java.io.IOException;
+
 public class VariableConstraint
     implements
     AlphaNodeFieldConstraint,
-    BetaNodeFieldConstraint {
+    BetaNodeFieldConstraint,
+    DroolsSerializable {
 
     private static final long         serialVersionUID = 400L;
 
-    private final FieldExtractor      fieldExtractor;
-    private final VariableRestriction restriction;
+    private FieldExtractor      fieldExtractor;
+    private VariableRestriction restriction;
 
     public VariableConstraint(final FieldExtractor fieldExtractor,
                               final Declaration declaration,
@@ -121,4 +127,14 @@
                                        (VariableRestriction) this.restriction.clone() );
     }
 
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(fieldExtractor);
+        out.writeObject(restriction);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        fieldExtractor = (FieldExtractor) in.readObject();
+        restriction = (VariableRestriction) in.readObject();
+        return this;
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableRestriction.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableRestriction.java	2007-12-26 11:23:38 UTC (rev 17406)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/VariableRestriction.java	2007-12-26 12:05:02 UTC (rev 17407)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,14 @@
  */
 
 import java.util.Arrays;
+import java.io.IOException;
 
 import org.drools.base.ValueType;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.common.DroolsSerializable;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Evaluator;
 import org.drools.spi.Extractor;
@@ -29,17 +33,18 @@
 
 public class VariableRestriction
     implements
-    Restriction {
+    Restriction,
+    DroolsSerializable {
 
     private static final long          serialVersionUID = 400L;
 
     private Declaration                declaration;
 
-    private final Declaration[]        requiredDeclarations;
+    private Declaration[]        requiredDeclarations;
 
-    private final Evaluator            evaluator;
+    private Evaluator            evaluator;
 
-    private final VariableContextEntry contextEntry;
+    private VariableContextEntry contextEntry;
 
     public VariableRestriction(final FieldExtractor fieldExtractor,
                                final Declaration declaration,
@@ -126,7 +131,7 @@
     private final VariableContextEntry createContextEntry(final Evaluator eval,
                                                           final FieldExtractor fieldExtractor) {
         ValueType coerced = eval.getCoercedValueType();
-        
+
         if ( coerced.isBoolean() ) {
             return new BooleanVariableContextEntry( fieldExtractor,
                                                     this.declaration,
@@ -160,6 +165,21 @@
                                         this.evaluator );
     }
 
+    public void droolsWriteObject(DroolsObjectOutputStream out) throws IOException {
+        out.writeObject(declaration);
+        out.writeObject(requiredDeclarations);
+        out.writeObject(evaluator);
+        out.writeObject(contextEntry);
+    }
+
+    public Object droolsReadObject(DroolsObjectInputStream in) throws IOException, ClassNotFoundException {
+        declaration = (Declaration) in.readObject();
+        requiredDeclarations = (Declaration[]) in.readObject();
+        evaluator = (Evaluator) in.readObject();
+        contextEntry = (VariableContextEntry) in.readObject();
+        return this;
+    }
+
     public static abstract class VariableContextEntry
         implements
         ContextEntry {




More information about the jboss-svn-commits mailing list