1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.server.core;
21
22
23 import javax.naming.Context;
24
25
26 /**
27 * Enumeration for referral handling modes.
28 *
29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30 * @version $Rev$, $Date$
31 */
32 public enum ReferralHandlingMode
33 {
34 THROW( "throw" ), FOLLOW( "follow" ), IGNORE( "ignore" ), THROW_FINDING_BASE( "throw-finding-base" );
35
36 /**
37 * The JNDI Context.REFERRAL key's value.
38 *
39 * @see {@link Context#REFERRAL}
40 */
41 private final String jndiValue;
42
43
44 /**
45 * Creates a new instance of ReferralHandlingMode.
46 *
47 * @see {@link Context#REFERRAL}
48 * @param jndiValue the JNDI Context.REFERRAL key's value
49 */
50 private ReferralHandlingMode( String jndiValue )
51 {
52 this.jndiValue = jndiValue;
53 }
54
55
56 /**
57 * Gets the equivalent JNDI Context.REFERRAL key's value for this enumeration constant.
58 *
59 * @see {@link Context#REFERRAL}
60 * @return the equivalent JNDI Context.REFERRAL key's value
61 */
62 public String getJndiValue()
63 {
64 return jndiValue;
65 }
66
67
68 /**
69 * Gets the enumeration constant for the JNDI Context.REFERRAL key's value.
70 *
71 * @see {@link Context#REFERRAL}
72 * @param jndiValue the JNDI Context.REFERRAL key's value
73 * @return the referral handling mode enumeration constant
74 * @throws IllegalArgumentException if the value is not a recognized value
75 */
76 public static final ReferralHandlingMode getModeFromJndi( String jndiValue )
77 {
78 jndiValue = jndiValue.trim().toLowerCase();
79
80 if ( jndiValue.equals( "throw" ) )
81 {
82 return THROW;
83 }
84
85 if ( jndiValue.equals( "follow" ) )
86 {
87 return FOLLOW;
88 }
89
90 if ( jndiValue.equals( "ignore" ) )
91 {
92 return IGNORE;
93 }
94
95 if ( jndiValue.equals( "throw-finding-base" ) )
96 {
97 return THROW_FINDING_BASE;
98 }
99
100 throw new IllegalArgumentException( "Unknown JNDI Context.REFERRAL value of " + jndiValue );
101 }
102 }