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.controls.sort;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.tlv.BerValue;
25 import org.apache.directory.api.asn1.util.Asn1Buffer;
26 import org.apache.directory.api.ldap.codec.api.AbstractControlFactory;
27 import org.apache.directory.api.ldap.codec.api.ControlFactory;
28 import org.apache.directory.api.ldap.codec.api.LdapApiService;
29 import org.apache.directory.api.ldap.model.message.Control;
30 import org.apache.directory.api.ldap.model.message.controls.SortResponse;
31 import org.apache.directory.api.ldap.model.message.controls.SortResponseImpl;
32 import org.apache.directory.api.util.Strings;
33
34
35
36
37
38
39
40
41 public class SortResponseFactory extends AbstractControlFactory<SortResponse>
42 {
43
44 public static final int ATTRIBUTE_TYPE_TAG = 0x80;
45
46
47
48
49
50
51 public SortResponseFactory( LdapApiService codec )
52 {
53 super( codec, SortResponse.OID );
54 }
55
56
57
58
59
60 @Override
61 public SortResponse newControl()
62 {
63 return new SortResponseImpl();
64 }
65
66
67
68
69
70 @Override
71 public void encodeValue( Asn1Buffer buffer, Control control )
72 {
73 SortResponse sortResponse = ( SortResponse ) control;
74
75 int start = buffer.getPos();
76
77
78 if ( sortResponse.getAttributeName() != null )
79 {
80 BerValue.encodeOctetString( buffer, ( byte ) ATTRIBUTE_TYPE_TAG,
81 Strings.getBytesUtf8Ascii( sortResponse.getAttributeName() ) );
82 }
83
84
85 BerValue.encodeEnumerated( buffer, sortResponse.getSortResult().getVal() );
86
87
88 BerValue.encodeSequence( buffer, start );
89 }
90
91
92
93
94
95 @Override
96 public void decodeValue( Control control, byte[] controlBytes ) throws DecoderException
97 {
98 decodeValue( new SortResponseContainer( control ), control, controlBytes );
99 }
100 }