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.TLV;
26 import org.apache.directory.api.i18n.I18n;
27 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
28 import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
29 import org.apache.directory.api.ldap.model.entry.Attribute;
30 import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
31 import org.apache.directory.api.ldap.model.entry.ModificationOperation;
32 import org.apache.directory.api.ldap.model.message.ModifyRequest;
33 import org.apache.directory.api.ldap.model.message.ModifyResponseImpl;
34 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
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
52
53
54
55 public class AddModifyRequestAttribute extends GrammarAction<LdapMessageContainer<ModifyRequest>>
56 {
57
58 private static final Logger LOG = LoggerFactory.getLogger( AddModifyRequestAttribute.class );
59
60
61
62
63 public AddModifyRequestAttribute()
64 {
65 super( "Store Modify request operation type" );
66 }
67
68
69
70
71
72 @Override
73 public void action( LdapMessageContainer<ModifyRequest> container ) throws DecoderException
74 {
75 ModifyRequest modifyRequest = container.getMessage();
76
77 TLV tlv = container.getCurrentTLV();
78
79
80 String type;
81
82 if ( tlv.getLength() == 0 )
83 {
84 String msg = I18n.err( I18n.ERR_05123_TYPE_CANT_BE_NULL );
85 LOG.error( msg );
86
87 ModifyResponseImpl response = new ModifyResponseImpl( modifyRequest.getMessageId() );
88 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
89 modifyRequest.getName(), null );
90 }
91 else
92 {
93 type = Strings.utf8ToString( tlv.getValue().getData() );
94 Attribute currentAttribute = new DefaultAttribute( type );
95 container.setCurrentAttribute( currentAttribute );
96 container.getCurrentModification().setAttribute( currentAttribute );
97 }
98
99
100 if ( container.getCurrentModification().getOperation() == ModificationOperation.INCREMENT_ATTRIBUTE )
101 {
102 container.setGrammarEndAllowed( true );
103 }
104
105 if ( LOG.isDebugEnabled() )
106 {
107 LOG.debug( I18n.msg( I18n.MSG_05128_MODIFYING_TYPE, type ) );
108 }
109 }
110 }