View Javadoc

1   /*
2    *   @(#) $Id: ProtocolViolationException.java 210062 2005-07-11 03:52:38Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */
19  package org.apache.mina.protocol;
20  
21  import org.apache.mina.common.ByteBuffer;
22  
23  /***
24   * An exception that is thrown when {@link ProtocolEncoder} cannot understand or
25   * failed to validate the specified message, or when {@link ProtocolDecoder}
26   * cannot understand or failed to validate the specified {@link ByteBuffer}
27   * content.
28   * 
29   * @author Trustin Lee (trustin@apache.org)
30   * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
31   */
32  public class ProtocolViolationException extends Exception
33  {
34      private static final long serialVersionUID = 3545799879533408565L;
35  
36  	private ByteBuffer buffer;
37  
38      /***
39       * Constructs a new instance.
40       */
41      public ProtocolViolationException()
42      {
43      }
44  
45      /***
46       * Constructs a new instance with the specified message.
47       */
48      public ProtocolViolationException( String message )
49      {
50          super( message );
51      }
52  
53      /***
54       * Constructs a new instance with the specified cause.
55       */
56      public ProtocolViolationException( Throwable cause )
57      {
58          super( cause );
59      }
60  
61      /***
62       * Constructs a new instance with the specified message and the specified
63       * cause.
64       */
65      public ProtocolViolationException( String message, Throwable cause )
66      {
67          super( message, cause );
68      }
69  
70      /***
71       * Returns the message and the hexdump of the unknown part.
72       */
73      public String getMessage()
74      {
75          String message = super.getMessage();
76  
77          if( message == null )
78          {
79              message = "";
80          }
81  
82          if( buffer != null )
83          {
84              return message + ( ( message.length() > 0 ) ? " " : "" )
85                     + "(Hexdump: " + buffer.getHexDump() + ')';
86          }
87          else
88          {
89              return message;
90          }
91      }
92  
93      /***
94       * Returns unknown message part.
95       */
96      public ByteBuffer getBuffer()
97      {
98          return buffer;
99      }
100 
101     /***
102      * Sets unknown message part.
103      */
104     public void setBuffer( ByteBuffer buffer )
105     {
106         this.buffer = buffer;
107     }
108 }