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.model.message;
21
22
23 import java.util.Map;
24
25 import org.apache.directory.api.i18n.I18n;
26 import org.apache.directory.api.ldap.model.constants.JndiPropertyConstants;
27
28
29
30
31
32
33
34
35
36
37
38 public enum AliasDerefMode
39 {
40
41 NEVER_DEREF_ALIASES(0, "never"),
42
43
44 DEREF_IN_SEARCHING(1, "searching"),
45
46
47 DEREF_FINDING_BASE_OBJ(2, "finding"),
48
49
50 DEREF_ALWAYS(3, "always");
51
52
53 private int value;
54
55 private String jndiValue;
56
57
58
59
60
61
62
63
64
65 AliasDerefMode( int value, String jndiValue )
66 {
67 this.value = value;
68 this.jndiValue = jndiValue;
69 }
70
71
72
73
74
75 public int getValue()
76 {
77 return value;
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91 public static AliasDerefMode getEnum( Map<String, Object> env )
92 {
93 String property = ( String ) env.get( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES );
94
95 if ( null == property )
96 {
97 return DEREF_ALWAYS;
98 }
99 else
100 {
101 String trimmedProperty = property.trim();
102
103 if ( "always".equalsIgnoreCase( trimmedProperty ) )
104 {
105 return DEREF_ALWAYS;
106 }
107 else if ( "never".equalsIgnoreCase( trimmedProperty ) )
108 {
109 return NEVER_DEREF_ALIASES;
110 }
111 else if ( "finding".equalsIgnoreCase( trimmedProperty ) )
112 {
113 return DEREF_FINDING_BASE_OBJ;
114 }
115 else if ( "searching".equalsIgnoreCase( trimmedProperty ) )
116 {
117 return DEREF_IN_SEARCHING;
118 }
119 else
120 {
121 throw new IllegalArgumentException( I18n.err( I18n.ERR_13507_UNRECOGNIZED_JNDI_PROPERTY_VALUE, property,
122 JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES ) );
123 }
124 }
125 }
126
127
128
129
130
131
132
133 public boolean isDerefAlways()
134 {
135 return this == DEREF_ALWAYS;
136 }
137
138
139
140
141
142
143
144 public boolean isNeverDeref()
145 {
146 return this == NEVER_DEREF_ALIASES;
147 }
148
149
150
151
152
153
154
155
156 public boolean isDerefInSearching()
157 {
158 return ( this == AliasDerefMode.DEREF_ALWAYS ) || ( this == AliasDerefMode.DEREF_IN_SEARCHING );
159 }
160
161
162
163
164
165
166
167
168 public boolean isDerefFindingBase()
169 {
170 switch ( this )
171 {
172 case DEREF_ALWAYS:
173 return true;
174
175 case DEREF_FINDING_BASE_OBJ:
176 return true;
177
178 case DEREF_IN_SEARCHING:
179 return false;
180
181 case NEVER_DEREF_ALIASES:
182 return false;
183
184 default:
185 throw new IllegalArgumentException( I18n.err( I18n.ERR_13518_CLASS_INVALID_ENULM_VALUE ) );
186 }
187 }
188
189
190
191
192
193
194
195
196 public static AliasDerefMode getDerefMode( int val )
197 {
198 switch ( val )
199 {
200 case 0:
201 return NEVER_DEREF_ALIASES;
202
203 case 1:
204 return DEREF_IN_SEARCHING;
205
206 case 2:
207 return DEREF_FINDING_BASE_OBJ;
208
209 case 3:
210 return DEREF_ALWAYS;
211
212 default:
213 throw new IllegalArgumentException( I18n.err( I18n.ERR_13510_UNKNOWN_DEREF_MODE, val ) );
214 }
215 }
216
217
218
219
220
221
222
223
224 public static AliasDerefMode getDerefMode( String val )
225 {
226 if ( val != null )
227 {
228 if ( val.equals( NEVER_DEREF_ALIASES.jndiValue ) )
229 {
230 return NEVER_DEREF_ALIASES;
231 }
232
233 if ( val.equals( DEREF_IN_SEARCHING.jndiValue ) )
234 {
235 return DEREF_IN_SEARCHING;
236 }
237
238 if ( val.equals( DEREF_FINDING_BASE_OBJ.jndiValue ) )
239 {
240 return DEREF_FINDING_BASE_OBJ;
241 }
242
243 if ( val.equals( DEREF_ALWAYS.jndiValue ) )
244 {
245 return DEREF_ALWAYS;
246 }
247 }
248
249 throw new IllegalArgumentException( I18n.err( I18n.ERR_13510_UNKNOWN_DEREF_MODE, val ) );
250 }
251
252
253
254
255
256 public String getJndiValue()
257 {
258 return jndiValue;
259 }
260 }