001 /*
002 * Copyright 2009-2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-2016 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.sdk.persist;
022
023
024
025 import com.unboundid.ldap.sdk.LDAPException;
026 import com.unboundid.ldap.sdk.ResultCode;
027 import com.unboundid.util.NotMutable;
028 import com.unboundid.util.StaticUtils;
029 import com.unboundid.util.ThreadSafety;
030 import com.unboundid.util.ThreadSafetyLevel;
031
032
033
034 /**
035 * This class defines an exception that may be thrown if a problem occurs while
036 * attempting to perform processing related to persisting Java objects in an
037 * LDAP directory server.
038 */
039 @NotMutable()
040 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041 public final class LDAPPersistException
042 extends LDAPException
043 {
044 /**
045 * The serial version UID for this serializable class.
046 */
047 private static final long serialVersionUID = 8625904586803506713L;
048
049
050
051 // The object that was in the process of being decoded, if available. If it
052 // is non-null, then it will likely only be partially initialized.
053 private final Object partiallyDecodedObject;
054
055
056
057 /**
058 * Creates a new LDAP persist exception that wraps the provided LDAP
059 * exception.
060 *
061 * @param e The LDAP exception to wrap with this LDAP persist exception.
062 */
063 public LDAPPersistException(final LDAPException e)
064 {
065 super(e);
066
067 partiallyDecodedObject = null;
068 }
069
070
071
072 /**
073 * Creates a new LDAP persist exception with the provided message.
074 *
075 * @param message The message for this exception.
076 */
077 public LDAPPersistException(final String message)
078 {
079 super(ResultCode.LOCAL_ERROR, message);
080
081 partiallyDecodedObject = null;
082 }
083
084
085
086 /**
087 * Creates a new LDAP persist exception with the provided message and cause.
088 *
089 * @param message The message for this exception.
090 * @param cause The underlying cause for this exception.
091 */
092 public LDAPPersistException(final String message, final Throwable cause)
093 {
094 super(ResultCode.LOCAL_ERROR, message, cause);
095
096 partiallyDecodedObject = null;
097 }
098
099
100
101 /**
102 * Creates a new LDAP persist exception with the provided message and cause.
103 *
104 * @param message The message for this exception.
105 * @param partiallyDecodedObject The object that was in the process of being
106 * decoded when this exception was thrown. It
107 * may be {@code null} if the exception was
108 * thrown outside of the context of decoding
109 * an object. If an object is available, then
110 * it will likely be only partially
111 * initialized.
112 * @param cause The underlying cause for this exception.
113 */
114 public LDAPPersistException(final String message,
115 final Object partiallyDecodedObject,
116 final Throwable cause)
117 {
118 super(ResultCode.LOCAL_ERROR, message, cause);
119
120 this.partiallyDecodedObject = partiallyDecodedObject;
121 }
122
123
124
125 /**
126 * Retrieves the partially-decoded object in the process of being initialized
127 * when this exception was thrown.
128 *
129 * @return The partially-decoded object in the process of being initialized
130 * when this exception was thrown, or {@code null} if none is
131 * available or the exception was not thrown while decoding an
132 * object.
133 */
134 public Object getPartiallyDecodedObject()
135 {
136 return partiallyDecodedObject;
137 }
138
139
140
141 /**
142 * {@inheritDoc}
143 */
144 @Override()
145 public void toString(final StringBuilder buffer)
146 {
147 buffer.append("LDAPPersistException(message='");
148 buffer.append(getMessage());
149 buffer.append('\'');
150
151 if (partiallyDecodedObject != null)
152 {
153 buffer.append(", partiallyDecodedObject=");
154 buffer.append(partiallyDecodedObject);
155 }
156
157 final Throwable cause = getCause();
158 if (cause != null)
159 {
160 buffer.append(", cause=");
161 buffer.append(StaticUtils.getExceptionMessage(cause));
162 }
163
164 buffer.append(')');
165 }
166 }