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;
16:
17: import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
18:
19: /**
20: * A wrapper that allows objects of a target type to be ordered. Each Orderable object is given a
21: * unique id and a set of pre-requisites (objects which should be ordered earlier) and
22: * post-requisites (objects which should be ordered later).
23: *
24: * @param <T>
25: */
26: public class Orderable<T> {
27: private final String _id;
28:
29: private final T _target;
30:
31: private final String[] _constraints;
32:
33: /**
34: * @param id
35: * unique identifier for the target object
36: * @param target
37: * the object to be ordered; this may also be null (in which case the id represents a
38: * placeholder)
39: */
40:
41: public Orderable(String id, T target, String... constraints) {
42: _id = notBlank(id, "id");
43: _target = target;
44: _constraints = constraints;
45: }
46:
47: public String getId() {
48: return _id;
49: }
50:
51: public T getTarget() {
52: return _target;
53: }
54:
55: public String[] getConstraints() {
56: return _constraints;
57: }
58:
59: @Override
60: public String toString() {
61: StringBuilder buffer = new StringBuilder("Orderable[");
62:
63: buffer.append(_id);
64:
65: for (String c : _constraints) {
66: buffer.append(" ");
67: buffer.append(c);
68: }
69:
70: buffer.append(" ");
71: buffer.append(_target.toString());
72: buffer.append("]");
73:
74: return buffer.toString();
75: }
76: }
|