AMQMethodBodyImpl.java
01 package org.apache.qpid.framing;
02 
03 /*
04  *
05  * Licensed to the Apache Software Foundation (ASF) under one
06  * or more contributor license agreements.  See the NOTICE file
07  * distributed with this work for additional information
08  * regarding copyright ownership.  The ASF licenses this file
09  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License.  You may obtain a copy of the License at
12  *
13  *   http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied.  See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  *
22  */
23 
24 import org.apache.mina.common.ByteBuffer;
25 import org.apache.qpid.AMQChannelException;
26 import org.apache.qpid.AMQConnectionException;
27 import org.apache.qpid.AMQException;
28 import org.apache.qpid.protocol.AMQConstant;
29 import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
30 
31 public abstract class AMQMethodBodyImpl implements AMQMethodBody
32 {
33     public static final byte TYPE = 1;
34 
35     public AMQMethodBodyImpl()
36     {
37     }
38 
39     public byte getFrameType()
40     {
41         return TYPE;
42     }
43 
44 
45     /** unsigned short */
46     abstract protected int getBodySize();
47 
48 
49     public AMQFrame generateFrame(int channelId)
50     {
51         return new AMQFrame(channelId, this);
52     }
53 
54     /**
55      * Creates an AMQChannelException for the corresponding body type (a channel exception should include the class and
56      * method ids of the body it resulted from).
57      */
58 
59     /**
60      * Convenience Method to create a channel not found exception
61      *
62      @param channelId The channel id that is not found
63      *
64      @return new AMQChannelException
65      */
66     public AMQChannelException getChannelNotFoundException(int channelId)
67     {
68         return getChannelException(AMQConstant.NOT_FOUND, "Channel not found for id:" + channelId);
69     }
70 
71     public AMQChannelException getChannelException(AMQConstant code, String message)
72     {
73         return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor()null);
74     }
75 
76     public AMQChannelException getChannelException(AMQConstant code, String message, Throwable cause)
77     {
78         return new AMQChannelException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
79     }
80 
81     public AMQConnectionException getConnectionException(AMQConstant code, String message)
82     {
83         return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor()null);
84     }
85 
86     public AMQConnectionException getConnectionException(AMQConstant code, String message, Throwable cause)
87     {
88         return new AMQConnectionException(code, message, getClazz(), getMethod(), getMajor(), getMinor(), cause);
89     }
90 
91     public void handle(final int channelId, final AMQVersionAwareProtocolSession sessionthrows AMQException
92     {
93         session.methodFrameReceived(channelId, this);
94     }
95 
96 }