01: package com.icesoft.faces.webapp.command;
02:
03: import java.io.IOException;
04: import java.io.Writer;
05: import java.util.ArrayList;
06: import java.util.Arrays;
07: import java.util.Collection;
08: import java.util.Iterator;
09:
10: public class Macro implements Command {
11: private Collection commands = new ArrayList();
12:
13: public Macro(Command commandA, Command commandB) {
14: commands.add(commandA);
15: commands.add(commandB);
16: }
17:
18: public Macro(Command[] commands) {
19: this .commands.addAll(Arrays.asList(commands));
20: }
21:
22: public Command coalesceWith(Command command) {
23: return command.coalesceWith(this );
24: }
25:
26: public Command coalesceWith(UpdateElements updateElements) {
27: commands.add(updateElements);
28: return this ;
29: }
30:
31: public Command coalesceWith(Redirect redirect) {
32: commands.add(redirect);
33: return this ;
34: }
35:
36: public Command coalesceWith(SessionExpired sessionExpired) {
37: return sessionExpired;
38: }
39:
40: public Command coalesceWith(Macro macro) {
41: commands.addAll(macro.commands);
42: return this ;
43: }
44:
45: public void addCommand(Command command) {
46: commands.add(command);
47: }
48:
49: public Command coalesceWith(SetCookie setCookie) {
50: commands.add(setCookie);
51: return this ;
52: }
53:
54: public Command coalesceWith(Pong pong) {
55: commands.add(pong);
56: return this ;
57: }
58:
59: public Command coalesceWith(NOOP noop) {
60: return this ;
61: }
62:
63: public void serializeTo(Writer writer) throws IOException {
64: Iterator i = commands.iterator();
65: writer.write("<macro>");
66: while (i.hasNext()) {
67: Command command = (Command) i.next();
68: command.serializeTo(writer);
69: }
70: writer.write("</macro>");
71: }
72: }
|