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-2021 Ping Identity Corporation
026 */
027package com.unboundid.directory.sdk.sync.types;
028
029import com.unboundid.ldap.sdk.LDAPException;
030import 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 * Data Sync Server what it should do after a failure.
038 */
039@Extensible()
040public 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
053   *                  Data Sync Server should proceed with the sync
054   *                  operation. The value of {@link PostStepResult#CONTINUE}
055   *                  is undefined in this 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
068   *                  Data Sync Server should proceed with the sync
069   *                  operation. The value of {@link PostStepResult#CONTINUE}
070   *                  is undefined in this 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
084   *                  Data Sync Server should proceed with the sync
085   *                  operation. The value of {@link PostStepResult#CONTINUE}
086   *                  is undefined in this 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
100   *                  Data Sync Server should proceed with the sync
101   *                  operation. The value of {@link PostStepResult#CONTINUE}
102   *                  is undefined in this 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 Data Sync 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 Data Sync Server
140   * 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}