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.request.modify;
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.model.entry.DefaultModification;
32 import org.apache.directory.api.ldap.model.entry.Modification;
33 import org.apache.directory.api.ldap.model.entry.ModificationOperation;
34 import org.apache.directory.api.ldap.model.message.ModifyRequest;
35 import org.apache.directory.api.util.Strings;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class StoreOperationType extends GrammarAction<LdapMessageContainer<ModifyRequest>>
52 {
53
54 private static final Logger LOG = LoggerFactory.getLogger( StoreOperationType.class );
55
56
57
58
59 public StoreOperationType()
60 {
61 super( "Store Modify request operation type" );
62 }
63
64
65
66
67
68 @Override
69 public void action( LdapMessageContainer<ModifyRequest> container ) throws DecoderException
70 {
71 ModifyRequest modifyRequest = container.getMessage();
72 TLV tlv = container.getCurrentTLV();
73
74
75 int operation = 0;
76
77 try
78 {
79
80 operation = IntegerDecoder.parse( tlv.getValue(), ModificationOperation.ADD_ATTRIBUTE.getValue(),
81 ModificationOperation.INCREMENT_ATTRIBUTE.getValue() );
82 Modification modification = new DefaultModification();
83 modification.setOperation( operation );
84 modifyRequest.addModification( modification );
85 container.setCurrentModification( modification );
86 }
87 catch ( IntegerDecoderException ide )
88 {
89 String msg = I18n.err( I18n.ERR_05124_INVALID_OPERATION, Strings.dumpBytes( tlv.getValue().getData() ) );
90 LOG.error( msg );
91
92
93 throw new DecoderException( msg, ide );
94 }
95
96 if ( LOG.isDebugEnabled() )
97 {
98 switch ( operation )
99 {
100 case LdapCodecConstants.OPERATION_ADD:
101 LOG.debug( I18n.msg( I18n.MSG_05133_MODIFY_OPERATION, "ADD" ) );
102 break;
103
104 case LdapCodecConstants.OPERATION_DELETE:
105 LOG.debug( I18n.msg( I18n.MSG_05133_MODIFY_OPERATION, "DELETE" ) );
106 break;
107
108 case LdapCodecConstants.OPERATION_REPLACE:
109 LOG.debug( I18n.msg( I18n.MSG_05133_MODIFY_OPERATION, "REPLACE" ) );
110 break;
111
112 default:
113 LOG.debug( I18n.msg( I18n.MSG_05133_MODIFY_OPERATION, "UNKNOWN" ) );
114 }
115 }
116 }
117 }