1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.dsmlv2.request; 21 22 23 import org.apache.directory.api.asn1.DecoderException; 24 import org.apache.directory.api.i18n.I18n; 25 26 27 /** 28 * Not Filter Object to store the Not filter. 29 * 30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 31 */ 32 public class NotFilter extends ConnectorFilter 33 { 34 /** 35 * Subclass the addFilterMethod, as this is specific for a NotFilter (we 36 * cannot have more than one elements). 37 * 38 * @param filter The Filter to add 39 */ 40 public void addFilter( Filter filter ) throws DecoderException 41 { 42 if ( filterSet != null ) 43 { 44 throw new DecoderException( I18n.err( I18n.ERR_04057 ) ); 45 } 46 47 super.addFilter( filter ); 48 } 49 50 51 /** 52 * Get the NotFilter 53 * 54 * @return Returns the notFilter. 55 */ 56 public Filter getNotFilter() 57 { 58 return filterSet.get( 0 ); 59 } 60 61 62 /** 63 * Set the NotFilter 64 * 65 * @param notFilter The notFilter to set. 66 * @throws DecoderException If the filter is invalid 67 */ 68 public void setNotFilter( Filter notFilter ) throws DecoderException 69 { 70 if ( filterSet != null ) 71 { 72 throw new DecoderException( I18n.err( I18n.ERR_04057 ) ); 73 } 74 75 super.addFilter( notFilter ); 76 } 77 78 79 /** 80 * Return a string compliant with RFC 2254 representing a NOT filter 81 * 82 * @return The NOT filter string 83 */ 84 public String toString() 85 { 86 StringBuffer sb = new StringBuffer(); 87 88 sb.append( '!' ).append( super.toString() ); 89 90 return sb.toString(); 91 } 92 }