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    
035    
036    /**
037     * A ReferralException which associates a resultCode namely the
038     * {@link ResultCodeEnum#REFERRAL} resultCode with the exception.
039     * 
040     * @see LdapException
041     * @see ReferralException
042     * @see <a
043     *      href="http://java.sun.com/j2se/1.4.2/docs/guide/jndi/jndi-ldap-gl.html#EXCEPT">
044     *      LDAP ResultCode to JNDI Exception Mappings</a>
045     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
046     * @version $Rev: 596222 $
047     */
048    public class LdapReferralException extends ReferralException implements LdapException
049    {
050        static final long serialVersionUID = -8611970137960601723L;
051    
052        private final List<String> refs;
053    
054        private int index = 0;
055    
056    
057        /**
058         * @see ReferralException#ReferralException()
059         */
060        public LdapReferralException( Collection<String> refs )
061        {
062            this.refs = new ArrayList<String>( refs );
063        }
064    
065    
066        /**
067         * @see ReferralException#ReferralException(java.lang.String)
068         */
069        public LdapReferralException( Collection<String> refs, String explanation )
070        {
071            super( explanation );
072            this.refs = new ArrayList<String>( refs );
073        }
074    
075    
076        /**
077         * Always returns {@link ResultCodeEnum#REFERRAL}
078         * 
079         * @see LdapException#getResultCode()
080         */
081        public ResultCodeEnum getResultCode()
082        {
083            return ResultCodeEnum.REFERRAL;
084        }
085    
086    
087        public String getReferralInfo()
088        {
089            return refs.get( index );
090        }
091    
092    
093        public Context getReferralContext() throws NamingException
094        {
095            throw new NotImplementedException();
096        }
097    
098    
099        public Context getReferralContext( Hashtable<?, ?> arg ) throws NamingException
100        {
101            throw new NotImplementedException();
102        }
103    
104    
105        public boolean skipReferral()
106        {
107            index++;
108            return index < refs.size();
109        }
110    
111    
112        public void retryReferral()
113        {
114            throw new NotImplementedException();
115        }
116    }