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.api; 21 22 23 import javax.naming.Context; 24 25 import org.apache.directory.api.util.Strings; 26 import org.apache.directory.server.i18n.I18n; 27 28 29 /** 30 * Enumeration for referral handling modes. 31 * 32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 33 */ 34 public enum ReferralHandlingMode 35 { 36 THROW("throw"), 37 FOLLOW("follow"), 38 IGNORE("ignore"), 39 THROW_FINDING_BASE("throw-finding-base"); 40 41 /** 42 * The JNDI Context.REFERRAL key's value. 43 * 44 * @see Context#REFERRAL 45 */ 46 private final String jndiValue; 47 48 49 /** 50 * Creates a new instance of ReferralHandlingMode. 51 * 52 * @see Context#REFERRAL 53 * @param jndiValue the JNDI Context.REFERRAL key's value 54 */ 55 ReferralHandlingMode( String jndiValue ) 56 { 57 this.jndiValue = jndiValue; 58 } 59 60 61 /** 62 * Gets the equivalent JNDI Context.REFERRAL key's value for this enumeration constant. 63 * 64 * @see Context#REFERRAL 65 * @return the equivalent JNDI Context.REFERRAL key's value 66 */ 67 public String getJndiValue() 68 { 69 return jndiValue; 70 } 71 72 73 /** 74 * Gets the enumeration constant for the JNDI Context.REFERRAL key's value. 75 * 76 * @see Context#REFERRAL 77 * @param jndiValue the JNDI Context.REFERRAL key's value 78 * @return the referral handling mode enumeration constant 79 * @throws IllegalArgumentException if the value is not a recognized value 80 */ 81 public static ReferralHandlingMode getModeFromJndi( String jndiValue ) 82 { 83 jndiValue = Strings.toLowerCaseAscii( Strings.trim( jndiValue ) ); 84 85 if ( jndiValue.equals( "throw" ) ) 86 { 87 return THROW; 88 } 89 90 if ( jndiValue.equals( "follow" ) ) 91 { 92 return FOLLOW; 93 } 94 95 if ( jndiValue.equals( "ignore" ) ) 96 { 97 return IGNORE; 98 } 99 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 }