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.modifydn;
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.exception.LdapInvalidDnException;
30 import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
31 import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
32 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
33 import org.apache.directory.api.ldap.model.name.Dn;
34 import org.apache.directory.api.ldap.model.name.DnFactory;
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 public class StoreModifyDnRequestEntryName extends GrammarAction<LdapMessageContainer<ModifyDnRequest>>
50 {
51
52 private static final Logger LOG = LoggerFactory.getLogger( StoreModifyDnRequestEntryName.class );
53
54
55
56
57 public StoreModifyDnRequestEntryName()
58 {
59 super( "Store ModifyDN request entry Name" );
60 }
61
62
63
64
65
66 @Override
67 public void action( LdapMessageContainer<ModifyDnRequest> container ) throws DecoderException
68 {
69 ModifyDnRequest modifyDnRequest = container.getMessage();
70
71
72 TLV tlv = container.getCurrentTLV();
73
74
75 if ( tlv.getLength() == 0 )
76 {
77
78 throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
79 }
80 else
81 {
82 byte[] dnBytes = tlv.getValue().getData();
83 String dnStr = Strings.utf8ToString( dnBytes );
84
85 try
86 {
87 DnFactory dnFactory = container.getDnFactory();
88 Dn entryDn;
89
90 if ( dnFactory == null )
91 {
92 entryDn = new Dn( dnStr );
93 }
94 else
95 {
96 entryDn = dnFactory.create( dnStr );
97 }
98
99 modifyDnRequest.setName( entryDn );
100 }
101 catch ( LdapInvalidDnException ine )
102 {
103 String msg = I18n.err( I18n.ERR_05113_INVALID_DN, dnStr, Strings.dumpBytes( dnBytes ) );
104 LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, ine.getMessage() ) );
105
106 ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
107 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
108 Dn.EMPTY_DN, ine );
109 }
110 }
111
112 if ( LOG.isDebugEnabled() )
113 {
114 LOG.debug( I18n.msg( I18n.MSG_05137_MODIFYING_DN, modifyDnRequest.getName() ) );
115 }
116 }
117 }