01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.test.web.framework.actions;
18:
19: import org.w3c.dom.Node;
20:
21: import edu.iu.uis.eden.test.web.framework.Property;
22: import edu.iu.uis.eden.test.web.framework.PropertyScheme;
23: import edu.iu.uis.eden.test.web.framework.Script;
24: import edu.iu.uis.eden.test.web.framework.Util;
25:
26: /**
27: * ScriptAction that puts the thread to sleep for a specified
28: * amount of seconds
29: * <pre>
30: * <sleep seconds="..." />
31: * </pre>
32: * The 'seconds' attribute is resolved via {@link edu.iu.uis.eden.test.web.framework.Util#getResolvableAttribute(Node, String, PropertyScheme)},
33: * defaulting to literal scheme.
34: * @author Aaron Hamid (arh14 at cornell dot edu)
35: * @author Aaron Hamid (arh14 at cornell dot edu)
36: */
37: public class SleepAction extends BaseScriptAction {
38: private static final String[] NAMES = { "sleep" };
39:
40: public String[] getNames() {
41: return NAMES;
42: }
43:
44: public void process(Script script, Node node) {
45: Property property = Util.getResolvableAttribute(node,
46: "seconds", PropertyScheme.LITERAL_SCHEME);
47: if (property == null) {
48: String message = "'seconds' attribute must be specified for 'sleep' element";
49: log.error(message);
50: throw new RuntimeException(message);
51: }
52: Object o = script.getState().retrieveProperty(property);
53: if (o == null) {
54: String message = "Could not load seconds property: "
55: + property;
56: log.error(message);
57: throw new RuntimeException(message);
58: }
59: int secs = Integer.parseInt(o.toString());
60: log.info("Sleeping for " + secs + " seconds...");
61: try {
62: Thread.sleep(secs * 1000);
63: } catch (InterruptedException ie) {
64: log.error("Interrupted during sleep", ie);
65: }
66: }
67:
68: public String toString() {
69: return "[SleepAction]";
70: }
71: }
|