1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.scxml2.model;
18
19 import org.apache.commons.scxml2.ActionExecutionContext;
20 import org.apache.commons.scxml2.Context;
21 import org.apache.commons.scxml2.Evaluator;
22 import org.apache.commons.scxml2.SCXMLExpressionException;
23
24 /**
25 * The class in this SCXML object model that corresponds to the
26 * <cancel> SCXML element.
27 *
28 */
29 public class Cancel extends Action {
30
31 /**
32 * Serial version UID.
33 */
34 private static final long serialVersionUID = 1L;
35
36 /**
37 * Constructor.
38 */
39 public Cancel() {
40 super();
41 }
42
43 /**
44 * The ID of the send message that should be cancelled.
45 */
46 private String sendid;
47
48 /**
49 * The expression that evaluates to the ID of the send message that should be cancelled.
50 */
51 private String sendidexpr;
52
53 /**
54 * Get the ID of the send message that should be cancelled.
55 *
56 * @return Returns the sendid.
57 */
58 public String getSendid() {
59 return sendid;
60 }
61
62 /**
63 * Set the ID of the send message that should be cancelled.
64 *
65 * @param sendid The sendid to set.
66 */
67 public void setSendid(final String sendid) {
68 this.sendid = sendid;
69 }
70
71 /**
72 * Get the expression that evaluates to the ID of the send message that should be cancelled.
73 *
74 * @return the expression that evaluates to the ID of the send message that should be cancelled.
75 */
76 public String getSendidexpr() {
77 return sendidexpr;
78 }
79
80 /**
81 * Set the expression that evaluates to the ID of the send message that should be cancelled.
82 *
83 * @param sendidexpr the expression that evaluates to the ID of the send message that should be cancelled.
84 */
85 public void setSendidexpr(String sendidexpr) {
86 this.sendidexpr = sendidexpr;
87 }
88
89 /**
90 * {@inheritDoc}
91 */
92 @Override
93 public void execute(ActionExecutionContext exctx) throws ModelException, SCXMLExpressionException {
94 EnterableState parentState = getParentEnterableState();
95 Context ctx = exctx.getContext(parentState);
96 ctx.setLocal(getNamespacesKey(), getNamespaces());
97 Evaluator eval = exctx.getEvaluator();
98
99 String sendidValue = sendid;
100 if (sendidValue == null && sendidexpr != null) {
101 sendidValue = (String) getTextContentIfNodeResult(eval.eval(ctx, sendidexpr));
102 if ((sendidValue == null || sendidValue.trim().length() == 0)
103 && exctx.getAppLog().isWarnEnabled()) {
104 exctx.getAppLog().warn("<send>: sendid expression \"" + sendidexpr
105 + "\" evaluated to null or empty String");
106 }
107 }
108
109 exctx.getEventDispatcher().cancel(sendidValue);
110 }
111 }
112