in src/main/java/org/apache/commons/scxml2/model/Send.java [385:479]
public void execute(final ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
// Send attributes evaluation
final EnterableState parentState = getParentEnterableState();
final Context ctx = exctx.getContext(parentState);
final Evaluator eval = exctx.getEvaluator();
// Most attributes of <send> are expressions so need to be
// evaluated before the EventDispatcher callback
Object hintsValue = null;
if (hints != null) {
hintsValue = eval.eval(ctx, hints);
}
if (idlocation != null) {
if (id == null) {
id = ctx.getSystemContext().generateSessionId();
}
eval.evalAssign(ctx, idlocation, id);
}
String targetValue = target;
if (targetValue == null && targetexpr != null) {
targetValue = (String)eval.eval(ctx, targetexpr);
if ((targetValue == null || targetValue.trim().isEmpty())
&& exctx.getAppLog().isWarnEnabled()) {
exctx.getAppLog().warn("<send>: target expression \"" + targetexpr
+ "\" evaluated to null or empty String");
}
}
String typeValue = type;
if (typeValue == null && typeexpr != null) {
typeValue = (String)eval.eval(ctx, typeexpr);
if ((typeValue == null || typeValue.trim().isEmpty())
&& exctx.getAppLog().isWarnEnabled()) {
exctx.getAppLog().warn("<send>: type expression \"" + typeexpr
+ "\" evaluated to null or empty String");
}
}
if (typeValue == null) {
// must default to 'scxml' when unspecified
typeValue = SCXMLIOProcessor.DEFAULT_EVENT_PROCESSOR;
} else if (!SCXMLIOProcessor.DEFAULT_EVENT_PROCESSOR.equals(typeValue) && typeValue.trim().equalsIgnoreCase(SCXMLIOProcessor.SCXML_EVENT_PROCESSOR)) {
typeValue = SCXMLIOProcessor.DEFAULT_EVENT_PROCESSOR;
}
Object payload = null;
final Map<String, Object> payloadDataMap = new LinkedHashMap<>();
PayloadBuilder.addNamelistDataToPayload(parentState, ctx, eval, exctx.getErrorReporter(), namelist, payloadDataMap);
PayloadBuilder.addParamsToPayload(ctx, eval, paramsList, payloadDataMap);
if (!payloadDataMap.isEmpty()) {
payload = payloadDataMap;
}
else if (content != null) {
if (content.getExpr() != null) {
Object evalResult;
try {
evalResult = 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 <send> <content> expression due to error: "+ e.getMessage()
+ ", Using empty value instead.", getParent());
evalResult = "";
}
payload = eval.cloneData(evalResult);
} else if (content.getParsedValue() != null) {
payload = content.getParsedValue().getValue();
}
}
long wait = 0L;
String delayString = delay;
if (delayString == null && delayexpr != null) {
final Object delayValue = eval.eval(ctx, delayexpr);
if (delayValue != null) {
delayString = delayValue.toString();
}
}
if (delayString != null) {
wait = parseDelay(delayString, delayexpr != null, delayexpr != null ? delayexpr : delay);
}
String eventValue = event;
if (eventValue == null && eventexpr != null) {
eventValue = (String)eval.eval(ctx, eventexpr);
if ((eventValue == null)) {
throw new SCXMLExpressionException("<send>: event expression \"" + eventexpr
+ "\" evaluated to null");
}
}
final Map<String, SCXMLIOProcessor> ioProcessors = (Map<String, SCXMLIOProcessor>) ctx.get(SCXMLSystemContext.IOPROCESSORS_KEY);
if (exctx.getAppLog().isDebugEnabled()) {
exctx.getAppLog().debug("<send>: Dispatching event '" + eventValue
+ "' to target '" + targetValue + "' of target type '"
+ typeValue + "' with suggested delay of " + wait
+ "ms");
}
exctx.getEventDispatcher().send(ioProcessors, id, targetValue, typeValue, eventValue,
payload, hintsValue, wait);
}