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 * https://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 * @throws DecoderException If the added filter is invalid 046 */ 047 public void addFilter( Filter filter ) throws DecoderException 048 { 049 050 if ( filterSet == null ) 051 { 052 filterSet = new ArrayList<>(); 053 } 054 055 filterSet.add( filter ); 056 } 057 058 059 /** 060 * Get the list of filters stored in the composite filter 061 * 062 * @return And array of filters 063 */ 064 public List<Filter> getFilterSet() 065 { 066 return filterSet; 067 } 068 069 070 /** 071 * Return a string compliant with RFC 2254 representing a composite filter, 072 * one of AND, OR and NOT 073 * 074 * @return The composite filter string 075 */ 076 @Override 077 public String toString() 078 { 079 StringBuilder sb = new StringBuilder(); 080 081 if ( ( filterSet != null ) && !filterSet.isEmpty() ) 082 { 083 for ( Filter filter : filterSet ) 084 { 085 sb.append( '(' ).append( filter ).append( ')' ); 086 } 087 } 088 089 return sb.toString(); 090 } 091}