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
021package org.apache.directory.shared.ldap.codec.api;
022
023import org.apache.directory.shared.asn1.DecoderException;
024import org.apache.directory.shared.ldap.model.message.Message;
025import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
026import org.apache.directory.shared.ldap.model.message.ResultResponse;
027import org.apache.directory.shared.ldap.model.name.Dn;
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 */
035public class ResponseCarryingException extends DecoderException
036{
037    /**
038     * Declares the Serial Version Uid.
039     * 
040     * @see <a
041     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
042     *      Declare Serial Version Uid</a>
043     */
044    private static final long serialVersionUID = 1L;
045
046    /** The response with the error cause */
047    private Message response;
048    
049    /**
050     * Creates a DecoderException
051     * 
052     * @param message A message with meaning to a human
053     */
054    public ResponseCarryingException(String message)
055    {
056        super( message );
057    }
058
059
060    /**
061     * Creates a DecoderException
062     * 
063     * @param message A message with meaning to a human
064     * @param cause The Exception which caused the error
065     */
066    public ResponseCarryingException(String message, ResultResponse response, ResultCodeEnum code,
067        Dn matchedDn, Throwable cause)
068    {
069        super( message, cause );
070
071        response.getLdapResult().setDiagnosticMessage( message );
072        response.getLdapResult().setResultCode( code );
073        response.getLdapResult().setMatchedDn( matchedDn );
074    
075        this.response = response; 
076    }
077    
078    /**
079     * Set a response if we get an exception while parsing the message
080     * @param response the constructed response
081     */
082    public void setResponse( Message response ) 
083    {
084        this.response = response;
085    }
086    
087    /**
088     * Get the constructed response
089     * @return The constructed response
090     */
091    public Message getResponse()
092    {
093        return response;
094    }
095
096}