1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.generic;
17
18
19 import org.apache.commons.chain.Command;
20 import org.apache.commons.chain.Context;
21
22
23 /***
24 * <p>Copy a specified literal value, or a context attribute stored under
25 * the <code>fromKey</code> (if any), to the <code>toKey</code>.</p>
26 *
27 * @author Craig R. McClanahan
28 * @version $Revision: 1.7 $ $Date: 2004/02/25 00:01:07 $
29 */
30
31 public class CopyCommand implements Command {
32
33
34
35
36
37 private String fromKey = null;
38
39
40 /***
41 * <p>Return the context attribute key for the source attribute.</p>
42 */
43 public String getFromKey() {
44
45 return (this.fromKey);
46
47 }
48
49
50 /***
51 * <p>Set the context attribute key for the source attribute.</p>
52 *
53 * @param fromKey The new key
54 */
55 public void setFromKey(String fromKey) {
56
57 this.fromKey = fromKey;
58
59 }
60
61
62 private String toKey = null;
63
64
65 /***
66 * <p>Return the context attribute key for the destination attribute.</p>
67 */
68 public String getToKey() {
69
70 return (this.toKey);
71
72 }
73
74
75 /***
76 * <p>Set the context attribute key for the destination attribute.</p>
77 *
78 * @param toKey The new key
79 */
80 public void setToKey(String toKey) {
81
82 this.toKey = toKey;
83
84 }
85
86
87 private String value = null;
88
89
90 /***
91 * <p>Return the literal value to be copied.</p>
92 */
93 public String getValue() {
94
95 return (this.value);
96
97 }
98
99
100 /***
101 * <p>Set the literal value to be copied.</p>
102 *
103 * @param value The new value
104 */
105 public void setValue(String value) {
106
107 this.value = value;
108
109 }
110
111
112
113
114
115 /***
116 * <p>Copy a specified literal value, or a context attribute stored under
117 * the <code>fromKey</code> (if any), to the <code>toKey</code>.</p>
118 *
119 * @param context {@link Context} in which we are operating
120 *
121 * @return <code>false</code> so that processing will continue
122 */
123 public boolean execute(Context context) throws Exception {
124
125 Object value = this.value;
126 if (value == null) {
127 context.get(getFromKey());
128 }
129 if (value != null) {
130 context.put(getToKey(), value);
131 } else {
132 context.remove(getToKey());
133 }
134 return (false);
135
136 }
137
138
139 }