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.search.subentries;
21
22
23 import java.nio.ByteBuffer;
24
25 import org.apache.directory.api.asn1.Asn1Object;
26 import org.apache.directory.api.asn1.DecoderException;
27 import org.apache.directory.api.asn1.EncoderException;
28 import org.apache.directory.api.asn1.ber.Asn1Decoder;
29 import org.apache.directory.api.asn1.ber.tlv.BerValue;
30 import org.apache.directory.api.i18n.I18n;
31 import org.apache.directory.api.ldap.codec.api.ControlDecorator;
32 import org.apache.directory.api.ldap.codec.api.LdapApiService;
33 import org.apache.directory.api.ldap.model.message.controls.Subentries;
34 import org.apache.directory.api.ldap.model.message.controls.SubentriesImpl;
35
36
37
38
39
40
41
42
43 public class SubentriesDecorator extends ControlDecorator<Subentries> implements Subentries
44 {
45
46 private static final Asn1Decoder DECODER = new Asn1Decoder();
47
48
49
50
51
52
53
54 public SubentriesDecorator( LdapApiService codec )
55 {
56 this( codec, new SubentriesImpl() );
57 }
58
59
60
61
62
63
64
65
66
67 public SubentriesDecorator( LdapApiService codec, Subentries control )
68 {
69 super( codec, control );
70 }
71
72
73
74
75
76
77
78
79
80
81 @Override
82 public int computeLength()
83 {
84 return 1 + 1 + 1;
85 }
86
87
88
89
90
91
92
93
94
95 @Override
96 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
97 {
98 if ( buffer == null )
99 {
100 throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
101 }
102
103
104 BerValue.encode( buffer, isVisible() );
105
106 return buffer;
107 }
108
109
110
111
112
113 @Override
114 public byte[] getValue()
115 {
116 if ( value == null )
117 {
118 try
119 {
120 computeLength();
121 ByteBuffer buffer = ByteBuffer.allocate( valueLength );
122
123
124 BerValue.encode( buffer, isVisible() );
125
126 value = buffer.array();
127 }
128 catch ( Exception e )
129 {
130 return null;
131 }
132 }
133
134 return value;
135 }
136
137
138
139
140
141 @Override
142 public boolean isVisible()
143 {
144 return getDecorated().isVisible();
145 }
146
147
148
149
150
151 @Override
152 public void setVisibility( boolean visibility )
153 {
154 getDecorated().setVisibility( visibility );
155 }
156
157
158
159
160
161 @Override
162 public Asn1Object decode( byte[] controlBytes ) throws DecoderException
163 {
164 ByteBuffer bb = ByteBuffer.wrap( controlBytes );
165 SubentriesContainer container = new SubentriesContainer( this );
166 DECODER.decode( bb, container );
167
168 return this;
169 }
170 }