001    // Copyright 2009 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    package org.apache.tapestry5.ioc;
015    
016    import java.util.ArrayList;
017    import java.util.List;
018    
019    /**
020     * Represents an order constraints for {@link OrderedConfiguration}.
021     * 
022     * @since 5.2.0.0
023     */
024    public class OrderConstraint
025    {
026        private static final String ALL = "*";
027        
028        private List<String> constraints = new ArrayList<String>();
029        
030        /**
031         * Adds an <i>after:id</i> constraint.
032         */
033        public OrderConstraint after(String id)
034        {
035            constraints.add("after:" + id);
036            
037            return this;
038        }
039        
040        /**
041         * Adds an <i>after:*</i> constraint.
042         */
043        public OrderConstraint afterAll()
044        {
045            return after(ALL);
046        }
047        /**
048         * Adds a <i>before:id</i> constraint.
049         */
050        public OrderConstraint before(String id)
051        {
052            constraints.add("before:" + id);
053            
054            return this;
055        }
056        
057        /**
058         * Adds a <i>before:*</i> constraint.
059         */
060        public OrderConstraint beforeAll()
061        {
062            return before(ALL);
063        }
064        
065        /**
066         * Returns all constraints as array of strings.
067         */
068        public String[] build()
069        {
070            return constraints.toArray(new String[]{});
071        }
072    }