1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec.search;
21
22
23 import java.nio.BufferOverflowException;
24 import java.nio.ByteBuffer;
25
26 import org.apache.directory.api.asn1.DecoderException;
27 import org.apache.directory.api.asn1.EncoderException;
28 import org.apache.directory.api.asn1.ber.tlv.TLV;
29 import org.apache.directory.api.i18n.I18n;
30 import org.apache.directory.api.ldap.codec.api.LdapConstants;
31
32
33
34
35
36
37
38 public class NotFilter extends ConnectorFilter
39 {
40
41
42
43
44
45
46 public NotFilter( int tlvId )
47 {
48 super( tlvId );
49 }
50
51
52
53
54
55 public NotFilter()
56 {
57 super();
58 }
59
60
61
62
63
64
65
66
67 public void addFilter( Filter filter ) throws DecoderException
68 {
69 if ( filterSet != null )
70 {
71 throw new DecoderException( I18n.err( I18n.ERR_04057 ) );
72 }
73
74 super.addFilter( filter );
75 }
76
77
78
79
80
81
82
83 public Filter getNotFilter()
84 {
85 return filterSet.get( 0 );
86 }
87
88
89
90
91
92
93
94 public void setNotFilter( Filter notFilter ) throws DecoderException
95 {
96 if ( filterSet != null )
97 {
98 throw new DecoderException( I18n.err( I18n.ERR_04057 ) );
99 }
100
101 super.addFilter( notFilter );
102 }
103
104
105
106
107
108
109
110
111
112
113 public int computeLength()
114 {
115 filtersLength = super.computeLength();
116
117 return 1 + TLV.getNbBytes( filtersLength ) + filtersLength;
118 }
119
120
121
122
123
124
125
126
127
128
129 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
130 {
131 if ( buffer == null )
132 {
133 throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
134 }
135
136 try
137 {
138
139 buffer.put( ( byte ) LdapConstants.NOT_FILTER_TAG );
140 buffer.put( TLV.getBytes( filtersLength ) );
141 }
142 catch ( BufferOverflowException boe )
143 {
144 throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
145 }
146
147 super.encode( buffer );
148
149 return buffer;
150 }
151
152
153
154
155
156
157
158 public String toString()
159 {
160 StringBuffer sb = new StringBuffer();
161
162 sb.append( '!' ).append( super.toString() );
163
164 return sb.toString();
165 }
166 }