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.del;
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.DeleteRequest;
31 import org.apache.directory.api.ldap.model.message.DeleteRequestImpl;
32 import org.apache.directory.api.ldap.model.message.DeleteResponseImpl;
33 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
34 import org.apache.directory.api.ldap.model.name.Dn;
35 import org.apache.directory.api.ldap.model.name.DnFactory;
36 import org.apache.directory.api.util.Strings;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41
42
43
44
45
46
47
48
49
50
51 public class InitDelRequest extends GrammarAction<LdapMessageContainer<DeleteRequest>>
52 {
53
54 private static final Logger LOG = LoggerFactory.getLogger( InitDelRequest.class );
55
56
57
58
59 public InitDelRequest()
60 {
61 super( "Delete Request initialization" );
62 }
63
64
65
66
67
68 @Override
69 public void action( LdapMessageContainer<DeleteRequest> container ) throws DecoderException
70 {
71
72 DeleteRequest delRequest = new DeleteRequestImpl();
73 delRequest.setMessageId( container.getMessageId() );
74 container.setMessage( delRequest );
75
76
77
78 TLV tlv = container.getCurrentTLV();
79
80
81 if ( tlv.getLength() == 0 )
82 {
83
84 throw new DecoderException( I18n.err( I18n.ERR_05119_NULL_ENTRY ) );
85 }
86 else
87 {
88 byte[] dnBytes = tlv.getValue().getData();
89 String dnStr = Strings.utf8ToString( dnBytes );
90
91 try
92 {
93 DnFactory dnFactory = container.getDnFactory();
94 Dn entryDn;
95
96 if ( dnFactory == null )
97 {
98 entryDn = new Dn( dnStr );
99 }
100 else
101 {
102 entryDn = dnFactory.create( dnStr );
103 }
104
105 delRequest.setName( entryDn );
106 }
107 catch ( LdapInvalidDnException ine )
108 {
109 String msg = I18n.err( I18n.ERR_05120_INVALID_DELETE_DN, dnStr,
110 Strings.dumpBytes( dnBytes ), ine.getLocalizedMessage() );
111 LOG.error( msg );
112
113 DeleteResponseImpl response = new DeleteResponseImpl( delRequest.getMessageId() );
114 throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
115 Dn.EMPTY_DN, ine );
116 }
117 }
118
119 if ( LOG.isDebugEnabled() )
120 {
121 LOG.debug( I18n.msg( I18n.MSG_05124_DELETING_DN, delRequest.getName() ) );
122 }
123
124
125 container.setGrammarEndAllowed( true );
126 }
127 }