[jboss-svn-commits] JBL Code SVN: r15489 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 15 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 1 18:19:24 EDT 2007
Author: tirelli
Date: 2007-10-01 18:19:24 -0400 (Mon, 01 Oct 2007)
New Revision: 15489
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractor.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorCache.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorFactory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/MVELClassFieldExtractor.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/CompositePackageClassLoader.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/BaseClassFieldExtractorFactoryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/BooleanClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/DoubleClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/FloatClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/LongClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/MVELClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ObjectClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/DeclarationTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
Log:
JBRULES-1239: fixing classloaders to allow rulebase creation with different class loader hierarchies
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -60,6 +60,15 @@
private Map accumulateFunctions;
/**
+ * Constructor that sets the parent class loader for the package being built/compiled
+ * @param classLoader
+ */
+ public PackageBuilderConfiguration(ClassLoader classLoader ) {
+ init( classLoader,
+ null );
+ }
+
+ /**
* Programmatic properties file, added with lease precedence
* @param properties
*/
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -2,6 +2,8 @@
import java.io.InputStreamReader;
import java.io.Reader;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
@@ -17,8 +19,10 @@
import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.rule.Package;
public class DynamicRulesTest extends TestCase {
@@ -184,15 +188,15 @@
reteooRuleBase.removeRule( "org.drools.test",
"like cheese" );
-
-// reteooRuleBase.removeRule( "org.drools.test",
-// "like cheese2" );
+ // reteooRuleBase.removeRule( "org.drools.test",
+ // "like cheese2" );
+
final Cheese muzzarela = new Cheese( "muzzarela",
5 );
assertEquals( 8,
workingMemory.getAgenda().getActivations().length );
-
+
workingMemory.insert( muzzarela );
assertEquals( 9,
@@ -214,10 +218,10 @@
final Package pkg = builder.getPackage();
org.drools.reteoo.ReteooRuleBase reteooRuleBase = null;
-
+
final RuleBase ruleBase = getRuleBase();
reteooRuleBase = (org.drools.reteoo.ReteooRuleBase) ruleBase;
-
+
ruleBase.addPackage( pkg );
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
@@ -265,10 +269,11 @@
assertEquals( new Integer( 5 ),
list.get( 0 ) );
-
+
// Check a function can be removed from a package.
// Once removed any efforts to use it should throw an Exception
- ruleBase.removeFunction( "org.drools.test", "addFive" );
+ ruleBase.removeFunction( "org.drools.test",
+ "addFive" );
final Cheese cheddar = new Cheese( "cheddar",
5 );
@@ -321,7 +326,7 @@
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert( new Precondition( "genericcode",
- "genericvalue" ) );
+ "genericvalue" ) );
workingMemory.fireAllRules();
final RuleBase ruleBaseWM = workingMemory.getRuleBase();
@@ -399,4 +404,118 @@
ruleBase.removePackage( pkg.getName() );
}
+ public void testClassLoaderSwitchsUsingConf() throws Exception {
+ try {
+ // Creates first class loader and use it to load fact classes
+ ClassLoader loader1 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" ).toURI().toURL()},
+ this.getClass().getClassLoader() );
+ Class cheeseClass = loader1.loadClass( "org.drools.Cheese" );
+
+ PackageBuilderConfiguration conf = new PackageBuilderConfiguration( loader1 );
+ PackageBuilder builder = new PackageBuilder( conf );
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
+
+ // must set the classloader for rulebase conf too
+ RuleBaseConfiguration rbconf = new RuleBaseConfiguration( loader1 );
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase( rbconf );
+ Package pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ StatefulSession wm = ruleBase.newStatefulSession();
+ wm.insert( cheeseClass.newInstance() );
+ wm.fireAllRules();
+
+ // Creates second class loader and use it to load fact classes
+ ClassLoader loader2 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" ).toURI().toURL()},
+ this.getClass().getClassLoader() );
+ cheeseClass = loader2.loadClass( "org.drools.Cheese" );
+
+ conf = new PackageBuilderConfiguration( loader2 );
+ builder = new PackageBuilder( conf );
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
+
+ rbconf = new RuleBaseConfiguration( loader2 );
+ ruleBase = RuleBaseFactory.newRuleBase( rbconf );
+ pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ wm = ruleBase.newStatefulSession();
+ wm.insert( cheeseClass.newInstance() );
+ wm.fireAllRules();
+ } catch ( ClassCastException cce ) {
+ cce.printStackTrace();
+ fail( "No ClassCastException should be raised." );
+ }
+
+ }
+
+ public void testClassLoaderSwitchsUsingContext() throws Exception {
+ try {
+ // Creates first class loader and use it to load fact classes
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader1 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" ).toURI().toURL()},
+ this.getClass().getClassLoader() );
+ Thread.currentThread().setContextClassLoader( loader1 );
+ Class cheeseClass = loader1.loadClass( "org.drools.Cheese" );
+
+ PackageBuilder builder = new PackageBuilder( );
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
+
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ Package pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ StatefulSession wm = ruleBase.newStatefulSession();
+ wm.insert( cheeseClass.newInstance() );
+ wm.fireAllRules();
+
+ // Creates second class loader and use it to load fact classes
+ ClassLoader loader2 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" ).toURI().toURL()},
+ this.getClass().getClassLoader() );
+ Thread.currentThread().setContextClassLoader( loader2 );
+ cheeseClass = loader2.loadClass( "org.drools.Cheese" );
+
+ builder = new PackageBuilder( );
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
+
+ ruleBase = RuleBaseFactory.newRuleBase();
+ pkg = builder.getPackage();
+ ruleBase.addPackage( pkg );
+
+ wm = ruleBase.newStatefulSession();
+ wm.insert( cheeseClass.newInstance() );
+ wm.fireAllRules();
+
+ Thread.currentThread().setContextClassLoader( original );
+ } catch ( ClassCastException cce ) {
+ cce.printStackTrace();
+ fail( "No ClassCastException should be raised." );
+ }
+ }
+
+ public class SubvertedClassLoader extends URLClassLoader {
+
+ private static final long serialVersionUID = 400L;
+
+ public SubvertedClassLoader(final URL[] urls,
+ final ClassLoader parentClassLoader) {
+ super( urls,
+ parentClassLoader );
+ }
+
+ protected synchronized Class loadClass(String name,
+ boolean resolve) throws ClassNotFoundException {
+ // First, check if the class has already been loaded
+ Class c = findLoadedClass( name );
+ if ( c == null ) {
+ try {
+ c = findClass( name );
+ } catch( ClassNotFoundException e ) {
+ c = super.loadClass( name, resolve );
+ }
+ }
+ return c;
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/java/AccumulateTemplateTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -21,8 +21,11 @@
public class AccumulateTemplateTest extends TestCase {
+ private ClassFieldExtractorCache cache;
+
protected void setUp() throws Exception {
super.setUp();
+ cache = ClassFieldExtractorCache.getInstance();
}
protected void tearDown() throws Exception {
@@ -41,9 +44,9 @@
final Declaration[] inner = new Declaration[]{new Declaration( "cheese",
new PatternExtractor( new ClassObjectType( Cheese.class ) ),
null ), new Declaration( "price",
- ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() ),
+ cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() ),
null )};
final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
@@ -115,20 +118,20 @@
final String[] declarationTypes = new String[]{"String", "int"};
final Declaration[] declarations = new Declaration[]{new Declaration( "name",
- ClassFieldExtractorCache.getExtractor( Person.class,
- "name",
- getClass().getClassLoader() ),
+ cache.getExtractor( Person.class,
+ "name",
+ getClass().getClassLoader() ),
null ), new Declaration( "age",
- ClassFieldExtractorCache.getExtractor( Person.class,
- "age",
- getClass().getClassLoader() ),
+ cache.getExtractor( Person.class,
+ "age",
+ getClass().getClassLoader() ),
null )};
final Declaration[] inner = new Declaration[]{new Declaration( "cheese",
new PatternExtractor( new ClassObjectType( Cheese.class ) ),
null ), new Declaration( "price",
- ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() ),
+ cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() ),
null )};
final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
@@ -185,7 +188,8 @@
map.put( "hashCode",
new Integer( 10 ) );
- map.put( "isMultiPattern", Boolean.FALSE );
+ map.put( "isMultiPattern",
+ Boolean.FALSE );
TemplateRegistry registry = getInvokerTemplateRegistry();
Object method = TemplateInterpreter.parse( registry.getTemplate( "accumulateInvoker" ),
@@ -201,19 +205,19 @@
final String[] declarationTypes = new String[]{"String", "int"};
final Declaration[] declarations = new Declaration[]{new Declaration( "name",
- ClassFieldExtractorCache.getExtractor( Person.class,
- "name",
- getClass().getClassLoader() ),
+ cache.getExtractor( Person.class,
+ "name",
+ getClass().getClassLoader() ),
null ), new Declaration( "age",
- ClassFieldExtractorCache.getExtractor( Person.class,
- "age",
- getClass().getClassLoader() ),
+ cache.getExtractor( Person.class,
+ "age",
+ getClass().getClassLoader() ),
null )};
final Declaration[] inner = new Declaration[]{new Declaration( "$cheese",
new PatternExtractor( new ClassObjectType( Cheese.class ) ),
null ), new Declaration( "$person",
- new PatternExtractor( new ClassObjectType ( Person.class ) ),
- null ) };
+ new PatternExtractor( new ClassObjectType( Person.class ) ),
+ null )};
final String[] globals = new String[]{"aGlobal", "anotherGlobal"};
final List globalTypes = Arrays.asList( new String[]{"String", "String"} );
@@ -269,7 +273,8 @@
map.put( "hashCode",
new Integer( 10 ) );
- map.put( "isMultiPattern", Boolean.TRUE );
+ map.put( "isMultiPattern",
+ Boolean.TRUE );
TemplateRegistry registry = getInvokerTemplateRegistry();
Object method = TemplateInterpreter.parse( registry.getTemplate( "accumulateInvoker" ),
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilderTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -13,7 +13,6 @@
import org.drools.base.ClassObjectType;
import org.drools.common.InternalFactHandle;
import org.drools.compiler.DialectConfiguration;
-import org.drools.compiler.DialectRegistry;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.lang.descr.EvalDescr;
@@ -27,16 +26,19 @@
public class MVELEvalBuilderTest extends TestCase {
+ private ClassFieldExtractorCache cache;
+
public void setUp() {
+ cache = ClassFieldExtractorCache.getInstance();
}
public void testSimpleExpression() {
final Package pkg = new Package( "pkg1" );
final RuleDescr ruleDescr = new RuleDescr( "rule 1" );
-
+
PackageBuilder pkgBuilder = new PackageBuilder( pkg );
final PackageBuilderConfiguration conf = pkgBuilder.getPackageBuilderConfiguration();
- MVELDialect mvelDialect = ( MVELDialect ) ( (DialectConfiguration) conf.getDialectConfiguration( "mvel" ) ).getDialect();
+ MVELDialect mvelDialect = (MVELDialect) ((DialectConfiguration) conf.getDialectConfiguration( "mvel" )).getDialect();
final InstrumentedBuildContent context = new InstrumentedBuildContent( conf,
pkg,
@@ -45,10 +47,11 @@
mvelDialect );
final InstrumentedDeclarationScopeResolver declarationResolver = new InstrumentedDeclarationScopeResolver();
-
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class, "price",
- getClass().getClassLoader() );
-
+
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
+
final Pattern pattern = new Pattern( 0,
new ClassObjectType( int.class ) );
final Declaration declaration = new Declaration( "a",
@@ -80,7 +83,7 @@
cheddar.setPrice( 9 );
wm.update( f0,
- cheddar );
+ cheddar );
assertFalse( eval.isAllowed( tuple,
wm ) );
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilderTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -15,7 +15,6 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.compiler.DialectConfiguration;
-import org.drools.compiler.DialectRegistry;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.lang.descr.PredicateDescr;
@@ -30,6 +29,8 @@
public class MVELPredicateBuilderTest extends TestCase {
+ private ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+
public void setUp() {
}
@@ -39,23 +40,24 @@
PackageBuilder pkgBuilder = new PackageBuilder( pkg );
final PackageBuilderConfiguration conf = pkgBuilder.getPackageBuilderConfiguration();
- MVELDialect mvelDialect = ( MVELDialect ) ( (DialectConfiguration) conf.getDialectConfiguration( "mvel" ) ).getDialect();
+ MVELDialect mvelDialect = (MVELDialect) ((DialectConfiguration) conf.getDialectConfiguration( "mvel" )).getDialect();
final InstrumentedBuildContent context = new InstrumentedBuildContent( conf,
pkg,
ruleDescr,
conf.getDialectRegistry(),
mvelDialect );
-
+
final InstrumentedDeclarationScopeResolver declarationResolver = new InstrumentedDeclarationScopeResolver();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class, "price",
- getClass().getClassLoader() );
-
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
+
final Pattern patternA = new Pattern( 0,
- new ClassObjectType( int.class ) );
+ new ClassObjectType( Cheese.class ) );
final Pattern patternB = new Pattern( 1,
- new ClassObjectType( int.class ) );
+ new ClassObjectType( Cheese.class ) );
final Declaration a = new Declaration( "a",
extractor,
@@ -113,7 +115,7 @@
cheddar.setPrice( 9 );
wm.update( f0,
- cheddar );
+ cheddar );
assertFalse( predicate.isAllowedCachedLeft( predicateContext,
stilton ) );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilderTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -17,7 +17,6 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.compiler.DialectConfiguration;
-import org.drools.compiler.DialectRegistry;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.lang.descr.ReturnValueRestrictionDescr;
@@ -27,12 +26,14 @@
import org.drools.rule.Package;
import org.drools.rule.Pattern;
import org.drools.rule.ReturnValueRestriction;
-import org.drools.rule.PredicateConstraint.PredicateContextEntry;
import org.drools.spi.FieldExtractor;
public class MVELReturnValueBuilderTest extends TestCase {
+
+ private ClassFieldExtractorCache cache;
public void setUp() {
+ cache = ClassFieldExtractorCache.getInstance();
}
public void testSimpleExpression() {
@@ -50,7 +51,7 @@
mvelDialect );
final InstrumentedDeclarationScopeResolver declarationResolver = new InstrumentedDeclarationScopeResolver();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class, "price",
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class, "price",
getClass().getClassLoader() );
final Pattern patternA = new Pattern( 0,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -98,17 +98,74 @@
private Map shadowProxyExcludes;
private static final String STAR = "*";
+ private transient ClassLoader classLoader;
+
+ /**
+ * Creates a new rulebase configuration using the provided properties
+ * as configuration options. Also, if a Thread.currentThread().getContextClassLoader()
+ * returns a non-null class loader, it will be used as the parent classloader
+ * for this rulebase class loaders, otherwise, the RuleBaseConfiguration.class.getClassLoader()
+ * class loader will be used.
+ *
+ * @param properties
+ */
public RuleBaseConfiguration(Properties properties) {
- init( properties );
+ init( null,
+ properties );
}
+ /**
+ * Creates a new rulebase with a default parent class loader set according
+ * to the following algorithm:
+ *
+ * If a Thread.currentThread().getContextClassLoader() returns a non-null class loader,
+ * it will be used as the parent class loader for this rulebase class loaders, otherwise,
+ * the RuleBaseConfiguration.class.getClassLoader() class loader will be used.
+ *
+ * @param properties
+ */
public RuleBaseConfiguration() {
- init( null );
+ init( null,
+ null );
}
- private void init(Properties properties) {
+ /**
+ * A constructor that sets the parent classloader to be used
+ * while dealing with this rule base
+ *
+ * @param classLoader
+ */
+ public RuleBaseConfiguration(ClassLoader classLoader) {
+ init( classLoader,
+ null );
+ }
+
+ /**
+ * A constructor that sets the classloader to be used as the parent classloader
+ * of this rule base classloaders, and the properties to be used
+ * as base configuration options
+ *
+ * @param classLoder
+ * @param properties
+ */
+ public RuleBaseConfiguration(ClassLoader classLoder,
+ Properties properties) {
+ init( classLoader,
+ properties );
+ }
+
+ private void init(ClassLoader classLoader,
+ Properties properties) {
this.immutable = false;
+ if ( classLoader != null ) {
+ this.classLoader = classLoader;
+ } else if ( Thread.currentThread().getContextClassLoader() != null ) {
+ this.classLoader = Thread.currentThread().getContextClassLoader();
+ } else {
+ this.classLoader = this.getClass().getClassLoader();
+ }
+
this.chainedProperties = new ChainedProperties( "rulebase.conf" );
if ( properties != null ) {
@@ -161,7 +218,6 @@
setConflictResolver( RuleBaseConfiguration.determineConflictResolver( this.chainedProperties.getProperty( "drools.conflictResolver",
"org.drools.conflict.DepthConflictResolver" ) ) );
-
setShadowProxy( determineShadowProxy( this.chainedProperties.getProperty( "drools.shadowproxy",
null ) ) );
@@ -401,6 +457,14 @@
return this.shadowProxy;
}
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
public void setShadowProxyExcludes(String excludes) {
checkCanChange(); // throws an exception if a change isn't possible;
if ( excludes == null || "".equals( excludes.trim() ) ) {
@@ -616,4 +680,5 @@
return "SequentialAgenda : " + ((this.value == 0) ? "sequential" : "dynamic");
}
}
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractor.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractor.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -18,9 +18,11 @@
import java.io.IOException;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import org.drools.RuntimeDroolsException;
+import org.drools.common.DroolsObjectInputStream;
import org.drools.common.InternalWorkingMemory;
import org.drools.spi.FieldExtractor;
import org.drools.util.ClassUtils;
@@ -44,40 +46,69 @@
private String fieldName;
private Class clazz;
private transient FieldExtractor extractor;
-
+
public ClassFieldExtractor(final Class clazz,
final String fieldName) {
- this( clazz, fieldName, null );
+ this( clazz,
+ fieldName,
+ clazz.getClassLoader() );
}
public ClassFieldExtractor(final Class clazz,
final String fieldName,
final ClassLoader classLoader) {
+ this( clazz,
+ fieldName,
+ classLoader == null ? clazz.getClassLoader() : classLoader,
+ new ClassFieldExtractorFactory() );
+ }
+
+ public ClassFieldExtractor(final Class clazz,
+ final String fieldName,
+ final ClassLoader classLoader,
+ final ClassFieldExtractorFactory factory) {
this.clazz = clazz;
this.fieldName = fieldName;
- init(classLoader);
+ init( classLoader,
+ factory );
}
+ private void writeObject(ObjectOutputStream s) throws IOException {
+ // Call even if there is no default serializable fields.
+ s.defaultWriteObject();
+ }
+
private void readObject(final ObjectInputStream is) throws ClassNotFoundException,
IOException,
Exception {
//always perform the default de-serialization first
is.defaultReadObject();
-
- // do not create the extractor yet, readResolver will do this, as it stops duplicate bytecode generation.
+ if ( is instanceof DroolsObjectInputStream ) {
+ DroolsObjectInputStream dois = (DroolsObjectInputStream) is;
+ this.extractor = dois.getExtractorFactory().getExtractor( this.clazz,
+ this.fieldName,
+ dois.getClassLoader() );
+ } else {
+ this.extractor = ClassFieldExtractorCache.getInstance().getExtractor( this.clazz,
+ this.fieldName,
+ this.clazz.getClassLoader() );
+
+ }
}
-
-
- private Object readResolve() {
- // always return the value from the cache
- return ClassFieldExtractorCache.getExtractor( this.clazz, this.fieldName, this.clazz.getClassLoader() );
- }
- public void init(final ClassLoader classLoader) {
+// private Object readResolve() {
+// // always return the value from the cache
+// return ClassFieldExtractorCache.getInstance().getExtractor( this.clazz,
+// this.fieldName,
+// this.clazz.getClassLoader() );
+// }
+
+ private void init(final ClassLoader classLoader,
+ final ClassFieldExtractorFactory factory) {
try {
- this.extractor = ClassFieldExtractorFactory.getClassFieldExtractor( this.clazz,
- this.fieldName,
- classLoader );
+ this.extractor = factory.getClassFieldExtractor( this.clazz,
+ this.fieldName,
+ classLoader );
} catch ( final Exception e ) {
throw new RuntimeDroolsException( e );
}
@@ -91,8 +122,10 @@
return this.fieldName;
}
- public Object getValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getValue( workingMemory, object );
+ public Object getValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getValue( workingMemory,
+ object );
}
public ValueType getValueType() {
@@ -129,48 +162,68 @@
return this.extractor.getValueType() == other.getValueType() && this.extractor.getIndex() == other.getIndex();
}
- public boolean getBooleanValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getBooleanValue( workingMemory, object );
+ public boolean getBooleanValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getBooleanValue( workingMemory,
+ object );
}
- public byte getByteValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getByteValue( workingMemory, object );
+ public byte getByteValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getByteValue( workingMemory,
+ object );
}
- public char getCharValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getCharValue( workingMemory, object );
+ public char getCharValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getCharValue( workingMemory,
+ object );
}
- public double getDoubleValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getDoubleValue( workingMemory, object );
+ public double getDoubleValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getDoubleValue( workingMemory,
+ object );
}
- public float getFloatValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getFloatValue( workingMemory, object );
+ public float getFloatValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getFloatValue( workingMemory,
+ object );
}
- public int getIntValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getIntValue( workingMemory, object );
+ public int getIntValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getIntValue( workingMemory,
+ object );
}
- public long getLongValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getLongValue( workingMemory, object );
+ public long getLongValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getLongValue( workingMemory,
+ object );
}
- public short getShortValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getShortValue( workingMemory, object );
+ public short getShortValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getShortValue( workingMemory,
+ object );
}
-
- public boolean isNullValue(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.isNullValue( workingMemory, object );
+
+ public boolean isNullValue(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.isNullValue( workingMemory,
+ object );
}
-
+
public Method getNativeReadMethod() {
return this.extractor.getNativeReadMethod();
}
- public int getHashCode(InternalWorkingMemory workingMemory, final Object object) {
- return this.extractor.getHashCode( workingMemory, object );
+ public int getHashCode(InternalWorkingMemory workingMemory,
+ final Object object) {
+ return this.extractor.getHashCode( workingMemory,
+ object );
}
public boolean isGlobal() {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorCache.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorCache.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorCache.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -1,5 +1,6 @@
package org.drools.base;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -13,32 +14,94 @@
*
*/
public class ClassFieldExtractorCache {
- private static ClassFieldExtractorCache instance = new ClassFieldExtractorCache();
- private static Map cache;
+ private static final ClassFieldExtractorCache INSTANCE = new ClassFieldExtractorCache();
+ private Map cache;
+ private ClassFieldExtractorFactory factory;
+
+ private ClassFieldExtractorCache() {
+ this.factory = new ClassFieldExtractorFactory();
+ }
+
public static ClassFieldExtractorCache getInstance() {
- return instance;
+ //return INSTANCE;
+ return new ClassFieldExtractorCache();
}
- public synchronized static ClassFieldExtractor getExtractor(final Class clazz,
- final String fieldName,
- ClassLoader classLoader) {
+ public synchronized ClassFieldExtractor getExtractor(final Class clazz,
+ final String fieldName,
+ ClassLoader classLoader) {
if ( cache == null ) {
cache = new HashMap();
}
- final String key = clazz.getName() + "|" + fieldName;
+ final ExtractorKey key = new ExtractorKey( clazz,
+ fieldName );
if ( cache.containsKey( key ) ) {
return (ClassFieldExtractor) cache.get( key );
} else {
final ClassFieldExtractor ex = new ClassFieldExtractor( clazz,
fieldName,
- classLoader );
+ classLoader,
+ factory );
cache.put( key,
ex );
return ex;
}
}
+ private static class ExtractorKey
+ implements
+ Serializable {
+ private static final long serialVersionUID = 400;
+
+ private final Class clazz;
+ private final String fieldName;
+ private final int hashCode;
+
+ public ExtractorKey(Class clazz,
+ String fieldName) {
+ super();
+ this.clazz = clazz;
+ this.fieldName = fieldName;
+
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((clazz == null) ? 0 : clazz.hashCode());
+ result = PRIME * result + ((fieldName == null) ? 0 : fieldName.hashCode());
+ this.hashCode = result;
+ }
+
+ public Class getClazz() {
+ return clazz;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final ExtractorKey other = (ExtractorKey) obj;
+ if ( clazz == null ) {
+ if ( other.clazz != null ) return false;
+ } else if ( !clazz.equals( other.clazz ) ) return false;
+ if ( fieldName == null ) {
+ if ( other.fieldName != null ) return false;
+ } else if ( !fieldName.equals( other.fieldName ) ) return false;
+ return true;
+ }
+
+ public String toString() {
+ return this.clazz + "@" + Math.abs( System.identityHashCode( this.clazz ) ) + "(" + this.fieldName + ")";
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorFactory.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassFieldExtractorFactory.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -60,10 +60,10 @@
private static final ProtectionDomain PROTECTION_DOMAIN;
- private static final Map inspectors = new HashMap();
-
- private static ByteArrayClassLoader byteArrayClassLoader;
+ private final Map inspectors = new HashMap();
+ private ByteArrayClassLoader byteArrayClassLoader;
+
static {
PROTECTION_DOMAIN = (ProtectionDomain) AccessController.doPrivileged( new PrivilegedAction() {
public Object run() {
@@ -72,14 +72,14 @@
} );
}
- public static BaseClassFieldExtractor getClassFieldExtractor(final Class clazz,
- final String fieldName,
- final ClassLoader classLoader) {
- if ( byteArrayClassLoader == null ) {
- if (classLoader == null ) {
- throw new RuntimeDroolsException("ClassFieldExtractorFactory cannot have a null parent ClassLoader" );
- }
- byteArrayClassLoader = new ByteArrayClassLoader( classLoader );
+ public BaseClassFieldExtractor getClassFieldExtractor(final Class clazz,
+ final String fieldName,
+ final ClassLoader classLoader) {
+ if ( byteArrayClassLoader == null || byteArrayClassLoader.getParent() != classLoader ) {
+ if ( classLoader == null ) {
+ throw new RuntimeDroolsException( "ClassFieldExtractorFactory cannot have a null parent ClassLoader" );
+ }
+ byteArrayClassLoader = new ByteArrayClassLoader( classLoader );
}
try {
// if it is a self reference
@@ -87,7 +87,7 @@
// then just create an instance of the special class field extractor
return new SelfReferenceClassFieldExtractor( clazz,
fieldName );
- } else if( fieldName.indexOf( '.' ) > -1 || fieldName.indexOf( '[' ) > -1 ) {
+ } else if ( fieldName.indexOf( '.' ) > -1 || fieldName.indexOf( '[' ) > -1 ) {
// we need MVEL extractor for expressions
return new MVELClassFieldExtractor( clazz,
fieldName,
@@ -102,8 +102,8 @@
}
final Class fieldType = (Class) inspector.getFieldTypes().get( fieldName );
final Method getterMethod = (Method) inspector.getGetterMethods().get( fieldName );
- if( fieldType != null && getterMethod != null ) {
- final String className = ClassFieldExtractorFactory.BASE_PACKAGE + "/" + Type.getInternalName( clazz ) + "$" + getterMethod.getName();
+ if ( fieldType != null && getterMethod != null ) {
+ final String className = ClassFieldExtractorFactory.BASE_PACKAGE + "/" + Type.getInternalName( clazz ) + Math.abs( System.identityHashCode( clazz ) ) + "$" + getterMethod.getName();
// generating byte array to create target class
final byte[] bytes = dump( clazz,
@@ -123,7 +123,7 @@
final Object[] params = {index, fieldType, valueType};
return (BaseClassFieldExtractor) newClass.getConstructors()[0].newInstance( params );
} else {
- throw new RuntimeDroolsException("Field/method '"+fieldName+"' not found for class '"+clazz.getName()+"'" );
+ throw new RuntimeDroolsException( "Field/method '" + fieldName + "' not found for class '" + clazz.getName() + "'" );
}
}
} catch ( final RuntimeDroolsException e ) {
@@ -133,11 +133,11 @@
}
}
- private static byte[] dump(final Class originalClass,
- final String className,
- final Method getterMethod,
- final Class fieldType,
- final boolean isInterface) throws Exception {
+ private byte[] dump(final Class originalClass,
+ final String className,
+ final Method getterMethod,
+ final Class fieldType,
+ final boolean isInterface) throws Exception {
final ClassWriter cw = new ClassWriter( true );
@@ -172,9 +172,9 @@
* @param className The extractor class name
* @param cw
*/
- protected static void buildClassHeader(final Class superClass,
- final String className,
- final ClassWriter cw) {
+ protected void buildClassHeader(final Class superClass,
+ final String className,
+ final ClassWriter cw) {
cw.visit( Opcodes.V1_2,
Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
className,
@@ -256,9 +256,9 @@
* @param className
* @param cw
*/
- private static void build3ArgConstructor(final Class superClazz,
- final String className,
- final ClassWriter cw) {
+ private void build3ArgConstructor(final Class superClazz,
+ final String className,
+ final ClassWriter cw) {
MethodVisitor mv;
{
mv = cw.visitMethod( Opcodes.ACC_PUBLIC,
@@ -326,11 +326,11 @@
* @param method
* @param cw
*/
- protected static void buildGetMethod(final Class originalClass,
- final String className,
- final Class superClass,
- final Method getterMethod,
- final ClassWriter cw) {
+ protected void buildGetMethod(final Class originalClass,
+ final String className,
+ final Class superClass,
+ final Method getterMethod,
+ final ClassWriter cw) {
final Class fieldType = getterMethod.getReturnType();
Method overridingMethod;
@@ -393,7 +393,7 @@
mv.visitEnd();
}
- private static String getOverridingMethodName(final Class fieldType) {
+ private String getOverridingMethodName(final Class fieldType) {
String ret = null;
if ( fieldType.isPrimitive() ) {
if ( fieldType == char.class ) {
@@ -426,7 +426,7 @@
* @param fieldType
* @return
*/
- private static Class getSuperClassFor(final Class fieldType) {
+ private Class getSuperClassFor(final Class fieldType) {
Class ret = null;
if ( fieldType.isPrimitive() ) {
if ( fieldType == char.class ) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/MVELClassFieldExtractor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/MVELClassFieldExtractor.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/MVELClassFieldExtractor.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -23,7 +23,6 @@
import java.util.Set;
import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.ValueType;
import org.drools.common.InternalWorkingMemory;
import org.drools.spi.Extractor;
@@ -62,7 +61,7 @@
for( Iterator it = inputs.iterator(); it.hasNext(); ) {
String basefield = (String) it.next();
- Extractor extr = ClassFieldExtractorCache.getExtractor( clazz, basefield, classLoader );
+ Extractor extr = ClassFieldExtractorCache.getInstance().getExtractor( clazz, basefield, classLoader );
this.extractors.put( basefield, extr );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractRuleBase.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -132,8 +132,8 @@
this.agendaGroupRuleTotals = new HashMap();
}
- this.packageClassLoader = new CompositePackageClassLoader( Thread.currentThread().getContextClassLoader() );
- this.classLoader = new MapBackedClassLoader( Thread.currentThread().getContextClassLoader() );
+ this.packageClassLoader = new CompositePackageClassLoader( this.config.getClassLoader() );
+ this.classLoader = new MapBackedClassLoader( this.config.getClassLoader() );
this.packageClassLoader.addClassLoader( this.classLoader );
this.pkgs = new HashMap();
this.processes = new HashMap();
@@ -216,6 +216,7 @@
this.globals = (Map) childStream.readObject();
this.config = (RuleBaseConfiguration) childStream.readObject();
+ this.config.setClassLoader( childStream.getClassLoader() );
this.eventSupport = (RuleBaseEventSupport) childStream.readObject();
this.statefulSessions = new ObjectHashSet();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -8,17 +8,20 @@
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.util.HashMap;
+
+import org.drools.base.ClassFieldExtractorCache;
import org.drools.rule.Package;
public class DroolsObjectInputStream extends ObjectInputStream {
- private final ClassLoader classLoader;
- private InternalRuleBase ruleBase;
- private InternalWorkingMemory workingMemory;
- private Package pkg;
+ private final ClassLoader classLoader;
+ private InternalRuleBase ruleBase;
+ private InternalWorkingMemory workingMemory;
+ private Package pkg;
+ private ClassFieldExtractorCache extractorFactory;
/** table mapping primitive type names to corresponding class objects */
- private static final HashMap primClasses = new HashMap( 8,
- 1.0F );
+ private static final HashMap primClasses = new HashMap( 8,
+ 1.0F );
static {
primClasses.put( "boolean",
boolean.class );
@@ -39,10 +42,11 @@
primClasses.put( "void",
void.class );
}
-
+
public DroolsObjectInputStream(final InputStream in) throws IOException {
- this( in, null );
- }
+ this( in,
+ null );
+ }
public DroolsObjectInputStream(final InputStream in,
ClassLoader classLoader) throws IOException {
@@ -52,9 +56,10 @@
if ( classLoader == null ) {
classLoader = this.getClass().getClassLoader();
}
- }
-
+ }
+
this.classLoader = classLoader;
+ this.extractorFactory = ClassFieldExtractorCache.getInstance();
enableResolveObject( true );
}
@@ -82,7 +87,7 @@
public InternalRuleBase getRuleBase() {
return ruleBase;
- }
+ }
public void setRuleBase(InternalRuleBase ruleBase) {
this.ruleBase = ruleBase;
@@ -96,14 +101,20 @@
return workingMemory;
}
- public Package getPackage() {
- return pkg;
- }
+ public Package getPackage() {
+ return pkg;
+ }
- public void setPackage(Package pkg) {
- this.pkg = pkg;
- }
-
-
+ public void setPackage(Package pkg) {
+ this.pkg = pkg;
+ }
+ public ClassFieldExtractorCache getExtractorFactory() {
+ return extractorFactory;
+ }
+
+ public void setExtractorFactory(ClassFieldExtractorCache extractorFactory) {
+ this.extractorFactory = extractorFactory;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/CompositePackageClassLoader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/CompositePackageClassLoader.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/CompositePackageClassLoader.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -4,8 +4,6 @@
import java.util.Iterator;
import java.util.List;
-import org.drools.rule.PackageCompilationData.PackageClassLoader;
-
public class CompositePackageClassLoader extends ClassLoader {
private final List classLoaders = new ArrayList();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PackageCompilationData.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -28,7 +28,6 @@
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -37,7 +36,6 @@
import org.drools.CheckedDroolsException;
import org.drools.RuntimeDroolsException;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.accumulators.JavaAccumulatorFunctionExecutor;
import org.drools.common.DroolsObjectInputStream;
import org.drools.spi.Accumulator;
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/BaseClassFieldExtractorFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/BaseClassFieldExtractorFactoryTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/BaseClassFieldExtractorFactoryTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -27,59 +27,74 @@
public class BaseClassFieldExtractorFactoryTest extends TestCase {
+ private ClassFieldExtractorCache cache;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ cache = ClassFieldExtractorCache.getInstance();
+ }
+
public void testIt() throws Exception {
- FieldExtractor ex = ClassFieldExtractorFactory.getClassFieldExtractor( TestBean.class,
- "name",
- Thread.currentThread().getContextClassLoader() );
+ ClassFieldExtractorFactory factory = new ClassFieldExtractorFactory();
+
+ FieldExtractor ex = factory.getClassFieldExtractor( TestBean.class,
+ "name",
+ Thread.currentThread().getContextClassLoader() );
assertEquals( 0,
ex.getIndex() );
assertEquals( "michael",
- ex.getValue( null, new TestBean() ) );
- ex = ClassFieldExtractorFactory.getClassFieldExtractor( TestBean.class,
- "age",
- Thread.currentThread().getContextClassLoader() );
+ ex.getValue( null,
+ new TestBean() ) );
+ ex = factory.getClassFieldExtractor( TestBean.class,
+ "age",
+ Thread.currentThread().getContextClassLoader() );
assertEquals( 1,
ex.getIndex() );
assertEquals( 42,
- ((Number) ex.getValue( null, new TestBean() )).intValue() );
+ ((Number) ex.getValue( null,
+ new TestBean() )).intValue() );
}
public void testInterface() throws Exception {
- final FieldExtractor ex = ClassFieldExtractorCache.getExtractor( TestInterface.class,
- "something",
- getClass().getClassLoader() );
+ final FieldExtractor ex = cache.getExtractor( TestInterface.class,
+ "something",
+ getClass().getClassLoader() );
assertEquals( 0,
ex.getIndex() );
assertEquals( "foo",
- ex.getValue( null, new TestInterfaceImpl() ) );
+ ex.getValue( null,
+ new TestInterfaceImpl() ) );
}
public void testAbstract() throws Exception {
- final FieldExtractor ex = ClassFieldExtractorCache.getExtractor( TestAbstract.class,
- "something",
- getClass().getClassLoader() );
+ final FieldExtractor ex = cache.getExtractor( TestAbstract.class,
+ "something",
+ getClass().getClassLoader() );
assertEquals( 0,
ex.getIndex() );
assertEquals( "foo",
- ex.getValue( null, new TestAbstractImpl() ) );
+ ex.getValue( null,
+ new TestAbstractImpl() ) );
}
public void testInherited() throws Exception {
- final FieldExtractor ex = ClassFieldExtractorCache.getExtractor( BeanInherit.class,
- "text",
- getClass().getClassLoader() );
+ final FieldExtractor ex = cache.getExtractor( BeanInherit.class,
+ "text",
+ getClass().getClassLoader() );
assertEquals( "hola",
- ex.getValue( null, new BeanInherit() ) );
+ ex.getValue( null,
+ new BeanInherit() ) );
}
public void testSelfReference() throws Exception {
- final FieldExtractor ex = ClassFieldExtractorCache.getExtractor( BeanInherit.class,
- "this",
- getClass().getClassLoader() );
+ final FieldExtractor ex = cache.getExtractor( BeanInherit.class,
+ "this",
+ getClass().getClassLoader() );
final TestBean bean = new TestBean();
assertEquals( bean,
- ex.getValue( null, bean ) );
+ ex.getValue( null,
+ bean ) );
}
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/ClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -29,6 +29,13 @@
public class ClassFieldExtractorTest extends TestCase {
+ private ClassFieldExtractorCache cache;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ cache = ClassFieldExtractorCache.getInstance();
+ }
+
public void testBasic() throws Exception {
final Object[] objArray = new Object[1];
@@ -37,75 +44,83 @@
obj.setSomething( "no" );
obj.setObjArray( objArray );
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "blah",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( TestBean.class,
+ "blah",
+ getClass().getClassLoader() );
assertEquals( false,
- ((Boolean) ext.getValue( null, obj )).booleanValue() );
+ ((Boolean) ext.getValue( null,
+ obj )).booleanValue() );
- final ClassFieldExtractor ext2 = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "fooBar",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext2 = cache.getExtractor( TestBean.class,
+ "fooBar",
+ getClass().getClassLoader() );
assertEquals( "fooBar",
- ext2.getValue( null, obj ) );
+ ext2.getValue( null,
+ obj ) );
- final ClassFieldExtractor ext3 = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "objArray",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext3 = cache.getExtractor( TestBean.class,
+ "objArray",
+ getClass().getClassLoader() );
assertEquals( objArray,
- ext3.getValue( null, obj ) );
+ ext3.getValue( null,
+ obj ) );
}
public void testInterface() throws Exception {
final TestInterface obj = new TestInterfaceImpl();
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( TestInterface.class,
- "something",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( TestInterface.class,
+ "something",
+ getClass().getClassLoader() );
assertEquals( "foo",
- (String) ext.getValue( null, obj ) );
+ (String) ext.getValue( null,
+ obj ) );
}
public void testAbstract() throws Exception {
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( TestAbstract.class,
- "something",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( TestAbstract.class,
+ "something",
+ getClass().getClassLoader() );
final TestAbstract obj = new TestAbstractImpl();
assertEquals( "foo",
- (String) ext.getValue( null, obj ) );
+ (String) ext.getValue( null,
+ obj ) );
}
public void testInherited() throws Exception {
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( BeanInherit.class,
- "text",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( BeanInherit.class,
+ "text",
+ getClass().getClassLoader() );
final BeanInherit obj = new BeanInherit();
assertEquals( "hola",
- (String) ext.getValue( null, obj ) );
+ (String) ext.getValue( null,
+ obj ) );
}
public void testMultipleInterfaces() throws Exception {
final ConcreteChild obj = new ConcreteChild();
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( InterfaceChild.class,
- "foo",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( InterfaceChild.class,
+ "foo",
+ getClass().getClassLoader() );
assertEquals( 42,
- ((Number) ext.getValue( null, obj )).intValue() );
+ ((Number) ext.getValue( null,
+ obj )).intValue() );
}
public void testLong() throws Exception {
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "longField",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ext = cache.getExtractor( TestBean.class,
+ "longField",
+ getClass().getClassLoader() );
final TestBean bean = new TestBean();
assertEquals( 424242,
- ((Number) ext.getValue( null, bean )).longValue() );
+ ((Number) ext.getValue( null,
+ bean )).longValue() );
}
public void testNonExistentField() throws Exception {
@@ -117,15 +132,15 @@
obj.setObjArray( objArray );
try {
- final ClassFieldExtractor ext = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "xyz",
- getClass().getClassLoader() );
- fail( "A RuntimeDroolsException should have been raised");
+ final ClassFieldExtractor ext = cache.getExtractor( TestBean.class,
+ "xyz",
+ getClass().getClassLoader() );
+ fail( "A RuntimeDroolsException should have been raised" );
} catch ( RuntimeDroolsException e ) {
e.printStackTrace();
// everything is fine, since field does not exist
} catch ( Exception e ) {
- fail( "A RuntimeDroolsException should have been raised");
+ fail( "A RuntimeDroolsException should have been raised" );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/BooleanClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/BooleanClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/BooleanClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -3,14 +3,13 @@
import junit.framework.Assert;
import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.TestBean;
import org.drools.spi.Extractor;
public class BooleanClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "booleanAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "booleanAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -19,7 +18,8 @@
public void testGetBooleanValue() {
try {
- Assert.assertTrue( this.extractor.getBooleanValue( null, this.bean ) );
+ Assert.assertTrue( this.extractor.getBooleanValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -27,7 +27,8 @@
public void testGetByteValue() {
try {
- this.extractor.getByteValue( null, this.bean );
+ this.extractor.getByteValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -36,7 +37,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -45,7 +47,8 @@
public void testGetDoubleValue() {
try {
- this.extractor.getDoubleValue( null, this.bean );
+ this.extractor.getDoubleValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -54,7 +57,8 @@
public void testGetFloatValue() {
try {
- this.extractor.getFloatValue( null, this.bean );
+ this.extractor.getFloatValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -63,7 +67,8 @@
public void testGetIntValue() {
try {
- this.extractor.getIntValue( null, this.bean );
+ this.extractor.getIntValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -72,7 +77,8 @@
public void testGetLongValue() {
try {
- this.extractor.getLongValue( null, this.bean );
+ this.extractor.getLongValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -81,7 +87,8 @@
public void testGetShortValue() {
try {
- this.extractor.getShortValue( null, this.bean );
+ this.extractor.getShortValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -91,7 +98,8 @@
public void testGetValue() {
try {
Assert.assertSame( Boolean.TRUE,
- this.extractor.getValue( null, this.bean ) );
+ this.extractor.getValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -99,7 +107,8 @@
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ByteClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -3,14 +3,13 @@
import junit.framework.Assert;
import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.TestBean;
import org.drools.spi.Extractor;
public class ByteClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "byteAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "byteAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -19,7 +18,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -29,7 +29,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( 1,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -37,7 +38,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -47,7 +49,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( 1.0,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -57,7 +60,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( 1.0f,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -67,7 +71,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( 1,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -76,7 +81,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( 1,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -85,7 +91,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( 1,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -94,15 +101,17 @@
public void testGetValue() {
try {
Assert.assertEquals( 1,
- ((Number) this.extractor.getValue( null, this.bean )).byteValue() );
+ ((Number) this.extractor.getValue( null,
+ this.bean )).byteValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
}
-
+
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/CharClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -7,9 +7,9 @@
import org.drools.spi.Extractor;
public class CharClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "charAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "charAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -18,7 +18,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -28,7 +29,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( 'a',
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -37,7 +39,8 @@
public void testGetCharValue() {
try {
Assert.assertEquals( 'a',
- this.extractor.getCharValue( null, this.bean ) );
+ this.extractor.getCharValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -46,7 +49,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( 'a',
- (int) this.extractor.getDoubleValue( null, this.bean ) );
+ (int) this.extractor.getDoubleValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -55,7 +59,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( 'a',
- (int) this.extractor.getFloatValue( null, this.bean ) );
+ (int) this.extractor.getFloatValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -64,7 +69,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( 'a',
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -73,7 +79,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( 'a',
- (int) this.extractor.getLongValue( null, this.bean ) );
+ (int) this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -82,7 +89,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( 'a',
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw exception" );
}
@@ -91,15 +99,17 @@
public void testGetValue() {
try {
Assert.assertEquals( 'a',
- ((Character) this.extractor.getValue( null, this.bean )).charValue() );
+ ((Character) this.extractor.getValue( null,
+ this.bean )).charValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
}
-
+
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/DoubleClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/DoubleClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/DoubleClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -3,16 +3,15 @@
import junit.framework.Assert;
import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.TestBean;
import org.drools.spi.Extractor;
public class DoubleClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
private static final double VALUE = 7;
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "doubleAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "doubleAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -21,7 +20,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -31,7 +31,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( (byte) DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -39,7 +40,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -49,7 +51,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -59,7 +62,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -69,7 +73,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( (int) DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -78,7 +83,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( (long) DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -87,7 +93,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( (short) DoubleClassFieldExtractorTest.VALUE,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -96,16 +103,19 @@
public void testGetValue() {
try {
Assert.assertEquals( new Double( DoubleClassFieldExtractorTest.VALUE ),
- this.extractor.getValue( null, this.bean ) );
- Assert.assertTrue( this.extractor.getValue( null, this.bean ) instanceof Double );
+ this.extractor.getValue( null,
+ this.bean ) );
+ Assert.assertTrue( this.extractor.getValue( null,
+ this.bean ) instanceof Double );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
}
-
+
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/FloatClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/FloatClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/FloatClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -3,16 +3,15 @@
import junit.framework.Assert;
import org.drools.base.ClassFieldExtractorCache;
-import org.drools.base.ClassFieldExtractorFactory;
import org.drools.base.TestBean;
import org.drools.spi.Extractor;
public class FloatClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
private static final float VALUE = 6;
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "floatAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "floatAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -21,7 +20,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -31,7 +31,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( (byte) FloatClassFieldExtractorTest.VALUE,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -39,7 +40,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -49,7 +51,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( FloatClassFieldExtractorTest.VALUE,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -59,7 +62,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( FloatClassFieldExtractorTest.VALUE,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -69,7 +73,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( (int) FloatClassFieldExtractorTest.VALUE,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -78,7 +83,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( (long) FloatClassFieldExtractorTest.VALUE,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -87,7 +93,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( (short) FloatClassFieldExtractorTest.VALUE,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -96,16 +103,19 @@
public void testGetValue() {
try {
Assert.assertEquals( new Float( FloatClassFieldExtractorTest.VALUE ),
- this.extractor.getValue( null, this.bean ) );
- Assert.assertTrue( this.extractor.getValue( null, this.bean ) instanceof Float );
+ this.extractor.getValue( null,
+ this.bean ) );
+ Assert.assertTrue( this.extractor.getValue( null,
+ this.bean ) instanceof Float );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
}
-
+
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/IntClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -9,9 +9,9 @@
public class IntClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
private static final int VALUE = 4;
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "intAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "intAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -20,7 +20,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -30,7 +31,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -38,7 +40,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -48,7 +51,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -58,7 +62,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -68,7 +73,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -77,7 +83,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -86,7 +93,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -95,7 +103,8 @@
public void testGetValue() {
try {
Assert.assertEquals( IntClassFieldExtractorTest.VALUE,
- ((Number) this.extractor.getValue( null, this.bean )).intValue() );
+ ((Number) this.extractor.getValue( null,
+ this.bean )).intValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -103,7 +112,8 @@
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/LongClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/LongClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/LongClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -9,9 +9,9 @@
public class LongClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
private static final long VALUE = 5;
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "longAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "longAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -20,7 +20,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -30,7 +31,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -38,7 +40,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -48,7 +51,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -58,7 +62,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -68,7 +73,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -77,7 +83,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -86,7 +93,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( LongClassFieldExtractorTest.VALUE,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -95,16 +103,19 @@
public void testGetValue() {
try {
Assert.assertEquals( new Long( (short) LongClassFieldExtractorTest.VALUE ),
- this.extractor.getValue( null, this.bean ) );
- Assert.assertTrue( this.extractor.getValue( null, this.bean ) instanceof Long );
+ this.extractor.getValue( null,
+ this.bean ) );
+ Assert.assertTrue( this.extractor.getValue( null,
+ this.bean ) instanceof Long );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
}
-
+
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/MVELClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/MVELClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/MVELClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -10,23 +10,31 @@
public class MVELClassFieldExtractorTest extends TestCase {
- Extractor extractor = ClassFieldExtractorCache.getExtractor( Person.class,
- "addresses['home'].street",
- getClass().getClassLoader() );
- Person person = null;
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Person.class,
+ "addresses['home'].street",
+ getClass().getClassLoader() );
+ Person person = null;
protected void setUp() throws Exception {
super.setUp();
- person = new Person("bob", 30);
- Address business = new Address("Business Street", "999", null);
- Address home = new Address("Home Street", "555", "55555555");
- person.getAddresses().put( "business", business );
- person.getAddresses().put( "home", home );
+ person = new Person( "bob",
+ 30 );
+ Address business = new Address( "Business Street",
+ "999",
+ null );
+ Address home = new Address( "Home Street",
+ "555",
+ "55555555" );
+ person.getAddresses().put( "business",
+ business );
+ person.getAddresses().put( "home",
+ home );
}
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.person );
+ this.extractor.getBooleanValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -35,7 +43,8 @@
public void testGetByteValue() {
try {
- this.extractor.getByteValue( null, this.person );
+ this.extractor.getByteValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -44,7 +53,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.person );
+ this.extractor.getCharValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -53,7 +63,8 @@
public void testGetDoubleValue() {
try {
- this.extractor.getDoubleValue( null, this.person );
+ this.extractor.getDoubleValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -62,7 +73,8 @@
public void testGetFloatValue() {
try {
- this.extractor.getFloatValue( null, this.person );
+ this.extractor.getFloatValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -71,7 +83,8 @@
public void testGetIntValue() {
try {
- this.extractor.getIntValue( null, this.person );
+ this.extractor.getIntValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -80,7 +93,8 @@
public void testGetLongValue() {
try {
- this.extractor.getLongValue( null, this.person );
+ this.extractor.getLongValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -89,7 +103,8 @@
public void testGetShortValue() {
try {
- this.extractor.getShortValue( null, this.person );
+ this.extractor.getShortValue( null,
+ this.person );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -99,8 +114,10 @@
public void testGetValue() {
try {
Assert.assertEquals( "Home Street",
- this.extractor.getValue( null, this.person ) );
- Assert.assertTrue( this.extractor.getValue( null, this.person ) instanceof String );
+ this.extractor.getValue( null,
+ this.person ) );
+ Assert.assertTrue( this.extractor.getValue( null,
+ this.person ) instanceof String );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -108,12 +125,14 @@
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.person ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.person ) );
- Extractor nullExtractor = ClassFieldExtractorCache.getExtractor( Person.class,
- "addresses['business'].phone",
- getClass().getClassLoader() );
- Assert.assertTrue( nullExtractor.isNullValue( null, this.person ) );
+ Extractor nullExtractor = ClassFieldExtractorCache.getInstance().getExtractor( Person.class,
+ "addresses['business'].phone",
+ getClass().getClassLoader() );
+ Assert.assertTrue( nullExtractor.isNullValue( null,
+ this.person ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ObjectClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ObjectClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ObjectClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -11,9 +11,9 @@
public class ObjectClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "listAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "listAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -22,7 +22,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -31,7 +32,8 @@
public void testGetByteValue() {
try {
- this.extractor.getByteValue( null, this.bean );
+ this.extractor.getByteValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -40,7 +42,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -49,7 +52,8 @@
public void testGetDoubleValue() {
try {
- this.extractor.getDoubleValue( null, this.bean );
+ this.extractor.getDoubleValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -58,7 +62,8 @@
public void testGetFloatValue() {
try {
- this.extractor.getFloatValue( null, this.bean );
+ this.extractor.getFloatValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -67,7 +72,8 @@
public void testGetIntValue() {
try {
- this.extractor.getIntValue( null, this.bean );
+ this.extractor.getIntValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -76,7 +82,8 @@
public void testGetLongValue() {
try {
- this.extractor.getLongValue( null, this.bean );
+ this.extractor.getLongValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -85,7 +92,8 @@
public void testGetShortValue() {
try {
- this.extractor.getShortValue( null, this.bean );
+ this.extractor.getShortValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -95,8 +103,10 @@
public void testGetValue() {
try {
Assert.assertEquals( Collections.EMPTY_LIST,
- this.extractor.getValue( null, this.bean ) );
- Assert.assertTrue( this.extractor.getValue( null, this.bean ) instanceof List );
+ this.extractor.getValue( null,
+ this.bean ) );
+ Assert.assertTrue( this.extractor.getValue( null,
+ this.bean ) instanceof List );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -104,12 +114,14 @@
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
- Extractor nullExtractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "nullAttr",
- getClass().getClassLoader() );
- Assert.assertTrue( nullExtractor.isNullValue( null, this.bean ) );
+ Extractor nullExtractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "nullAttr",
+ getClass().getClassLoader() );
+ Assert.assertTrue( nullExtractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/extractors/ShortClassFieldExtractorTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -9,9 +9,9 @@
public class ShortClassFieldExtractorTest extends BaseClassFieldExtractorsTest {
private static final short VALUE = 3;
- Extractor extractor = ClassFieldExtractorCache.getExtractor( TestBean.class,
- "shortAttr",
- getClass().getClassLoader() );
+ Extractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( TestBean.class,
+ "shortAttr",
+ getClass().getClassLoader() );
TestBean bean = new TestBean();
protected void setUp() throws Exception {
@@ -20,7 +20,8 @@
public void testGetBooleanValue() {
try {
- this.extractor.getBooleanValue( null, this.bean );
+ this.extractor.getBooleanValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -30,7 +31,8 @@
public void testGetByteValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getByteValue( null, this.bean ) );
+ this.extractor.getByteValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -38,7 +40,8 @@
public void testGetCharValue() {
try {
- this.extractor.getCharValue( null, this.bean );
+ this.extractor.getCharValue( null,
+ this.bean );
fail( "Should have throw an exception" );
} catch ( final Exception e ) {
// success
@@ -48,7 +51,8 @@
public void testGetDoubleValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getDoubleValue( null, this.bean ),
+ this.extractor.getDoubleValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -58,7 +62,8 @@
public void testGetFloatValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getFloatValue( null, this.bean ),
+ this.extractor.getFloatValue( null,
+ this.bean ),
0.01 );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
@@ -68,7 +73,8 @@
public void testGetIntValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getIntValue( null, this.bean ) );
+ this.extractor.getIntValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -77,7 +83,8 @@
public void testGetLongValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getLongValue( null, this.bean ) );
+ this.extractor.getLongValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -86,7 +93,8 @@
public void testGetShortValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- this.extractor.getShortValue( null, this.bean ) );
+ this.extractor.getShortValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -95,7 +103,8 @@
public void testGetValue() {
try {
Assert.assertEquals( ShortClassFieldExtractorTest.VALUE,
- ((Number) this.extractor.getValue( null, this.bean )).shortValue() );
+ ((Number) this.extractor.getValue( null,
+ this.bean )).shortValue() );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
@@ -103,7 +112,8 @@
public void testIsNullValue() {
try {
- Assert.assertFalse( this.extractor.isNullValue( null, this.bean ) );
+ Assert.assertFalse( this.extractor.isNullValue( null,
+ this.bean ) );
} catch ( final Exception e ) {
fail( "Should not throw an exception" );
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/BaseBetaConstraintsTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -29,12 +29,12 @@
public abstract class BaseBetaConstraintsTest extends TestCase {
protected BetaNodeFieldConstraint getConstraint(String identifier,
- Operator operator,
- String fieldName,
- Class clazz) {
- FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( clazz,
- fieldName,
- getClass().getClassLoader() );
+ Operator operator,
+ String fieldName,
+ Class clazz) {
+ FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( clazz,
+ fieldName,
+ getClass().getClassLoader() );
Declaration declaration = new Declaration( identifier,
extractor,
new Pattern( 0,
@@ -43,82 +43,89 @@
return new VariableConstraint( extractor,
declaration,
evaluator );
- }
-
-
- protected void checkBetaConstraints(VariableConstraint[] constraints, Class cls) {
+ }
+
+ protected void checkBetaConstraints(VariableConstraint[] constraints,
+ Class cls) {
RuleBaseConfiguration config = new RuleBaseConfiguration();
int depth = config.getCompositeKeyDepth();
-
+
BetaConstraints betaConstraints = null;
-
+
try {
- betaConstraints = ( BetaConstraints ) cls.getConstructor( new Class[] { BetaNodeFieldConstraint[].class, RuleBaseConfiguration.class } ).newInstance( new Object[] { constraints, config } );
+ betaConstraints = (BetaConstraints) cls.getConstructor( new Class[]{BetaNodeFieldConstraint[].class, RuleBaseConfiguration.class} ).newInstance( new Object[]{constraints, config} );
} catch ( Exception e ) {
throw new RuntimeException( "could not invoke constructor for " + cls.getName() );
}
-
+
//BetaConstraints betaConstraints = new DefaultBetaConstraints(constraints, config );
-
- constraints = convertToConstraints( betaConstraints.getConstraints() );
-
+
+ constraints = convertToConstraints( betaConstraints.getConstraints() );
+
List list = new ArrayList();
// get indexed positions
for ( int i = 0; i < constraints.length && list.size() < depth; i++ ) {
if ( constraints[i].getEvaluator().getOperator() == Operator.EQUAL ) {
- list.add( new Integer(i) );
+ list.add( new Integer( i ) );
}
}
-
+
// convert to array
- int[] indexedPositions = new int[ list.size() ];
+ int[] indexedPositions = new int[list.size()];
for ( int i = 0; i < list.size(); i++ ) {
indexedPositions[i] = i;
- }
-
- assertEquals( ( indexedPositions.length > 0 ), betaConstraints.isIndexed() );
- assertEquals(indexedPositions.length, betaConstraints.getIndexCount() );
- BetaMemory betaMemory = betaConstraints.createBetaMemory( config );
-
+ }
+
+ assertEquals( (indexedPositions.length > 0),
+ betaConstraints.isIndexed() );
+ assertEquals( indexedPositions.length,
+ betaConstraints.getIndexCount() );
+ BetaMemory betaMemory = betaConstraints.createBetaMemory( config );
+
if ( indexedPositions.length > 0 ) {
- TupleIndexHashTable tupleHashTable = ( TupleIndexHashTable ) betaMemory.getTupleMemory();
+ TupleIndexHashTable tupleHashTable = (TupleIndexHashTable) betaMemory.getTupleMemory();
assertTrue( tupleHashTable.isIndexed() );
Index index = tupleHashTable.getIndex();
-
+
for ( int i = 0; i < indexedPositions.length; i++ ) {
- checkSameConstraintForIndex( constraints[indexedPositions[i]], index.getFieldIndex(i) );
+ checkSameConstraintForIndex( constraints[indexedPositions[i]],
+ index.getFieldIndex( i ) );
}
-
- FactHandleIndexHashTable factHashTable = ( FactHandleIndexHashTable ) betaMemory.getFactHandleMemory();
+
+ FactHandleIndexHashTable factHashTable = (FactHandleIndexHashTable) betaMemory.getFactHandleMemory();
assertTrue( factHashTable.isIndexed() );
- index = factHashTable.getIndex();
-
+ index = factHashTable.getIndex();
+
for ( int i = 0; i < indexedPositions.length; i++ ) {
- checkSameConstraintForIndex( constraints[indexedPositions[i]], index.getFieldIndex(i) );
- }
+ checkSameConstraintForIndex( constraints[indexedPositions[i]],
+ index.getFieldIndex( i ) );
+ }
} else {
- TupleHashTable tupleHashTable = ( TupleHashTable ) betaMemory.getTupleMemory();
+ TupleHashTable tupleHashTable = (TupleHashTable) betaMemory.getTupleMemory();
assertFalse( tupleHashTable.isIndexed() );
-
- FactHashTable factHashTable = ( FactHashTable ) betaMemory.getFactHandleMemory();
- assertFalse( factHashTable.isIndexed() );
- }
+
+ FactHashTable factHashTable = (FactHashTable) betaMemory.getFactHandleMemory();
+ assertFalse( factHashTable.isIndexed() );
+ }
}
-
-
- protected void checkSameConstraintForIndex(VariableConstraint constraint, FieldIndex fieldIndex) {
- assertSame( constraint.getRequiredDeclarations()[0], fieldIndex.getDeclaration() );
- assertSame( constraint.getEvaluator(), fieldIndex.getEvaluator() );
- assertSame( constraint.getFieldExtractor(), fieldIndex.getExtractor() );
- }
-
+
+ protected void checkSameConstraintForIndex(VariableConstraint constraint,
+ FieldIndex fieldIndex) {
+ assertSame( constraint.getRequiredDeclarations()[0],
+ fieldIndex.getDeclaration() );
+ assertSame( constraint.getEvaluator(),
+ fieldIndex.getEvaluator() );
+ assertSame( constraint.getFieldExtractor(),
+ fieldIndex.getExtractor() );
+ }
+
protected VariableConstraint[] convertToConstraints(LinkedList list) {
final VariableConstraint[] array = new VariableConstraint[list.size()];
int i = 0;
for ( LinkedListEntry entry = (LinkedListEntry) list.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
array[i++] = (VariableConstraint) entry.getObject();
- }
+ }
return array;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/AgendaEventSupportTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.List;
+import junit.framework.TestCase;
+
import org.drools.Cheese;
import org.drools.FactHandle;
import org.drools.RuleBase;
@@ -32,17 +34,15 @@
import org.drools.base.ShadowProxy;
import org.drools.base.ValueType;
import org.drools.base.evaluators.Operator;
+import org.drools.rule.LiteralConstraint;
+import org.drools.rule.Package;
import org.drools.rule.Pattern;
-import org.drools.rule.LiteralConstraint;
import org.drools.rule.Rule;
-import org.drools.rule.Package;
import org.drools.spi.Consequence;
import org.drools.spi.Evaluator;
import org.drools.spi.FieldValue;
import org.drools.spi.KnowledgeHelper;
-import junit.framework.TestCase;
-
/**
* @author <a href="mailto:simon at redhillconsulting.com.au">Simon Harris</a>
*/
@@ -60,19 +60,19 @@
rule.setAgendaGroup( "test group" );
final ClassObjectType cheeseObjectType = new ClassObjectType( Cheese.class );
final Pattern pattern = new Pattern( 0,
- cheeseObjectType );
+ cheeseObjectType );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
- evaluator,
- field );
+ evaluator,
+ field );
pattern.addConstraint( constraint );
rule.addPattern( pattern );
@@ -124,7 +124,7 @@
// assert the cheese fact
final Cheese cheddar = new Cheese( "cheddar",
- 15 );
+ 15 );
FactHandle cheddarHandle = wm.insert( cheddar );
// should be one ActivationCreatedEvent
@@ -138,7 +138,7 @@
// update results in a ActivationCancelledEvent and an ActivationCreatedEvent, note the object is always resolvable
cheddar.setPrice( 14 );
wm.update( cheddarHandle,
- cheddar );
+ cheddar );
assertEquals( 2,
agendaList.size() );
ActivationCancelledEvent cancelledEvent = (ActivationCancelledEvent) agendaList.get( 0 );
@@ -184,7 +184,7 @@
assertEquals( "test group",
poppedEvent.getAgendaGroup().getName() );
}
-
+
private Object unwrapShadow(Object object) {
if ( object instanceof ShadowProxy ) {
return ((ShadowProxy) object).getShadowedObject();
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/event/RuleBaseEventListenerTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -44,40 +44,39 @@
*/
public class RuleBaseEventListenerTest extends TestCase {
- private RuleBase ruleBase;
+ private RuleBase ruleBase;
private TestRuleBaseListener listener1;
private TestRuleBaseListener listener2;
- private Package pkg;
+ private Package pkg;
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
-
+
ruleBase = RuleBaseFactory.newRuleBase();
- listener1 = new TestRuleBaseListener("(listener-1) ");
- listener2 = new TestRuleBaseListener("(listener-2) ");
+ listener1 = new TestRuleBaseListener( "(listener-1) " );
+ listener2 = new TestRuleBaseListener( "(listener-2) " );
ruleBase.addEventListener( listener1 );
ruleBase.addEventListener( listener2 );
-
-
+
final Rule rule1 = new Rule( "test1" );
final ClassObjectType cheeseObjectType = new ClassObjectType( Cheese.class );
final Pattern pattern = new Pattern( 0,
- cheeseObjectType );
+ cheeseObjectType );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
final Evaluator evaluator = ValueType.STRING_TYPE.getEvaluator( Operator.EQUAL );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
- evaluator,
- field );
+ evaluator,
+ field );
pattern.addConstraint( constraint );
rule1.addPattern( pattern );
@@ -88,17 +87,17 @@
final WorkingMemory workingMemory) throws Exception {
}
} );
-
+
final Rule rule2 = new Rule( "test2" );
final ClassObjectType cheeseObjectType2 = new ClassObjectType( Cheese.class );
final Pattern pattern2 = new Pattern( 0,
- cheeseObjectType2 );
+ cheeseObjectType2 );
final FieldValue field2 = FieldFactory.getFieldValue( "stilton" );
final LiteralConstraint constraint2 = new LiteralConstraint( extractor,
- evaluator,
- field2 );
+ evaluator,
+ field2 );
pattern2.addConstraint( constraint2 );
rule2.addPattern( pattern2 );
@@ -109,11 +108,11 @@
final WorkingMemory workingMemory) throws Exception {
}
} );
-
- pkg = new Package("org.drools.test1");
+
+ pkg = new Package( "org.drools.test1" );
pkg.addRule( rule1 );
pkg.addRule( rule2 );
-
+
}
/* (non-Javadoc)
@@ -142,7 +141,7 @@
listener2.getAfterRuleAdded() );
this.ruleBase.addPackage( pkg );
-
+
assertEquals( 1,
listener1.getBeforePackageAdded() );
assertEquals( 1,
@@ -160,7 +159,7 @@
assertEquals( 2,
listener2.getAfterRuleAdded() );
}
-
+
public void testRemovePackageEvents() throws Exception {
this.ruleBase.addPackage( pkg );
@@ -183,7 +182,7 @@
listener2.getAfterRuleRemoved() );
this.ruleBase.removePackage( "org.drools.test1" );
-
+
assertEquals( 1,
listener1.getBeforePackageRemoved() );
assertEquals( 1,
@@ -202,18 +201,19 @@
listener2.getAfterRuleRemoved() );
}
-
- public static class TestRuleBaseListener implements RuleBaseEventListener {
+
+ public static class TestRuleBaseListener
+ implements
+ RuleBaseEventListener {
private String id;
- private int beforePackageAdded = 0;
- private int afterPackageAdded = 0;
- private int beforePackageRemoved = 0;
- private int afterPackageRemoved = 0;
- private int beforeRuleAdded = 0;
- private int afterRuleAdded = 0;
- private int beforeRuleRemoved = 0;
- private int afterRuleRemoved = 0;
-
+ private int beforePackageAdded = 0;
+ private int afterPackageAdded = 0;
+ private int beforePackageRemoved = 0;
+ private int afterPackageRemoved = 0;
+ private int beforeRuleAdded = 0;
+ private int afterRuleAdded = 0;
+ private int beforeRuleRemoved = 0;
+ private int afterRuleRemoved = 0;
public TestRuleBaseListener(String id) {
super();
@@ -221,12 +221,12 @@
}
public void afterPackageAdded(AfterPackageAddedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.afterPackageAdded++;
}
public void beforePackageAdded(BeforePackageAddedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.beforePackageAdded++;
}
@@ -243,12 +243,12 @@
}
public void afterPackageRemoved(AfterPackageRemovedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.afterPackageRemoved++;
}
public void beforePackageRemoved(BeforePackageRemovedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.beforePackageRemoved++;
}
@@ -269,12 +269,12 @@
}
public void afterRuleAdded(AfterRuleAddedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.afterRuleAdded++;
}
public void beforeRuleAdded(BeforeRuleAddedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.beforeRuleAdded++;
}
@@ -287,15 +287,15 @@
}
public void afterRuleRemoved(AfterRuleRemovedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.afterRuleRemoved++;
}
public void beforeRuleRemoved(BeforeRuleRemovedEvent event) {
-// System.out.println( this.id + event );
+ // System.out.println( this.id + event );
this.beforeRuleRemoved++;
}
-
+
}
-
+
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/BaseMannersTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -238,7 +238,7 @@
drools.modifyRetract( context );;
context.setState( Context.ASSIGN_SEATS );
drools.modifyInsert( context );
-
+
System.err.println( "assign first seat : " + seating + " : " + path );
} catch ( Exception e ) {
@@ -478,8 +478,10 @@
Context context = (Context) drools.get( contextDeclaration );
Count count = (Count) drools.get( countDeclaration );
- int seatId = seatingIdDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory, tuple.get( seatingIdDeclaration ).getObject() );
- int seatingRightSeat = seatingRightSeatDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory, tuple.get( seatingRightSeatDeclaration ).getObject() );
+ int seatId = seatingIdDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory,
+ tuple.get( seatingIdDeclaration ).getObject() );
+ int seatingRightSeat = seatingRightSeatDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory,
+ tuple.get( seatingRightSeatDeclaration ).getObject() );
String leftGuestName = (String) drools.get( leftGuestNameDeclaration );
String rightGuestName = (String) drools.get( seatingRightGuestNameDeclaration );
@@ -654,8 +656,10 @@
Rule rule = drools.getRule();
Tuple tuple = drools.getTuple();
- int id = seatingIdDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory, tuple.get( seatingIdDeclaration ).getObject() );
- int seat = pathSeatDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory, tuple.get( pathSeatDeclaration ).getObject() );
+ int id = seatingIdDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory,
+ tuple.get( seatingIdDeclaration ).getObject() );
+ int seat = pathSeatDeclaration.getExtractor().getIntValue( (InternalWorkingMemory) workingMemory,
+ tuple.get( pathSeatDeclaration ).getObject() );
String guestName = (String) drools.get( pathGuestNameDeclaration );
Path path = new Path( id,
@@ -1110,9 +1114,9 @@
final Evaluator evaluator) throws IntrospectionException {
final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( clazz,
- fieldName,
- getClass().getClassLoader() );
+ final FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( clazz,
+ fieldName,
+ getClass().getClassLoader() );
final FieldValue field = new LongFieldImpl( fieldValue );
@@ -1127,9 +1131,9 @@
final Evaluator evaluator) throws IntrospectionException {
final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( clazz,
- fieldName,
- getClass().getClassLoader() );
+ final FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( clazz,
+ fieldName,
+ getClass().getClassLoader() );
final FieldValue field = new BooleanFieldImpl( fieldValue );
@@ -1143,9 +1147,9 @@
final String identifier) throws IntrospectionException {
final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( clazz,
- fieldName,
- getClass().getClassLoader() );
+ final FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( clazz,
+ fieldName,
+ getClass().getClassLoader() );
pattern.addDeclaration( identifier,
extractor );
@@ -1157,9 +1161,9 @@
final Evaluator evaluator) throws IntrospectionException {
final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( clazz,
- fieldName,
- getClass().getClassLoader() );
+ final FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( clazz,
+ fieldName,
+ getClass().getClassLoader() );
return new VariableConstraint( extractor,
declaration,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -41,6 +41,8 @@
public class AlphaNodeTest extends DroolsTestCase {
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+
public void testMemory() {
RuleBaseConfiguration config = new RuleBaseConfiguration();
config.setAlphaMemory( false );
@@ -75,9 +77,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -162,9 +164,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -225,9 +227,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -312,9 +314,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -399,9 +401,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -467,9 +469,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -551,9 +553,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -639,9 +641,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -723,9 +725,9 @@
final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -22,12 +22,13 @@
public class CompositeObjectSinkAdapterTest extends TestCase {
private ReteooRuleBase ruleBase;
- private BuildContext buildContext;
-
+ private BuildContext buildContext;
+
protected void setUp() throws Exception {
- this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
- this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
- }
+ this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+ this.buildContext = new BuildContext( ruleBase,
+ ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
+ }
public int la;
public int blah;
@@ -225,9 +226,9 @@
public void testPropagationWithNullValue() {
final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
- FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- this.getClass().getClassLoader() );
+ FieldExtractor extractor = ClassFieldExtractorCache.getInstance().getExtractor( Cheese.class,
+ "type",
+ this.getClass().getClassLoader() );
final LiteralConstraint lit1 = new LiteralConstraint( extractor,
StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
new ObjectFieldImpl( "stilton" ) );
@@ -262,7 +263,7 @@
null,
null );
} catch ( RuntimeException e ) {
- fail( "Not supposed to throw any exception: "+e.getMessage());
+ fail( "Not supposed to throw any exception: " + e.getMessage() );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -23,9 +23,9 @@
import org.drools.common.InternalFactHandle;
import org.drools.common.PropagationContextImpl;
import org.drools.common.SingleBetaConstraints;
-import org.drools.rule.Pattern;
import org.drools.rule.Declaration;
import org.drools.rule.LiteralConstraint;
+import org.drools.rule.Pattern;
import org.drools.rule.VariableConstraint;
import org.drools.spi.AlphaNodeFieldConstraint;
import org.drools.spi.DataProvider;
@@ -36,6 +36,7 @@
import org.drools.util.LinkedListEntry;
public class FromNodeTest extends TestCase {
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
public void testAlphaNode() {
final PropagationContext context = new PropagationContextImpl( 0,
@@ -44,9 +45,9 @@
null );
final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
(ReteooRuleBase) RuleBaseFactory.newRuleBase() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "stilton" );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
@@ -136,13 +137,13 @@
final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
(ReteooRuleBase) RuleBaseFactory.newRuleBase() );
- final ClassFieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final ClassFieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
- final ClassFieldExtractor ageExtractor = ClassFieldExtractorCache.getExtractor( Person.class,
- "age",
- getClass().getClassLoader() );
+ final ClassFieldExtractor ageExtractor = cache.getExtractor( Person.class,
+ "age",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Person.class ) );
@@ -241,9 +242,9 @@
null );
final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
(ReteooRuleBase) RuleBaseFactory.newRuleBase() );
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "stilton" );
final LiteralConstraint constraint = new LiteralConstraint( extractor,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -43,14 +43,17 @@
import org.drools.spi.FieldValue;
public class QueryTerminalNodeTest extends TestCase {
- private ReteooRuleBase ruleBase;
- private BuildContext buildContext;
-
+ private ReteooRuleBase ruleBase;
+ private BuildContext buildContext;
+
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+
protected void setUp() throws Exception {
- this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
- this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+ this.ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+ this.buildContext = new BuildContext( ruleBase,
+ ((ReteooRuleBase) ruleBase).getReteooBuilder().getIdGenerator() );
}
-
+
public void testQueryTerminalNode() {
final ClassObjectType queryObjectType = new ClassObjectType( DroolsQuery.class );
final ObjectTypeNode queryObjectTypeNode = new ObjectTypeNode( this.buildContext.getNextId(),
@@ -58,9 +61,9 @@
buildContext );
queryObjectTypeNode.attach();
- ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( DroolsQuery.class,
- "name",
- DroolsQuery.class.getClassLoader() );
+ ClassFieldExtractor extractor = cache.getExtractor( DroolsQuery.class,
+ "name",
+ DroolsQuery.class.getClassLoader() );
FieldValue field = FieldFactory.getFieldValue( "query-1" );
@@ -72,7 +75,7 @@
AlphaNode alphaNode = new AlphaNode( this.buildContext.getNextId(),
constraint,
queryObjectTypeNode,
- buildContext );
+ buildContext );
alphaNode.attach();
final LeftInputAdapterNode liaNode = new LeftInputAdapterNode( this.buildContext.getNextId(),
@@ -86,9 +89,9 @@
buildContext );
cheeseObjectTypeNode.attach();
- extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
field = FieldFactory.getFieldValue( "stilton" );
@@ -99,12 +102,13 @@
alphaNode = new AlphaNode( this.buildContext.getNextId(),
constraint,
cheeseObjectTypeNode,
- buildContext );
+ buildContext );
alphaNode.attach();
- BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+ BuildContext buildContext = new BuildContext( ruleBase,
+ ruleBase.getReteooBuilder().getIdGenerator() );
buildContext.setTupleMemoryEnabled( false );
-
+
final JoinNode joinNode = new JoinNode( this.buildContext.getNextId(),
liaNode,
alphaNode,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/DeclarationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/DeclarationTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/DeclarationTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -23,20 +23,21 @@
import junit.framework.TestCase;
import org.drools.Cheese;
-import org.drools.base.ClassFieldExtractor;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ClassObjectType;
import org.drools.spi.FieldExtractor;
public class DeclarationTest extends TestCase {
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+
public void testDeclaration() throws IntrospectionException {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 5,
- new ClassObjectType( Cheese.class ) );
+ new ClassObjectType( Cheese.class ) );
// Bind the extractor to a decleration
// Declarations know the pattern they derive their value from
@@ -59,12 +60,12 @@
}
public void testGetFieldValue() throws IntrospectionException {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 5,
- new ClassObjectType( Cheese.class ) );
+ new ClassObjectType( Cheese.class ) );
// Bind the extractor to a decleration
// Declarations know the pattern they derive their value from
@@ -78,7 +79,8 @@
// Check we can extract Declarations correctly
assertEquals( "cheddar",
- declaration.getValue( null, cheddar ) );
+ declaration.getValue( null,
+ cheddar ) );
}
public static int getIndex(final Class clazz,
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/rule/FieldConstraintTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -45,6 +45,9 @@
import org.drools.spi.Tuple;
public class FieldConstraintTest extends TestCase {
+
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
+
public FieldConstraintTest() {
super();
}
@@ -67,9 +70,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -113,9 +116,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( 5 );
@@ -160,9 +163,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final FieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final FieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -194,8 +197,10 @@
Declaration[] previousDeclarations,
Declaration[] localDeclarations,
WorkingMemory workingMemory) {
- int price1 = previousDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory, workingMemory.getObject( tuple.get( previousDeclarations[0] ) ) );
- int price2 = localDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory, object );
+ int price1 = previousDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory,
+ workingMemory.getObject( tuple.get( previousDeclarations[0] ) ) );
+ int price2 = localDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory,
+ object );
return (price2 == (price1 * 2));
@@ -243,9 +248,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final FieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final FieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -267,7 +272,8 @@
Declaration[] previousDeclarations,
Declaration[] localDeclarations,
WorkingMemory workingMemory) {
- int price = ((Number) previousDeclarations[0].getValue( (InternalWorkingMemory) workingMemory, workingMemory.getObject( tuple.get( previousDeclarations[0] ) ) )).intValue();
+ int price = ((Number) previousDeclarations[0].getValue( (InternalWorkingMemory) workingMemory,
+ workingMemory.getObject( tuple.get( previousDeclarations[0] ) ) )).intValue();
return FieldFactory.getFieldValue( 2 * price );
}
@@ -344,9 +350,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -356,9 +362,9 @@
evaluator,
field );
- final ClassFieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final ClassFieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
final FieldValue priceField = FieldFactory.getFieldValue( 10 );
@@ -414,9 +420,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
@@ -426,9 +432,9 @@
evaluator,
field );
- final ClassFieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final ClassFieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
final FieldValue priceField = FieldFactory.getFieldValue( 10 );
@@ -484,9 +490,9 @@
final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
- final ClassFieldExtractor typeExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor typeExtractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldValue cheddarField = FieldFactory.getFieldValue( "cheddar" );
@@ -497,9 +503,9 @@
stringEqual,
cheddarField );
- final ClassFieldExtractor priceExtractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "price",
- getClass().getClassLoader() );
+ final ClassFieldExtractor priceExtractor = cache.getExtractor( Cheese.class,
+ "price",
+ getClass().getClassLoader() );
final FieldValue field10 = FieldFactory.getFieldValue( 10 );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -15,11 +15,12 @@
import org.drools.util.FactHandleIndexHashTable.FieldIndexEntry;
public class FieldIndexEntryTest extends TestCase {
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
public void testSingleEntry() {
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
@@ -61,9 +62,9 @@
}
public void testTwoEntries() {
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
@@ -113,9 +114,9 @@
}
public void testThreeEntries() {
- final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final ClassFieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final FieldIndex fieldIndex = new FieldIndex( extractor,
null,
StringFactory.getInstance().getEvaluator( Operator.EQUAL ) );
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2007-10-01 22:07:10 UTC (rev 15488)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexHashTableTest.java 2007-10-01 22:19:24 UTC (rev 15489)
@@ -7,7 +7,6 @@
import junit.framework.TestCase;
import org.drools.Cheese;
-import org.drools.base.ClassFieldExtractor;
import org.drools.base.ClassFieldExtractorCache;
import org.drools.base.ClassObjectType;
import org.drools.base.evaluators.ObjectFactory;
@@ -16,8 +15,8 @@
import org.drools.common.DefaultFactHandle;
import org.drools.common.InternalFactHandle;
import org.drools.reteoo.ReteTuple;
+import org.drools.rule.Declaration;
import org.drools.rule.Pattern;
-import org.drools.rule.Declaration;
import org.drools.spi.FieldExtractor;
import org.drools.util.AbstractHashTable.FactEntryImpl;
import org.drools.util.AbstractHashTable.FieldIndex;
@@ -25,11 +24,12 @@
import org.drools.util.ObjectHashMap.ObjectEntry;
public class FieldIndexHashTableTest extends TestCase {
+ ClassFieldExtractorCache cache = ClassFieldExtractorCache.getInstance();
public void testSingleEntry() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -76,9 +76,9 @@
}
public void testTwoDifferentEntries() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -133,9 +133,9 @@
}
public void testTwoEqualEntries() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -190,9 +190,9 @@
}
public void testTwoDifferentEntriesSameHashCode() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( TestClass.class,
- "object",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( TestClass.class,
+ "object",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( TestClass.class ) );
@@ -237,9 +237,9 @@
}
public void testRemove() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -304,9 +304,9 @@
}
public void testResize() throws Exception {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
@@ -521,9 +521,9 @@
}
public void testEmptyIterator() {
- final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
- "type",
- getClass().getClassLoader() );
+ final FieldExtractor extractor = cache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
final Pattern pattern = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
More information about the jboss-svn-commits
mailing list