View Javadoc
1   /*
2    * 
3    * $Revision: 1.5 $
4    * $Date: 2004/07/09 18:02:28 $
5    *
6    * ====================================================================
7    * struts-it
8    * Copyright (C) 2004 - strutsit community
9    * 
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   * 
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   * 
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   *
22   * created: 2004-06-05  Manfred Wolff
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      /// List of all dependencies as names
42      private List dependencyNames = new ArrayList();
43  
44      /// List of all dependencies as classnames
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 }