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.LdapCodecConstants;
31
32
33
34
35
36
37
38 public class NotFilter extends ConnectorFilter
39 {
40
41
42
43
44
45 public NotFilter( int tlvId )
46 {
47 super( tlvId );
48 }
49
50
51
52
53
54 public NotFilter()
55 {
56 super();
57 }
58
59
60
61
62
63
64
65
66 @Override
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
95 public void setNotFilter( Filter notFilter ) throws DecoderException
96 {
97 if ( filterSet != null )
98 {
99 throw new DecoderException( I18n.err( I18n.ERR_04057 ) );
100 }
101
102 super.addFilter( notFilter );
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 @Override
120 public int computeLength()
121 {
122 filtersLength = super.computeLength();
123
124 return 1 + TLV.getNbBytes( filtersLength ) + filtersLength;
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139 @Override
140 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
141 {
142 if ( buffer == null )
143 {
144 throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
145 }
146
147 try
148 {
149
150 buffer.put( ( byte ) LdapCodecConstants.NOT_FILTER_TAG );
151 buffer.put( TLV.getBytes( filtersLength ) );
152 }
153 catch ( BufferOverflowException boe )
154 {
155 throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe );
156 }
157
158 super.encode( buffer );
159
160 return buffer;
161 }
162
163
164
165
166
167
168
169 @Override
170 public String toString()
171 {
172 StringBuilder sb = new StringBuilder();
173
174 sb.append( '!' ).append( super.toString() );
175
176 return sb.toString();
177 }
178 }