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.modifyRequest;
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.IntegerDecoder;
26 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
27 import org.apache.directory.api.asn1.ber.tlv.TLV;
28 import org.apache.directory.api.i18n.I18n;
29 import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
30 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
31 import org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator;
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 public class StoreOperationType extends GrammarAction<LdapMessageContainer<ModifyRequestDecorator>>
49 {
50
51 private static final Logger LOG = LoggerFactory.getLogger( StoreOperationType.class );
52
53
54 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
55
56
57
58
59
60 public StoreOperationType()
61 {
62 super( "Store Modify request operation type" );
63 }
64
65
66
67
68
69 public void action( LdapMessageContainer<ModifyRequestDecorator> container ) throws DecoderException
70 {
71 ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
72
73 TLV tlv = container.getCurrentTLV();
74
75
76 int operation = 0;
77
78 try
79 {
80 operation = IntegerDecoder.parse( tlv.getValue(), 0, 2 );
81 }
82 catch ( IntegerDecoderException ide )
83 {
84 String msg = I18n.err( I18n.ERR_04082, Strings.dumpBytes( tlv.getValue().getData() ) );
85 LOG.error( msg );
86
87
88 throw new DecoderException( msg, ide );
89 }
90
91
92 modifyRequestDecorator.setCurrentOperation( operation );
93
94 if ( IS_DEBUG )
95 {
96 switch ( operation )
97 {
98 case LdapCodecConstants.OPERATION_ADD:
99 LOG.debug( "Modification operation : ADD" );
100 break;
101
102 case LdapCodecConstants.OPERATION_DELETE:
103 LOG.debug( "Modification operation : DELETE" );
104 break;
105
106 case LdapCodecConstants.OPERATION_REPLACE:
107 LOG.debug( "Modification operation : REPLACE" );
108 break;
109
110 default:
111 LOG.debug( "Modification operation : UNKNOWN" );
112 }
113 }
114 }
115 }