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 org.apache.directory.api.asn1.DecoderException; 024import org.apache.directory.api.i18n.I18n; 025 026 027/** 028 * Not Filter Object to store the Not filter. 029 * 030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 031 */ 032public class NotFilter extends ConnectorFilter 033{ 034 /** 035 * Subclass the addFilterMethod, as this is specific for a NotFilter (we 036 * cannot have more than one elements). 037 * 038 * @param filter The Filter to add 039 */ 040 public void addFilter( Filter filter ) throws DecoderException 041 { 042 if ( filterSet != null ) 043 { 044 throw new DecoderException( I18n.err( I18n.ERR_04057 ) ); 045 } 046 047 super.addFilter( filter ); 048 } 049 050 051 /** 052 * Get the NotFilter 053 * 054 * @return Returns the notFilter. 055 */ 056 public Filter getNotFilter() 057 { 058 return filterSet.get( 0 ); 059 } 060 061 062 /** 063 * Set the NotFilter 064 * 065 * @param notFilter The notFilter to set. 066 * @throws DecoderException If the filter is invalid 067 */ 068 public void setNotFilter( Filter notFilter ) throws DecoderException 069 { 070 if ( filterSet != null ) 071 { 072 throw new DecoderException( I18n.err( I18n.ERR_04057 ) ); 073 } 074 075 super.addFilter( notFilter ); 076 } 077 078 079 /** 080 * Return a string compliant with RFC 2254 representing a NOT filter 081 * 082 * @return The NOT filter string 083 */ 084 public String toString() 085 { 086 StringBuffer sb = new StringBuffer(); 087 088 sb.append( '!' ).append( super.toString() ); 089 090 return sb.toString(); 091 } 092}