001 // Copyright 2006, 2010 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.ioc;
016
017 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
018
019 /**
020 * A wrapper that allows objects of a target type to be ordered. Each Orderable object is given a unique id and a set of
021 * pre-requisites (objects which should be ordered earlier) and post-requisites (objects which should be ordered
022 * later).
023 *
024 * @param <T>
025 */
026 public class Orderable<T>
027 {
028 private final String id;
029
030 private final T target;
031
032 private final String[] constraints;
033
034 /**
035 * @param id unique identifier for the target object
036 * @param target the object to be ordered; this may also be null (in which case the id represents a placeholder)
037 */
038
039 public Orderable(String id, T target, String... constraints)
040 {
041 assert InternalUtils.isNonBlank(id);
042 this.id = id;
043 this.target = target;
044 this.constraints = constraints;
045 }
046
047 public String getId()
048 {
049 return id;
050 }
051
052 public T getTarget()
053 {
054 return target;
055 }
056
057 public String[] getConstraints()
058 {
059 return constraints;
060 }
061
062 @Override
063 public String toString()
064 {
065 StringBuilder buffer = new StringBuilder("Orderable[");
066
067 buffer.append(id);
068
069 for (String c : constraints)
070 {
071 buffer.append(" ");
072 buffer.append(c);
073 }
074
075 buffer.append(" ");
076 buffer.append(target.toString());
077 buffer.append("]");
078
079 return buffer.toString();
080 }
081 }