[jboss-svn-commits] JBL Code SVN: r17378 - in labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools: base/field and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Dec 23 02:01:29 EST 2007
Author: haruki_zaemon
Date: 2007-12-23 02:01:28 -0500 (Sun, 23 Dec 2007)
New Revision: 17378
Modified:
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ClassObjectType.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/SalienceInteger.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ValueType.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Declaration.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ImportDeclaration.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Package.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Pattern.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Rule.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/FieldValue.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/ObjectType.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/PatternExtractor.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Restriction.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/RuleComponent.java
labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Salience.java
Log:
Switch from using Serializable to Externalizable for new custom serialization.
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ClassObjectType.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ClassObjectType.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ClassObjectType.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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,22 +18,23 @@
import org.drools.spi.ObjectType;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
/**
* Java class semantics <code>ObjectType</code>.
- *
+ *
* @author <a href="mailto:bob at werken.com">bob at werken.com </a>
- *
+ *
* @version $Id: ClassObjectType.java,v 1.5 2005/02/04 02:13:36 mproctor Exp $
*/
public class ClassObjectType
implements
- ObjectType {
+ ObjectType,
+ Externalizable {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
-
/** Java object class. */
protected Class objectTypeClass;
@@ -45,9 +46,12 @@
// Constructors
// ------------------------------------------------------------
+ private ClassObjectType() {
+ }
+
/**
* Creates a new class object type with shadow disabled.
- *
+ *
* @param objectTypeClass
* Java object class.
*/
@@ -57,7 +61,7 @@
/**
* Creates a new class object type
- *
+ *
* @param objectTypeClass the class represented by this class object type
* @param isEvent true if it is an event class, false otherwise
*/
@@ -73,7 +77,7 @@
/**
* Return the Java object class.
- *
+ *
* @return The Java object class.
*/
public Class getClassType() {
@@ -87,10 +91,10 @@
/**
* Determine if the passed <code>Class</code> matches to the object type
* defined by this <code>objectType</code> instance.
- *
+ *
* @param clazz
* The <code>Class</code> to test.
- *
+ *
* @return <code>true</code> if the <code>Class</code> matches this
* object type, else <code>false</code>.
*/
@@ -101,10 +105,10 @@
/**
* Determine if the passed <code>Object</code> belongs to the object type
* defined by this <code>objectType</code> instance.
- *
+ *
* @param object
* The <code>Object</code> to test.
- *
+ *
* @return <code>true</code> if the <code>Object</code> matches this
* object type, else <code>false</code>.
*/
@@ -142,10 +146,10 @@
/**
* Determine if another object is equal to this.
- *
+ *
* @param object
* The object to test.
- *
+ *
* @return <code>true</code> if <code>object</code> is equal to this,
* otherwise <code>false</code>.
*/
@@ -157,7 +161,7 @@
if ( object == null || object.getClass() != ClassObjectType.class ) {
return false;
}
-
+
return this.objectTypeClass == ((ClassObjectType) object).objectTypeClass;
}
@@ -165,4 +169,15 @@
return this.objectTypeClass.hashCode();
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(objectTypeClass);
+ out.writeObject(valueType);
+ out.writeBoolean(isEvent);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ objectTypeClass = (Class) in.readObject();
+ valueType = (ValueType) in.readObject();
+ isEvent = in.readBoolean();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/SalienceInteger.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/SalienceInteger.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/SalienceInteger.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -1,22 +1,27 @@
package org.drools.base;
import org.drools.WorkingMemory;
+import org.drools.common.Resolvable;
import org.drools.spi.Salience;
import org.drools.spi.Tuple;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
public class SalienceInteger
implements
- Salience {
-
- /**
- *
- */
- private static final long serialVersionUID = 400L;
+ Salience,
+ Resolvable {
- public static final Salience DEFAULT_SALIENCE = new SalienceInteger( 0 );
-
- private final int value;
+ private static final int DEFAULT_VALUE = 0;
+ public static final Salience DEFAULT_SALIENCE = new SalienceInteger(DEFAULT_VALUE);
+ private int value;
+
+ private SalienceInteger() {
+ }
+
public SalienceInteger(int value) {
this.value = value;
}
@@ -25,9 +30,20 @@
final WorkingMemory workingMemory) {
return this.value;
}
-
+
public String toString() {
return String.valueOf( this.value );
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(value);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ value = in.readInt();
+ }
+
+ public Object readResolve() {
+ return value == DEFAULT_VALUE ? DEFAULT_SALIENCE : this;
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ValueType.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ValueType.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/ValueType.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -1,19 +1,20 @@
package org.drools.base;
-import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import org.drools.RuntimeDroolsException;
+import org.drools.common.Resolvable;
import org.drools.facttemplates.FactTemplate;
public class ValueType
implements
- Serializable {
+ Resolvable {
- private static final long serialVersionUID = 400L;
-
public static final ValueType NULL_TYPE = new ValueType( "null",
null,
SimpleValueType.NULL);
@@ -90,10 +91,13 @@
BigInteger.class,
SimpleValueType.OBJECT );
- private final String name;
- private final Class classType;
- private final int simpleType;
+ private String name;
+ private Class classType;
+ private int simpleType;
+ private ValueType() {
+ }
+
private ValueType(final String name,
final Class classType,
final int simpleType) {
@@ -102,10 +106,6 @@
this.simpleType = simpleType;
}
- private Object readResolve() throws java.io.ObjectStreamException {
- return determineValueType( this.classType );
- }
-
public String getName() {
return this.name;
}
@@ -210,4 +210,15 @@
return this.simpleType == SimpleValueType.CHAR;
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(classType);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ classType = (Class) in.readObject();
+ }
+
+ public Object readResolve() {
+ return determineValueType(this.classType);
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/base/field/ObjectFieldImpl.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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,24 +17,35 @@
*/
import java.util.Collection;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import org.drools.RuntimeDroolsException;
import org.drools.spi.FieldValue;
public class ObjectFieldImpl
implements
- FieldValue {
+ FieldValue,
+ Externalizable {
- private static final long serialVersionUID = 400L;
- private final Object value;
-
- private final boolean isCollection;
- private final boolean isNumber;
- private final boolean isBoolean;
- private final boolean isCharacter;
- private final boolean isString;
+ private Object value;
+ private boolean isCollection;
+ private boolean isNumber;
+ private boolean isBoolean;
+ private boolean isCharacter;
+ private boolean isString;
+
+ private ObjectFieldImpl() {
+ }
+
public ObjectFieldImpl(final Object value) {
+ setValue(value);
+ }
+
+ private void setValue(Object value) {
this.value = value;
this.isCollection = value instanceof Collection;
this.isNumber = value instanceof Number;
@@ -65,7 +76,7 @@
return ((Number) this.value).byteValue();
} else if( isString ) {
return Byte.valueOf( (String) this.value ).byteValue();
- }
+ }
throw new RuntimeDroolsException( "Conversion to byte not supported for type: " + this.value.getClass() );
}
@@ -142,7 +153,7 @@
return 0;
}
}
-
+
public boolean isNull() {
return value == null;
}
@@ -162,12 +173,20 @@
public boolean isObjectField() {
return true;
}
-
+
public boolean isCollectionField() {
return this.isCollection;
}
-
+
public boolean isStringField() {
return this.isString;
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(value);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ setValue(in.readObject());
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Declaration.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Declaration.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Declaration.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -40,7 +40,10 @@
*
*/
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Iterator;
@@ -53,13 +56,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.
@@ -75,33 +78,31 @@
*/
public class Declaration
implements
- Serializable,
+ Externalizable,
Cloneable {
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
- /**
- *
- */
- private static final long serialVersionUID = 400L;
-
/** The identifier for the variable. */
- private final String identifier;
+ private String identifier;
- private final Extractor extractor;
+ private Extractor extractor;
private Pattern pattern;
- private final boolean internalFact;
+ private boolean internalFact;
// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
+ private Declaration() {
+ }
+
/**
* Construct.
- *
+ *
* @param identifier
* The name of the variable.
* @param objectType
@@ -120,7 +121,7 @@
/**
* Construct.
- *
+ *
* @param identifier
* The name of the variable.
* @param objectType
@@ -147,7 +148,7 @@
/**
* Retrieve the variable's identifier.
- *
+ *
* @return The variable's identifier.
*/
public String getIdentifier() {
@@ -156,7 +157,7 @@
/**
* Retrieve the <code>ValueType</code>.
- *
+ *
* @return The ValueType.
*/
public ValueType getValueType() {
@@ -165,7 +166,7 @@
/**
* Returns the index of the pattern
- *
+ *
* @return the pattern
*/
public Pattern getPattern() {
@@ -186,7 +187,7 @@
/**
* Returns the Extractor expression
- *
+ *
* @return
*/
public Extractor getExtractor() {
@@ -287,7 +288,7 @@
throw new RuntimeDroolsException( "This is a bug. Please report to development team: " + e.getMessage(),
e );
}
- }
+ }
return this.extractor.getNativeReadMethod();
}
@@ -323,9 +324,22 @@
protected boolean isInternalFact() {
return internalFact;
}
-
+
public Object clone() {
return new Declaration( this.identifier, this.extractor, this.pattern );
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(identifier);
+ out.writeObject(extractor);
+ out.writeObject(pattern);
+ out.writeBoolean(internalFact);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ identifier = (String) in.readObject();
+ extractor = (Extractor) in.readObject();
+ pattern = (Pattern) in.readObject();
+ internalFact = in.readBoolean();
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ImportDeclaration.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ImportDeclaration.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/ImportDeclaration.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -1,12 +1,12 @@
/*
* Copyright 2007 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,41 +17,37 @@
*/
package org.drools.rule;
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
/**
* A class to represent an import declaration. That declaration
* may have additional metadata associated to it, like a flag
* stating if the imported class is an event or not
- *
+ *
* @author etirelli
*/
-public class ImportDeclaration implements Serializable {
-
- private static final long serialVersionUID = 6410032114027977766L;
-
+public class ImportDeclaration implements Externalizable {
private String target;
private boolean isEvent;
- /**
- * Creates an empty import declaration
- */
- public ImportDeclaration() {
- this( null, false );
+ private ImportDeclaration() {
}
/**
* Creates an import declaration for the given target.
- *
+ *
* @param target
*/
public ImportDeclaration( String target ) {
- this( target, false );
+ this( target, false );
}
-
+
/**
* Creates an import declaration for the given target.
- *
+ *
* @param target the import target
* @param isEvent true if the target is an event-type target, false otherwise.
*/
@@ -101,7 +97,7 @@
/**
* Returns true if this ImportDeclaration correctly matches to
* the given clazz
- *
+ *
* @param name
* @return
*/
@@ -110,16 +106,16 @@
if( this.target.equals( clazz.getName() ) ) {
return true;
}
-
+
// wild card imports
if( this.target.endsWith( ".*" ) ) {
String prefix = this.target.substring( 0, this.target.indexOf( ".*" ) );
-
+
// package import: import my.package.*
if( prefix.equals( clazz.getPackage().getName() ) ) {
return true;
}
-
+
// inner class imports with wild card?
// by looking at the ClassTypeResolver class, it seems we do not support
// the usage of wild cards when importing static inner classes like the
@@ -127,4 +123,14 @@
}
return false;
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(target);
+ out.writeBoolean(isEvent);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ target = (String) in.readObject();
+ isEvent = in.readBoolean();
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralConstraint.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -23,18 +23,22 @@
import org.drools.spi.FieldExtractor;
import org.drools.spi.FieldValue;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
public class LiteralConstraint
implements
- AlphaNodeFieldConstraint {
+ AlphaNodeFieldConstraint,
+ Externalizable {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
+ private FieldExtractor extractor;
- private final FieldExtractor extractor;
+ private LiteralRestriction restriction;
- private final LiteralRestriction restriction;
+ private LiteralConstraint() {
+ }
public LiteralConstraint(final FieldExtractor extractor,
final Evaluator evaluator,
@@ -114,4 +118,14 @@
this.getEvaluator(),
this.getField() );
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(extractor);
+ out.writeObject(restriction);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ extractor = (FieldExtractor) in.readObject();
+ restriction = (LiteralRestriction) in.readObject();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/LiteralRestriction.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -25,19 +25,26 @@
import org.drools.spi.FieldValue;
import org.drools.spi.Restriction;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
+
public class LiteralRestriction
implements
- Restriction {
+ Restriction,
+ Externalizable {
- private static final long serialVersionUID = 400L;
+ private static final Declaration[] requiredDeclarations = new Declaration[0];
- private final FieldValue field;
+ private FieldValue field;
- private final Evaluator evaluator;
+ private Evaluator evaluator;
- private static final Declaration[] requiredDeclarations = new Declaration[0];
+ private LiteralContextEntry contextEntry;
- private final LiteralContextEntry contextEntry;
+ private LiteralRestriction() {
+ }
public LiteralRestriction(final FieldValue field,
final Evaluator evaluator,
@@ -127,6 +134,18 @@
this.contextEntry.extractor );
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(field);
+ out.writeObject(evaluator);
+ out.writeObject(contextEntry);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ field = (FieldValue) in.readObject();
+ evaluator = (Evaluator) in.readObject();
+ contextEntry = (LiteralContextEntry) in.readObject();
+ }
+
private static class LiteralContextEntry
implements
ContextEntry {
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Package.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Package.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -16,13 +16,10 @@
* limitations under the License.
*/
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -33,7 +30,6 @@
import java.util.Map;
import java.util.Set;
-import org.drools.common.DroolsObjectInputStream;
import org.drools.facttemplates.FactTemplate;
import org.drools.ruleflow.common.core.Process;
import org.drools.util.StringUtils;
@@ -51,14 +47,9 @@
implements
Externalizable {
// ------------------------------------------------------------
- // Constants`
+ // Constants
// ------------------------------------------------------------
- /**
- *
- */
- private static final long serialVersionUID = 400L;
-
// ------------------------------------------------------------
// Instance members
// ------------------------------------------------------------
@@ -97,7 +88,7 @@
* Default constructor - for Externalizable. This should never be used by a user, as it
* will result in an invalid state for the instance.
*/
- public Package() {
+ private Package() {
}
@@ -144,23 +135,17 @@
* The Package uses PackageCompilationData to hold a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*
*/
- public void writeExternal(final ObjectOutput stream) throws IOException {
- stream.writeObject( this.packageCompilationData );
- stream.writeObject( this.name );
- stream.writeObject( this.imports );
- stream.writeObject( this.staticImports );
- stream.writeObject( this.functions );
- stream.writeObject( this.factTemplates );
- stream.writeObject( this.ruleFlows );
- stream.writeObject( this.globals );
- stream.writeBoolean( this.valid );
-
- // Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
- // a byte[]
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutput out = new ObjectOutputStream( bos );
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ out.writeObject( this.packageCompilationData );
+ out.writeObject( this.name );
+ out.writeObject( this.imports );
+ out.writeObject( this.staticImports );
+ out.writeObject( this.functions );
+ out.writeObject( this.factTemplates );
+ out.writeObject( this.ruleFlows );
+ out.writeObject( this.globals );
+ out.writeBoolean( this.valid );
out.writeObject( this.rules );
- stream.writeObject( bos.toByteArray() );
}
/**
@@ -169,27 +154,19 @@
* A custom ObjectInputStream, able to resolve classes against the bytecode in the PackageCompilationData, is used to restore the Rules.
*
*/
- public void readExternal(final ObjectInput stream) throws IOException,
+ public void readExternal(final ObjectInput in) throws IOException,
ClassNotFoundException {
// PackageCompilationData must be restored before Rules as it has the ClassLoader needed to resolve the generated code references in Rules
- this.packageCompilationData = (PackageCompilationData) stream.readObject();
- this.name = (String) stream.readObject();
- this.imports = (Map<String, ImportDeclaration>) stream.readObject();
- this.staticImports = (Set) stream.readObject();
- this.functions = (List) stream.readObject();
- this.factTemplates = (Map) stream.readObject();
- this.ruleFlows = (Map) stream.readObject();
- this.globals = (Map) stream.readObject();
- this.valid = stream.readBoolean();
-
- // Return the rules stored as a byte[]
- final byte[] bytes = (byte[]) stream.readObject();
-
- // Use a custom ObjectInputStream that can resolve against a given classLoader
- final DroolsObjectInputStream streamWithLoader = new DroolsObjectInputStream( new ByteArrayInputStream( bytes ),
- this.packageCompilationData.getClassLoader() );
-
- this.rules = (Map) streamWithLoader.readObject();
+ this.packageCompilationData = (PackageCompilationData) in.readObject();
+ this.name = (String) in.readObject();
+ this.imports = (Map<String, ImportDeclaration>) in.readObject();
+ this.staticImports = (Set) in.readObject();
+ this.functions = (List) in.readObject();
+ this.factTemplates = (Map) in.readObject();
+ this.ruleFlows = (Map) in.readObject();
+ this.globals = (Map) in.readObject();
+ this.valid = in.readBoolean();
+ this.rules = (Map) in.readObject();
}
// ------------------------------------------------------------
@@ -447,9 +424,9 @@
public int hashCode() {
return this.name.hashCode();
}
-
+
/**
- * Returns true if clazz is imported as an Event class in this package
+ * Returns true if clazz is imported as an Event class in this package
* @param clazz
* @return
*/
@@ -463,11 +440,11 @@
return true;
}
}
- // if it is not resolved, try superclass
+ // if it is not resolved, try superclass
if( this.isEvent( clazz.getSuperclass() ) ) {
return true;
}
-
+
// if it is no resolved, try interfaces
for( Class interf : clazz.getInterfaces() ) {
if( this.isEvent( interf ) ) {
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -17,13 +17,11 @@
*/
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
@@ -69,7 +67,7 @@
private transient PackageClassLoader classLoader;
private transient ClassLoader parentClassLoader;
-
+
private boolean dirty;
static {
@@ -84,8 +82,7 @@
* Default constructor - for Externalizable. This should never be used by a user, as it
* will result in an invalid state for the instance.
*/
- public PackageCompilationData() {
-
+ private PackageCompilationData() {
}
public PackageCompilationData(final ClassLoader parentClassLoader) {
@@ -95,7 +92,7 @@
this.lineMappings = new HashMap();
this.dirty = false;
}
-
+
public boolean isDirty() {
return this.dirty;
}
@@ -113,16 +110,10 @@
* default methods. The PackageCompilationData holds a reference to the generated bytecode. The generated bytecode must be restored before any Rules.
*
*/
- public void writeExternal(final ObjectOutput stream) throws IOException {
- stream.writeObject( this.store );
- stream.writeObject( this.AST );
-
- // Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
- // a byte[]
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutput out = new ObjectOutputStream( bos );
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ out.writeObject( this.store );
+ out.writeObject( this.AST );
out.writeObject( this.invokerLookups );
- stream.writeObject( bos.toByteArray() );
}
/**
@@ -131,25 +122,17 @@
* A custom ObjectInputStream, able to resolve classes against the bytecode, is used to restore the Rules.
*
*/
- public void readExternal(final ObjectInput stream) throws IOException,
- ClassNotFoundException {
- if ( stream instanceof DroolsObjectInputStream ) {
- DroolsObjectInputStream droolsStream = (DroolsObjectInputStream) stream;
+ public void readExternal(final ObjectInput input) throws IOException, ClassNotFoundException {
+ if (input instanceof DroolsObjectInputStream ) {
+ DroolsObjectInputStream droolsStream = (DroolsObjectInputStream) input;
initClassLoader( droolsStream.getClassLoader() );
} else {
initClassLoader( Thread.currentThread().getContextClassLoader() );
}
- this.store = (Map) stream.readObject();
- this.AST = stream.readObject();
-
- // Return the rules stored as a byte[]
- final byte[] bytes = (byte[]) stream.readObject();
-
- // Use a custom ObjectInputStream that can resolve against a given classLoader
- final DroolsObjectInputStream streamWithLoader = new DroolsObjectInputStream( new ByteArrayInputStream( bytes ),
- this.classLoader );
- this.invokerLookups = (Map) streamWithLoader.readObject();
+ this.store = (Map) input.readObject();
+ this.AST = input.readObject();
+ this.invokerLookups = (Map) input.readObject();
}
public ClassLoader getClassLoader() {
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Pattern.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Pattern.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Pattern.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -22,6 +22,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import org.drools.spi.Constraint;
import org.drools.spi.Extractor;
@@ -30,22 +34,23 @@
public class Pattern
implements
- RuleConditionElement {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
- private final ObjectType objectType;
+ RuleConditionElement,
+ Externalizable {
+
+ private ObjectType objectType;
private List constraints = Collections.EMPTY_LIST;
- final Declaration declaration;
+ private Declaration declaration;
private Map declarations;
- private final int index;
+ private int index;
private PatternSource source;
// this is the offset of the related fact inside a tuple. i.e:
- // the position of the related fact inside the tuple;
+ // the position of the related fact inside the tuple;
private int offset;
+ private Pattern() {
+ }
+
public Pattern(final int index,
final ObjectType objectType) {
this( index,
@@ -114,7 +119,7 @@
decl.getExtractor() );
} else {
Constraint constraint = (Constraint) ((Constraint) constr).clone();
-
+
// we must update pattern references in cloned declarations
Declaration[] oldDecl = ((Constraint) constr).getRequiredDeclarations();
Declaration[] newDecl = constraint.getRequiredDeclarations();
@@ -125,7 +130,7 @@
constraint.replaceDeclaration( oldDecl[i], newDecl[i] );
}
}
-
+
clone.addConstraint( constraint );
}
}
@@ -186,9 +191,9 @@
}
/**
- * The offset of the fact related to this pattern
+ * The offset of the fact related to this pattern
* inside the tuple
- *
+ *
* @return the offset
*/
public int getOffset() {
@@ -268,4 +273,21 @@
return this.source != null ? Collections.singletonList( this.source ) : Collections.EMPTY_LIST;
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(objectType);
+ out.writeObject(constraints);
+ out.writeObject(declaration);
+ out.writeObject(declarations);
+ out.writeInt(index);
+ out.writeObject(source);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ objectType = (ObjectType) in.readObject();
+ constraints = (List) in.readObject();
+ declaration = (Declaration) in.readObject();
+ declarations = (Map) in.readObject();
+ index = in.readInt();
+ source = (PatternSource) in.readObject();
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Rule.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Rule.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/rule/Rule.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -16,7 +16,10 @@
* limitations under the License.
*/
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
@@ -41,12 +44,8 @@
*/
public class Rule
implements
- Serializable,
+ Externalizable,
Dialectable {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
/** */
// ------------------------------------------------------------
@@ -56,7 +55,7 @@
private String pkg;
/** Name of the rule. */
- private final String name;
+ private String name;
/** Salience value. */
private Salience salience;
@@ -108,6 +107,9 @@
// Constructors
// ------------------------------------------------------------
+ private Rule() {
+ }
+
/**
* Construct a
* <code>Rule<code> with the given name for the specified pkg parent
@@ -552,4 +554,54 @@
public boolean isEnabled() {
return this.enabled;
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(pkg);
+ out.writeObject(name);
+ out.writeObject(salience);
+ out.writeBoolean(dirty);
+ out.writeObject(declarations);
+ out.writeObject(declarationArray);
+ out.writeObject(lhsRoot);
+ out.writeObject(dialect);
+ out.writeObject(agendaGroup);
+ out.writeObject(consequence);
+ out.writeObject(duration);
+ out.writeLong(loadOrder);
+ out.writeBoolean(noLoop);
+ out.writeBoolean(autoFocus);
+ out.writeObject(activationGroup);
+ out.writeObject(ruleFlowGroup);
+ out.writeBoolean(lockOnActive);
+ out.writeBoolean(hasLogicalDependency);
+ out.writeBoolean(semanticallyValid);
+ out.writeObject(dateEffective);
+ out.writeObject(dateExpires);
+ out.writeBoolean(enabled);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ pkg = (String) in.readObject();
+ name = (String) in.readObject();
+ salience = (Salience) in.readObject();
+ dirty = in.readBoolean();
+ declarations = (Map) in.readObject();
+ declarationArray = (Declaration[]) in.readObject();
+ lhsRoot = (GroupElement) in.readObject();
+ dialect = (String) in.readObject();
+ agendaGroup = (String) in.readObject();
+ consequence = (Consequence) in.readObject();
+ duration = (Duration) in.readObject();
+ loadOrder = in.readLong();
+ noLoop = in.readBoolean();
+ autoFocus = in.readBoolean();
+ activationGroup = (String) in.readObject();
+ ruleFlowGroup = (String) in.readObject();
+ lockOnActive = in.readBoolean();
+ hasLogicalDependency = in.readBoolean();
+ semanticallyValid = in.readBoolean();
+ dateEffective = (Calendar) in.readObject();
+ dateExpires = (Calendar) in.readObject();
+ enabled = in.readBoolean();
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/FieldValue.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/FieldValue.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/FieldValue.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -16,12 +16,8 @@
* limitations under the License.
*/
-import java.io.Serializable;
+public interface FieldValue {
-public interface FieldValue
- extends
- Serializable {
-
public Object getValue();
public char getCharValue();
@@ -39,7 +35,7 @@
public double getDoubleValue();
public boolean getBooleanValue();
-
+
public boolean isNull();
public boolean isBooleanField();
@@ -55,7 +51,7 @@
* @return
*/
public boolean isCollectionField();
-
+
public boolean isStringField();
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/ObjectType.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/ObjectType.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/ObjectType.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -16,36 +16,32 @@
* limitations under the License.
*/
-import java.io.Serializable;
-
import org.drools.base.ValueType;
/**
* Semantic object type differentiator.
- *
+ *
* @see org.drools.rule.Declaration
- *
+ *
* @author <a href="mailto:bob at werken.com">bob mcwhirter </a>
*/
-public interface ObjectType
- extends
- Serializable {
+public interface ObjectType {
/**
* Determine if the passed <code>Object</code> belongs to the object type
* defined by this <code>objectType</code> instance.
- *
+ *
* @param object
* The <code>Object</code> to test.
- *
+ *
* @return <code>true</code> if the <code>Object</code> matches this
* object type, else <code>false</code>.
*/
boolean matches(Object object);
-
+
boolean isAssignableFrom(Object object);
-
+
boolean isAssignableFrom(ObjectType objectType);
-
+
/**
* Returns true if the object type represented by this object
* is an event object type. False otherwise.
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/PatternExtractor.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/PatternExtractor.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/PatternExtractor.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -3,6 +3,10 @@
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Iterator;
+import java.io.Externalizable;
+import java.io.ObjectOutput;
+import java.io.IOException;
+import java.io.ObjectInput;
import org.drools.RuntimeDroolsException;
import org.drools.base.ClassObjectType;
@@ -14,13 +18,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.
@@ -30,14 +34,14 @@
public class PatternExtractor
implements
- Extractor {
+ Extractor,
+ Externalizable {
- /**
- *
- */
- private static final long serialVersionUID = 400L;
private ObjectType objectType;
+ private PatternExtractor() {
+ }
+
public PatternExtractor(final ObjectType objectType) {
this.objectType = objectType;
}
@@ -168,4 +172,12 @@
public boolean isGlobal() {
return false;
}
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(objectType);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ objectType = (ObjectType) in.readObject();
+ }
}
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Restriction.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Restriction.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Restriction.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -1,7 +1,5 @@
package org.drools.spi;
-import java.io.Serializable;
-
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.reteoo.ReteTuple;
@@ -10,7 +8,6 @@
public interface Restriction
extends
- Serializable,
Cloneable {
Declaration[] getRequiredDeclarations();
@@ -29,7 +26,7 @@
/**
* A restriction may be required to replace an old
* declaration object by a new updated one
- *
+ *
* @param oldDecl
* @param newDecl
*/
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/RuleComponent.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/RuleComponent.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/RuleComponent.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -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.
@@ -16,17 +16,12 @@
* limitations under the License.
*/
-import java.io.Serializable;
-
/**
* Semantic component marker.
- *
+ *
* @author <a href="mailto:bob at werken.com">bob mcwhirter </a>
- *
+ *
* @version $Id$
*/
-public interface RuleComponent
- extends
- Serializable {
-
+public interface RuleComponent {
}
\ No newline at end of file
Modified: labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Salience.java
===================================================================
--- labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Salience.java 2007-12-23 06:22:55 UTC (rev 17377)
+++ labs/jbossrules/branches/serialization/drools-core/src/main/java/org/drools/spi/Salience.java 2007-12-23 07:01:28 UTC (rev 17378)
@@ -1,10 +1,8 @@
package org.drools.spi;
-import java.io.Serializable;
-
import org.drools.WorkingMemory;
-public interface Salience extends Serializable {
+public interface Salience {
public int getValue(final Tuple tuple,
final WorkingMemory workingMemory);
}
More information about the jboss-svn-commits
mailing list