001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core;
021
022
023 import javax.naming.Context;
024
025 import org.apache.directory.server.i18n.I18n;
026
027
028 /**
029 * Enumeration for referral handling modes.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev$, $Date$
033 */
034 public enum ReferralHandlingMode
035 {
036 THROW( "throw" ),
037 FOLLOW( "follow" ),
038 IGNORE( "ignore" ),
039 THROW_FINDING_BASE( "throw-finding-base" );
040
041 /**
042 * The JNDI Context.REFERRAL key's value.
043 *
044 * @see {@link Context#REFERRAL}
045 */
046 private final String jndiValue;
047
048
049 /**
050 * Creates a new instance of ReferralHandlingMode.
051 *
052 * @see {@link Context#REFERRAL}
053 * @param jndiValue the JNDI Context.REFERRAL key's value
054 */
055 private ReferralHandlingMode( String jndiValue )
056 {
057 this.jndiValue = jndiValue;
058 }
059
060
061 /**
062 * Gets the equivalent JNDI Context.REFERRAL key's value for this enumeration constant.
063 *
064 * @see {@link Context#REFERRAL}
065 * @return the equivalent JNDI Context.REFERRAL key's value
066 */
067 public String getJndiValue()
068 {
069 return jndiValue;
070 }
071
072
073 /**
074 * Gets the enumeration constant for the JNDI Context.REFERRAL key's value.
075 *
076 * @see {@link Context#REFERRAL}
077 * @param jndiValue the JNDI Context.REFERRAL key's value
078 * @return the referral handling mode enumeration constant
079 * @throws IllegalArgumentException if the value is not a recognized value
080 */
081 public static final ReferralHandlingMode getModeFromJndi( String jndiValue )
082 {
083 jndiValue = jndiValue.trim().toLowerCase();
084
085 if ( jndiValue.equals( "throw" ) )
086 {
087 return THROW;
088 }
089
090 if ( jndiValue.equals( "follow" ) )
091 {
092 return FOLLOW;
093 }
094
095 if ( jndiValue.equals( "ignore" ) )
096 {
097 return IGNORE;
098 }
099
100 if ( jndiValue.equals( "throw-finding-base" ) )
101 {
102 return THROW_FINDING_BASE;
103 }
104
105 throw new IllegalArgumentException( I18n.err( I18n.ERR_437, jndiValue ) );
106 }
107 }