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