01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.services;
16:
17: import java.util.List;
18:
19: /**
20: * A service which can assemble an implementation based on a command interface, and an ordered list
21: * of objects implementing that interface (the "commands"). This is an implementation of the Gang of
22: * Four Chain Of Command pattern.
23: * <p>
24: * For each method in the interface, the chain implementation will call the corresponding method on
25: * each command object in turn (with the order defined by the list). If any of the command objects
26: * return true, then the chain of command stops and the initial method invocation returns true.
27: * Otherwise, the chain of command continues to the next command (and will return false if none of
28: * the commands returns true).
29: * <p>
30: * For methods whose return type is not boolean, the chain stops with the first non-null (for object
31: * types), or non-zero (for numeric types). The chain returns the value that was returned by the
32: * command. If the method return type is void, all commands will be invoked.
33: * <p>
34: * Method invocations will also be terminated if an exception is thrown.
35: *
36: *
37: */
38: public interface ChainBuilder {
39: /**
40: * Creates a chain instance from a command interface and a list of commands (implementing the
41: * interface).
42: */
43: <T> T build(Class<T> commandInterface, List<T> commands);
44: }
|