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 * https://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 */ 019package org.apache.directory.api.ldap.model.cursor; 020 021 022import org.apache.directory.api.ldap.model.exception.LdapReferralException; 023import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 024import org.apache.directory.api.ldap.model.name.Dn; 025 026 027/** 028 * A specific form of CursorException used when a referral is met 029 * 030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 031 */ 032public class CursorLdapReferralException extends CursorException 033{ 034 /** The serialVersion UID */ 035 private static final long serialVersionUID = -5723233489761854394L; 036 037 /** A static exception to be used by the monitor */ 038 public static final CursorLdapReferralException INSTANCE = new CursorLdapReferralException( null ); 039 040 /** The contained referralException */ 041 private final LdapReferralException ldapReferralException; 042 043 044 /** 045 * Creates a new instance of CursorClosedException. 046 * 047 * @param ldapReferralException The associated exception 048 */ 049 public CursorLdapReferralException( LdapReferralException ldapReferralException ) 050 { 051 this.ldapReferralException = ldapReferralException; 052 } 053 054 055 /** 056 * Creates a new instance of CursorClosedException. 057 * 058 * @param ldapReferralException The associated exception 059 * @param message The associated message 060 */ 061 public CursorLdapReferralException( LdapReferralException ldapReferralException, String message ) 062 { 063 super( message ); 064 065 this.ldapReferralException = ldapReferralException; 066 } 067 068 069 /** 070 * Creates a new instance of CursorClosedException. 071 * 072 * @param ldapReferralException The associated exception 073 * @param message The associated message 074 * @param cause The original cause 075 */ 076 public CursorLdapReferralException( LdapReferralException ldapReferralException, String message, Throwable cause ) 077 { 078 super( message, cause ); 079 080 this.ldapReferralException = ldapReferralException; 081 } 082 083 084 /** 085 * Always returns {@link ResultCodeEnum#REFERRAL} 086 * 087 * @see LdapReferralException#getResultCode() 088 * 089 * @return the underlying LdapReferral result code, if any 090 */ 091 public ResultCodeEnum getResultCode() 092 { 093 if ( ldapReferralException != null ) 094 { 095 return ldapReferralException.getResultCode(); 096 } 097 else 098 { 099 return ResultCodeEnum.UNKNOWN; 100 } 101 } 102 103 104 /** 105 * @return The current Referral 106 */ 107 public String getReferralInfo() 108 { 109 if ( ldapReferralException != null ) 110 { 111 return ldapReferralException.getReferralInfo(); 112 } 113 else 114 { 115 return ""; 116 } 117 } 118 119 120 /** 121 * Move to the next referral 122 * 123 * @return true if there is some next referral 124 */ 125 public boolean skipReferral() 126 { 127 if ( ldapReferralException != null ) 128 { 129 return ldapReferralException.skipReferral(); 130 } 131 else 132 { 133 return false; 134 } 135 } 136 137 138 /** 139 * @return the remainingDn 140 */ 141 public Dn getRemainingDn() 142 { 143 if ( ldapReferralException != null ) 144 { 145 return ldapReferralException.getRemainingDn(); 146 } 147 else 148 { 149 return Dn.EMPTY_DN; 150 } 151 } 152 153 154 /** 155 * @return the resolvedObject 156 */ 157 public Object getResolvedObject() 158 { 159 if ( ldapReferralException != null ) 160 { 161 return ldapReferralException.getResolvedObject(); 162 } 163 else 164 { 165 return null; 166 } 167 } 168}