01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.extension.applet.runner;
03:
04: import com.canoo.webtest.boundary.StreamBoundary;
05: import com.canoo.webtest.boundary.AppletRunnerBoundary;
06: import com.canoo.webtest.extension.applet.AppletPluginArguments;
07: import org.apache.log4j.Logger;
08:
09: import java.io.FileInputStream;
10: import java.io.IOException;
11: import java.io.ObjectInputStream;
12:
13: /**
14: * Helper class for applet test scenarii.
15: * @author Denis N. Antonioli
16: * @author Paul King
17: */
18: public class AppletRunnerHelper {
19: private static final Logger LOG = Logger
20: .getLogger(AppletRunnerHelper.class);
21: private final int fClassNotFoundErrorCode;
22: private final int fIoErrorCode;
23: private final AppletRunnerBoundary fBoundary;
24:
25: public AppletRunnerHelper(int classNotFoundErrorCode,
26: int ioErrorCode, AppletRunnerBoundary boundary) {
27: fClassNotFoundErrorCode = classNotFoundErrorCode;
28: fIoErrorCode = ioErrorCode;
29: fBoundary = boundary;
30: }
31:
32: public AppletPluginArguments readPluginArguments(String file) {
33: FileInputStream fis = null;
34: ObjectInputStream ois = null;
35: try {
36: fis = new FileInputStream(file);
37: ois = createObjectInputStream(fis);
38: return (AppletPluginArguments) readObject(ois);
39: } catch (ClassNotFoundException e) {
40: LOG.error("Can't deserialize the arguments.", e);
41: fBoundary.processClassNotFound(fClassNotFoundErrorCode);
42: } catch (IOException e) {// as well as FileNotFoundException
43: LOG.error("Can't read the arguments file.", e);
44: fBoundary.processIoException(fIoErrorCode);
45: } finally {
46: StreamBoundary.closeInputStream(ois);
47: StreamBoundary.closeInputStream(fis);
48: }
49: return null;
50: }
51:
52: protected ObjectInputStream createObjectInputStream(
53: FileInputStream fis) throws IOException {
54: return new ObjectInputStream(fis);
55: }
56:
57: protected Object readObject(ObjectInputStream ois)
58: throws IOException, ClassNotFoundException {
59: return ois.readObject();
60: }
61:
62: }
|