View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.exception;
21  
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  import java.util.Map;
27  
28  import javax.naming.Context;
29  import javax.naming.NamingException;
30  
31  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
32  import org.apache.directory.api.ldap.model.name.Dn;
33  import org.apache.directory.api.util.exception.NotImplementedException;
34  
35  
36  /**
37   * A {@link LdapOperationException} which associates a resultCode namely the
38   * {@link org.apache.directory.api.ldap.model.message.ResultCodeEnum#REFERRAL} resultCode with the exception.
39   * 
40   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
41   */
42  public class LdapReferralException extends AbstractLdapReferralException
43  {
44      /** The serial version UUID */
45      static final long serialVersionUID = 1L;
46  
47      /** The list of referrals */
48      private final List<String> refs;
49  
50      /** The current index in the list of referrals */
51      private int index = 0;
52  
53      /** The remaining Dn */
54      private Dn remainingDn;
55  
56      /** The resolved Object */
57      private Object resolvedObject;
58  
59  
60      /**
61       * 
62       * Creates a new instance of LdapReferralException.
63       *
64       * @param refs The list of referrals
65       */
66      public LdapReferralException( Collection<String> refs )
67      {
68          super( null );
69          this.refs = new ArrayList<>( refs );
70      }
71  
72  
73      /**
74       * 
75       * Creates a new instance of LdapReferralException.
76       *
77       * @param refs The list of referrals
78       * @param explanation The associated error message
79       */
80      public LdapReferralException( Collection<String> refs, String explanation )
81      {
82          super( explanation );
83          this.refs = new ArrayList<>( refs );
84      }
85  
86  
87      /**
88       * Always returns {@link ResultCodeEnum#REFERRAL}
89       * 
90       * @return The ResultCode
91       */
92      @Override
93      public ResultCodeEnum getResultCode()
94      {
95          return ResultCodeEnum.REFERRAL;
96      }
97  
98  
99      /**
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 }