001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020
021 package org.apache.directory.shared.ldap.codec;
022
023 import org.apache.directory.shared.asn1.codec.DecoderException;
024 import org.apache.directory.shared.ldap.message.InternalMessage;
025 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
026 import org.apache.directory.shared.ldap.message.InternalResultResponse;
027 import org.apache.directory.shared.ldap.name.LdapDN;
028
029
030 /**
031 * Thrown when a Decoder has encountered a failure condition during a decode.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 * @version $Rev$, $Date$,
035 */
036 public class ResponseCarryingException extends DecoderException
037 {
038 /**
039 * Declares the Serial Version Uid.
040 *
041 * @see <a
042 * href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
043 * Declare Serial Version Uid</a>
044 */
045 private static final long serialVersionUID = 1L;
046
047 /** The response with the error cause */
048 private transient InternalMessage response;
049
050 /**
051 * Creates a DecoderException
052 *
053 * @param message A message with meaning to a human
054 */
055 public ResponseCarryingException(String message)
056 {
057 super( message );
058 }
059
060
061 /**
062 * Creates a DecoderException
063 *
064 * @param message A message with meaning to a human
065 * @param cause The Exception which caused the error
066 */
067 public ResponseCarryingException(String message, InternalResultResponse response, ResultCodeEnum code,
068 LdapDN matchedDn, Throwable cause)
069 {
070 super( message, cause );
071
072 response.getLdapResult().setErrorMessage( message );
073 response.getLdapResult().setResultCode( code );
074 response.getLdapResult().setMatchedDn( matchedDn );
075
076 this.response = response;
077 }
078
079 /**
080 * Set a response if we get an exception while parsing the message
081 * @param response the constructed response
082 */
083 public void setResponse( InternalMessage response )
084 {
085 this.response = response;
086 }
087
088 /**
089 * Get the constructed response
090 * @return The constructed response
091 */
092 public InternalMessage getResponse()
093 {
094 return response;
095 }
096
097 }