You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2015/08/14 21:07:56 UTC
[23/50] [abbrv] qpid-proton git commit: Checking in interim changes.
Checking in interim changes.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/e4204f04
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/e4204f04
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/e4204f04
Branch: refs/heads/rajith-codec
Commit: e4204f0426a575a6b85e821dce76d66f31835d2f
Parents: 8a11434
Author: Rajith Attapattu <ra...@apache.org>
Authored: Tue May 5 07:50:11 2015 -0400
Committer: Rajith Attapattu <ra...@apache.org>
Committed: Thu Jul 9 09:12:38 2015 -0400
----------------------------------------------------------------------
.../qpid/proton/codec2/DiscriptorRegistry.java | 94 ++
.../apache/qpid/proton/codec2/POJOBuilder.java | 1 -
.../qpid/proton/message2/MessageImpl2.java | 853 +++++++++++++++++++
3 files changed, 947 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e4204f04/proton-j/src/main/java/org/apache/qpid/proton/codec2/DiscriptorRegistry.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/DiscriptorRegistry.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/DiscriptorRegistry.java
index 2c28995..7c1f0a2 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/DiscriptorRegistry.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/DiscriptorRegistry.java
@@ -23,18 +23,112 @@ package org.apache.qpid.proton.codec2;
import java.util.HashMap;
import java.util.Map;
+import org.apache.qpid.proton.message2.Accepted;
+import org.apache.qpid.proton.message2.AmqpSequence;
+import org.apache.qpid.proton.message2.AmqpValue;
+import org.apache.qpid.proton.message2.ApplicationProperties;
+import org.apache.qpid.proton.message2.Data;
+import org.apache.qpid.proton.message2.DeliveryAnnotations;
+import org.apache.qpid.proton.message2.Footer;
+import org.apache.qpid.proton.message2.Header;
+import org.apache.qpid.proton.message2.LifetimePolicy;
+import org.apache.qpid.proton.message2.MessageAnnotations;
+import org.apache.qpid.proton.message2.Modified;
+import org.apache.qpid.proton.message2.Received;
+import org.apache.qpid.proton.message2.Rejected;
+import org.apache.qpid.proton.message2.Released;
+import org.apache.qpid.proton.security.SaslChallenge;
+import org.apache.qpid.proton.security.SaslInit;
+import org.apache.qpid.proton.security.SaslMechanisms;
+import org.apache.qpid.proton.security.SaslOutcome;
+import org.apache.qpid.proton.security.SaslResponse;
+import org.apache.qpid.proton.transport.Attach;
+import org.apache.qpid.proton.transport.Begin;
+import org.apache.qpid.proton.transport.Close;
+import org.apache.qpid.proton.transport.Detach;
+import org.apache.qpid.proton.transport.Disposition;
+import org.apache.qpid.proton.transport.End;
+import org.apache.qpid.proton.transport.ErrorCondition;
+import org.apache.qpid.proton.transport.Flow;
+import org.apache.qpid.proton.transport.Open;
+import org.apache.qpid.proton.transport.Source;
+import org.apache.qpid.proton.transport.Target;
+import org.apache.qpid.proton.transport.Transfer;
+
public class DiscriptorRegistry
{
private static Map<String, DescribedTypeFactory> _typeRegByStrCode = new HashMap<String, DescribedTypeFactory>();
private static Map<Long, DescribedTypeFactory> _typeRegByLongCode = new HashMap<Long, DescribedTypeFactory>();
+ // Register the standard types
+ static
+ {
+ registerTransportTypes();
+ registerMessageTypes();
+ registerSaslTypes();
+ }
+
public static void registerType(long longCode, String strCode, DescribedTypeFactory factory)
{
_typeRegByStrCode.put(strCode, factory);
_typeRegByLongCode.put(longCode, factory);
}
+ private static void registerTransportTypes()
+ {
+ registerType(Open.DESCRIPTOR_LONG, Open.DESCRIPTOR_STRING, Open.FACTORY);
+ registerType(Begin.DESCRIPTOR_LONG, Begin.DESCRIPTOR_STRING, Begin.FACTORY);
+ registerType(Attach.DESCRIPTOR_LONG, Attach.DESCRIPTOR_STRING, Attach.FACTORY);
+ registerType(Flow.DESCRIPTOR_LONG, Flow.DESCRIPTOR_STRING, Flow.FACTORY);
+ registerType(Transfer.DESCRIPTOR_LONG, Transfer.DESCRIPTOR_STRING, Transfer.FACTORY);
+ registerType(Disposition.DESCRIPTOR_LONG, Disposition.DESCRIPTOR_STRING, Disposition.FACTORY);
+ registerType(Detach.DESCRIPTOR_LONG, Detach.DESCRIPTOR_STRING, Detach.FACTORY);
+ registerType(End.DESCRIPTOR_LONG, End.DESCRIPTOR_STRING, End.FACTORY);
+ registerType(Close.DESCRIPTOR_LONG, Close.DESCRIPTOR_STRING, Close.FACTORY);
+ registerType(ErrorCondition.DESCRIPTOR_LONG, ErrorCondition.DESCRIPTOR_STRING, ErrorCondition.FACTORY);
+ }
+
+ private static void registerMessageTypes()
+ {
+ registerType(Header.DESCRIPTOR_LONG, Header.DESCRIPTOR_STRING, Header.FACTORY);
+ registerType(DeliveryAnnotations.DESCRIPTOR_LONG, DeliveryAnnotations.DESCRIPTOR_STRING,
+ DeliveryAnnotations.FACTORY);
+ registerType(MessageAnnotations.DESCRIPTOR_LONG, MessageAnnotations.DESCRIPTOR_STRING,
+ MessageAnnotations.FACTORY);
+ registerType(ApplicationProperties.DESCRIPTOR_LONG, ApplicationProperties.DESCRIPTOR_STRING,
+ ApplicationProperties.FACTORY);
+ registerType(Data.DESCRIPTOR_LONG, Data.DESCRIPTOR_STRING, Data.FACTORY);
+ registerType(AmqpSequence.DESCRIPTOR_LONG, AmqpSequence.DESCRIPTOR_STRING, AmqpSequence.FACTORY);
+ registerType(AmqpValue.DESCRIPTOR_LONG, AmqpValue.DESCRIPTOR_STRING, AmqpValue.FACTORY);
+ registerType(Footer.DESCRIPTOR_LONG, Footer.DESCRIPTOR_STRING, Footer.FACTORY);
+ registerType(Accepted.DESCRIPTOR_LONG, Accepted.DESCRIPTOR_STRING, Accepted.FACTORY);
+ registerType(Received.DESCRIPTOR_LONG, Received.DESCRIPTOR_STRING, Received.FACTORY);
+ registerType(Rejected.DESCRIPTOR_LONG, Rejected.DESCRIPTOR_STRING, Rejected.FACTORY);
+ registerType(Released.DESCRIPTOR_LONG, Released.DESCRIPTOR_STRING, Released.FACTORY);
+ registerType(Modified.DESCRIPTOR_LONG, Modified.DESCRIPTOR_STRING, Modified.FACTORY);
+ registerType(Source.DESCRIPTOR_LONG, Source.DESCRIPTOR_STRING, Source.FACTORY);
+ registerType(Target.DESCRIPTOR_LONG, Target.DESCRIPTOR_STRING, Target.FACTORY);
+ registerType(LifetimePolicy.DELETE_ON_CLOSE_TYPE.getLongDesc(),
+ LifetimePolicy.DELETE_ON_CLOSE_TYPE.getStringDesc(), LifetimePolicy.DELETE_ON_CLOSE_TYPE);
+ registerType(LifetimePolicy.DELETE_ON_NO_LINKS_TYPE.getLongDesc(),
+ LifetimePolicy.DELETE_ON_NO_LINKS_TYPE.getStringDesc(), LifetimePolicy.DELETE_ON_NO_LINKS_TYPE);
+ registerType(LifetimePolicy.DELETE_ON_NO_MSGS_TYPE.getLongDesc(),
+ LifetimePolicy.DELETE_ON_NO_MSGS_TYPE.getStringDesc(), LifetimePolicy.DELETE_ON_NO_MSGS_TYPE);
+ registerType(LifetimePolicy.DELETE_ON_NO_LINKS_OR_MSGS_TYPE.getLongDesc(),
+ LifetimePolicy.DELETE_ON_NO_LINKS_OR_MSGS_TYPE.getStringDesc(),
+ LifetimePolicy.DELETE_ON_NO_LINKS_OR_MSGS_TYPE);
+ }
+
+ public static void registerSaslTypes()
+ {
+ registerType(SaslMechanisms.DESCRIPTOR_LONG, SaslMechanisms.DESCRIPTOR_STRING, SaslMechanisms.FACTORY);
+ registerType(SaslInit.DESCRIPTOR_LONG, SaslInit.DESCRIPTOR_STRING, SaslInit.FACTORY);
+ registerType(SaslChallenge.DESCRIPTOR_LONG, SaslChallenge.DESCRIPTOR_STRING, SaslChallenge.FACTORY);
+ registerType(SaslResponse.DESCRIPTOR_LONG, SaslResponse.DESCRIPTOR_STRING, SaslResponse.FACTORY);
+ registerType(SaslOutcome.DESCRIPTOR_LONG, SaslOutcome.DESCRIPTOR_STRING, SaslOutcome.FACTORY);
+ }
+
public static DescribedTypeFactory lookup(Object code)
{
if (code instanceof Long)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e4204f04/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
index 47d6018..3d89465 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
@@ -38,7 +38,6 @@ public class POJOBuilder implements DataHandler
private class DescribedBuilder implements Builder
{
-
private Object descriptor;
private Object described;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e4204f04/proton-j/src/main/java/org/apache/qpid/proton/message2/MessageImpl2.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/message2/MessageImpl2.java b/proton-j/src/main/java/org/apache/qpid/proton/message2/MessageImpl2.java
new file mode 100644
index 0000000..1450cfd
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/message2/MessageImpl2.java
@@ -0,0 +1,853 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+package org.apache.qpid.proton.message2;
+
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.messaging.*;
+import org.apache.qpid.proton.codec2.*;
+import org.apache.qpid.proton.message.*;
+
+public class MessageImpl2 implements Message
+{
+ private final AMQPMessageFormat _parser = new AMQPMessageFormat();
+
+ private Header _header;
+ private DeliveryAnnotations _deliveryAnnotations;
+ private MessageAnnotations _messageAnnotations;
+ private Properties _properties;
+ private ApplicationProperties _applicationProperties;
+ private Object _body;
+ private Footer _footer;
+ private MessageFormat _format = MessageFormat.DATA;
+
+ private static class EncoderDecoderPair {
+ /*DecoderImpl decoder = new DecoderImpl();
+ EncoderImpl encoder = new EncoderImpl(decoder);
+ {
+ AMQPDefinedTypes.registerAllTypes(decoder, encoder);
+ }*/
+ ByteArrayEncoder encoder = new ByteArrayEncoder();
+ ByteArrayDecoder decoder = new ByteArrayDecoder();
+ }
+
+ private static final ThreadLocal<EncoderDecoderPair> tlsCodec = new ThreadLocal<EncoderDecoderPair>() {
+ @Override protected EncoderDecoderPair initialValue() {
+ return new EncoderDecoderPair();
+ }
+ };
+
+ /**
+ * @deprecated This constructor's visibility will be reduced to the default scope in a future release.
+ * Client code outside this module should use a {@link MessageFactory} instead
+ */
+ @Deprecated public MessageImpl2()
+ {
+ }
+
+ /**
+ * @deprecated This constructor's visibility will be reduced to the default scope in a future release.
+ * Client code outside this module should use a {@link MessageFactory} instead
+ */
+ @Deprecated public MessageImpl2(Header header, DeliveryAnnotations deliveryAnnotations, MessageAnnotations messageAnnotations,
+ Properties properties, ApplicationProperties applicationProperties, Section body, Footer footer)
+ {
+ _header = header;
+ _deliveryAnnotations = deliveryAnnotations;
+ _messageAnnotations = messageAnnotations;
+ _properties = properties;
+ _applicationProperties = applicationProperties;
+ _body = body;
+ _footer = footer;
+ }
+
+ @Override
+ public boolean isDurable()
+ {
+ return (_header == null || _header.getDurable() == null) ? false : _header.getDurable();
+ }
+
+
+ @Override
+ public long getDeliveryCount()
+ {
+ return (_header == null ? 0l : _header.getDeliveryCount());
+ }
+
+
+ @Override
+ public short getPriority()
+ {
+ return (_header == null ? DEFAULT_PRIORITY
+ : _header.getPriority());
+ }
+
+ @Override
+ public boolean isFirstAcquirer()
+ {
+ return (_header == null || _header.getFirstAcquirer() == null) ? false : _header.getFirstAcquirer();
+ }
+
+ @Override
+ public long getTtl()
+ {
+ return (_header == null ? 0l : _header.getTtl());
+ }
+
+ @Override
+ public void setDurable(boolean durable)
+ {
+ if (_header == null)
+ {
+ if (durable)
+ {
+ _header = new Header();
+ }
+ else
+ {
+ return;
+ }
+ }
+ _header.setDurable(durable);
+ }
+
+ @Override
+ public void setTtl(long ttl)
+ {
+
+ if (_header == null)
+ {
+ if (ttl != 0l)
+ {
+ _header = new Header();
+ }
+ else
+ {
+ return;
+ }
+ }
+ //TODO
+ _header.setTtl((int)ttl);
+ }
+
+ @Override
+ public void setDeliveryCount(long deliveryCount)
+ {
+ if (_header == null)
+ {
+ if (deliveryCount == 0l)
+ {
+ return;
+ }
+ _header = new Header();
+ }
+ _header.setDeliveryCount(deliveryCount);
+ }
+
+
+ @Override
+ public void setFirstAcquirer(boolean firstAcquirer)
+ {
+
+ if (_header == null)
+ {
+ if (!firstAcquirer)
+ {
+ return;
+ }
+ _header = new Header();
+ }
+ _header.setFirstAcquirer(firstAcquirer);
+ }
+
+ @Override
+ public void setPriority(short priority)
+ {
+
+ if (_header == null)
+ {
+ if (priority == DEFAULT_PRIORITY)
+ {
+ return;
+ }
+ _header = new Header();
+ }
+ _header.setPriority((byte) priority);
+ }
+
+ @Override
+ public Object getMessageId()
+ {
+ return _properties == null ? null : _properties.getMessageId();
+ }
+
+ @Override
+ public long getGroupSequence()
+ {
+ return (_properties == null ? 0l : _properties.getGroupSequence());
+ }
+
+ @Override
+ public String getReplyToGroupId()
+ {
+ return _properties == null ? null : _properties.getReplyToGroupId();
+ }
+
+ @Override
+ public long getCreationTime()
+ {
+ return (_properties == null || _properties.getCreationTime() == null) ? 0l : _properties.getCreationTime().getTime();
+ }
+
+ @Override
+ public String getAddress()
+ {
+ return _properties == null ? null : _properties.getTo();
+ }
+
+ @Override
+ public byte[] getUserId()
+ {
+ if(_properties == null || _properties.getUserId() == null)
+ {
+ return null;
+ }
+ else
+ {
+ return _properties.getUserId();
+ }
+ }
+
+ @Override
+ public String getReplyTo()
+ {
+ return _properties == null ? null : _properties.getReplyTo();
+ }
+
+ @Override
+ public String getGroupId()
+ {
+ return _properties == null ? null : _properties.getGroupId();
+ }
+
+ @Override
+ public String getContentType()
+ {
+ return (_properties == null || _properties.getContentType() == null) ? null : _properties.getContentType();
+ }
+
+ @Override
+ public long getExpiryTime()
+ {
+ return (_properties == null || _properties.getAbsoluteExpiryTime() == null) ? 0l : _properties.getAbsoluteExpiryTime().getTime();
+ }
+
+ @Override
+ public Object getCorrelationId()
+ {
+ return (_properties == null) ? null : _properties.getCorrelationId();
+ }
+
+ @Override
+ public String getContentEncoding()
+ {
+ return (_properties == null || _properties.getContentEncoding() == null) ? null : _properties.getContentEncoding();
+ }
+
+ @Override
+ public String getSubject()
+ {
+ return _properties == null ? null : _properties.getSubject();
+ }
+
+ @Override
+ public void setGroupSequence(long groupSequence)
+ {
+ if(_properties == null)
+ {
+ if(groupSequence == 0l)
+ {
+ return;
+ }
+ else
+ {
+ _properties = new Properties();
+ }
+ }
+ _properties.setGroupSequence((int) groupSequence);
+ }
+
+ @Override
+ public void setUserId(byte[] userId)
+ {
+ if(userId == null)
+ {
+ if(_properties != null)
+ {
+ _properties.setUserId(null);
+ }
+
+ }
+ else
+ {
+ if(_properties == null)
+ {
+ _properties = new Properties();
+ }
+ _properties.setUserId(userId);
+ }
+ }
+
+ @Override
+ public void setCreationTime(long creationTime)
+ {
+ if(_properties == null)
+ {
+ if(creationTime == 0l)
+ {
+ return;
+ }
+ _properties = new Properties();
+
+ }
+ _properties.setCreationTime(new Date(creationTime));
+ }
+
+ @Override
+ public void setSubject(String subject)
+ {
+ if(_properties == null)
+ {
+ if(subject == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setSubject(subject);
+ }
+
+ @Override
+ public void setGroupId(String groupId)
+ {
+ if(_properties == null)
+ {
+ if(groupId == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setGroupId(groupId);
+ }
+
+ @Override
+ public void setAddress(String to)
+ {
+ if(_properties == null)
+ {
+ if(to == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setTo(to);
+ }
+
+ @Override
+ public void setExpiryTime(long absoluteExpiryTime)
+ {
+ if(_properties == null)
+ {
+ if(absoluteExpiryTime == 0l)
+ {
+ return;
+ }
+ _properties = new Properties();
+
+ }
+ _properties.setAbsoluteExpiryTime(new Date(absoluteExpiryTime));
+ }
+
+ @Override
+ public void setReplyToGroupId(String replyToGroupId)
+ {
+ if(_properties == null)
+ {
+ if(replyToGroupId == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setReplyToGroupId(replyToGroupId);
+ }
+
+ @Override
+ public void setContentEncoding(String contentEncoding)
+ {
+ if(_properties == null)
+ {
+ if(contentEncoding == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setContentEncoding(contentEncoding);
+ }
+
+ @Override
+ public void setContentType(String contentType)
+ {
+ if(_properties == null)
+ {
+ if(contentType == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setContentType(contentType);
+ }
+
+ @Override
+ public void setReplyTo(String replyTo)
+ {
+
+ if(_properties == null)
+ {
+ if(replyTo == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setReplyTo(replyTo);
+ }
+
+ @Override
+ public void setCorrelationId(Object correlationId)
+ {
+
+ if(_properties == null)
+ {
+ if(correlationId == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setCorrelationId(correlationId);
+ }
+
+ @Override
+ public void setMessageId(Object messageId)
+ {
+
+ if(_properties == null)
+ {
+ if(messageId == null)
+ {
+ return;
+ }
+ _properties = new Properties();
+ }
+ _properties.setMessageId(messageId);
+ }
+
+
+ @Override
+ public Header getHeader()
+ {
+ return _header;
+ }
+
+ @Override
+ public DeliveryAnnotations getDeliveryAnnotations()
+ {
+ return _deliveryAnnotations;
+ }
+
+ @Override
+ public MessageAnnotations getMessageAnnotations()
+ {
+ return _messageAnnotations;
+ }
+
+ @Override
+ public Properties getProperties()
+ {
+ return _properties;
+ }
+
+ @Override
+ public ApplicationProperties getApplicationProperties()
+ {
+ return _applicationProperties;
+ }
+
+ @Override
+ public Object getBody()
+ {
+ return _body;
+ }
+
+ @Override
+ public Footer getFooter()
+ {
+ return _footer;
+ }
+
+ @Override
+ public void setHeader(Header header)
+ {
+ _header = header;
+ }
+
+ @Override
+ public void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations)
+ {
+ _deliveryAnnotations = deliveryAnnotations;
+ }
+
+ @Override
+ public void setMessageAnnotations(MessageAnnotations messageAnnotations)
+ {
+ _messageAnnotations = messageAnnotations;
+ }
+
+ @Override
+ public void setProperties(Properties properties)
+ {
+ _properties = properties;
+ }
+
+ @Override
+ public void setApplicationProperties(ApplicationProperties applicationProperties)
+ {
+ _applicationProperties = applicationProperties;
+ }
+
+ @Override
+ public void setBody(Object body)
+ {
+ _body = body;
+ }
+
+ @Override
+ public void setFooter(Footer footer)
+ {
+ _footer = footer;
+ }
+
+ @Override
+ public int decode(byte[] data, int offset, int length)
+ {
+ ByteArrayDecoder decoder = tlsCodec.get().decoder;
+ decoder.init(data, 0, data.length);
+
+ _header = null;
+ _deliveryAnnotations = null;
+ _messageAnnotations = null;
+ _properties = null;
+ _applicationProperties = null;
+ _body = null;
+ _footer = null;
+ Section section = null;
+
+ POJOBuilder pb = new POJOBuilder();
+ decoder.decode(pb);
+ System.out.println(pb.build());
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder
+ }
+ if(section instanceof Header)
+ {
+ _header = (Header) section;
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section instanceof DeliveryAnnotations)
+ {
+ _deliveryAnnotations = (DeliveryAnnotations) section;
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.readObject();
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section instanceof MessageAnnotations)
+ {
+ _messageAnnotations = (MessageAnnotations) section;
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.readObject();
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section instanceof Properties)
+ {
+ _properties = (Properties) section;
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.readObject();
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section instanceof ApplicationProperties)
+ {
+ _applicationProperties = (ApplicationProperties) section;
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.readObject();
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section != null && !(section instanceof Footer))
+ {
+ _body = section;
+
+ if(buffer.hasRemaining())
+ {
+ section = (Section) decoder.readObject();
+ }
+ else
+ {
+ section = null;
+ }
+
+ }
+ if(section instanceof Footer)
+ {
+ _footer = (Footer) section;
+
+ }
+
+ decoder.setByteBuffer(null);
+ }
+
+ @Override
+ public int encode(byte[] data, int offset, int length)
+ {
+ ByteBuffer buffer = ByteBuffer.wrap(data, offset, length);
+ return encode(new WritableBuffer.ByteBufferWrapper(buffer));
+ }
+
+ @Override
+ public int encode2(byte[] data, int offset, int length)
+ {
+ ByteBuffer buffer = ByteBuffer.wrap(data, offset, length);
+ WritableBuffer.ByteBufferWrapper first = new WritableBuffer.ByteBufferWrapper(buffer);
+ DroppingWritableBuffer second = new DroppingWritableBuffer();
+ CompositeWritableBuffer composite = new CompositeWritableBuffer(first, second);
+ int start = composite.position();
+ encode(composite);
+ return composite.position() - start;
+ }
+
+ @Override
+ public int encode(WritableBuffer buffer)
+ {
+ int length = buffer.remaining();
+ EncoderImpl encoder = tlsCodec.get().encoder;
+ encoder.setByteBuffer(buffer);
+
+ if(getHeader() != null)
+ {
+ encoder.writeObject(getHeader());
+ }
+ if(getDeliveryAnnotations() != null)
+ {
+ encoder.writeObject(getDeliveryAnnotations());
+ }
+ if(getMessageAnnotations() != null)
+ {
+ encoder.writeObject(getMessageAnnotations());
+ }
+ if(getProperties() != null)
+ {
+ encoder.writeObject(getProperties());
+ }
+ if(getApplicationProperties() != null)
+ {
+ encoder.writeObject(getApplicationProperties());
+ }
+ if(getBody() != null)
+ {
+ encoder.writeObject(getBody());
+ }
+ if(getFooter() != null)
+ {
+ encoder.writeObject(getFooter());
+ }
+ encoder.setByteBuffer((WritableBuffer)null);
+
+ return length - buffer.remaining();
+ }
+
+ @Override
+ public void load(Object data)
+ {
+ switch (_format)
+ {
+ case DATA:
+ Binary binData;
+ if(data instanceof byte[])
+ {
+ binData = new Binary((byte[])data);
+ }
+ else if(data instanceof Binary)
+ {
+ binData = (Binary) data;
+ }
+ else if(data instanceof String)
+ {
+ final String strData = (String) data;
+ byte[] bin = new byte[strData.length()];
+ for(int i = 0; i < bin.length; i++)
+ {
+ bin[i] = (byte) strData.charAt(i);
+ }
+ binData = new Binary(bin);
+ }
+ else
+ {
+ binData = null;
+ }
+ _body = new Data(binData);
+ break;
+ case TEXT:
+ _body = new AmqpValue(data == null ? "" : data.toString());
+ break;
+ default:
+ // AMQP
+ _body = new AmqpValue(parseAMQPFormat((String) data));
+ }
+
+ }
+
+ @Override
+ public Object save()
+ {
+ switch (_format)
+ {
+ case DATA:
+ if(_body instanceof Data)
+ {
+ return ((Data)_body).getValue().getArray();
+ }
+ else return null;
+ case AMQP:
+ if(_body instanceof AmqpValue)
+ {
+ return toAMQPFormat(((AmqpValue) _body).getValue());
+ }
+ else
+ {
+ return null;
+ }
+ case TEXT:
+ if(_body instanceof AmqpValue)
+ {
+ final Object value = ((AmqpValue) _body).getValue();
+ return value == null ? "" : value.toString();
+ }
+ return null;
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String toAMQPFormat(Object value)
+ {
+ return _parser.encode(value);
+ }
+
+ @Override
+ public Object parseAMQPFormat(String value)
+ {
+
+ Object obj = _parser.format(value);
+ return obj;
+ }
+
+ @Override
+ public void setMessageFormat(MessageFormat format)
+ {
+ _format = format;
+ }
+
+ @Override
+ public MessageFormat getMessageFormat()
+ {
+ return _format;
+ }
+
+ @Override
+ public void clear()
+ {
+ _body = null;
+ }
+
+ @Override
+ public MessageError getError()
+ {
+ return MessageError.OK;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org