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   *  http://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  package org.apache.directory.api.ldap.model.cursor;
20  
21  
22  import org.apache.directory.api.ldap.model.exception.LdapReferralException;
23  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
24  import org.apache.directory.api.ldap.model.name.Dn;
25  
26  
27  /**
28   * A specific form of CursorException used when a referral is met
29   *
30   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31   */
32  public class CursorLdapReferralException extends CursorException
33  {
34      /** The serialVersion UID */
35      private static final long serialVersionUID = -5723233489761854394L;
36  
37      /** A static exception to be used by the monitor */
38      public static final CursorLdapReferralException INSTANCE = new CursorLdapReferralException( null );
39  
40      /** The contained referralException */
41      private LdapReferralException ldapReferralException;
42  
43  
44      /**
45       * Creates a new instance of CursorClosedException.
46       * 
47       * @param ldapReferralException The associated exception
48       */
49      public CursorLdapReferralException( LdapReferralException ldapReferralException )
50      {
51          this.ldapReferralException = ldapReferralException;
52      }
53  
54  
55      /**
56       * Creates a new instance of CursorClosedException.
57       *
58       * @param ldapReferralException The associated exception
59       * @param message The associated message
60       */
61      public CursorLdapReferralException( LdapReferralException ldapReferralException, String message )
62      {
63          super( message );
64  
65          this.ldapReferralException = ldapReferralException;
66      }
67  
68  
69      /**
70       * Creates a new instance of CursorClosedException.
71       *
72       * @param ldapReferralException The associated exception
73       * @param message The associated message
74       * @param cause The original cause
75       */
76      public CursorLdapReferralException( LdapReferralException ldapReferralException, String message, Throwable cause )
77      {
78          super( message, cause );
79  
80          this.ldapReferralException = ldapReferralException;
81      }
82  
83  
84      /**
85       * Always returns {@link ResultCodeEnum#REFERRAL}
86       * 
87       * @see LdapReferralException#getResultCode()
88       * 
89       * @return the underlying LdapReferral result code, if any
90       */
91      public ResultCodeEnum getResultCode()
92      {
93          if ( ldapReferralException != null )
94          {
95              return ldapReferralException.getResultCode();
96          }
97          else
98          {
99              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 }