KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > generic > CopyCommand


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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     // -------------------------------------------------------------- Properties
35

36
37     private String JavaDoc fromKey = null;
38
39
40     /**
41      * <p>Return the context attribute key for the source attribute.</p>
42      */

43     public String JavaDoc 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 JavaDoc fromKey) {
56
57     this.fromKey = fromKey;
58
59     }
60
61
62     private String JavaDoc toKey = null;
63
64
65     /**
66      * <p>Return the context attribute key for the destination attribute.</p>
67      */

68     public String JavaDoc 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 JavaDoc toKey) {
81
82     this.toKey = toKey;
83
84     }
85
86
87     private String JavaDoc value = null;
88
89
90     /**
91      * <p>Return the literal value to be copied.</p>
92      */

93     public String JavaDoc 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 JavaDoc value) {
106
107         this.value = value;
108
109     }
110
111
112     // ---------------------------------------------------------- Filter Methods
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 JavaDoc {
124
125     Object JavaDoc 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 }
140
Popular Tags