[jboss-svn-commits] JBL Code SVN: r18730 - in labs/jbossrules/branches/ming-serialization/drools-compiler/src: main/resources/org/drools/rule/builder/dialect/java and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 6 09:25:50 EST 2008
Author: mingjin
Date: 2008-03-06 09:25:50 -0500 (Thu, 06 Mar 2008)
New Revision: 18730
Modified:
labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java
labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
Log:
Using custom serialization.
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -1,6 +1,10 @@
package org.drools.rule.builder.dialect.mvel;
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.ArrayList;
import java.util.HashMap;
@@ -76,7 +80,7 @@
public class MVELDialect
implements
- Dialect {
+ Dialect, Externalizable {
public final static String ID = "mvel";
@@ -126,6 +130,34 @@
public MVELDialect() {
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ interceptors = (Map)in.readObject();
+ results = (List)in.readObject();
+ src = (MemoryResourceReader)in.readObject();
+ pkg = (Package)in.readObject();
+ data = (MVELDialectData)in.readObject();
+ configuration = (MVELDialectConfiguration)in.readObject();
+ typeResolver = (TypeResolver)in.readObject();
+ classFieldExtractorCache = (ClassFieldExtractorCache)in.readObject();
+ analyzer = (MVELExprAnalyzer)in.readObject();
+ imports = (Map)in.readObject();
+ packageImports = (Map)in.readObject();
+ strictMode = in.readBoolean();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(interceptors);
+ out.writeObject(results);
+ out.writeObject(src);
+ out.writeObject(pkg);
+ out.writeObject(data);
+ out.writeObject(configuration);
+ out.writeObject(typeResolver);
+ out.writeObject(classFieldExtractorCache);
+ out.writeObject(analyzer);
+ out.writeObject(imports);
+ out.writeBoolean(strictMode);
+ }
public static void setLanguageLevel(int level) {
synchronized ( languageSet ) {
// this synchronisation is needed as setLanguageLevel is now thread safe
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -1,12 +1,12 @@
/*
* Copyright 2006 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,6 +17,7 @@
package org.drools.rule.builder.dialect.mvel;
import java.io.Serializable;
+import java.io.Externalizable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -66,9 +67,9 @@
final DroolsMVELFactory factory = new DroolsMVELFactory( previousMap,
localMap,
context.getPkg().getGlobals() );
-
+
MVELDialectData data = (MVELDialectData) context.getPkg().getDialectDatas().getDialectData( "mvel" );
- factory.setNextFactory( data.getFunctionFactory() );
+ factory.setNextFactory( data.getFunctionFactory() );
Dialect.AnalysisResult analysis = context.getDialect().analyzeExpression( context,
returnValueRestrictionDescr,
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel 2008-03-06 14:25:50 UTC (rev 18730)
@@ -4,7 +4,7 @@
java.io.InputStream is = @{ruleClassName}.class.getClassLoader().getResourceAsStream( "@{package}.@{ruleClassName}".replace( '.', '/' ) + ".class" );
-
+
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] data = new byte[1024];
int byteCount;
@@ -12,21 +12,21 @@
while ( (byteCount = is.read( data,
0,
1024 )) > -1 )
- {
+ {
bos.write(data, 0, byteCount);
}
} catch ( java.io.IOException e ) {
throw new org.drools.RuntimeDroolsException("Unable getResourceAsStream for Class '@{ruleClassName}' ");
- }
-
+ }
+
org.drools.asm.ClassReader classReader = new org.drools.asm.ClassReader( bos.toByteArray() );
classReader.accept( visit, true );
org.drools.asm.util.TraceMethodVisitor trace = visit.getTrace();
- return trace.getText();
+ return trace.getText();
}
>>=::
-
+
equals() ::=<<
public boolean equals(Object object) {
if (object == null ) {
@@ -34,13 +34,13 @@
} else if ( object == this ){
return true;
}
-
+
if ( ! (object instanceof org.drools.spi.CompiledInvoker) ) {
return false;
}
-
+
org.drools.spi.CompiledInvoker other = ( org.drools.spi.CompiledInvoker ) object;
-
+
return org.drools.util.asm.MethodComparator.compareBytecode( getMethodBytecode(), other.getMethodBytecode() );
}
>>=::
@@ -54,21 +54,21 @@
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, java.io.Externalizable
{
private static final long serialVersionUID = 400L;
-
+
public Object createContext() { return null; }
-
+
public org.drools.spi.FieldValue evaluate(java.lang.Object object,
org.drools.spi.Tuple tuple,
- org.drools.rule.Declaration[] previousDeclarations,
- org.drools.rule.Declaration[] localDeclarations,
+ org.drools.rule.Declaration[] previousDeclarations,
+ org.drools.rule.Declaration[] localDeclarations,
org.drools.WorkingMemory workingMemory,
- Object context ) throws Exception {
+ Object context ) throws Exception {
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) previousDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) tuple.get( previousDeclarations[@{i0}] ) ).getObject() );
- @end{}
+ @end{}
@if{readLocalsFromTuple}
@foreach{localDeclarationTypes as type, localDeclarations as declr} @{type} @{declr.identifier} = ( @{type} ) localDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) tuple.get( localDeclarations[@{i0}] ) ).getObject() );
@end{}
@@ -78,97 +78,115 @@
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
@end{}
-
- return @{ruleClassName}.@{methodName}(
+
+ return @{ruleClassName}.@{methodName}(
@foreach{declarations as declr} @{declr.identifier}
- @end{","} @if{localDeclarations != empty && declarations != empty}, at end{}
+ @end{","} @if{localDeclarations != empty && declarations != empty}, at end{}
@foreach{localDeclarations as declr} @{declr.identifier}
@end{","}@if{globals != empty && (localDeclarations != empty || declarations != empty)}, at end{}
@foreach{globals as identifier}@{identifier}
@end{","} );
- }
-
+ }
+
@includeByRef{hashCode(hashCode = hashCode)}
-
+
@includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
-
- @includeByRef{equals()}
-}
+
+ @includeByRef{equals()}
+
+ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
+ }
+
+ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException {
+ }
+}
>>=::
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, java.io.Externalizable
{
private static final long serialVersionUID = 400L;
-
+
public Object createContext() { return null; }
-
+
public boolean evaluate(java.lang.Object object,
org.drools.spi.Tuple tuple,
- org.drools.rule.Declaration[] previousDeclarations,
- org.drools.rule.Declaration[] localDeclarations,
+ org.drools.rule.Declaration[] previousDeclarations,
+ org.drools.rule.Declaration[] localDeclarations,
org.drools.WorkingMemory workingMemory,
- Object context ) throws Exception {
+ Object context ) throws Exception {
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) previousDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) tuple.get( previousDeclarations[@{i0}] ) ).getObject() );
- @end{}
+ @end{}
@foreach{localDeclarationTypes as type, localDeclarations as declr} @{type} @{declr.identifier} = ( @{type} ) localDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, object );
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
@end{}
-
- return @{ruleClassName}.@{methodName}(
- @foreach{declarations as declr} @{declr.identifier}
- @end{","} @if{localDeclarations != empty && declarations != empty}, at end{}
- @foreach{localDeclarations as declr} @{declr.identifier}
+
+ return @{ruleClassName}.@{methodName}(
+ @foreach{declarations as declr} @{declr.identifier}
+ @end{","} @if{localDeclarations != empty && declarations != empty}, at end{}
+ @foreach{localDeclarations as declr} @{declr.identifier}
@end{","}@if{globals != empty && (localDeclarations != empty || declarations != empty)}, at end{}
@foreach{globals as identifier}@{identifier}
@end{","} );
- }
-
+ }
+
@includeByRef{hashCode(hashCode = hashCode)}
-
+
@includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
-
- @includeByRef{equals()}
-}
+
+ @includeByRef{equals()}
+
+ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
+ }
+
+ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException {
+ }
+}
>>=::
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, java.io.Externalizable
{
private static final long serialVersionUID = 400L;
- // no need for context
+ // no need for context
public Object createContext() { return null; }
-
+
public boolean evaluate(org.drools.spi.Tuple tuple,
- org.drools.rule.Declaration[] declarations,
+ org.drools.rule.Declaration[] declarations,
org.drools.WorkingMemory workingMemory,
- Object context ) throws Exception {
+ Object context ) throws Exception {
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) declarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) tuple.get( declarations[@{i0}] ) ).getObject() );
- @end{}
+ @end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
@end{}
-
- return @{ruleClassName}.@{methodName}(
- @foreach{declarations as declr} @{declr.identifier}
+
+ return @{ruleClassName}.@{methodName}(
+ @foreach{declarations as declr} @{declr.identifier}
@end{","} @if{globals != empty && declarations != empty}, at end{}
@foreach{globals as identifier}@{identifier}
@end{","} );
- }
-
+ }
+
@includeByRef{hashCode(hashCode = hashCode)}
-
+
@includeByRef{getMethodBytecode(package = package, ruleClassName = ruleClassName, methodName = methodName)}
-
- @includeByRef{equals()}
-}
+
+ @includeByRef{equals()}
+
+ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
+ }
+
+ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException {
+ }
+}
>>=::
accumulateInvoker() ::=<<
@@ -181,11 +199,11 @@
public class @{invokerClassName} implements org.drools.spi.Accumulator, org.drools.spi.CompiledInvoker
{
private static final long serialVersionUID = 400L;
-
+
public Object createContext() {
return new @{ruleClassName}.@{className}();
}
-
+
public void init(java.lang.Object workingMemoryContext,
java.lang.Object context,
org.drools.spi.Tuple leftTuple,
@@ -194,12 +212,12 @@
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) declarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( declarations[@{i0}] ) ).getObject() );
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
-
+ @end{}
+
((@{ruleClassName}.@{className})context).init(
@foreach{declarations as declr} @{declr.identifier}@end{","}@if{globals != empty && declarations != empty}, at end{}
@foreach{globals as identifier} @{identifier}@end{","} );
-
+
}
public void accumulate(java.lang.Object workingMemoryContext,
@@ -212,7 +230,7 @@
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) declarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( declarations[@{i0}] ) ).getObject() );
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
+ @end{}
@if{isMultiPattern}
@foreach{innerDeclarations as declr} @{declr.extractor.extractToClassName} @{declr.identifier} = (@{declr.extractor.extractToClassName}) innerDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( innerDeclarations[@{i0}] ) ).getObject() );
@end{}
@@ -223,7 +241,7 @@
((@{ruleClassName}.@{className})context).accumulate(
workingMemory,
innerDeclarations,
- handle.getObject()@if{declarations != empty}, at end{}
+ handle.getObject()@if{declarations != empty}, at end{}
@foreach{declarations as declr} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
@foreach{globals as identifier} @{identifier}@end{","}@if{innerDeclarations != empty}, at end{}
@foreach{innerDeclarations as declr} @{declr.identifier}@end{","});
@@ -239,7 +257,7 @@
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) declarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( declarations[@{i0}] ) ).getObject() );
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
+ @end{}
@if{isMultiPattern}
@foreach{innerDeclarations as declr} @{declr.extractor.extractToClassName} @{declr.identifier} = (@{declr.extractor.extractToClassName}) innerDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( innerDeclarations[@{i0}] ) ).getObject() );
@end{}
@@ -247,11 +265,11 @@
@foreach{innerDeclarations as declr} @{declr.extractor.extractToClassName} @{declr.identifier} = (@{declr.extractor.extractToClassName}) innerDeclarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, handle.getObject() );
@end{}
@end{}
-
+
((@{ruleClassName}.@{className})context).reverse(
workingMemory,
innerDeclarations,
- handle.getObject()@if{declarations != empty}, at end{}
+ handle.getObject()@if{declarations != empty}, at end{}
@foreach{declarations as declr} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
@foreach{globals as identifier} @{identifier}@end{","}@if{innerDeclarations != empty}, at end{}
@foreach{innerDeclarations as declr} @{declr.identifier}@end{","});
@@ -265,13 +283,13 @@
@foreach{declarationTypes as type, declarations as declr} @{type} @{declr.identifier} = ( @{type} ) declarations[@{i0}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) leftTuple.get( declarations[@{i0}] ) ).getObject() );
@end{}
@foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
-
+ @end{}
+
return ((@{ruleClassName}.@{className})context).getResult(
@foreach{declarations as declr} @{declr.identifier}@end{","}@if{globals != empty && declarations != empty}, at end{}
@foreach{globals as identifier} @{identifier}@end{","} );
}
-
+
public boolean supportsReverse() {
return @{supportsReverse};
}
@@ -279,14 +297,14 @@
public Object createWorkingMemoryContext() {
return null;
}
-
+
@includeByRef{hashCode(hashCode = hashCode)}
-
- @includeByRef{equals()}
+ @includeByRef{equals()}
+
public java.util.List getMethodBytecode() {
java.io.InputStream is = @{ruleClassName}.class.getClassLoader().getResourceAsStream( "@{package}.@{ruleClassName}".replace( '.', '/' ) + "$@{className}" + ".class" );
-
+
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] data = new byte[1024];
int byteCount;
@@ -294,48 +312,53 @@
while ( (byteCount = is.read( data,
0,
1024 )) > -1 )
- {
+ {
bos.write(data, 0, byteCount);
}
} catch ( java.io.IOException e ) {
throw new org.drools.RuntimeDroolsException("Unable getResourceAsStream for Class '@{ruleClassName}$@{className}' ");
- }
- return Collections.singletonList( bos );
+ }
+ return Collections.singletonList( bos );
}
-}
+}
>>=::
consequenceInvoker() ::=<<
package @{package};
-public class @{invokerClassName} implements org.drools.spi.Consequence
+public class @{invokerClassName} implements org.drools.spi.Consequence, java.io.Externalizable
{
private static final long serialVersionUID = 400L;
public void evaluate(org.drools.spi.KnowledgeHelper knowledgeHelper,
- org.drools.WorkingMemory workingMemory) throws Exception {
-
+ org.drools.WorkingMemory workingMemory) throws Exception {
+
org.drools.spi.Tuple tuple = knowledgeHelper.getTuple();
org.drools.rule.Rule rule = knowledgeHelper.getRule();
- org.drools.rule.Declaration[] declarations = rule.getDeclarations();
+ org.drools.rule.Declaration[] declarations = rule.getDeclarations();
@foreach{declarationTypes as type, declarations as declr ,indexes as index, notPatterns as notPattern}
- org.drools.common.InternalFactHandle @{declr.identifier}__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[@{index}].getIdentifier() ) );
+ org.drools.common.InternalFactHandle @{declr.identifier}__Handle__ = ( org.drools.common.InternalFactHandle ) tuple.get( knowledgeHelper.getDeclaration( declarations[@{index}].getIdentifier() ) );
@{type} @{declr.identifier} = ( @{type} ) declarations[@{index}].@{declr.nativeReadMethod.name}( (org.drools.common.InternalWorkingMemory) workingMemory, @{declr.identifier}__Handle__.getObject() );
@if{notPattern}@{declr.identifier}__Handle__ = (org.drools.common.InternalFactHandle) knowledgeHelper.getWorkingMemory().getFactHandle( @{declr.identifier} );@end{}
@end{}
-
- @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
-
- @{ruleClassName}.@{methodName} (
+
+ @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
+ @end{}
+
+ @{ruleClassName}.@{methodName} (
knowledgeHelper at if{declarations != empty}, at end{}
@foreach{declarations as declr} @{declr.identifier}, @{declr.identifier}__Handle__
@end{","}@if{globals != empty}, at end{}
@foreach{globals as identifier} @{identifier}
@end{","} );
}
-}
+ public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
+ }
+
+ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException {
+ }
+}
>>=::
actionInvoker() ::=<<
@@ -345,16 +368,16 @@
{
private static final long serialVersionUID = 400L;
- public void execute(org.drools.WorkingMemory workingMemory) throws Exception {
-
- @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
-
- @{processClassName}.@{methodName} (
+ public void execute(org.drools.WorkingMemory workingMemory) throws Exception {
+
+ @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
+ @end{}
+
+ @{processClassName}.@{methodName} (
@foreach{globals as identifier} @{identifier}
@end{","} );
}
-}
+}
>>=::
returnValueEvaluatorInvoker() ::=<<
@@ -364,14 +387,14 @@
{
private static final long serialVersionUID = 400L;
- public Object evaluate(org.drools.WorkingMemory workingMemory) throws Exception {
-
- @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
- @end{}
-
- return @{processClassName}.@{methodName} (
+ public Object evaluate(org.drools.WorkingMemory workingMemory) throws Exception {
+
+ @foreach{globalTypes as type, globals as identifier} @{type} @{identifier} = ( @{type} ) workingMemory.getGlobal( "@{identifier}" );
+ @end{}
+
+ return @{processClassName}.@{methodName} (
@foreach{globals as identifier} @{identifier}
@end{","} );
}
-}
+}
>>=::
\ No newline at end of file
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderTest.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -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.
@@ -46,6 +46,7 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.LogicalDependency;
import org.drools.common.RuleFlowGroupNode;
+import org.drools.common.DroolsObjectOutputStream;
import org.drools.commons.jci.compilers.EclipseJavaCompiler;
import org.drools.commons.jci.compilers.JaninoJavaCompiler;
import org.drools.commons.jci.compilers.JavaCompiler;
@@ -194,7 +195,7 @@
((JavaDialectData)pkg.getDialectDatas().getDialectData( "java" )).list().length );
builder.addPackage( packageDescr );
-
+
pkg = builder.getPackage();
rule = pkg.getRule( "rule-1" );
@@ -281,7 +282,7 @@
private byte[] serializeOut(final Object obj) throws IOException {
// Serialize to a byte array
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutput out = new ObjectOutputStream( bos );
+ final ObjectOutput out = new DroolsObjectOutputStream( bos );
out.writeObject( obj );
out.close();
@@ -1005,7 +1006,7 @@
PackageBuilder builder = new PackageBuilder();
PackageDescr pkgDescr = new PackageDescr( "org.test" );
builder.addPackage( pkgDescr );
-
+
final Field dialectField = builder.getClass().getDeclaredField( "dialect" );
dialectField.setAccessible( true );
JavaDialect dialect = (JavaDialect) dialectField.get( builder );
@@ -1022,7 +1023,7 @@
javaConf.setCompiler( JavaDialectConfiguration.JANINO );
builder = new PackageBuilder( conf );
builder.addPackage( pkgDescr );
-
+
dialect = (JavaDialect) dialectField.get( builder );
compiler = (JavaCompiler) compilerField.get( dialect );
assertSame( JaninoJavaCompiler.class,
@@ -1034,7 +1035,7 @@
javaConf.setCompiler( JavaDialectConfiguration.ECLIPSE );
builder = new PackageBuilder( conf );
builder.addPackage( pkgDescr );
-
+
dialect = (JavaDialect) dialectField.get( builder );
compiler = (JavaCompiler) compilerField.get( dialect );
assertSame( EclipseJavaCompiler.class,
@@ -1212,10 +1213,10 @@
//now serialization
ByteArrayOutputStream data = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream( data );
+ ObjectOutput out = new DroolsObjectOutputStream( data );
out.writeObject( pkg );
- ObjectInputStream objIn = new DroolsObjectInputStream( new ByteArrayInputStream( data.toByteArray() ) );
+ ObjectInput objIn = new DroolsObjectInputStream( new ByteArrayInputStream( data.toByteArray() ) );
Package pkg2 = (Package) objIn.readObject();
assertNotNull( pkg2 );
@@ -1252,22 +1253,22 @@
assertFalse( pkg.getRuleFlows().containsKey( "1" ) );
}
-
+
public void testJaninoWithStaticImports() throws Exception {
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = ( JavaDialectConfiguration ) cfg.getDialectConfiguration( "java" );
javaConf.setCompiler( JavaDialectConfiguration.JANINO );
-
-
+
+
PackageBuilder bldr = new PackageBuilder(cfg);
bldr.addPackageFromDrl( new StringReader("package testBuilderPackageConfig \n import java.util.List") );
bldr.addPackageFromDrl( new StringReader("function void doSomething() {\n System.err.println(List.class.toString()); }"));
-
+
assertFalse(bldr.hasErrors());
-
+
}
-
+
class MockRuleFlow
implements
Process {
@@ -1293,7 +1294,7 @@
public String getVersion() {
return null;
}
-
+
public String getPackageName() {
return null;
}
@@ -1309,7 +1310,7 @@
public void setVersion(String version) {
}
-
+
public void setPackageName(String packageName) {
}
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -31,6 +31,8 @@
import org.drools.StatefulSession;
import org.drools.WorkingMemory;
import org.drools.common.InternalFactHandle;
+import org.drools.common.DroolsObjectOutputStream;
+import org.drools.common.DroolsObjectInputStream;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.rule.Package;
@@ -113,7 +115,7 @@
ruleBase.addPackage( pkg3 );
// Package 3 has a rule working on Person instances.
- // As we added person instance in advance, rule should fire now
+ // As we added person instance in advance, rule should fire now
Assert.assertEquals( "Rule from package 3 should have been fired",
"match Person ok",
@@ -199,7 +201,7 @@
"like cheese" );
// reteooRuleBase.removeRule( "org.drools.test",
- // "like cheese2" );
+ // "like cheese2" );
final Cheese muzzarela = new Cheese( "muzzarela",
5 );
@@ -542,7 +544,7 @@
public void testDynamicRulesAddRemove() {
try {
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
+
PackageBuilder tomBuilder = new PackageBuilder();
tomBuilder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DynamicRulesTom.drl" ) ) );
ruleBase.addPackage( tomBuilder.getPackage() );
@@ -550,7 +552,7 @@
StatefulSession session = ruleBase.newStatefulSession();
List results = new ArrayList();
session.setGlobal( "results", results );
-
+
InternalFactHandle h1 = (InternalFactHandle) session.insert( new Person( "tom", 1 ) );
InternalFactHandle h2 = (InternalFactHandle) session.insert( new Person( "fred", 2 ) );
InternalFactHandle h3 = (InternalFactHandle) session.insert( new Person( "harry", 3 ) );
@@ -561,9 +563,9 @@
InternalFactHandle h8 = (InternalFactHandle) session.insert( new Person( "jill", 8 ) );
InternalFactHandle h9 = (InternalFactHandle) session.insert( new Person( "ed", 9 ) );
InternalFactHandle h10 = (InternalFactHandle) session.insert( new Person( "tom", 10 ) );
-
+
session.fireAllRules();
-
+
assertEquals( 3, results.size() );
assertTrue( results.contains( h1.getObject() ) );
assertTrue( results.contains( h6.getObject() ) );
@@ -593,7 +595,7 @@
((Person) h3.getObject()).setName( "ed" );
session.update( h3, h3.getObject() );
session.fireAllRules();
-
+
assertEquals( 1, results.size() );
assertTrue( results.contains( h3.getObject() ) );
} catch( Exception e ) {
@@ -622,25 +624,25 @@
final List list = new ArrayList();
workingMemory.setGlobal( "results",
list );
-
+
Order order = new Order();
-
+
OrderItem item1 = new OrderItem(order, 1, "Adventure Guide Brazil", OrderItem.TYPE_BOOK, 24);
order.addItem(item1);
workingMemory.insert(item1);
-
+
OrderItem item2 = new OrderItem(order, 2, "Prehistoric Britain", OrderItem.TYPE_BOOK, 15);
order.addItem(item2);
workingMemory.insert(item2);
-
+
OrderItem item3 = new OrderItem(order, 3, "Holiday Music", OrderItem.TYPE_CD, 9);
order.addItem(item3);
workingMemory.insert(item3);
-
+
OrderItem item4 = new OrderItem(order, 4, "Very Best of Mick Jagger", OrderItem.TYPE_CD, 11);
order.addItem(item4);
workingMemory.insert(item4);
-
+
workingMemory.insert(order);
assertEquals( 11,
@@ -723,19 +725,19 @@
workingMemory.setGlobal( "results", results );
Order order = new Order();
-
+
OrderItem item1 = new OrderItem(order, 1, "Adventure Guide Brazil", OrderItem.TYPE_BOOK, 24);
OrderItem item2 = new OrderItem(order, 2, "Prehistoric Britain", OrderItem.TYPE_BOOK, 15);
OrderItem item3 = new OrderItem(order, 3, "Holiday Music", OrderItem.TYPE_CD, 9);
OrderItem item4 = new OrderItem(order, 4, "Very Best of Mick Jagger", OrderItem.TYPE_CD, 11);
OrderItem item5 = new OrderItem(order, 5, "The Master and Margarita", OrderItem.TYPE_BOOK, 29);
-
+
order.addItem( item1 );
order.addItem( item2 );
order.addItem( item3 );
order.addItem( item4 );
order.addItem( item5 );
-
+
workingMemory.insert( order );
workingMemory.fireAllRules();
assertEquals( 1, results.size() );
@@ -789,7 +791,7 @@
}
}
-
+
public class SubvertedClassLoader extends URLClassLoader {
private static final long serialVersionUID = 400L;
@@ -828,7 +830,7 @@
protected Object serializeIn(final byte[] bytes) throws IOException,
ClassNotFoundException {
- final ObjectInput in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
+ final ObjectInput in = new DroolsObjectInputStream( new ByteArrayInputStream( bytes ) );
final Object obj = in.readObject();
in.close();
return obj;
@@ -837,7 +839,7 @@
protected byte[] serializeOut(final Object obj) throws IOException {
// Serialize to a byte array
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutput out = new ObjectOutputStream( bos );
+ final ObjectOutput out = new DroolsObjectOutputStream( bos );
out.writeObject( obj );
out.close();
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -7,6 +7,7 @@
import java.io.ObjectOutputStream;
import java.io.Reader;
import java.io.Serializable;
+import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -21,6 +22,7 @@
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.common.DroolsObjectInputStream;
+import org.drools.common.DroolsObjectOutputStream;
import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
@@ -38,7 +40,7 @@
// Bellow lines are a way to make sure serialization is fine
// start of serialization block
ByteArrayOutputStream out = new ByteArrayOutputStream();
- ObjectOutputStream obj = new ObjectOutputStream( out );
+ ObjectOutput obj = new DroolsObjectOutputStream( out );
obj.writeObject( ruleBase );
obj.close();
@@ -71,54 +73,54 @@
Date dt = DateUtils.parseDate( "10-Jul-1974" );
assertEquals(dt, c.getUsedBy());
}
-
+
public void testLocalVariableMVELConsequence() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LocalVariableMVELConsequence.drl" ) ) );
final Package pkg = builder.getPackage();
-
+
final RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
-
+
final List list = new ArrayList();
workingMemory.setGlobal( "results",
list );
-
+
workingMemory.insert( new Person( "bob", "stilton" ) );
workingMemory.insert( new Person( "mark", "brie" ) );
-
+
try {
workingMemory.fireAllRules();
-
- assertEquals( "should have fired twice",
+
+ assertEquals( "should have fired twice",
2,
list.size() );
-
+
} catch (Exception e) {
e.printStackTrace();
fail( "Should not raise any exception");
}
-
- }
+ }
+
public void testDuplicateLocalVariableMVELConsequence() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DuplicateLocalVariableMVELConsequence.drl" ) ) );
-
+
try {
final Package pkg = builder.getPackage();
-
+
final RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
-
+
fail( "Should have raised exception because of the duplicate variable definition");
} catch (Exception e) {
// success
}
-
- }
+ }
+
public Object compiledExecute(String ex) {
Serializable compiled = MVEL.compileExpression(ex);
return MVEL.executeExpression(compiled, new Object(), new HashMap());
Modified: labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2008-03-06 14:02:03 UTC (rev 18729)
+++ labs/jbossrules/branches/ming-serialization/drools-compiler/src/test/java/org/drools/integrationtests/MarshallingTest.java 2008-03-06 14:25:50 UTC (rev 18730)
@@ -23,6 +23,8 @@
import org.drools.StatefulSession;
import org.drools.WorkingMemory;
import org.drools.common.InternalFactHandle;
+import org.drools.common.DroolsObjectInputStream;
+import org.drools.common.DroolsObjectOutputStream;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
import org.drools.rule.Rule;
@@ -184,7 +186,7 @@
assertEquals( 0,
builder.getErrors().getErrors().length );
- RuleBase ruleBase = getRuleBase();// RuleBaseFactory.newRuleBase();
+ RuleBase ruleBase = getRuleBase();// RuleBaseFactory.newRuleBase();
// serialise a hashmap with the RuleBase as a key
Map map = new HashMap();
@@ -326,49 +328,49 @@
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
Package pkg = serialisePackage( builder.getPackage() );
ruleBase.addPackage( pkg );
-
+
StatefulSession session = ruleBase.newStatefulSession();
List list = new ArrayList();
session.setGlobal( "list", list );
-
+
InternalFactHandle stilton = (InternalFactHandle) session.insert( new Cheese( "stilton", 10 ) );
InternalFactHandle brie = (InternalFactHandle) session.insert( new Cheese( "brie", 10 ) );
session.fireAllRules();
-
+
assertEquals( list.size(), 1 );
assertEquals( "stilton", list.get( 0 ));
-
+
byte[] serializedSession = serializeOut( session );
session.dispose();
-
+
byte[] serializedRulebase = serializeOut( ruleBase );
-
+
// now recreate the rulebase, deserialize the session and test it
ruleBase = (RuleBase) serializeIn( serializedRulebase );
-
+
session = ruleBase.newStatefulSession( new ByteArrayInputStream( serializedSession ) );
list = (List) session.getGlobal( "list" );
-
+
assertNotNull( list );
assertEquals( list.size(), 1 );
assertEquals( "stilton", list.get( 0 ));
-
+
builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic3.drl" ) ) );
pkg = serialisePackage( builder.getPackage() );
ruleBase.addPackage( pkg );
-
+
InternalFactHandle stilton2 = (InternalFactHandle) session.insert( new Cheese( "stilton", 10 ) );
InternalFactHandle brie2 = (InternalFactHandle) session.insert( new Cheese( "brie", 10 ) );
InternalFactHandle bob = (InternalFactHandle) session.insert( new Person( "bob", 30 ) );
session.fireAllRules();
-
+
assertEquals( list.size(), 3 );
assertEquals( bob.getObject(), list.get( 1 ));
assertEquals( "stilton", list.get( 2 ));
-
+
session.dispose();
-
+
}
public void testSerializationOfIndexedWM() throws Exception {
@@ -446,7 +448,7 @@
return RuleBaseFactory.newRuleBase( RuleBase.RETEOO,
config );
}
-
+
protected Package serialisePackage(Package pkg) {
try {
byte[] bytes = serializeOut( pkg );
@@ -455,11 +457,11 @@
throw new RuntimeException( "trouble serialising package.",
e );
}
- }
+ }
protected Object serializeIn(final byte[] bytes) throws IOException,
ClassNotFoundException {
- final ObjectInput in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
+ final ObjectInput in = new DroolsObjectInputStream( new ByteArrayInputStream( bytes ) );
final Object obj = in.readObject();
in.close();
return obj;
@@ -468,7 +470,7 @@
protected byte[] serializeOut(final Object obj) throws IOException {
// Serialize to a byte array
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ObjectOutput out = new ObjectOutputStream( bos );
+ final ObjectOutput out = new DroolsObjectOutputStream( bos );
out.writeObject( obj );
out.close();
More information about the jboss-svn-commits
mailing list