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.shared.ldap.exception; 021 022 023 import java.util.ArrayList; 024 import java.util.Collection; 025 import java.util.Hashtable; 026 import java.util.List; 027 028 import javax.naming.Context; 029 import javax.naming.NamingException; 030 import javax.naming.ReferralException; 031 032 import org.apache.directory.shared.ldap.NotImplementedException; 033 import org.apache.directory.shared.ldap.message.ResultCodeEnum; 034 import org.apache.directory.shared.ldap.name.DN; 035 036 037 /** 038 * A {@link LdapOperationException} which associates a resultCode namely the 039 * {@link ResultCodeEnum#REFERRAL} resultCode with the exception. 040 * 041 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 042 * @version $Rev: 925499 $ 043 */ 044 public class LdapReferralException extends AbstractLdapReferralException 045 { 046 /** The serial version UUID */ 047 static final long serialVersionUID = 1L; 048 049 /** The list of referrals */ 050 private final List<String> refs; 051 052 /** The current index in the list of referrals */ 053 private int index = 0; 054 055 /** The remaining DN */ 056 private DN remainingDn; 057 058 /** TODO */ 059 private Object resolvedObject; 060 061 062 /** 063 * @see ReferralException#ReferralException() 064 */ 065 public LdapReferralException( Collection<String> refs ) 066 { 067 super( null ); 068 this.refs = new ArrayList<String>( refs ); 069 } 070 071 072 /** 073 * @see ReferralException#ReferralException(java.lang.String) 074 */ 075 public LdapReferralException( Collection<String> refs, String explanation ) 076 { 077 super( explanation ); 078 this.refs = new ArrayList<String>( refs ); 079 } 080 081 082 /** 083 * Always returns {@link ResultCodeEnum#REFERRAL} 084 * 085 * @see LdapException#getResultCode() 086 */ 087 public ResultCodeEnum getResultCode() 088 { 089 return ResultCodeEnum.REFERRAL; 090 } 091 092 093 public String getReferralInfo() 094 { 095 return refs.get( index ); 096 } 097 098 099 public Context getReferralContext() throws NamingException 100 { 101 throw new NotImplementedException(); 102 } 103 104 105 public Context getReferralContext( Hashtable<?, ?> arg ) throws NamingException 106 { 107 throw new NotImplementedException(); 108 } 109 110 111 public boolean skipReferral() 112 { 113 index++; 114 return index < refs.size(); 115 } 116 117 118 public void retryReferral() 119 { 120 throw new NotImplementedException(); 121 } 122 123 124 /** 125 * @return the remainingDn 126 */ 127 public DN getRemainingDn() 128 { 129 return remainingDn; 130 } 131 132 133 /** 134 * @param remainingDn the remainingName to set 135 */ 136 public void setRemainingDn( DN remainingDn ) 137 { 138 this.remainingDn = remainingDn; 139 } 140 141 142 /** 143 * @return the resolvedObject 144 */ 145 public Object getResolvedObject() 146 { 147 return resolvedObject; 148 } 149 150 151 /** 152 * @param resolvedObject the resolvedObject to set 153 */ 154 public void setResolvedObject( Object resolvedObject ) 155 { 156 this.resolvedObject = resolvedObject; 157 } 158 }