1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.strutsit.chain;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.commons.chain.Command;
30 import org.apache.commons.chain.Context;
31
32 /***
33 * Abstract Command for checking dependencies
34 *
35 * @author <a href="mailto:wolff@struts-it.de">Manfred Wolff </a>
36 * @since JDK 1.4
37 * @version $Revision: 1.5 $
38 */
39 public abstract class DependCommand implements Command {
40
41
42 private List dependencyNames = new ArrayList();
43
44
45 private List dependencyClassNames = new ArrayList();
46
47 /***
48 * Register a dependency as a name.
49 *
50 * @param name
51 * The name of the command that depends
52 */
53 protected void registerName(String name) {
54
55 if (!dependencyNames.contains(name)) {
56 dependencyNames.add(name);
57 }
58 }
59
60 /***
61 * Register a dependency as a className
62 *
63 * @param className
64 * The className of the command that depends
65 */
66 protected void registerClassName(String className) {
67
68 if (!dependencyClassNames.contains(className)) {
69 dependencyClassNames.add(className);
70 }
71 }
72
73 /***
74 * Returns all names as a List object.
75 *
76 * @return A List object with all names.
77 */
78 public List getNames() {
79 return dependencyNames;
80 }
81
82 /***
83 * Returns all classNames as a List object.
84 *
85 * @return A List object with all ClassNames.
86 */
87 public List getClassNames() {
88 return dependencyClassNames;
89 }
90
91 /***
92 * A DependCommand has to registers his dependencies.
93 */
94 public abstract void doRegister();
95
96 /***
97 * <p>
98 * Execute a unit of processing work to be performed. This {@link Command}
99 * may either complete the required processing and return <code>true</code>,
100 * or delegate remaining processing to the next {@link Command}in a
101 * {@link Chain}containing this {@link Command}by returning
102 * <code>false</code>
103 *
104 * @param context
105 * The {@link Context}to be processed by this {@link Command}
106 *
107 * @exception ChainException
108 * general purpose exception return to indicate abnormal
109 * termination
110 *
111 * @return <code>true</code> if the processing of this {@link Context}has
112 * been completed, or <code>false</code> if the processing of this
113 * {@link Context}should be delegated to a subsequent
114 * {@link Command}in an enclosing {@link Chain}
115 */
116 public abstract boolean execute(Context context) throws Exception;
117
118 }