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.actions.controls;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
25 import org.apache.directory.api.asn1.ber.tlv.BerValue;
26 import org.apache.directory.api.asn1.ber.tlv.TLV;
27 import org.apache.directory.api.ldap.codec.api.CodecControl;
28 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
29 import org.apache.directory.api.ldap.codec.api.MessageDecorator;
30 import org.apache.directory.api.ldap.model.message.Control;
31 import org.apache.directory.api.ldap.model.message.Message;
32 import org.apache.directory.api.util.Strings;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class StoreControlValue extends GrammarAction<LdapMessageContainer<MessageDecorator<? extends Message>>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreControlValue.class );
53
54
55 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
56
57
58
59
60
61 public StoreControlValue()
62 {
63 super( "Store the control value" );
64 }
65
66
67
68
69
70 public void action( LdapMessageContainer<MessageDecorator<? extends Message>> container ) throws DecoderException
71 {
72 TLV tlv = container.getCurrentTLV();
73
74 MessageDecorator<?> message = container.getMessage();
75 CodecControl<? extends Control> control = message.getCurrentControl();
76
77
78 BerValue value = tlv.getValue();
79
80
81 if ( tlv.getLength() == 0 )
82 {
83 control.setValue( Strings.EMPTY_BYTES );
84 }
85 else
86 {
87 control.setValue( value.getData() );
88 control.decode( value.getData() );
89 }
90
91
92 container.setGrammarEndAllowed( true );
93
94 if ( IS_DEBUG )
95 {
96 LOG.debug( "Control value : " + Strings.dumpBytes( control.getValue() ) );
97 }
98 }
99 }