KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > webapp > command > Macro


1 package com.icesoft.faces.webapp.command;
2
3 import java.io.IOException JavaDoc;
4 import java.io.Writer JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Arrays JavaDoc;
7 import java.util.Collection JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 public class Macro implements Command {
11     private Collection JavaDoc commands = new ArrayList JavaDoc();
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 JavaDoc writer) throws IOException JavaDoc {
64         Iterator JavaDoc 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 }
73
Popular Tags