final Package pkg = new Package( "pkg1" );
final RuleDescr ruleDescr = new RuleDescr( "rule 1" );
PackageBuilder pkgBuilder = new PackageBuilder( pkg );
final PackageBuilderConfiguration conf = pkgBuilder.getPackageBuilderConfiguration();
PackageRegistry pkgRegistry = pkgBuilder.getPackageRegistry( pkg.getName() );
MVELDialect mvelDialect = ( MVELDialect ) pkgRegistry.getDialectCompiletimeRegistry().getDialect( "mvel" );
final InstrumentedBuildContent context = new InstrumentedBuildContent( pkgBuilder,
ruleDescr,
pkgRegistry.getDialectCompiletimeRegistry(),
pkg,
mvelDialect );
final InstrumentedDeclarationScopeResolver declarationResolver = new InstrumentedDeclarationScopeResolver();
final InternalReadAccessor extractor = store.getReader( Cheese.class,
"price",
getClass().getClassLoader() );
final Pattern patternA = new Pattern( 0,
new ClassObjectType( Cheese.class ) );
final Pattern patternB = new Pattern( 1,
new ClassObjectType( Cheese.class ) );
final Declaration a = new Declaration( "a",
extractor,
patternA );
final Declaration b = new Declaration( "b",
extractor,
patternB );
context.getBuildStack().add( patternA );
context.getBuildStack().add( patternB );
final Map map = new HashMap();
map.put( "a",
a );
map.put( "b",
b );
declarationResolver.setDeclarations( map );
context.setDeclarationResolver( declarationResolver );
final PredicateDescr predicateDescr = new PredicateDescr();
predicateDescr.setContent( "a == b" );
final MVELPredicateBuilder builder = new MVELPredicateBuilder();
final Declaration[] previousDeclarations = new Declaration[]{a};
final Declaration[] localDeclarations = new Declaration[]{b};
final PredicateConstraint predicate = new PredicateConstraint( null,
localDeclarations );
AnalysisResult analysis = context.getDialect().analyzeExpression( context,
predicateDescr,
predicateDescr.getContent(),
new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap(), null, Cheese.class ) );
builder.build( context,
new BoundIdentifiers( declarationResolver.getDeclarationClasses( (Rule) null ), new HashMap() ),
previousDeclarations,
localDeclarations,
predicate,
predicateDescr,
analysis );
( (MVELPredicateExpression) predicate.getPredicateExpression()).compile( (MVELDialectRuntimeData) pkgRegistry.getDialectRuntimeRegistry().getDialectData( "mvel" ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
final InternalWorkingMemory wm = (InternalWorkingMemory) ruleBase.newStatefulSession();
final Cheese stilton = new Cheese( "stilton",