private void parseRhs( RuleModel m,
String rhs,
boolean isJavaDialect,
Map<String, String> boundParams,
ExpandedDRLInfo expandedDRLInfo ) {
PortableWorkDefinition pwd = null;
Map<String, List<String>> setStatements = new HashMap<String, List<String>>();
Map<String, String> factsType = new HashMap<String, String>();
int lineCounter = -1;
for ( String line : rhs.split( "\n" ) ) {
lineCounter++;
if ( expandedDRLInfo.hasDsl ) {
String dslLine = expandedDRLInfo.dslStatementsInRhs.get( lineCounter );
while ( dslLine != null ) {
m.addRhsItem( toDSLSentence( expandedDRLInfo.rhsDslPatterns, dslLine ) );
dslLine = expandedDRLInfo.dslStatementsInRhs.get( ++lineCounter );
}
}
line = line.trim();
if ( line.startsWith( "insertLogical" ) ) {
String fact = unwrapParenthesis( line );
String type = getStatementType( fact, factsType );
if ( type != null ) {
ActionInsertLogicalFact action = new ActionInsertLogicalFact( type );
m.addRhsItem( action );
if ( factsType.containsKey( fact ) ) {
addSettersToAction( setStatements, fact, action, isJavaDialect );
}
}
} else if ( line.startsWith( "insert" ) ) {
String fact = unwrapParenthesis( line );
String type = getStatementType( fact, factsType );
if ( type != null ) {
ActionInsertFact action = new ActionInsertFact( type );
m.addRhsItem( action );
if ( factsType.containsKey( fact ) ) {
action.setBoundName( fact );
addSettersToAction( setStatements, fact, action, isJavaDialect );
}
}
} else if ( line.startsWith( "update" ) ) {
String variable = unwrapParenthesis( line );
ActionUpdateField action = new ActionUpdateField();
action.setVariable( variable );
m.addRhsItem( action );
addSettersToAction( setStatements, variable, action, isJavaDialect );
} else if ( line.startsWith( "retract" ) ) {
String variable = unwrapParenthesis( line );
m.addRhsItem( new ActionRetractFact( variable ) );
} else if ( line.startsWith( "org.kie.internal.process.instance.impl.WorkItemImpl wiWorkItem" ) ) {
ActionExecuteWorkItem awi = new ActionExecuteWorkItem();
pwd = new PortableWorkDefinition();
pwd.setName( "WorkItem" );
awi.setWorkDefinition( pwd );
m.addRhsItem( awi );
} else if ( line.startsWith( "wiWorkItem.getParameters().put" ) ) {
String statement = line.substring( "wiWorkItem.getParameters().put".length() );
statement = unwrapParenthesis( statement );
int commaPos = statement.indexOf( ',' );
String name = statement.substring( 0, commaPos ).trim();
String value = statement.substring( commaPos + 1 ).trim();
pwd.addParameter( buildPortableParameterDefinition( name, value, boundParams ) );
} else if ( line.startsWith( "wim.internalExecuteWorkItem" ) || line.startsWith( "wiWorkItem.setName" ) ) {
// ignore
} else {
int dotPos = line.indexOf( '.' );
int argStart = line.indexOf( '(' );