001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021
022 package org.apache.qpid.framing.amqp_8_0;
023
024 import org.apache.qpid.framing.abstraction.ProtocolVersionMethodConverter;
025 import org.apache.qpid.framing.abstraction.ContentChunk;
026 import org.apache.qpid.framing.abstraction.MessagePublishInfo;
027 import org.apache.qpid.framing.abstraction.AbstractMethodConverter;
028 import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl;
029 import org.apache.qpid.framing.amqp_8_0.BasicPublishBodyImpl;
030 import org.apache.qpid.framing.*;
031
032 import org.apache.mina.common.ByteBuffer;
033
034 public class MethodConverter_8_0 extends AbstractMethodConverter implements ProtocolVersionMethodConverter
035 {
036 private int _basicPublishClassId;
037 private int _basicPublishMethodId;
038
039 public MethodConverter_8_0()
040 {
041 super((byte)8,(byte)0);
042
043
044 }
045
046 public AMQBody convertToBody(ContentChunk contentChunk)
047 {
048 return new ContentBody(contentChunk.getData());
049 }
050
051 public ContentChunk convertToContentChunk(AMQBody body)
052 {
053 final ContentBody contentBodyChunk = (ContentBody) body;
054
055 return new ContentChunk()
056 {
057
058 public int getSize()
059 {
060 return contentBodyChunk.getSize();
061 }
062
063 public ByteBuffer getData()
064 {
065 return contentBodyChunk.payload;
066 }
067
068 public void reduceToFit()
069 {
070 contentBodyChunk.reduceBufferToFit();
071 }
072 };
073
074 }
075
076 public void configure()
077 {
078
079 _basicPublishClassId = BasicPublishBodyImpl.CLASS_ID;
080 _basicPublishMethodId = BasicPublishBodyImpl.METHOD_ID;
081
082 }
083
084 public MessagePublishInfo convertToInfo(AMQMethodBody methodBody)
085 {
086 final BasicPublishBody publishBody = ((BasicPublishBody) methodBody);
087
088 final AMQShortString exchange = publishBody.getExchange();
089 final AMQShortString routingKey = publishBody.getRoutingKey();
090
091 return new MessagePublishInfoImpl(exchange == null ? null : exchange.intern(),
092 publishBody.getImmediate(),
093 publishBody.getMandatory(),
094 routingKey == null ? null : routingKey.intern());
095
096 }
097
098 public AMQMethodBody convertToBody(MessagePublishInfo info)
099 {
100
101 return new BasicPublishBodyImpl(0,
102 info.getExchange(),
103 info.getRoutingKey(),
104 info.isMandatory(),
105 info.isImmediate()) ;
106
107 }
108 }
|