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.api.ldap.codec.api;
022
023
024import org.apache.directory.api.asn1.DecoderException;
025import org.apache.directory.api.ldap.model.message.Message;
026import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
027import org.apache.directory.api.ldap.model.message.ResultResponse;
028import org.apache.directory.api.ldap.model.name.Dn;
029
030
031/**
032 * Thrown when a Decoder has encountered a failure condition during a decode.
033 * 
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public 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 Message response;
049
050
051    /**
052     * Creates a DecoderException
053     * 
054     * @param message A message with meaning to a human
055     */
056    public ResponseCarryingException( String message )
057    {
058        super( message );
059    }
060
061
062    /**
063     * Creates a DecoderException
064     * 
065     * @param message A message with meaning to a human
066     * @param cause The original cause
067     */
068    public ResponseCarryingException( String message, Throwable cause )
069    {
070        super( message, cause );
071    }
072
073
074    /**
075     * Creates a DecoderException
076     * 
077     * @param message A message with meaning to a human
078     * @param response The response to store
079     * @param code the ResultCode
080     * @param matchedDn The Matched DN
081     * @param cause The Exception which caused the error
082     */
083    public ResponseCarryingException( String message, ResultResponse response, ResultCodeEnum code,
084        Dn matchedDn, Throwable cause )
085    {
086        super( message, cause );
087
088        response.getLdapResult().setDiagnosticMessage( message );
089        response.getLdapResult().setResultCode( code );
090        response.getLdapResult().setMatchedDn( matchedDn );
091
092        this.response = response;
093    }
094
095
096    /**
097     * Set a response if we get an exception while parsing the message
098     * @param response the constructed response
099     */
100    public void setResponse( Message response )
101    {
102        this.response = response;
103    }
104
105
106    /**
107     * Get the constructed response
108     * @return The constructed response
109     */
110    public Message getResponse()
111    {
112        return response;
113    }
114
115}