1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.impl;
17
18
19 import org.apache.commons.chain.Command;
20 import org.apache.commons.chain.Context;
21
22
23 /***
24 * <p>Implementation of {@link Command} that simply logs its identifier
25 * and returns.</p>
26 *
27 * @author Craig R. McClanahan
28 * @version $Revision: 1.6 $ $Date: 2004/02/25 00:01:05 $
29 */
30
31 public class NonDelegatingCommand implements Command {
32
33
34
35
36
37 public NonDelegatingCommand() {
38 this("");
39 }
40
41
42
43 public NonDelegatingCommand(String id) {
44 this.id = id;
45 }
46
47
48
49
50
51
52 protected String id = null;
53
54 String getId() {
55 return (this.id);
56 }
57
58 public void setId(String id) {
59 this.id = id;
60 }
61
62
63
64
65
66
67 public boolean execute(Context context) throws Exception {
68
69 if (context == null) {
70 throw new IllegalArgumentException();
71 }
72 log(context, id);
73 return (true);
74
75 }
76
77
78
79
80
81
82 /***
83 * <p>Log the specified <code>id</code> into a StringBuffer attribute
84 * named "log" in the specified <code>context</code>, creating it if
85 * necessary.</p>
86 *
87 * @param context The {@link Context} into which we log the identifiers
88 * @param id The identifier to be logged
89 */
90 protected void log(Context context, String id) {
91 StringBuffer sb = (StringBuffer) context.get("log");
92 if (sb == null) {
93 sb = new StringBuffer();
94 context.put("log", sb);
95 }
96 if (sb.length() > 0) {
97 sb.append('/');
98 }
99 sb.append(id);
100 }
101
102
103 }