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