01: // Copyright © 2004-2005 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.boundary;
03:
04: import com.canoo.webtest.engine.StepExecutionException;
05: import com.canoo.webtest.extension.applet.AppletRunnerStep;
06: import com.canoo.webtest.steps.Step;
07: import org.apache.log4j.Logger;
08: import org.apache.tools.ant.taskdefs.Execute;
09: import org.apache.tools.ant.types.CommandlineJava;
10:
11: import java.io.IOException;
12: import java.net.MalformedURLException;
13: import java.net.URL;
14:
15: /**
16: * Boundary class for {@link AppletRunnerStep}.
17: *
18: * @author Paul King
19: */
20: public final class AppletRunnerStepBoundary {
21: private static final Logger LOG = Logger
22: .getLogger(AppletRunnerStepBoundary.class);
23:
24: private AppletRunnerStepBoundary() {
25: }
26:
27: public static CommandlineJava tryClone(
28: final CommandlineJava fCommandline, final Step step) {
29: try {
30: return (CommandlineJava) fCommandline.clone();
31: } catch (CloneNotSupportedException e) {
32: throw new StepExecutionException(e.getMessage(), step);
33: }
34: }
35:
36: public static int tryExecute(final Execute execute, final Step step) {
37: try {
38: return execute.execute();
39: } catch (IOException e) {
40: final String message = "Execute fork failed: ";
41: LOG.error(message, e);
42: throw new StepExecutionException(message + e.getMessage(),
43: step);
44: }
45: }
46:
47: public static URL tryGetUrlForClass(final String aClassName,
48: final AppletRunnerStep step) {
49: try {
50: return AppletRunnerStep.getUrlForClass(aClassName);
51: } catch (MalformedURLException e) {
52: final String msg = e.getMessage() + " for class "
53: + aClassName;
54: LOG.error(msg, e);
55: throw new StepExecutionException(msg, step);
56: }
57: }
58: }
|