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 public SubentriesDecorator( LdapApiService codec )
53 {
54 this( codec, new SubentriesImpl() );
55 }
56
57
58
59
60
61
62
63
64 public SubentriesDecorator( LdapApiService codec, Subentries control )
65 {
66 super( codec, control );
67 }
68
69
70
71
72
73 public int computeLength()
74 {
75 return 1 + 1 + 1;
76 }
77
78
79
80
81
82
83
84
85
86 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
87 {
88 if ( buffer == null )
89 {
90 throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
91 }
92
93
94 BerValue.encode( buffer, isVisible() );
95
96 return buffer;
97 }
98
99
100
101
102
103 public byte[] getValue()
104 {
105 if ( value == null )
106 {
107 try
108 {
109 computeLength();
110 ByteBuffer buffer = ByteBuffer.allocate( valueLength );
111
112
113 BerValue.encode( buffer, isVisible() );
114
115 value = buffer.array();
116 }
117 catch ( Exception e )
118 {
119 return null;
120 }
121 }
122
123 return value;
124 }
125
126
127 public boolean isVisible()
128 {
129 return getDecorated().isVisible();
130 }
131
132
133 public void setVisibility( boolean visibility )
134 {
135 getDecorated().setVisibility( visibility );
136 }
137
138
139
140
141
142 public Asn1Object decode( byte[] controlBytes ) throws DecoderException
143 {
144 ByteBuffer bb = ByteBuffer.wrap( controlBytes );
145 SubentriesContainer container = new SubentriesContainer( this );
146 decoder.decode( bb, container );
147
148 return this;
149 }
150 }