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 cause The Exception which caused the error
079     */
080    public ResponseCarryingException( String message, ResultResponse response, ResultCodeEnum code,
081        Dn matchedDn, Throwable cause )
082    {
083        super( message, cause );
084
085        response.getLdapResult().setDiagnosticMessage( message );
086        response.getLdapResult().setResultCode( code );
087        response.getLdapResult().setMatchedDn( matchedDn );
088
089        this.response = response;
090    }
091
092
093    /**
094     * Set a response if we get an exception while parsing the message
095     * @param response the constructed response
096     */
097    public void setResponse( Message response )
098    {
099        this.response = response;
100    }
101
102
103    /**
104     * Get the constructed response
105     * @return The constructed response
106     */
107    public Message getResponse()
108    {
109        return response;
110    }
111
112}