1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.server;
24
25 import java.io.IOException;
26 import java.io.PrintWriter;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import de.bea.domingo.DNotesException;
31 import de.bea.domingo.DSession;
32
33 /***
34 * Domingo server.
35 * TODO.
36 *
37 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
38 */
39 public final class DomingoServer extends BaseCommand implements Command {
40
41 private final Map commands = new HashMap();
42
43 /***
44 * Constructor.
45 */
46 public DomingoServer() {
47 super();
48 commands.put("error", new ErrorCommand());
49 commands.put("readdatabase", new ReadDatabaseCommand());
50 commands.put("readdocument", new ReadDocumentCommand());
51 commands.put("savedocument", new SaveDocumentCommand());
52 commands.put("createdatabase", new CreateDatabaseCommand());
53 commands.put("createdatabasefromtemplate", new CreateDatabaseFromTemplateCommand());
54 }
55
56 /***
57 * Executes a domingo request with the specified parameters.
58 * Depending on the <code>cmd</code> parameter, the request is delegated to the
59 * corresponsing implementation of the {@link Command} interface.
60 *
61 * @see de.bea.domingo.server.Command#execute(de.bea.domingo.DSession, java.util.Map, java.io.PrintWriter)
62 *
63 * @param session domingo session for execution
64 * @param parameters request parameters
65 * @param printWriter response stream for output
66 * @throws DNotesException if the command cannot be executed
67 * @throws IOException if the response could not be created or completed
68 * @throws UnsupportedOperationException if the specified command doesn't exist
69 */
70 public void execute(final DSession session, final Map parameters, final PrintWriter printWriter)
71 throws UnsupportedOperationException, DNotesException, IOException {
72 final String commandString = getParameterString(parameters, "cmd");
73 final Command command = (Command) commands.get(commandString.toLowerCase());
74 Exception exception = null;
75 if (command == null) {
76 throw new UnsupportedOperationException("Cannot execute command " + commandString);
77 }
78 try {
79 command.execute(session, parameters, printWriter);
80 } catch (UnsupportedOperationException e) {
81 parameters.put("error_id", "7001");
82 exception = e;
83 } catch (DNotesException e) {
84 parameters.put("error_id", "7002");
85 exception = e;
86 } catch (IOException e) {
87 parameters.put("error_id", "7003");
88 exception = e;
89 }
90 if (exception != null) {
91 parameters.put("exception", exception);
92 Command errorCommand = (Command) commands.get("error");
93 errorCommand.execute(session, parameters, printWriter);
94 }
95 }
96 }