1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.model;
18
19 import org.apache.commons.logging.LogFactory;
20 import org.apache.commons.scxml.SCXMLHelper;
21
22 /***
23 * A custom action is simply a tuple consisting of a namespace URI,
24 * the local name for the custom action and the corresponding
25 * {@link Action} class.
26 *
27 */
28 public class CustomAction {
29
30 /***
31 * Error logged while attempting to define a custom action
32 * in a null or empty namespace.
33 */
34 private static final String ERR_NO_NAMESPACE =
35 "Cannot define a custom SCXML action with a null or empty namespace";
36
37 /***
38 * The SCXML namespace, to which custom actions may not be added.
39 */
40 private static final String NAMESPACE_SCXML =
41 "http://www.w3.org/2005/07/scxml";
42
43 /***
44 * Error logged while attempting to define a custom action
45 * with the SCXML namespace.
46 */
47 private static final String ERR_RESERVED_NAMESPACE =
48 "Cannot define a custom SCXML action within the SCXML namespace '"
49 + NAMESPACE_SCXML + "'";
50
51 /***
52 * Error logged while attempting to define a custom action
53 * in a null or empty local name.
54 */
55 private static final String ERR_NO_LOCAL_NAME =
56 "Cannot define a custom SCXML action with a null or empty local name";
57
58 /***
59 * Error logged while attempting to define a custom action
60 * which does not extend {@link Action}.
61 */
62 private static final String ERR_NOT_AN_ACTION =
63 "Custom SCXML action does not extend Action superclass";
64
65 /***
66 * The namespace this custom action belongs to.
67 */
68 private String namespaceURI;
69
70 /***
71 * The local name of the custom action.
72 */
73 private String localName;
74
75 /***
76 * The implementation of this custom action.
77 */
78 private Class actionClass;
79
80 /***
81 * The log for this custom action.
82 */
83 private org.apache.commons.logging.Log log;
84
85 /***
86 * Constructor, if the namespace or local name is null or empty,
87 * or if the implementation is not an {@link Action}, an
88 * {@link IllegalArgumentException} is thrown.
89 *
90 * @param namespaceURI The namespace URI for this custom action.
91 * @param localName The local name for this custom action.
92 * @param actionClass The {@link Action} subclass implementing this
93 * custom action.
94 */
95 public CustomAction(final String namespaceURI, final String localName,
96 final Class actionClass) {
97 this.log = LogFactory.getLog(CustomAction.class);
98 if (SCXMLHelper.isStringEmpty(namespaceURI)) {
99 log.error(ERR_NO_NAMESPACE);
100 throw new IllegalArgumentException(ERR_NO_NAMESPACE);
101 }
102 if (namespaceURI.trim().equalsIgnoreCase(NAMESPACE_SCXML)) {
103 log.error(ERR_RESERVED_NAMESPACE);
104 throw new IllegalArgumentException(ERR_RESERVED_NAMESPACE);
105 }
106 if (SCXMLHelper.isStringEmpty(localName)) {
107 log.error(ERR_NO_LOCAL_NAME);
108 throw new IllegalArgumentException(ERR_NO_LOCAL_NAME);
109 }
110 if (actionClass == null
111 || !Action.class.isAssignableFrom(actionClass)) {
112 log.error(ERR_NOT_AN_ACTION);
113 throw new IllegalArgumentException(ERR_NOT_AN_ACTION);
114 }
115 this.namespaceURI = namespaceURI;
116 this.localName = localName;
117 this.actionClass = actionClass;
118 }
119
120 /***
121 * Get this custom action's implementation.
122 *
123 * @return Returns the action class.
124 */
125 public Class getActionClass() {
126 return actionClass;
127 }
128
129 /***
130 * Get the local name for this custom action.
131 *
132 * @return Returns the local name.
133 */
134 public String getLocalName() {
135 return localName;
136 }
137
138 /***
139 * Get the namespace URI for this custom action.
140 *
141 * @return Returns the namespace URI.
142 */
143 public String getNamespaceURI() {
144 return namespaceURI;
145 }
146
147 }
148