summaryrefslogtreecommitdiff
path: root/java/common/templates/method/version/MethodBodyClass.vm
blob: a739110d7048593619fb649008f9501d04b63427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#macro( UpperCamel $name )
#set( $name = "${name.substring(0,1).toUpperCase()}${name.substring(1)}" )
#end
#macro( toUpperCamel $name )${name.substring(0,1).toUpperCase()}${name.substring(1)}#end



#set( $amqp_ClassName = $amqpClass.Name) 
#UpperCamel( $amqp_ClassName )
#set( $amqp_MethodName = $amqpMethod.Name ) 
#UpperCamel( $amqp_MethodName )
#set( $javaClassName = "${amqp_ClassName}${amqp_MethodName}BodyImpl" )
#set( $interfaceName = "${amqp_ClassName}${amqp_MethodName}Body" )
#set( $amqpPackageName = "amqp_$version.getMajor()_$version.getMinor()" )

#set( $filename = "${amqpPackageName}/${javaClassName}.java")
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

/*
 * This file is auto-generated by ${generator} - do not modify.
 * Supported AMQP version:
 *   $version.getMajor()-$version.getMinor()
 */
 
#set( $clazz = $amqpClass.asSingleVersionClass( $version ) ) 
#set( $method = $amqpMethod.asSingleVersionMethod( $version ) )
 
package org.apache.qpid.framing.amqp_$version.getMajor()_$version.getMinor();

import java.util.HashMap;

import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.framing.*;
import org.apache.qpid.AMQException;

public class ${javaClassName} extends AMQMethodBody_$version.getMajor()_$version.getMinor() implements $interfaceName
{
    private static final AMQMethodBodyInstanceFactory FACTORY_INSTANCE = new AMQMethodBodyInstanceFactory()
    {
        public AMQMethodBody newInstance(ByteBuffer in, long size) throws AMQFrameDecodingException
        {
            return new ${javaClassName}(in);
        }
		
 
    };
    
	
    public static AMQMethodBodyInstanceFactory getFactory()
    {
        return FACTORY_INSTANCE;
    }

    public static final int CLASS_ID =  $clazz.ClassId; 
    
    public static final int METHOD_ID = $method.MethodId; 
    

	
    // Fields declared in specification
#foreach( $field in $method.ConsolidatedFields )
    private final $field.NativeType _$field.getName(); // $field.UnderlyingFields
#end

    
    // Constructor

    public ${javaClassName}(ByteBuffer buffer) throws AMQFrameDecodingException
    {
#foreach( $field in $method.ConsolidatedFields )
        _$field.Name = read$field.getEncodingType()( buffer );
#end
	}
	
    public ${javaClassName}(
#foreach( $field in $method.FieldList )
#if( $velocityCount == $method.getFieldList().size() )
                                $field.NativeType $field.Name
#else
                                $field.NativeType $field.Name,
#end
#end
                            )
    {
#set( $consolidatedFieldName = "" )
#foreach( $field in $method.FieldList )
#if( $method.isConsolidated( $field.Name ) )
#if( !$method.getConsolidatedFieldName( $field.Name ).equals( $consolidatedFieldName ) )
#if( !$consolidatedFieldName.equals("") )
        _$consolidatedFieldName = $consolidatedFieldName; // 1
#end
#set( $consolidatedFieldName = $method.getConsolidatedFieldName( $field.Name ) )
        byte $consolidatedFieldName = (byte)0;
#end
        if( $field.Name )
		{		    
            $consolidatedFieldName = (byte) (((int) $consolidatedFieldName) | (1 << $method.getPositionInBitField( $field.Name )));
		}
#if( $velocityCount == $method.getFieldList().size())
        _$consolidatedFieldName = $consolidatedFieldName; 
#else  
 
#end 
#else
#if( !$consolidatedFieldName.equals("") )
        _$consolidatedFieldName = $consolidatedFieldName; 
#end
#set( $consolidatedFieldName = "" )
        _$field.Name = $field.Name;
#end
#end
    }
    
    public int getClazz() 
    { 
        return CLASS_ID; 
    }
    
    public int getMethod() 
    { 
        return METHOD_ID; 
    }

    
#foreach( $field in $method.FieldList )
    public final $field.NativeType get#toUpperCamel( ${field.Name} )()
    {
#if( $method.isConsolidated( $field.Name ) )
        return (((int)(_$method.getConsolidatedFieldName( $field.Name ))) & ( 1 << $method.getPositionInBitField( $field.Name ))) != 0;
#else
        return _$field.Name;
#end
    }
#end

    protected int getBodySize()
    {      
#set( $fixedSize = 0 )
#foreach( $field in $method.ConsolidatedFields )
#if( $field.isFixedSize() )        
#set( $fixedSize = $fixedSize + $field.Size )
#end
#end
	    int size = $fixedSize;
#foreach( $field in $method.ConsolidatedFields )
#if( ! $field.isFixedSize() )        
        size += getSizeOf( _$field.Name );
#end
#end
        return size;        
    }

    public void writeMethodPayload(ByteBuffer buffer)
    {
#foreach( $field in $method.ConsolidatedFields )
        write$field.getEncodingType()( buffer, _$field.Name );
#end
    }

    public boolean execute(MethodDispatcher dispatcher, int channelId) throws AMQException
	{
#set( $amqpMethodNameFirstChar = $amqpMethod.getName().substring(0,1) )
#set( $amqpMethodNameFirstCharU = $amqpMethodNameFirstChar.toUpperCase() )
#set( $amqpMethodNameUpperCamel = "$amqpMethodNameFirstCharU$amqpMethod.getName().substring(1)" )
#if( $amqpMethod.inAllVersions() )
    return dispatcher.dispatch${amqpClassNameUpperCamel}${amqpMethodNameUpperCamel}(this, channelId);	
#else
    return ((MethodDispatcher_$version.getMajor()_$version.getMinor())dispatcher).dispatch${amqp_ClassName}${amqpMethodNameUpperCamel}(this, channelId);	

#end	
	    
	}
	
	
    public String toString()
    {
        StringBuilder buf = new StringBuilder("[$javaClassName: ");
#foreach( $field in $method.FieldList )
        buf.append( "$field.Name=" );
#if( $field.NativeType == "byte[]" )
		buf.append(  get#toUpperCamel( $field.Name )() == null  ? "null" : java.util.Arrays.toString( get#toUpperCamel( $field.Name )() ) );
#else
		buf.append(  get#toUpperCamel( $field.Name )() );
#end
#if( $velocityCount	!= $method.FieldList.size() )
		buf.append( ", " );		
#end		
#end
        buf.append("]");
        return buf.toString();
    }


}