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 Exception which caused the error 067 */ 068 public ResponseCarryingException( String message, ResultResponse response, ResultCodeEnum code, 069 Dn matchedDn, Throwable cause ) 070 { 071 super( message, cause ); 072 073 response.getLdapResult().setDiagnosticMessage( message ); 074 response.getLdapResult().setResultCode( code ); 075 response.getLdapResult().setMatchedDn( matchedDn ); 076 077 this.response = response; 078 } 079 080 081 /** 082 * Set a response if we get an exception while parsing the message 083 * @param response the constructed response 084 */ 085 public void setResponse( Message response ) 086 { 087 this.response = response; 088 } 089 090 091 /** 092 * Get the constructed response 093 * @return The constructed response 094 */ 095 public Message getResponse() 096 { 097 return response; 098 } 099 100}