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