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