001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.dsmlv2.request;
021
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.apache.directory.api.asn1.DecoderException;
027
028
029/**
030 * This Filter abstract class is used to store a set of filters used by
031 * OR/AND/NOT filters.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public abstract class ConnectorFilter extends Filter
036{
037    /** The set of filters used by And/Or filters */
038    protected List<Filter> filterSet;
039
040
041    /**
042     * Add a new Filter to the list.
043     * 
044     * @param filter The filter to add
045     */
046    public void addFilter( Filter filter ) throws DecoderException
047    {
048
049        if ( filterSet == null )
050        {
051            filterSet = new ArrayList<Filter>();
052        }
053
054        filterSet.add( filter );
055    }
056
057
058    /**
059     * Get the list of filters stored in the composite filter
060     * 
061     * @return And array of filters
062     */
063    public List<Filter> getFilterSet()
064    {
065        return filterSet;
066    }
067
068
069    /**
070     * Return a string compliant with RFC 2254 representing a composite filter,
071     * one of AND, OR and NOT
072     * 
073     * @return The composite filter string
074     */
075    public String toString()
076    {
077        StringBuffer sb = new StringBuffer();
078
079        if ( ( filterSet != null ) && ( filterSet.size() != 0 ) )
080        {
081            for ( Filter filter : filterSet )
082            {
083                sb.append( '(' ).append( filter ).append( ')' );
084            }
085        }
086
087        return sb.toString();
088    }
089}