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