final String rhs,
final boolean isJavaDialect,
final Map<String, String> boundParams,
final ExpandedDRLInfo expandedDRLInfo,
final PackageDataModelOracle dmo ) {
PortableWorkDefinition pwd = null;
Map<String, List<String>> setStatements = new HashMap<String, List<String>>();
Map<String, Integer> setStatementsPosition = new HashMap<String, Integer>();
Map<String, String> factsType = new HashMap<String, String>();
String modifiedVariable = null;
String modifiers = null;
int lineCounter = -1;
String[] lines = rhs.split( "\n" );
for ( String line : lines ) {
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 ( modifiedVariable != null ) {
int modifyBlockEnd = line.lastIndexOf( '}' );
if ( modifiers == null ) {
modifiers = modifyBlockEnd > 0 ?
line.substring( line.indexOf( '{' ) + 1,
modifyBlockEnd ).trim() :
line.substring( line.indexOf( '{' ) + 1 ).trim();
} else if ( modifyBlockEnd != 0 ) {
modifiers += modifyBlockEnd > 0 ?
line.substring( 0,
modifyBlockEnd ).trim() :
line;
}
if ( modifyBlockEnd >= 0 ) {
ActionUpdateField action = new ActionUpdateField();
action.setVariable( modifiedVariable );
m.addRhsItem( action );
addModifiersToAction( modifiers,
action,
boundParams,
dmo,
m.getImports(),
isJavaDialect );
modifiedVariable = null;
modifiers = null;
}
} else 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,
boundParams,
dmo,
m.getImports(),
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,
boundParams,
dmo,
m.getImports(),
isJavaDialect );
}
}
} else if ( line.startsWith( "update" ) ) {
String variable = unwrapParenthesis( line );
ActionUpdateField action = new ActionUpdateField();
action.setVariable( variable );
m.addRhsItem( action );
addSettersToAction( setStatements,
variable,
action,
boundParams,
dmo,
m.getImports(),
isJavaDialect );
} else if ( line.startsWith( "modify" ) ) {
int modifyBlockEnd = line.lastIndexOf( '}' );
if ( modifyBlockEnd > 0 ) {
String variable = line.substring( line.indexOf( '(' ) + 1,
line.indexOf( ')' ) ).trim();
ActionUpdateField action = new ActionUpdateField();
action.setVariable( variable );
m.addRhsItem( action );
addModifiersToAction( line.substring( line.indexOf( '{' ) + 1,
modifyBlockEnd ).trim(),
action,
boundParams,
dmo,
m.getImports(),
isJavaDialect );
} else {
modifiedVariable = line.substring( line.indexOf( '(' ) + 1,
line.indexOf( ')' ) ).trim();
int modifyBlockStart = line.indexOf( '{' );
if ( modifyBlockStart > 0 ) {
modifiers = line.substring( modifyBlockStart + 1 ).trim();
}
}
} else if ( line.startsWith( "retract" ) || line.startsWith( "delete" ) ) {
String variable = unwrapParenthesis( line );
m.addRhsItem( new ActionRetractFact( variable ) );
} else if ( line.startsWith( "org.drools.core.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 {