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.TLV;
26 import org.apache.directory.api.asn1.util.Oid;
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 public class AddControl extends GrammarAction<ControlsContainer>
47 {
48
49 private static final Logger LOG = LoggerFactory.getLogger( AddControl.class );
50
51
52
53
54 public AddControl()
55 {
56 super( "Add a new control" );
57 }
58
59
60
61
62
63 @Override
64 public void action( ControlsContainer container ) throws DecoderException
65 {
66 TLV tlv = container.getCurrentTLV();
67
68
69
70 if ( tlv.getLength() == 0 )
71 {
72 String msg = I18n.err( I18n.ERR_08214_NULL_OID );
73 LOG.error( msg );
74
75
76 throw new DecoderException( msg );
77 }
78
79 byte[] value = tlv.getValue().getData();
80 String oidValue = Strings.asciiBytesToString( value );
81
82
83 if ( !Oid.isOid( oidValue ) )
84 {
85 String msg = I18n.err( I18n.ERR_08215_INVALID_CONTROL_OID, oidValue );
86 LOG.error( msg );
87
88
89 throw new DecoderException( msg );
90 }
91
92 ControlFactory<?> factory = container.getLdapCodecService().getResponseControlFactories().get( oidValue );
93 container.setFactory( factory );
94 Control control = factory.newControl();
95
96 container.setCurrentControl( control );
97 container.addControl( control );
98
99
100 container.setGrammarEndAllowed( true );
101
102 if ( LOG.isDebugEnabled() )
103 {
104 LOG.debug( I18n.msg( I18n.MSG_08201_CONTROL_OID, oidValue ) );
105 }
106 }
107 }