01: /*
02: * Copyright 2003-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;
17:
18: /**
19: * <p>A {@link Filter} is a specialized {@link Command} that also expects
20: * the {@link Chain} that is executing it to call the
21: * <code>postprocess()</code> method if it called the <code>execute()</code>
22: * method. This promise must be fulfilled in spite of any possible
23: * exceptions thrown by the <code>execute()</code> method of this
24: * {@link Command}, or any subsequent {@link Command} whose
25: * <code>execute()</code> method was called. The owning {@link Chain}
26: * must call the <code>postprocess()</code> method of each {@link Filter}
27: * in a {@link Chain} in reverse order of the invocation of their
28: * <code>execute()</code> methods.</p>
29: *
30: * <p>The most common use case for a {@link Filter}, as opposed to a
31: * {@link Command}, is where potentially expensive resources must be acquired
32: * and held until the processing of a particular request has been completed,
33: * even if execution is delegated to a subsequent {@link Command} via the
34: * <code>execute()</code> returning <code>false</code>. A {@link Filter}
35: * can reliably release such resources in the <code>postprocess()</code>
36: * method, which is guaranteed to be called by the owning {@link Chain}.</p>
37: *
38: * @author Craig R. McClanahan
39: * @version $Revision: 155403 $ $Date: 2005-02-26 12:52:46 +0000 (Sat, 26 Feb 2005) $
40: */
41:
42: public interface Filter extends Command {
43:
44: /**
45: * <p>Execute any cleanup activities, such as releasing resources that
46: * were acquired during the <code>execute()</code> method of this
47: * {@link Filter} instance.</p>
48: *
49: * @param context The {@link Context} to be processed by this
50: * {@link Filter}
51: * @param exception The <code>Exception</code> (if any) that was thrown
52: * by the last {@link Command} that was executed; otherwise
53: * <code>null</code>
54: *
55: * @exception IllegalArgumentException if <code>context</code>
56: * is <code>null</code>
57: *
58: * @return If a non-null <code>exception</code> was "handled" by this
59: * method (and therefore need not be rethrown), return <code>true</code>;
60: * otherwise return <code>false</code>
61: */
62: boolean postprocess(Context context, Exception exception);
63:
64: }
|