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 import java.util.List;
26
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 AndFilter extends ConnectorFilter
39 {
40
41
42
43
44
45
46 public AndFilter( int tlvId )
47 {
48 super( tlvId );
49 }
50
51
52
53
54
55
56 public AndFilter()
57 {
58 super();
59 }
60
61
62
63
64
65
66
67 public List<Filter> getAndFilter()
68 {
69 return filterSet;
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 @Override
87 public int computeLength()
88 {
89 filtersLength = super.computeLength();
90
91 return 1 + TLV.getNbBytes( filtersLength ) + filtersLength;
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 @Override
108 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
109 {
110 if ( buffer == null )
111 {
112 throw new EncoderException( I18n.err( I18n.ERR_08000_CANNOT_PUT_A_PDU_IN_NULL_BUFFER ) );
113 }
114
115 try
116 {
117
118 buffer.put( ( byte ) LdapCodecConstants.AND_FILTER_TAG );
119 buffer.put( TLV.getBytes( filtersLength ) );
120 }
121 catch ( BufferOverflowException boe )
122 {
123 throw new EncoderException( I18n.err( I18n.ERR_08212_PDU_BUFFER_TOO_SMALL ), boe );
124 }
125
126 super.encode( buffer );
127
128 return buffer;
129 }
130
131
132
133
134
135
136
137 @Override
138 public String toString()
139 {
140 StringBuilder sb = new StringBuilder();
141
142 sb.append( '&' ).append( super.toString() );
143
144 return sb.toString();
145 }
146 }