in src/main/java/org/apache/commons/scxml2/model/Invoke.java [359:462]
public void execute(final ActionExecutionContext axctx) throws ModelException {
final EnterableState parentState = getParentEnterableState();
final Context ctx = axctx.getContext(parentState);
final SCXMLExecutionContext exctx = (SCXMLExecutionContext)ctx.getVars().get(getCurrentSCXMLExecutionContextKey());
if (exctx == null) {
throw new ModelException("Missing current SCXMLExecutionContext instance in context under key: "+ getCurrentSCXMLExecutionContextKey());
}
try {
final Evaluator eval = axctx.getEvaluator();
String typeValue = type;
if (typeValue == null && typeexpr != null) {
typeValue = (String)eval.eval(ctx, typeexpr);
if (typeValue == null) {
throw new SCXMLExpressionException("<invoke> for state "+parentState.getId() +
": type expression \"" + typeexpr + "\" evaluated to null or empty String");
}
}
if (typeValue == null) {
typeValue = SCXMLExecutionContext.SCXML_INVOKER_TYPE;
}
final Invoker invoker = exctx.newInvoker(typeValue);
String invokeId = getId();
if (invokeId == null) {
invokeId = parentState.getId() + "." + ctx.get(SCXMLSystemContext.SESSIONID_KEY) + "." + invokeIndex;
}
if (getId() == null && getIdlocation() != null) {
eval.evalAssign(ctx, idlocation, invokeId);
}
invoker.setInvokeId(invokeId);
String src = getSrc();
if (src == null && getSrcexpr() != null) {
src = (String)eval.eval(ctx, getSrcexpr());
}
if (src != null) {
final PathResolver pr = exctx.getStateMachine().getPathResolver();
if (pr != null) {
src = pr.resolvePath(src);
}
}
Object contentValue = null;
if (src == null && content != null) {
if (content.getExpr() != null) {
try {
contentValue = eval.eval(ctx, content.getExpr());
} catch (final SCXMLExpressionException e) {
exctx.getInternalIOProcessor().addEvent(new EventBuilder(TriggerEvent.ERROR_EXECUTION,
TriggerEvent.ERROR_EVENT).build());
exctx.getErrorReporter().onError(ErrorConstants.EXPRESSION_ERROR,
"Failed to evaluate <invoke> <content> expression due to error: "+ e.getMessage()
+ ", Using empty value instead.", getParent());
contentValue = "";
}
} else if (content.getParsedValue() != null) {
contentValue = content.getParsedValue().getValue();
}
if (contentValue instanceof String) {
// inline content
} else if (contentValue instanceof Element) {
// xml based content (must be assigned through data)
final Element contentElement = (Element)contentValue;
if (!SCXMLConstants.ELEM_SCXML.equals(contentElement.getLocalName()) || !SCXMLConstants.XMLNS_SCXML.equals(contentElement.getNamespaceURI())) {
throw new ActionExecutionError("<invoke> for state "+parentState.getId() +
": invalid <content> definition");
}
// statemachine definition: transform to string as we cannot (yet) pass XML directly to invoker
try {
contentValue = ContentParser.DEFAULT_PARSER.toXml(contentElement);
}
catch (final IOException e) {
throw new ActionExecutionError("<invoke> for state "+parentState.getId() +
": invalid <content><scxml> definition");
}
} else {
throw new ActionExecutionError("<invoke> for state "+parentState.getId() +
": invalid <content> definition");
}
}
if (src == null && contentValue == null) {
throw new ActionExecutionError("<invoke> for state "+parentState.getId() +
": no src and no content defined");
}
final Map<String, Object> payloadDataMap = new HashMap<>();
PayloadBuilder.addNamelistDataToPayload(parentState, ctx, eval, exctx.getErrorReporter(), namelist, payloadDataMap);
PayloadBuilder.addParamsToPayload(ctx, eval, paramsList, payloadDataMap);
invoker.setParentSCXMLExecutor(exctx.getSCXMLExecutor());
if (src != null) {
invoker.invoke(src, payloadDataMap);
}
else {
invoker.invokeContent((String)contentValue, payloadDataMap);
}
exctx.registerInvoker(this, invoker);
}
catch (InvokerException|ActionExecutionError|SCXMLExpressionException e) {
axctx.getInternalIOProcessor().addEvent(new EventBuilder(TriggerEvent.ERROR_EXECUTION, TriggerEvent.ERROR_EVENT).build());
if (e.getMessage() != null) {
axctx.getErrorReporter().onError(e instanceof SCXMLExpressionException
? ErrorConstants.EXPRESSION_ERROR : ErrorConstants.EXECUTION_ERROR, e.getMessage(), this);
}
}
}