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.searchRequest;
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.BerValue;
26 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoder;
27 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
28 import org.apache.directory.api.asn1.ber.tlv.TLV;
29 import org.apache.directory.api.i18n.I18n;
30 import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
31 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
32 import org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator;
33 import org.apache.directory.api.ldap.model.message.SearchRequest;
34 import org.apache.directory.api.ldap.model.message.SearchScope;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class StoreSearchRequestScope extends GrammarAction<LdapMessageContainer<SearchRequestDecorator>>
53 {
54
55 private static final Logger LOG = LoggerFactory.getLogger( StoreSearchRequestScope.class );
56
57
58 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
59
60
61
62
63
64 public StoreSearchRequestScope()
65 {
66 super( "Store SearchRequest scope" );
67 }
68
69
70
71
72
73 public void action( LdapMessageContainer<SearchRequestDecorator> container ) throws DecoderException
74 {
75 SearchRequest searchRequest = container.getMessage().getDecorated();
76
77 TLV tlv = container.getCurrentTLV();
78
79
80 BerValue value = tlv.getValue();
81 int scope = 0;
82
83 try
84 {
85 scope = IntegerDecoder.parse( value, LdapCodecConstants.SCOPE_BASE_OBJECT,
86 LdapCodecConstants.SCOPE_WHOLE_SUBTREE );
87 }
88 catch ( IntegerDecoderException ide )
89 {
90 String msg = I18n.err( I18n.ERR_04101, value.toString() );
91 LOG.error( msg );
92 throw new DecoderException( msg );
93 }
94
95 searchRequest.setScope( SearchScope.getSearchScope( scope ) );
96
97 if ( IS_DEBUG )
98 {
99 switch ( scope )
100 {
101 case LdapCodecConstants.SCOPE_BASE_OBJECT:
102 LOG.debug( "Searching within BASE_OBJECT scope " );
103 break;
104
105 case LdapCodecConstants.SCOPE_SINGLE_LEVEL:
106 LOG.debug( "Searching within SINGLE_LEVEL scope " );
107 break;
108
109 case LdapCodecConstants.SCOPE_WHOLE_SUBTREE:
110 LOG.debug( "Searching within WHOLE_SUBTREE scope " );
111 break;
112 }
113 }
114 }
115 }