01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import org.apache.commons.chain.Chain;
19: import org.apache.commons.chain.Command;
20: import org.apache.commons.chain.Context;
21:
22: /**
23: * <p>Implementation of {@link Command} that logs its identifier and
24: * and attempts to add a new {@link Command} to the {@link Chain}. This
25: * should cause an IllegalStateException if the {@link Chain} implementation
26: * subclasses <code>ChainBase</code>.</p>
27: *
28: * @author Craig R. McClanahan
29: * @version $Revision: 155403 $ $Date: 2005-02-26 12:52:46 +0000 (Sat, 26 Feb 2005) $
30: */
31:
32: public class AddingCommand extends NonDelegatingCommand {
33:
34: // ------------------------------------------------------------ Constructor
35:
36: public AddingCommand() {
37: this ("", null);
38: }
39:
40: // Construct an instance that will log the specified identifier
41: public AddingCommand(String id, Chain parent) {
42: super (id);
43: this .parent = parent;
44: }
45:
46: // The parent Chain
47: private Chain parent = null;
48:
49: // -------------------------------------------------------- Command Methods
50:
51: // Execution method for this Command
52: public boolean execute(Context context, Chain chain)
53: throws Exception {
54:
55: super .execute(context);
56: parent.addCommand(new NonDelegatingCommand("NEW")); // Should cause ISE
57: return (true);
58:
59: }
60:
61: }
|