IPattern ifp = findByFactPattern( patterns,
pattern.getBoundName() );
//If the pattern does not exist create one suitable
if ( ifp == null ) {
FactPattern fp = new FactPattern( pattern.getFactType() );
fp.setBoundName( pattern.getBoundName() );
fp.setNegated( pattern.isNegated() );
fp.setWindow( pattern.getWindow() );
if ( pattern.getEntryPointName() != null && pattern.getEntryPointName().length() > 0 ) {
FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
fep.setEntryPointName( pattern.getEntryPointName() );
fep.setFactPattern( fp );
patterns.add( fep );
ifp = fep;
} else {
patterns.add( fp );
ifp = fp;
}
}
//Extract the FactPattern from the IFactPattern
FactPattern fp;
if ( ifp instanceof FactPattern ) {
fp = (FactPattern) ifp;
} else if ( ifp instanceof FromEntryPointFactPattern ) {
FromEntryPointFactPattern fep = (FromEntryPointFactPattern) ifp;
fp = fep.getFactPattern();
} else {
throw new IllegalArgumentException( "Inexpected IFactPattern implementation found." );
}
//Add the constraint from this cell
switch ( c.getConstraintValueType() ) {
case BaseSingleFieldConstraint.TYPE_LITERAL:
case BaseSingleFieldConstraint.TYPE_RET_VALUE:
if ( !isOtherwise ) {
FieldConstraint fc = makeSingleFieldConstraint( c,
cell );
fp.addConstraint( fc );
} else {
FieldConstraint fc = makeSingleFieldConstraint( c,
allColumns,
data );
fp.addConstraint( fc );
}
break;
case BaseSingleFieldConstraint.TYPE_PREDICATE:
SingleFieldConstraint pred = new SingleFieldConstraint();
pred.setConstraintValueType( c.getConstraintValueType() );
if ( c.getFactField() != null
&& c.getFactField().indexOf( "$param" ) > -1 ) {
// handle interpolation
pred.setValue( c.getFactField().replace( "$param",
cell ) );
} else {
pred.setValue( cell );
}
fp.addConstraint( pred );
break;
default:
throw new IllegalArgumentException( "Unknown constraintValueType: "
+ c.getConstraintValueType() );
}