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