}
final Process process = ((InternalRuleBase) getRuleBase()).getProcess( processId );
if ( process == null ) {
throw new IllegalArgumentException( "Unknown process ID: " + processId );
}
ProcessInstance processInstance = ( ProcessInstance ) getProcessInstance( process );
processInstance.setWorkingMemory( this );
processInstance.setProcess( process );
processInstanceManager.addProcessInstance( processInstance );
// set variable default values
// TODO: should be part of processInstanceImpl?
VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext( VariableScope.VARIABLE_SCOPE );
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
// set input parameters
if ( parameters != null ) {
if ( variableScope != null ) {
for ( Map.Entry<String, Object> entry : parameters.entrySet() ) {
variableScopeInstance.setVariable( entry.getKey(),
entry.getValue() );
}
} else {
throw new IllegalArgumentException( "This process does not support parameters!" );
}
}
// start
getRuleFlowEventSupport().fireBeforeRuleFlowProcessStarted( processInstance,
this );
processInstance.start();
getRuleFlowEventSupport().fireAfterRuleFlowProcessStarted( processInstance,
this );
return processInstance;
}