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.extras.extended.ads_impl.endTransaction.controls.actions;
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.i18n.I18n;
28 import org.apache.directory.api.ldap.codec.api.ControlFactory;
29 import org.apache.directory.api.ldap.extras.extended.ads_impl.endTransaction.controls.ControlsContainer;
30 import org.apache.directory.api.ldap.model.message.Control;
31 import org.apache.directory.api.util.Strings;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class StoreControlValue extends GrammarAction<ControlsContainer>
49 {
50
51 private static final Logger LOG = LoggerFactory.getLogger( StoreControlValue.class );
52
53
54
55
56 public StoreControlValue()
57 {
58 super( "Store the control value" );
59 }
60
61
62
63
64
65 @Override
66 public void action( ControlsContainer container ) throws DecoderException
67 {
68 TLV tlv = container.getCurrentTLV();
69
70 Control control = container.getCurrentControl();
71 ControlFactory<?> controlFactory = container.getFactory();
72
73
74 BerValue value = tlv.getValue();
75
76
77 try
78 {
79 if ( tlv.getLength() == 0 )
80 {
81 controlFactory.decodeValue( control, Strings.EMPTY_BYTES );
82 }
83 else
84 {
85 controlFactory.decodeValue( control, value.getData() );
86 }
87 }
88 catch ( DecoderException de )
89 {
90 String message = I18n.err( I18n.ERR_08109_BAD_CONTROL_VALUE,
91 Strings.dumpBytes( value.getData() ) );
92 LOG.error( message );
93
94
95 throw new DecoderException( message, de );
96
97 }
98
99
100 container.setGrammarEndAllowed( true );
101
102 if ( LOG.isDebugEnabled() )
103 {
104 LOG.debug( I18n.msg( I18n.MSG_08203_CONTROL_VALUE, Strings.dumpBytes( value.getData() ) ) );
105 }
106 }
107 }