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