001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * docs/licenses/cddl.txt
011     * or http://www.opensource.org/licenses/cddl1.php.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * docs/licenses/cddl.txt.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2010-2012 UnboundID Corp.
026     */
027    package com.unboundid.directory.sdk.sync.types;
028    
029    import com.unboundid.ldap.sdk.LDAPException;
030    import com.unboundid.util.Extensible;
031    
032    
033    /**
034     * This class provides a type of {@link Exception} which is used to indicate
035     * an error when interfacing with an external resource. There is an included
036     * {@link PostStepResult} which can be used to communicate back to the
037     * Synchronization Server what it should do after a failure.
038     */
039    @Extensible()
040    public class EndpointException extends Exception
041    {
042      //Generated servial version UID
043      private static final long serialVersionUID = -5331807629501618293L;
044    
045      //Retry policy associated with this exception
046      private final PostStepResult retryPolicy;
047    
048    
049      /**
050       * Creates a new EndpointException with the provided information.
051       *
052       * @param  result   The result object which indicates how the Synchronization
053       *                  server should proceed with the sync operation. The value
054       *                  of {@link PostStepResult#CONTINUE} is undefined in this
055       *                  context and cannot be used.
056       */
057      public EndpointException(final PostStepResult result)
058      {
059        this(result, null, null);
060      }
061    
062    
063    
064      /**
065       * Creates a new EndpointException with the provided information.
066       *
067       * @param  result   The result object which indicates how the Synchronization
068       *                  server should proceed with the sync operation. The value
069       *                  of {@link PostStepResult#CONTINUE} is undefined in this
070       *                  context and cannot be used.
071       * @param  message  The message that explains the problem that occurred.
072       */
073      public EndpointException(final PostStepResult result, final String message)
074      {
075        this(result, message, null);
076      }
077    
078    
079    
080      /**
081       * Creates a new EndpointException with the provided information.
082       *
083       * @param  result   The result object which indicates how the Synchronization
084       *                  server should proceed with the sync operation. The value
085       *                  of {@link PostStepResult#CONTINUE} is undefined in this
086       *                  context and cannot be used.
087       * @param  cause    The underlying cause that triggered this exception.
088       */
089      public EndpointException(final PostStepResult result, final Throwable cause)
090      {
091        this(result, null, cause);
092      }
093    
094    
095    
096      /**
097       * Creates a new EndpointException with the provided information.
098       *
099       * @param  result   The result object which indicates how the Synchronization
100       *                  server should proceed with the sync operation. The value
101       *                  of {@link PostStepResult#CONTINUE} is undefined in this
102       *                  context and cannot be used.
103       * @param  message  The message that explains the problem that occurred.
104       * @param  cause    The underlying cause that triggered this exception.
105       */
106      public EndpointException(final PostStepResult result,
107                               final String message,
108                               final Throwable cause)
109      {
110        super(message, cause);
111        this.retryPolicy = result;
112        if(result == null)
113        {
114          throw new NullPointerException("The PostStepResult cannot be null.");
115        }
116        else if(PostStepResult.CONTINUE.equals(result))
117        {
118          throw new IllegalArgumentException("The PostStepResult parameter cannot" +
119                                              "be CONTINUE.");
120        }
121      }
122    
123    
124      /**
125       * Creates a new EndpointException with the provided information. No
126       * PostStepResult is required here because the Synchronization Server has
127       * built-in logic to interpret an {@link LDAPException}.
128       *
129       * @param cause The underlying cause that triggered this exception.
130       */
131      public EndpointException(final LDAPException cause)
132      {
133        super(cause);
134        this.retryPolicy = null;
135      }
136    
137    
138      /**
139       * Gets the result object which indicates how the Synchronization
140       * server should proceed with the sync operation. The value will never be
141       * {@link PostStepResult#CONTINUE}, because this is undefined in this context.
142       * If the object was constructed with
143       * {@link #EndpointException(LDAPException)} then this method will return
144       * null.
145       *
146       * @return a {@link PostStepResult} indicating the retry policy that should
147       *         be taken
148       */
149      public final PostStepResult getPostStepResult() {
150        return retryPolicy;
151      }
152    }