KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > impl > AddingCommand


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.impl;
17
18
19 import org.apache.commons.chain.Chain;
20 import org.apache.commons.chain.Command;
21 import org.apache.commons.chain.Context;
22
23
24 /**
25  * <p>Implementation of {@link Command} that logs its identifier and
26  * and attempts to add a new {@link Command} to the {@link Chain}. This
27  * should cause an IllegalStateException if the {@link Chain} implementation
28  * subclasses <code>ChainBase</code>.</p>
29  *
30  * @author Craig R. McClanahan
31  * @version $Revision: 1.4 $ $Date: 2004/02/25 00:01:05 $
32  */

33
34 public class AddingCommand extends NonDelegatingCommand {
35
36
37     // ------------------------------------------------------------ Constructor
38

39
40     public AddingCommand() {
41     this("", null);
42     }
43
44     // Construct an instance that will log the specified identifier
45
public AddingCommand(String JavaDoc id, Chain parent) {
46         super(id);
47         this.parent = parent;
48     }
49
50
51     // The parent Chain
52
private Chain parent = null;
53
54
55     // -------------------------------------------------------- Command Methods
56

57
58     // Execution method for this Command
59
public boolean execute(Context context, Chain chain) throws Exception JavaDoc {
60
61         super.execute(context);
62         parent.addCommand(new NonDelegatingCommand("NEW")); // Should cause ISE
63
return (true);
64
65     }
66
67
68 }
69
Popular Tags