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 AliasDerefMode( int value, String jndiValue )
65 {
66 this.value = value;
67 this.jndiValue = jndiValue;
68 }
69
70
71
72
73
74 public int getValue()
75 {
76 return value;
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90 public static AliasDerefMode getEnum( Map<String, Object> env )
91 {
92 String property = ( String ) env.get( JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES );
93
94 if ( null == property )
95 {
96 return DEREF_ALWAYS;
97 }
98 else
99 {
100 String trimmedProperty = property.trim();
101
102 if ( "always".equalsIgnoreCase( trimmedProperty ) )
103 {
104 return DEREF_ALWAYS;
105 }
106 else if ( "never".equalsIgnoreCase( trimmedProperty ) )
107 {
108 return NEVER_DEREF_ALIASES;
109 }
110 else if ( "finding".equalsIgnoreCase( trimmedProperty ) )
111 {
112 return DEREF_FINDING_BASE_OBJ;
113 }
114 else if ( "searching".equalsIgnoreCase( trimmedProperty ) )
115 {
116 return DEREF_IN_SEARCHING;
117 }
118 else
119 {
120 throw new IllegalArgumentException( I18n.err( I18n.ERR_04186, property,
121 JndiPropertyConstants.JNDI_LDAP_DAP_DEREF_ALIASES ) );
122 }
123 }
124 }
125
126
127
128
129
130
131
132 public boolean isDerefAlways()
133 {
134 return this == DEREF_ALWAYS;
135 }
136
137
138
139
140
141
142
143 public boolean isNeverDeref()
144 {
145 return this == NEVER_DEREF_ALIASES;
146 }
147
148
149
150
151
152
153
154
155 public boolean isDerefInSearching()
156 {
157 switch ( this )
158 {
159 case DEREF_ALWAYS:
160 return true;
161
162 case DEREF_FINDING_BASE_OBJ:
163 return false;
164
165 case DEREF_IN_SEARCHING:
166 return true;
167
168 case NEVER_DEREF_ALIASES:
169 return false;
170
171 default:
172 throw new IllegalArgumentException( I18n.err( I18n.ERR_04187 ) );
173 }
174 }
175
176
177
178
179
180
181
182
183 public boolean isDerefFindingBase()
184 {
185 switch ( this )
186 {
187 case DEREF_ALWAYS:
188 return true;
189
190 case DEREF_FINDING_BASE_OBJ:
191 return true;
192
193 case DEREF_IN_SEARCHING:
194 return false;
195
196 case NEVER_DEREF_ALIASES:
197 return false;
198
199 default:
200 throw new IllegalArgumentException( "Class has bug: check for valid enumeration values" );
201 }
202 }
203
204
205
206
207
208
209
210
211 public static AliasDerefMode getDerefMode( int val )
212 {
213 switch ( val )
214 {
215 case 0:
216 return NEVER_DEREF_ALIASES;
217
218 case 1:
219 return DEREF_IN_SEARCHING;
220
221 case 2:
222 return DEREF_FINDING_BASE_OBJ;
223
224 case 3:
225 return DEREF_ALWAYS;
226
227 default:
228 throw new IllegalArgumentException( "Unknown derefmode " + val );
229 }
230 }
231
232
233
234
235
236
237
238
239 public static AliasDerefMode getDerefMode( String val )
240 {
241 if ( val != null )
242 {
243 if ( val.equals( NEVER_DEREF_ALIASES.jndiValue ) )
244 {
245 return NEVER_DEREF_ALIASES;
246 }
247
248 if ( val.equals( DEREF_IN_SEARCHING.jndiValue ) )
249 {
250 return DEREF_IN_SEARCHING;
251 }
252
253 if ( val.equals( DEREF_FINDING_BASE_OBJ.jndiValue ) )
254 {
255 return DEREF_FINDING_BASE_OBJ;
256 }
257
258 if ( val.equals( DEREF_ALWAYS.jndiValue ) )
259 {
260 return DEREF_ALWAYS;
261 }
262 }
263
264 throw new IllegalArgumentException( "Unknown derefmode " + val );
265 }
266
267
268
269
270
271 public String getJndiValue()
272 {
273 return jndiValue;
274 }
275 }