summaryrefslogtreecommitdiff
path: root/qpid/java/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/common/src')
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/AMQChannelException.java13
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java84
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java3
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java2
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQFrame.java2
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java18
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java7
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java662
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java (renamed from qpid/java/common/src/main/versions/ProtocolVersionList.java.tmpl)88
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java54
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java2
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java6
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java2
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java17
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java7
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java684
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java9
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java18
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java1281
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java12
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/pool/Event.java98
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java120
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/pool/ReadWriteThreadModel.java7
-rw-r--r--qpid/java/common/src/main/xsl/cluster.asl59
-rw-r--r--qpid/java/common/src/main/xsl/framing.xsl64
-rw-r--r--qpid/java/common/src/main/xsl/java.xsl248
-rw-r--r--qpid/java/common/src/main/xsl/prepare1.xsl114
-rw-r--r--qpid/java/common/src/main/xsl/prepare2.xsl69
-rw-r--r--qpid/java/common/src/main/xsl/prepare3.xsl65
-rw-r--r--qpid/java/common/src/main/xsl/readme.txt52
-rw-r--r--qpid/java/common/src/main/xsl/registry.template25
-rw-r--r--qpid/java/common/src/main/xsl/registry.xsl32
-rw-r--r--qpid/java/common/src/main/xsl/utils.xsl207
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java12
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java52
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java349
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/pool/PoolingFilterTest.java2
37 files changed, 1707 insertions, 2839 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/AMQChannelException.java b/qpid/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
index 4d604f8c0b..2ead0a03e6 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/AMQChannelException.java
@@ -27,23 +27,30 @@ public class AMQChannelException extends AMQException
{
private final int _classId;
private final int _methodId;
+ /* AMQP version for which exception ocurred */
+ private final byte major;
+ private final byte minor;
- public AMQChannelException(int errorCode, String msg, int classId, int methodId, Throwable t)
+ public AMQChannelException(int errorCode, String msg, int classId, int methodId, byte major, byte minor, Throwable t)
{
super(errorCode, msg, t);
_classId = classId;
_methodId = methodId;
+ this.major = major;
+ this.minor = minor;
}
- public AMQChannelException(int errorCode, String msg, int classId, int methodId)
+ public AMQChannelException(int errorCode, String msg, int classId, int methodId, byte major, byte minor)
{
super(errorCode, msg);
_classId = classId;
_methodId = methodId;
+ this.major = major;
+ this.minor = minor;
}
public AMQFrame getCloseFrame(int channel)
{
- return ChannelCloseBody.createAMQFrame(channel, getErrorCode(), getMessage(), _classId, _methodId);
+ return ChannelCloseBody.createAMQFrame(channel, major, minor, _classId, _methodId, getErrorCode(), getMessage());
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java b/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
index 3a96821e93..f4f764db1b 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/common/QpidProperties.java
@@ -20,27 +20,99 @@
*/
package org.apache.qpid.common;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+import java.util.Map;
+import java.io.IOException;
+import java.io.InputStream;
+
public class QpidProperties
{
+ private static final Logger _logger = Logger.getLogger(QpidProperties.class);
+
+ public static final String VERSION_RESOURCE = "qpidversion.properties";
+
+ public static final String PRODUCT_NAME_PROPERTY = "qpid.name";
+ public static final String RELEASE_VERSION_PROPERTY = "qpid.version";
+ public static final String BUILD_VERSION_PROPERTY = "qpid.svnversion";
+
+ private static final String DEFAULT = "unknown";
+ private static String productName = DEFAULT;
+ private static String releaseVersion = DEFAULT;
+ private static String buildVersion = DEFAULT;
+
+ /** Loads the values from the version properties file. */
static
{
- //load values from property file.
+ Properties props = new Properties();
+
+ try
+ {
+ InputStream propertyStream = QpidProperties.class.getClassLoader().getResourceAsStream(VERSION_RESOURCE);
+ if (propertyStream == null)
+ {
+ _logger.warn("Unable to find resource " + VERSION_RESOURCE + " from classloader");
+ }
+ else
+ {
+ props.load(propertyStream);
+
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Dumping QpidProperties");
+ for (Map.Entry<Object,Object> entry : props.entrySet())
+ {
+ _logger.debug("Property: " + entry.getKey() + " Value: "+ entry.getValue());
+ }
+ _logger.debug("End of property dump");
+ }
+
+ productName = readPropertyValue(props, PRODUCT_NAME_PROPERTY);
+ releaseVersion = readPropertyValue(props, RELEASE_VERSION_PROPERTY);
+ buildVersion = readPropertyValue(props, BUILD_VERSION_PROPERTY);
+ }
+ }
+ catch (IOException e)
+ {
+ // Log a warning about this and leave the values initialized to unknown.
+ _logger.error("Could not load version.properties resource: " + e, e);
+ }
}
public static String getProductName()
{
- return "Qpid";
+ return productName;
}
- public static String getReleaseVerision()
+ public static String getReleaseVersion()
{
- return "1.0";
+ return releaseVersion;
}
+ public static String getBuildVersion()
+ {
+ return buildVersion;
+ }
+
+ public static String getVersionString()
+ {
+ return getProductName() + " - " + getReleaseVersion() + " build: " + getBuildVersion();
+ }
+
+ private static String readPropertyValue(Properties props, String propertyName)
+ {
+ String retVal = (String) props.get(propertyName);
+ if (retVal == null)
+ {
+ retVal = DEFAULT;
+ }
+ return retVal;
+ }
- public static String getBuildVerision()
+ public static void main(String[] args)
{
- return "1";
+ System.out.println(getVersionString());
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
index d829144b11..36287d2923 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQBody.java
@@ -34,5 +34,6 @@ public abstract class AMQBody
protected abstract void writePayload(ByteBuffer buffer);
- protected abstract void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException;
+ protected abstract void populateFromBuffer(ByteBuffer buffer, long size)
+ throws AMQFrameDecodingException, AMQProtocolVersionException;
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
index 438bfa8d82..2a999fe130 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQDataBlockDecoder.java
@@ -81,7 +81,7 @@ public class AMQDataBlockDecoder
}
protected Object createAndPopulateFrame(ByteBuffer in)
- throws AMQFrameDecodingException
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
final byte type = in.get();
if (!isSupportedFrameType(type))
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQFrame.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQFrame.java
index e75f37d623..6af691fbe8 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQFrame.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQFrame.java
@@ -62,7 +62,7 @@ public class AMQFrame extends AMQDataBlock implements EncodableAMQDataBlock
* @throws AMQFrameDecodingException
*/
public void populateFromBuffer(ByteBuffer buffer, int channel, long bodySize, BodyFactory bodyFactory)
- throws AMQFrameDecodingException
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
this.channel = channel;
bodyFrame = bodyFactory.createBody(buffer);
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
index 6659b4ff8f..5ccc900b2c 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBody.java
@@ -26,6 +26,20 @@ import org.apache.qpid.AMQChannelException;
public abstract class AMQMethodBody extends AMQBody
{
public static final byte TYPE = 1;
+
+ /**
+ * AMQP version
+ */
+ protected byte major;
+ protected byte minor;
+ public byte getMajor() { return major; }
+ public byte getMinor() { return minor; }
+
+ public AMQMethodBody(byte major, byte minor)
+ {
+ this.major = major;
+ this.minor = minor;
+ }
/** unsigned short */
protected abstract int getBodySize();
@@ -80,11 +94,11 @@ public abstract class AMQMethodBody extends AMQBody
*/
public AMQChannelException getChannelException(int code, String message)
{
- return new AMQChannelException(code, message, getClazz(), getMethod());
+ return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor);
}
public AMQChannelException getChannelException(int code, String message, Throwable cause)
{
- return new AMQChannelException(code, message, getClazz(), getMethod(), cause);
+ return new AMQChannelException(code, message, getClazz(), getMethod(), major, minor, cause);
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
index 107af67dc7..da0909d32f 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQMethodBodyFactory.java
@@ -41,6 +41,11 @@ public class AMQMethodBodyFactory implements BodyFactory
public AMQBody createBody(ByteBuffer in) throws AMQFrameDecodingException
{
- return MethodBodyDecoderRegistry.get(in.getUnsignedShort(), in.getUnsignedShort());
+ // AMQP version change: MethodBodyDecoderRegistry is obsolete, since all the XML
+ // segments generated together are now handled by MainRegistry. The Cluster class,
+ // if generated together with amqp.xml is a part of MainRegistry.
+ // TODO: Connect with version acquired from ProtocolInitiation class.
+ return MainRegistry.get((short)in.getUnsignedShort(), (short)in.getUnsignedShort(),
+ (byte)8, (byte)0);
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
new file mode 100644
index 0000000000..ad07634554
--- /dev/null
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
@@ -0,0 +1,662 @@
+/*
+ *
+ * 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.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+public enum AMQType
+{
+
+
+ //AMQP FieldTable Wire Types
+
+ LONG_STRING('S')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedLongStringLength((String) value);
+ }
+
+
+ public String toNativeValue(Object value)
+ {
+ if (value != null)
+ {
+ return value.toString();
+ }
+ else
+ {
+ throw new NullPointerException("Cannot convert: null to String.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeLongStringBytes(buffer, (String) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readLongString(buffer);
+ }
+
+ },
+
+ INTEGER('I')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+ },
+
+ DECIMAL('D')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public Object toNativeValue(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+ },
+
+ TIMESTAMP('T')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+ },
+
+ FIELD_TABLE('F')
+ {
+ public int getEncodingSize(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ // TODO : fixme
+ throw new UnsupportedOperationException();
+ }
+ },
+
+ VOID('V')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return 0;
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to null String.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return null;
+ }
+ },
+
+ // Extended types
+
+ BINARY('x')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return 1 + (value == null ? 0 : ((byte[]) value).length);
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ if((value instanceof byte[]) || (value == null))
+ {
+ return value;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value: " + value + " (" + value.getClass().getName() +
+ ") cannot be converted to byte[]");
+ }
+ }
+
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeBytes(buffer, (byte[]) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readBytes(buffer);
+ }
+
+ },
+
+ ASCII_STRING('c')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedLongStringLength((String) value);
+ }
+
+
+ public String toNativeValue(Object value)
+ {
+ if (value != null)
+ {
+ return value.toString();
+ }
+ else
+ {
+ throw new NullPointerException("Cannot convert: null to String.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeLongStringBytes(buffer, (String) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readLongString(buffer);
+ }
+
+ },
+
+ WIDE_STRING('C')
+ {
+ public int getEncodingSize(Object value)
+ {
+ // FIXME: use proper charset encoder
+ return EncodingUtils.encodedLongStringLength((String) value);
+ }
+
+
+ public String toNativeValue(Object value)
+ {
+ if (value != null)
+ {
+ return value.toString();
+ }
+ else
+ {
+ throw new NullPointerException("Cannot convert: null to String.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeLongStringBytes(buffer, (String) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readLongString(buffer);
+ }
+ },
+
+ BOOLEAN('t')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedBooleanLength();
+ }
+
+
+ public Object toNativeValue(Object value)
+ {
+ if (value instanceof Boolean)
+ {
+ return (Boolean) value;
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Boolean.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to boolean.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeBoolean(buffer, (Boolean) value);
+ }
+
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readBoolean(buffer);
+ }
+ },
+
+ ASCII_CHARACTER('k')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedCharLength();
+ }
+
+
+ public Character toNativeValue(Object value)
+ {
+ if (value instanceof Character)
+ {
+ return (Character) value;
+ }
+ else if (value == null)
+ {
+ throw new NullPointerException("Cannot convert null into char");
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to char.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeChar(buffer, (Character) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readChar(buffer);
+ }
+
+ },
+
+ BYTE('b')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedByteLength();
+ }
+
+
+ public Byte toNativeValue(Object value)
+ {
+ if (value instanceof Byte)
+ {
+ return (Byte) value;
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Byte.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to byte.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeByte(buffer, (Byte) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readByte(buffer);
+ }
+ },
+
+ SHORT('s')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedShortLength();
+ }
+
+
+ public Short toNativeValue(Object value)
+ {
+ if (value instanceof Short)
+ {
+ return (Short) value;
+ }
+ else if (value instanceof Byte)
+ {
+ return ((Byte) value).shortValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Short.valueOf((String)value);
+ }
+
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to short.");
+ }
+
+
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeShort(buffer, (Short) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readShort(buffer);
+ }
+ },
+
+ INT('i')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedIntegerLength();
+ }
+
+ public Integer toNativeValue(Object value)
+ {
+ if (value instanceof Integer)
+ {
+ return (Integer) value;
+ }
+ else if (value instanceof Short)
+ {
+ return ((Short) value).intValue();
+ }
+ else if (value instanceof Byte)
+ {
+ return ((Byte) value).intValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Integer.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to int.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeInteger(buffer, (Integer) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readInteger(buffer);
+ }
+ },
+
+ LONG('l')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedLongLength();
+ }
+
+ public Object toNativeValue(Object value)
+ {
+ if(value instanceof Long)
+ {
+ return (Long) value;
+ }
+ else if (value instanceof Integer)
+ {
+ return ((Integer) value).longValue();
+ }
+ else if (value instanceof Short)
+ {
+ return ((Short) value).longValue();
+ }
+ else if (value instanceof Byte)
+ {
+ return ((Byte) value).longValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Long.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to long.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeLong(buffer, (Long) value);
+ }
+
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readLong(buffer);
+ }
+ },
+
+ FLOAT('f')
+ {
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedFloatLength();
+ }
+
+
+ public Float toNativeValue(Object value)
+ {
+ if (value instanceof Float)
+ {
+ return (Float) value;
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Float.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to float.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeFloat(buffer, (Float) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readFloat(buffer);
+ }
+ },
+
+ DOUBLE('d')
+ {
+
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedDoubleLength();
+ }
+
+
+ public Double toNativeValue(Object value)
+ {
+ if (value instanceof Double)
+ {
+ return (Double) value;
+ }
+ else if (value instanceof Float)
+ {
+ return ((Float) value).doubleValue();
+ }
+ else if ((value instanceof String) || (value == null))
+ {
+ return Double.valueOf((String)value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to double.");
+ }
+ }
+
+ public void writeValueImpl(Object value, ByteBuffer buffer)
+ {
+ EncodingUtils.writeDouble(buffer, (Double) value);
+ }
+
+ public Object readValueFromBuffer(ByteBuffer buffer)
+ {
+ return EncodingUtils.readDouble(buffer);
+ }
+ };
+
+ private final byte _identifier;
+
+ AMQType(char identifier)
+ {
+ _identifier = (byte) identifier;
+ }
+
+ public final byte identifier()
+ {
+ return _identifier;
+ }
+
+
+ public abstract int getEncodingSize(Object value);
+
+ public abstract Object toNativeValue(Object value);
+
+ public AMQTypedValue asTypedValue(Object value)
+ {
+ return new AMQTypedValue(this, toNativeValue(value));
+ }
+
+ public void writeToBuffer(Object value, ByteBuffer buffer)
+ {
+ buffer.put((byte)identifier());
+ writeValueImpl(value, buffer);
+ }
+
+ abstract void writeValueImpl(Object value, ByteBuffer buffer);
+
+ abstract Object readValueFromBuffer(ByteBuffer buffer);
+}
diff --git a/qpid/java/common/src/main/versions/ProtocolVersionList.java.tmpl b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java
index f0e202dac9..5ac7f8827b 100644
--- a/qpid/java/common/src/main/versions/ProtocolVersionList.java.tmpl
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java
@@ -1,40 +1,48 @@
-/**
- *
- * 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 class is autogenerated, do not modify.
- */
-
-package org.apache.qpid.framing;
-
-/**
- * NOTE: Don't remove the line containing the token VER or VER1 - these are
- * markers for code generation.
- */
-
-public interface ProtocolVersionList
-{
- public final int PROTOCOL_MAJOR = 0;
- public final int PROTOCOL_MINOR = 1;
- public final byte pv[][] = {
- // !VER1!
- };
-}
+/*
+ *
+ * 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.framing;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class AMQTypeMap
+{
+ public static Map<Byte, AMQType> _reverseTypeMap = new HashMap<Byte, AMQType>();
+
+ static
+ {
+ for(AMQType type : AMQType.values())
+ {
+ _reverseTypeMap.put(type.identifier(), type);
+ }
+ }
+
+ public static AMQType getType(Byte identifier)
+ {
+ AMQType result = _reverseTypeMap.get(identifier);
+ if (result == null) {
+ throw new IllegalArgumentException
+ ("no such type code: " + Integer.toHexString(identifier.intValue()));
+ }
+ return result;
+ }
+
+}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java
new file mode 100644
index 0000000000..b29c23c2a2
--- /dev/null
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java
@@ -0,0 +1,54 @@
+package org.apache.qpid.framing;
+
+import org.apache.mina.common.ByteBuffer;
+
+public class AMQTypedValue
+{
+ private final AMQType _type;
+ private final Object _value;
+
+
+ public AMQTypedValue(AMQType type, Object value)
+ {
+ if(type == null)
+ {
+ throw new NullPointerException("Cannot create a typed value with null type");
+ }
+ _type = type;
+ _value = type.toNativeValue(value);
+ }
+
+ private AMQTypedValue(AMQType type, ByteBuffer buffer)
+ {
+ _type = type;
+ _value = type.readValueFromBuffer( buffer );
+ }
+
+
+ public AMQType getType()
+ {
+ return _type;
+ }
+
+ public Object getValue()
+ {
+ return _value;
+ }
+
+
+ public void writeToBuffer(ByteBuffer buffer)
+ {
+ _type.writeToBuffer(_value,buffer);
+ }
+
+ public int getEncodingSize()
+ {
+ return _type.getEncodingSize(_value);
+ }
+
+ public static AMQTypedValue readFromBuffer(ByteBuffer buffer)
+ {
+ AMQType type = AMQTypeMap.getType(buffer.get());
+ return new AMQTypedValue(type, buffer);
+ }
+}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
index 61837f65cc..fc80d93f82 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
@@ -245,7 +245,7 @@ public class BasicContentHeaderProperties implements ContentHeaderProperties
}
public void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size)
- throws AMQFrameDecodingException
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
_propertyFlags = propertyFlags;
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
index a59869b1d8..4ee36ee831 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
@@ -58,7 +58,8 @@ public class ContentHeaderBody extends AMQBody
return TYPE;
}
- protected void populateFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException
+ protected void populateFromBuffer(ByteBuffer buffer, long size)
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
classId = buffer.getUnsignedShort();
weight = buffer.getUnsignedShort();
@@ -75,7 +76,8 @@ public class ContentHeaderBody extends AMQBody
* @return
* @throws AMQFrameDecodingException
*/
- public static ContentHeaderBody createFromBuffer(ByteBuffer buffer, long size) throws AMQFrameDecodingException
+ public static ContentHeaderBody createFromBuffer(ByteBuffer buffer, long size)
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
ContentHeaderBody body = new ContentHeaderBody();
body.populateFromBuffer(buffer, size);
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java
index 561d7852fd..88bdefca88 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java
@@ -41,7 +41,7 @@ public interface ContentHeaderProperties
* @throws AMQFrameDecodingException when the buffer does not contain valid data
*/
void populatePropertiesFromBuffer(ByteBuffer buffer, int propertyFlags, int size)
- throws AMQFrameDecodingException;
+ throws AMQFrameDecodingException, AMQProtocolVersionException;
/**
* @return the size of the encoded property list in bytes.
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
index cec413cb9d..cfcc5db857 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
@@ -37,16 +37,19 @@ public class ContentHeaderPropertiesFactory
public ContentHeaderProperties createContentHeaderProperties(int classId, int propertyFlags,
ByteBuffer buffer, int size)
- throws AMQFrameDecodingException
+ throws AMQFrameDecodingException, AMQProtocolVersionException
{
ContentHeaderProperties properties;
- switch (classId)
+ // AMQP version change: "Hardwired" version to major=8, minor=0
+ // TODO: Change so that the actual version is obtained from
+ // the ProtocolInitiation object for this session.
+ if (classId == BasicConsumeBody.getClazz((byte)8, (byte)0))
{
- case BasicConsumeBody.CLASS_ID:
- properties = new BasicContentHeaderProperties();
- break;
- default:
- throw new AMQFrameDecodingException("Unsupport content header class id: " + classId);
+ properties = new BasicContentHeaderProperties();
+ }
+ else
+ {
+ throw new AMQFrameDecodingException("Unsupport content header class id: " + classId);
}
properties.populatePropertiesFromBuffer(buffer, propertyFlags, size);
return properties;
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
index 46dff9ffa8..ebda2c5d2b 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
@@ -88,12 +88,12 @@ public class EncodingUtils
{
if (table == null)
{
- // size is encoded as 4 octets
+ // length is encoded as 4 octets
return 4;
}
else
{
- // size of the table plus 4 octets for the size
+ // length of the table plus 4 octets for the length
return (int) table.getEncodedSize() + 4;
}
}
@@ -104,6 +104,7 @@ public class EncodingUtils
return 0;
}
+
public static void writeShortStringBytes(ByteBuffer buffer, String s)
{
if (s != null)
@@ -448,7 +449,7 @@ public class EncodingUtils
byte[] from = new byte[size];
// Is this not the same.
- //bb.get(from, 0, size);
+ //bb.get(from, 0, length);
for (int i = 0; i < size; i++)
{
from[i] = bb.get(i);
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
index 193c7adf1c..3c18683609 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
@@ -1,98 +1,612 @@
/*
- * 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
+ * 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
*
- * 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.
+ * 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.framing;
+import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.AMQPInvalidClassException;
-import java.util.Map;
-import java.util.Enumeration;
+import java.util.*;
-public interface FieldTable extends Map
+//extends FieldTable
+public class FieldTable
{
- void writeToBuffer(ByteBuffer buffer);
-
- void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException;
-
- byte[] getDataAsBytes();
-
- public long getEncodedSize();
-
- Object put(Object key, Object value);
-
- Object remove(Object key);
-
-
- public Enumeration getPropertyNames();
-
- public boolean propertyExists(String propertyName);
-
- //Getters
-
- public Boolean getBoolean(String string);
-
- public Byte getByte(String string);
-
- public Short getShort(String string);
-
- public Integer getInteger(String string);
-
- public Long getLong(String string);
-
- public Float getFloat(String string);
-
- public Double getDouble(String string);
-
- public String getString(String string);
-
- public Character getCharacter(String string);
-
- public byte[] getBytes(String string);
-
- public Object getObject(String string);
-
- // Setters
- public Object setBoolean(String string, boolean b);
-
- public Object setByte(String string, byte b);
-
- public Object setShort(String string, short i);
-
- public Object setInteger(String string, int i);
-
- public Object setLong(String string, long l);
-
- public Object setFloat(String string, float v);
-
- public Object setDouble(String string, double v);
-
- public Object setString(String string, String string1);
-
- public Object setChar(String string, char c);
-
- public Object setBytes(String string, byte[] bytes);
-
- public Object setBytes(String string, byte[] bytes, int start, int length);
-
- public Object setObject(String string, Object object);
-
- public boolean isNullStringValue(String name);
+ private static final Logger _logger = Logger.getLogger(FieldTable.class);
+
+ private LinkedHashMap<String, AMQTypedValue> _properties;
+
+ public FieldTable()
+ {
+ super();
+ _properties = new LinkedHashMap<String, AMQTypedValue>();
+
+ }
+
+
+
+ /**
+ * Construct a new field table.
+ *
+ * @param buffer the buffer from which to read data. The length byte must be read already
+ * @param length the length of the field table. Must be > 0.
+ * @throws AMQFrameDecodingException if there is an error decoding the table
+ */
+ public FieldTable(ByteBuffer buffer, long length) throws AMQFrameDecodingException
+ {
+ this();
+ setFromBuffer(buffer, length);
+ }
+
+
+
+ public Boolean getBoolean(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.BOOLEAN))
+ {
+ return (Boolean) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Byte getByte(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.BYTE))
+ {
+ return (Byte) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Short getShort(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.SHORT))
+ {
+ return (Short) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Integer getInteger(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.INT))
+ {
+ return (Integer) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Long getLong(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.LONG))
+ {
+ return (Long) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Float getFloat(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.FLOAT))
+ {
+ return (Float) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Double getDouble(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.DOUBLE))
+ {
+ return (Double) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public String getString(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if ((value != null) && ((value.getType() == AMQType.WIDE_STRING) ||
+ (value.getType() == AMQType.ASCII_STRING)))
+ {
+ return (String) value.getValue();
+ }
+
+ else if ((value != null) && (value.getValue() != null) && !(value.getValue() instanceof byte[]))
+ {
+ return String.valueOf(value.getValue());
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ public Character getCharacter(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.ASCII_CHARACTER))
+ {
+ return (Character) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public byte[] getBytes(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if (value != null && (value.getType() == AMQType.BINARY))
+ {
+ return (byte[]) value.getValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Object getObject(String string)
+ {
+ AMQTypedValue value = _properties.get(string);
+ if(value != null)
+ {
+ return value.getValue();
+ }
+ else
+ {
+ return value;
+ }
+
+ }
+
+ // ************ Setters
+
+ public Object setBoolean(String string, boolean b)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.BOOLEAN.asTypedValue(b));
+ }
+
+ public Object setByte(String string, byte b)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.BYTE.asTypedValue(b));
+ }
+
+ public Object setShort(String string, short i)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.SHORT.asTypedValue(i));
+ }
+
+ public Object setInteger(String string, int i)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.INT.asTypedValue(i));
+ }
+
+ public Object setLong(String string, long l)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.LONG.asTypedValue(l));
+ }
+
+ public Object setFloat(String string, float v)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.FLOAT.asTypedValue(v));
+ }
+
+ public Object setDouble(String string, double v)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.DOUBLE.asTypedValue(v));
+ }
+
+ public Object setString(String string, String value)
+ {
+ checkPropertyName(string);
+ if (value == null)
+ {
+ return _properties.put(string, AMQType.VOID.asTypedValue(null));
+ }
+ else
+ {
+ //FIXME: determine string encoding and set either WIDE or ASCII string
+// if ()
+ {
+ return _properties.put(string, AMQType.WIDE_STRING.asTypedValue(value));
+ }
+// else
+// {
+// return _properties.put(string, AMQType.ASCII_STRING.asTypedValue(value));
+// }
+ }
+ }
+
+ public Object setChar(String string, char c)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.ASCII_CHARACTER.asTypedValue(c));
+ }
+
+ public Object setBytes(String string, byte[] bytes)
+ {
+ checkPropertyName(string);
+ return _properties.put(string, AMQType.BINARY.asTypedValue(bytes));
+ }
+
+ public Object setBytes(String string, byte[] bytes, int start, int length)
+ {
+ checkPropertyName(string);
+ byte[] newBytes = new byte[length];
+ System.arraycopy(bytes,start,newBytes,0,length);
+ return setBytes(string, bytes);
+ }
+
+
+ public Object setObject(String string, Object object)
+ {
+ if (object instanceof Boolean)
+ {
+ return setBoolean(string, (Boolean) object);
+ }
+ else if (object instanceof Byte)
+ {
+ return setByte(string, (Byte) object);
+ }
+ else if (object instanceof Short)
+ {
+ return setShort(string, (Short) object);
+ }
+ else if (object instanceof Integer)
+ {
+ return setInteger(string, (Integer) object);
+ }
+ else if (object instanceof Long)
+ {
+ return setLong(string, (Long) object);
+ }
+ else if (object instanceof Float)
+ {
+ return setFloat(string, (Float) object);
+ }
+ else if (object instanceof Double)
+ {
+ return setDouble(string, (Double) object);
+ }
+ else if (object instanceof String)
+ {
+ return setString(string, (String) object);
+ }
+ else if (object instanceof Character)
+ {
+ return setChar(string, (Character) object);
+ }
+ else if (object instanceof byte[])
+ {
+ return setBytes(string, (byte[]) object);
+ }
+
+ throw new AMQPInvalidClassException("Only Primatives objects allowed Object is:" + object.getClass());
+ }
+
+
+ public boolean isNullStringValue(String name)
+ {
+ AMQTypedValue value = _properties.get(name);
+ return (value != null) && (value.getType() == AMQType.VOID);
+ }
+
+ // ***** Methods
+
+ public Enumeration getPropertyNames()
+ {
+ return Collections.enumeration(_properties.keySet());
+ }
+
+ public boolean propertyExists(String propertyName)
+ {
+ return itemExists(propertyName);
+ }
+
+ public boolean itemExists(String string)
+ {
+ return _properties.containsKey(string);
+ }
+
+ public String toString()
+ {
+ return _properties.toString();
+ }
+
+
+
+ private void checkPropertyName(String propertyName)
+ {
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name must not be null");
+ }
+ else if ("".equals(propertyName))
+ {
+ throw new IllegalArgumentException("Property name must not be the empty string");
+ }
+
+ checkIdentiferFormat(propertyName);
+ }
+
+
+ protected static void checkIdentiferFormat(String propertyName)
+ {
+// AMQP Spec: 4.2.5.5 Field Tables
+// Guidelines for implementers:
+// * Field names MUST start with a letter, '$' or '#' and may continue with
+// letters, '$' or '#', digits, or underlines, to a maximum length of 128
+// characters.
+// * The server SHOULD validate field names and upon receiving an invalid
+// field name, it SHOULD signal a connection exception with reply code
+// 503 (syntax error). Conformance test: amq_wlp_table_01.
+// * A peer MUST handle duplicate fields by using only the first instance.
+
+
+ // AMQP length limit
+ if (propertyName.length() > 128)
+ {
+ throw new IllegalArgumentException("AMQP limits property names to 128 characters");
+ }
+
+ // AMQ start character
+ if (!(Character.isLetter(propertyName.charAt(0))
+ || propertyName.charAt(0) == '$'
+ || propertyName.charAt(0) == '#'
+ || propertyName.charAt(0) == '_')) // Not official AMQP added for JMS.
+ {
+ throw new IllegalArgumentException("Identifier '" + propertyName + "' does not start with a valid AMQP start character");
+ }
+ }
+
+
+ // ************************* Byte Buffer Processing
+
+ public void writeToBuffer(ByteBuffer buffer)
+ {
+ final boolean trace = _logger.isTraceEnabled();
+
+ if (trace)
+ {
+ _logger.trace("FieldTable::writeToBuffer: Writing encoded length of " + getEncodedSize() + "...");
+ }
+
+ EncodingUtils.writeUnsignedInteger(buffer, getEncodedSize());
+
+ putDataInBuffer(buffer);
+ }
+
+ public byte[] getDataAsBytes()
+ {
+ final int encodedSize = (int) getEncodedSize();
+ final ByteBuffer buffer = ByteBuffer.allocate(encodedSize); // FIXME XXX: Is cast a problem?
+
+ putDataInBuffer(buffer);
+
+ final byte[] result = new byte[encodedSize];
+ buffer.flip();
+ buffer.get(result);
+ buffer.release();
+ return result;
+ }
+
+ public long getEncodedSize()
+ {
+ int encodedSize = 0;
+ for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+ {
+ encodedSize += EncodingUtils.encodedShortStringLength(e.getKey());
+ encodedSize++; // the byte for the encoding Type
+ encodedSize += e.getValue().getEncodingSize();
+
+ }
+ return encodedSize;
+ }
+
+ public void addAll(FieldTable fieldTable)
+ {
+ _properties.putAll(fieldTable._properties);
+ }
+
+
+ public static interface FieldTableElementProcessor
+ {
+ public boolean processElement(String propertyName, AMQTypedValue value);
+ public Object getResult();
+ }
+
+ public Object processOverElements(FieldTableElementProcessor processor)
+ {
+ for(Map.Entry<String,AMQTypedValue> e : _properties.entrySet())
+ {
+ boolean result = processor.processElement(e.getKey(), e.getValue());
+ if(!result)
+ {
+ break;
+ }
+ }
+ return processor.getResult();
+ }
+
+
+ public int size()
+ {
+ return _properties.size();
+ }
+
+ public boolean isEmpty()
+ {
+ return _properties.isEmpty();
+ }
+
+ public boolean containsKey(String key)
+ {
+ return _properties.containsKey(key);
+ }
+
+ public Set<String> keys()
+ {
+ return _properties.keySet();
+ }
+
+
+ public Object get(Object key)
+ {
+
+ return getObject((String)key);
+ }
+
+
+ public Object put(Object key, Object value)
+ {
+ return setObject(key.toString(), value);
+ }
+
+
+ public Object remove(String key)
+ {
+ AMQTypedValue value = _properties.remove(key);
+ return value == null ? null : value.getValue();
+ }
+
+
+
+ public void clear()
+ {
+ _properties.clear();
+ }
+
+ public Set keySet()
+ {
+ return _properties.keySet();
+ }
+
+ private void putDataInBuffer(ByteBuffer buffer)
+ {
+
+ final Iterator<Map.Entry<String,AMQTypedValue>> it = _properties.entrySet().iterator();
+
+ //If there are values then write out the encoded Size... could check _encodedSize != 0
+ // write out the total length, which we have kept up to date as data is added
+
+
+ while (it.hasNext())
+ {
+ final Map.Entry<String,AMQTypedValue> me = it.next();
+ try
+ {
+ if (_logger.isTraceEnabled())
+ {
+ _logger.trace("Writing Property:" + me.getKey() +
+ " Type:" + me.getValue().getType() +
+ " Value:" + me.getValue().getValue());
+ _logger.trace("Buffer Position:" + buffer.position() +
+ " Remaining:" + buffer.remaining());
+ }
+
+
+
+ //Write the actual parameter name
+ EncodingUtils.writeShortStringBytes(buffer, me.getKey());
+ me.getValue().writeToBuffer(buffer);
+ }
+ catch (Exception e)
+ {
+ if (_logger.isTraceEnabled())
+ {
+ _logger.trace("Exception thrown:" + e);
+ _logger.trace("Writing Property:" + me.getKey() +
+ " Type:" + me.getValue().getType() +
+ " Value:" + me.getValue().getValue());
+ _logger.trace("Buffer Position:" + buffer.position() +
+ " Remaining:" + buffer.remaining());
+ }
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+
+ public void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
+ {
+ final boolean trace = _logger.isTraceEnabled();
+
+ int sizeRead = 0;
+ while (sizeRead < length)
+ {
+ int sizeRemaining = buffer.remaining();
+ final String key = EncodingUtils.readShortString(buffer);
+ AMQTypedValue value = AMQTypedValue.readFromBuffer(buffer);
+ sizeRead += (sizeRemaining - buffer.remaining());
+
+ if (trace)
+ {
+ _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + value.getType() + "', key '" + key + "', value '" + value.getValue() + "' (now read " + sizeRead + " of " + length + " encoded bytes)...");
+ }
+
+ _properties.put(key,value);
+ }
+
+ if (trace)
+ {
+ _logger.trace("FieldTable::FieldTable(buffer," + length + "): Done.");
+ }
+ }
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java
index b1fcd8a20b..e9d75137ef 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java
@@ -26,16 +26,13 @@ public class FieldTableFactory
{
public static FieldTable newFieldTable()
{
- return new PropertyFieldTable();
+ return new FieldTable();
}
public static FieldTable newFieldTable(ByteBuffer byteBuffer, long length) throws AMQFrameDecodingException
{
- return new PropertyFieldTable(byteBuffer, length);
+ return new FieldTable(byteBuffer, length);
}
- public static FieldTable newFieldTable(String text)
- {
- return new PropertyFieldTable(text);
- }
+
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
index 142a689a01..d78034cf2f 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/JMSPropertyFieldTable.java
@@ -32,29 +32,11 @@ public class JMSPropertyFieldTable
{
private FieldTable _fieldtable;
- public JMSPropertyFieldTable()
- {
- _fieldtable = new PropertyFieldTable();
- }
-
public JMSPropertyFieldTable(FieldTable table)
{
_fieldtable = table;
}
- public JMSPropertyFieldTable(ByteBuffer buffer, long length) throws JMSException
- {
- try
- {
- _fieldtable = new PropertyFieldTable(buffer, length);
- }
- catch (AMQFrameDecodingException e)
- {
- JMSException error = new JMSException(e.getMessage());
- error.setLinkedException(e);
- throw error;
- }
- }
private void checkPropertyName(String propertyName)
{
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
deleted file mode 100644
index 4b8f56e4e8..0000000000
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/PropertyFieldTable.java
+++ /dev/null
@@ -1,1281 +0,0 @@
-/*
- *
- * 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.framing;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.AMQPInvalidClassException;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.HashMap;
-
-//extends FieldTable
-public class PropertyFieldTable implements FieldTable
-{
- private static final Logger _logger = Logger.getLogger(PropertyFieldTable.class);
-
- private static final String BOOLEAN = "boolean";
- private static final String BYTE = "byte";
- private static final String BYTES = "bytes";
- private static final String SHORT = "short";
- private static final String INT = "int";
- private static final String LONG = "long";
- private static final String FLOAT = "float";
- private static final String DOUBLE = "double";
- private static final String STRING = "string";
- private static final String NULL_STRING = "nullstring";
- private static final String CHAR = "char";
- private static final String UNKNOWN = "unknown type";
-
- private static final String PROPERTY_FIELD_TABLE_CLOSE_XML = "</PropertyFieldTable>";
- private static final String PROPERTY_FIELD_TABLE_OPEN_XML = "<PropertyFieldTable>";
- private static final String BYTES_CLOSE_XML = "</" + BYTES + ">";
- private static final String BYTES_OPEN_XML_START = "<" + BYTES;
-
- public static enum Prefix
- {
- //AMQP FieldTable Wire Types
- AMQP_DECIMAL_PROPERTY_PREFIX('D'),
- AMQP_UNSIGNED_SHORT_PROPERTY_PREFIX('S'),
- AMQP_UNSIGNED_INT_PROPERTY_PREFIX('I'),
- AMQP_UNSIGNED_LONG_PROPERTY_PREFIX('L'),
- AMQP_DOUBLE_EXTTENDED_PROPERTY_PREFIX('D'),
-
- AMQP_TIMESTAMP_PROPERTY_PREFIX('T'),
- AMQP_BINARY_PROPERTY_PREFIX('x'),
-
- //Strings
- AMQP_ASCII_STRING_PROPERTY_PREFIX('c'),
- AMQP_WIDE_STRING_PROPERTY_PREFIX('C'),
- AMQP_NULL_STRING_PROPERTY_PREFIX('n'),
-
- //Java Primative Types
- AMQP_BOOLEAN_PROPERTY_PREFIX('t'),
- AMQP_BYTE_PROPERTY_PREFIX('b'),
- AMQP_ASCII_CHARACTER_PROPERTY_PREFIX('k'),
- AMQP_SHORT_PROPERTY_PREFIX('s'),
- AMQP_INT_PROPERTY_PREFIX('i'),
- AMQP_LONG_PROPERTY_PREFIX('l'),
- AMQP_FLOAT_PROPERTY_PREFIX('f'),
- AMQP_DOUBLE_PROPERTY_PREFIX('d');
-
- private final char _identifier;
-
- Prefix(char identifier)
- {
- _identifier = identifier;
- //_reverseTypeMap.put(identifier, this);
- }
-
- public final char identifier()
- {
- return _identifier;
- }
-
- }
-
- public static Map<Character, Prefix> _reverseTypeMap = new HashMap<Character, Prefix>();
-
- static
- {
- for (Prefix p : Prefix.values())
- {
- _reverseTypeMap.put(p.identifier(), p);
- }
- }
-
- private LinkedHashMap<String, Object> _properties;
- private LinkedHashMap<String, Prefix> _propertyNamesTypeMap;
- private long _encodedSize = 0;
-
- public PropertyFieldTable()
- {
- super();
- _properties = new LinkedHashMap<String, Object>();
- _propertyNamesTypeMap = new LinkedHashMap<String, Prefix>();
- }
-
- public PropertyFieldTable(String textFormat)
- {
- this();
- try
- {
- parsePropertyFieldTable(textFormat);
- }
- catch (Exception e)
- {
- _logger.warn("Unable to decode PropertyFieldTable format:" + textFormat);
- throw new IllegalArgumentException("Unable to decode PropertyFieldTable format:" + textFormat);
- }
- }
-
- /**
- * Construct a new field table.
- *
- * @param buffer the buffer from which to read data. The length byte must be read already
- * @param length the length of the field table. Must be > 0.
- * @throws AMQFrameDecodingException if there is an error decoding the table
- */
- public PropertyFieldTable(ByteBuffer buffer, long length) throws AMQFrameDecodingException
- {
- this();
- setFromBuffer(buffer, length);
- }
-
- // ************ Getters
- private Object get(String propertyName, Prefix prefix)
- {
- //Retrieve the type associated with this name
- Prefix type = _propertyNamesTypeMap.get(propertyName);
-
- if (type == null)
- {
- return null;
- }
-
- if (type.equals(prefix))
- {
- return _properties.get(propertyName);
- }
- else
- {
- return null;
- }
- }
-
- public Boolean getBoolean(String string)
- {
- Object o = get(string, Prefix.AMQP_BOOLEAN_PROPERTY_PREFIX);
- if (o != null && o instanceof Boolean)
- {
- return (Boolean) o;
- }
- else
- {
- return null;
- }
- }
-
- public Byte getByte(String string)
- {
- Object o = get(string, Prefix.AMQP_BYTE_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Byte) o;
- }
- else
- {
- return null;
- }
- }
-
- public Short getShort(String string)
- {
- Object o = get(string, Prefix.AMQP_SHORT_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Short) o;
- }
- else
- {
- return null;
- }
- }
-
- public Integer getInteger(String string)
- {
- Object o = get(string, Prefix.AMQP_INT_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Integer) o;
- }
- else
- {
- return null;
- }
- }
-
- public Long getLong(String string)
- {
- Object o = get(string, Prefix.AMQP_LONG_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Long) o;
- }
- else
- {
- return null;
- }
- }
-
- public Float getFloat(String string)
- {
- Object o = get(string, Prefix.AMQP_FLOAT_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Float) o;
- }
- else
- {
- return null;
- }
- }
-
- public Double getDouble(String string)
- {
- Object o = get(string, Prefix.AMQP_DOUBLE_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Double) o;
- }
- else
- {
- return null;
- }
- }
-
- public String getString(String string)
- {
- Object o = get(string, Prefix.AMQP_ASCII_STRING_PROPERTY_PREFIX);
- if (o != null)
- {
- return (String) o;
- }
- else
- {
- o = get(string, Prefix.AMQP_WIDE_STRING_PROPERTY_PREFIX);
- if (o != null)
- {
- return (String) o;
- }
- else
- {
-
- Prefix type = _propertyNamesTypeMap.get(string);
-
- if (type == null || type.equals(Prefix.AMQP_NULL_STRING_PROPERTY_PREFIX))
- {
- return null;
- }
- else
- {
- switch (type)
- {
- case AMQP_ASCII_STRING_PROPERTY_PREFIX:
- case AMQP_WIDE_STRING_PROPERTY_PREFIX:
- case AMQP_BINARY_PROPERTY_PREFIX:
- return null;
- default:
- case AMQP_BYTE_PROPERTY_PREFIX:
- case AMQP_BOOLEAN_PROPERTY_PREFIX:
- case AMQP_SHORT_PROPERTY_PREFIX:
- case AMQP_INT_PROPERTY_PREFIX:
- case AMQP_LONG_PROPERTY_PREFIX:
- case AMQP_FLOAT_PROPERTY_PREFIX:
- case AMQP_DOUBLE_PROPERTY_PREFIX:
- return String.valueOf(_properties.get(string));
- case AMQP_ASCII_CHARACTER_PROPERTY_PREFIX:
- Object value = _properties.get(string);
- if (value == null)
- {
- throw new NullPointerException("null char cannot be converted to String");
- }
- else
- {
- return String.valueOf(value);
- }
- }
- }
- }
- }
- }
-
- public Character getCharacter(String string)
- {
- Object o = get(string, Prefix.AMQP_ASCII_CHARACTER_PROPERTY_PREFIX);
- if (o != null)
- {
- return (Character) o;
- }
- else
- {
- return null;
- }
- }
-
- public byte[] getBytes(String string)
- {
- Object o = get(string, Prefix.AMQP_BINARY_PROPERTY_PREFIX);
- if (o != null)
- {
- return (byte[]) o;
- }
- else
- {
- return null;
- }
- }
-
- public Object getObject(String string)
- {
- return _properties.get(string);
- }
-
- // ************ Setters
-
- public Object setBoolean(String string, boolean b)
- {
- return put(Prefix.AMQP_BOOLEAN_PROPERTY_PREFIX, string, b);
- }
-
- public Object setByte(String string, byte b)
- {
- return put(Prefix.AMQP_BYTE_PROPERTY_PREFIX, string, b);
- }
-
- public Object setShort(String string, short i)
- {
- return put(Prefix.AMQP_SHORT_PROPERTY_PREFIX, string, i);
- }
-
- public Object setInteger(String string, int i)
- {
- return put(Prefix.AMQP_INT_PROPERTY_PREFIX, string, i);
- }
-
- public Object setLong(String string, long l)
- {
- return put(Prefix.AMQP_LONG_PROPERTY_PREFIX, string, l);
- }
-
- public Object setFloat(String string, float v)
- {
- return put(Prefix.AMQP_FLOAT_PROPERTY_PREFIX, string, v);
- }
-
- public Object setDouble(String string, double v)
- {
- return put(Prefix.AMQP_DOUBLE_PROPERTY_PREFIX, string, v);
- }
-
- public Object setString(String string, String string1)
- {
- if (string1 == null)
- {
- return put(Prefix.AMQP_NULL_STRING_PROPERTY_PREFIX, string, null);
- }
- else
- {
- //FIXME: determine string encoding and set either WIDE or ASCII string
-// if ()
- {
- return put(Prefix.AMQP_WIDE_STRING_PROPERTY_PREFIX, string, string1);
- }
-// else
-// {
-// return put(Prefix.AMQP_ASCII_STRING_PROPERTY_PREFIX, string, string1);
-// }
- }
- }
-
- public Object setChar(String string, char c)
- {
- return put(Prefix.AMQP_ASCII_CHARACTER_PROPERTY_PREFIX, string, c);
- }
-
- public Object setBytes(String string, byte[] bytes)
- {
- return setBytes(string, bytes, 0, bytes.length);
- }
-
- public Object setBytes(String string, byte[] bytes, int start, int length)
- {
- return put(Prefix.AMQP_BINARY_PROPERTY_PREFIX, string, sizeByteArray(bytes, start, length));
- }
-
- private byte[] sizeByteArray(byte[] bytes, int start, int length)
- {
- byte[] resized = new byte[length];
- int newIndex = 0;
- for (int oldIndex = start; oldIndex < length; oldIndex++)
- {
- resized[newIndex] = bytes[oldIndex];
- newIndex++;
- }
-
- return resized;
- }
-
-
- public Object setObject(String string, Object object)
- {
- if (object instanceof Boolean)
- {
- return setBoolean(string, (Boolean) object);
- }
- else if (object instanceof Byte)
- {
- return setByte(string, (Byte) object);
- }
- else if (object instanceof Short)
- {
- return setShort(string, (Short) object);
- }
- else if (object instanceof Integer)
- {
- return setInteger(string, (Integer) object);
- }
- else if (object instanceof Long)
- {
- return setLong(string, (Long) object);
- }
- else if (object instanceof Float)
- {
- return setFloat(string, (Float) object);
- }
- else if (object instanceof Double)
- {
- return setDouble(string, (Double) object);
- }
- else if (object instanceof String)
- {
- return setString(string, (String) object);
- }
- else if (object instanceof Character)
- {
- return setChar(string, (Character) object);
- }
- else if (object instanceof byte[])
- {
- return setBytes(string, (byte[]) object);
- }
-
- throw new AMQPInvalidClassException("Only Primatives objects allowed Object is:" + object.getClass());
- }
-
-
- public boolean isNullStringValue(String name)
- {
- return _properties.containsKey(name) && (_properties.get(name) == null) &&
- _propertyNamesTypeMap.get(name).equals(Prefix.AMQP_NULL_STRING_PROPERTY_PREFIX);
-
-
- }
-
- // ***** Methods
-
- public Enumeration getPropertyNames()
- {
- Vector<String> names = new Vector<String>();
-
- Iterator keys = _properties.keySet().iterator();
-
- while (keys.hasNext())
- {
- String key = (String) keys.next();
-
- names.add(key);
- }
-
- return names.elements();
- }
-
- public boolean propertyExists(String propertyName)
- {
- return itemExists(propertyName);
- }
-
- public boolean itemExists(String string)
- {
- return _properties.containsKey(string);
- }
-
- public String toString()
- {
- return valueOf(this);
- }
-
- public static String valueOf(PropertyFieldTable table)
- {
- StringBuffer buf = new StringBuffer(PROPERTY_FIELD_TABLE_OPEN_XML);
-
- final Iterator it = table._properties.entrySet().iterator();
-
- while (it.hasNext())
- {
- final Map.Entry entry = (Map.Entry) it.next();
- final String propertyName = (String) entry.getKey();
-
- buf.append('\n');
- buf.append(valueAsXML(table._propertyNamesTypeMap.get(propertyName), propertyName, entry.getValue()));
- }
- buf.append("\n");
- buf.append(PROPERTY_FIELD_TABLE_CLOSE_XML);
-
- return buf.toString();
- }
-
- private static String valueAsXML(Prefix type, String propertyName, Object value)
- {
- StringBuffer buf = new StringBuffer();
- // Start Tag
- buf.append(propertyXML(type, propertyName, true));
-
- // Value
- if (type.equals(Prefix.AMQP_BINARY_PROPERTY_PREFIX))
- {
- //remove '>'
- buf.deleteCharAt(buf.length() - 1);
-
- byte[] bytes = (byte[]) value;
- buf.append(" length='").append(bytes.length).append("'>");
-
- buf.append(byteArrayToXML(propertyName, bytes));
- }
- else
- {
- if (!type.equals(Prefix.AMQP_NULL_STRING_PROPERTY_PREFIX))
- {
- buf.append(String.valueOf(value));
- }
- }
- //End Tag
- buf.append(propertyXML(type, propertyName, false));
-
- return buf.toString();
- }
-
- private void checkPropertyName(String propertyName)
- {
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name must not be null");
- }
- else if ("".equals(propertyName))
- {
- throw new IllegalArgumentException("Property name must not be the empty string");
- }
-
- checkIdentiferFormat(propertyName);
- }
-
-
- protected static void checkIdentiferFormat(String propertyName)
- {
-// AMQP Spec: 4.2.5.5 Field Tables
-// Guidelines for implementers:
-// * Field names MUST start with a letter, '$' or '#' and may continue with
-// letters, '$' or '#', digits, or underlines, to a maximum length of 128
-// characters.
-// * The server SHOULD validate field names and upon receiving an invalid
-// field name, it SHOULD signal a connection exception with reply code
-// 503 (syntax error). Conformance test: amq_wlp_table_01.
-// * A peer MUST handle duplicate fields by using only the first instance.
-
- // AMQP length limit
- if (propertyName.length() > 128)
- {
- throw new IllegalArgumentException("AMQP limits property names to 128 characters");
- }
-
- // AMQ start character
- if (!(Character.isLetter(propertyName.charAt(0))
- || propertyName.charAt(0) == '$'
- || propertyName.charAt(0) == '#'
- || propertyName.charAt(0) == '_')) // Not official AMQP added for JMS.
- {
- throw new IllegalArgumentException("Identifier '" + propertyName + "' does not start with a valid AMQP start character");
- }
- }
-
- private static String propertyXML(Prefix type, String propertyName, boolean start)
- {
- StringBuffer buf = new StringBuffer();
-
- if (start)
- {
- buf.append("<");
- }
- else
- {
- buf.append("</");
- }
-
- switch (type)
- {
- case AMQP_BOOLEAN_PROPERTY_PREFIX:
- buf.append(BOOLEAN);
- break;
- case AMQP_BYTE_PROPERTY_PREFIX:
- buf.append(BYTE);
- break;
- case AMQP_BINARY_PROPERTY_PREFIX:
- buf.append(BYTES);
- break;
- case AMQP_SHORT_PROPERTY_PREFIX:
- buf.append(SHORT);
- break;
- case AMQP_INT_PROPERTY_PREFIX:
- buf.append(INT);
- break;
- case AMQP_LONG_PROPERTY_PREFIX:
- buf.append(LONG);
- break;
- case AMQP_FLOAT_PROPERTY_PREFIX:
- buf.append(FLOAT);
- break;
- case AMQP_DOUBLE_PROPERTY_PREFIX:
- buf.append(DOUBLE);
- break;
- case AMQP_NULL_STRING_PROPERTY_PREFIX:
- buf.append(NULL_STRING);
- break;
- case AMQP_ASCII_STRING_PROPERTY_PREFIX:
- case AMQP_WIDE_STRING_PROPERTY_PREFIX:
- buf.append(STRING);
- break;
- case AMQP_ASCII_CHARACTER_PROPERTY_PREFIX:
- buf.append(CHAR);
- break;
- default:
- buf.append(UNKNOWN + " (identifier ").append(type.identifier()).append(")");
- break;
- }
-
- if (start)
- {
- buf.append(" name='").append(propertyName).append("'");
- }
-
- buf.append(">");
-
- return buf.toString();
- }
-
- private static String byteArrayToXML(String propertyName, byte[] bytes)
- {
- StringBuffer buf = new StringBuffer();
-
- for (int index = 0; index < bytes.length; index++)
- {
- buf.append("\n");
- buf.append(propertyXML(Prefix.AMQP_BYTE_PROPERTY_PREFIX, propertyName + "[" + index + "]", true));
- buf.append(bytes[index]);
- buf.append(propertyXML(Prefix.AMQP_BYTE_PROPERTY_PREFIX, propertyName + "[" + index + "]", false));
- }
- buf.append("\n");
- return buf.toString();
- }
-
- private void processBytesXMLLine(String xmlline)
- {
- String propertyName = xmlline.substring(xmlline.indexOf('\'') + 1,
- xmlline.indexOf('\'', xmlline.indexOf('\'') + 1));
- String value = xmlline.substring(xmlline.indexOf(">") + 1,
- xmlline.indexOf("</"));
-
- Integer index = Integer.parseInt(propertyName.substring(propertyName.lastIndexOf("[") + 1,
- propertyName.lastIndexOf("]")));
- propertyName = propertyName.substring(0, propertyName.lastIndexOf("["));
-
- getBytes(propertyName)[index] = Byte.parseByte(value);
- }
-
- private void parsePropertyFieldTable(String textFormat)
- {
- StringTokenizer tokenizer = new StringTokenizer(textFormat, "\n");
-
- boolean finished = false;
- boolean processing = false;
-
- boolean processing_bytes = false;
-
- if (!tokenizer.hasMoreTokens())
- {
- throw new IllegalArgumentException("XML has no tokens to parse.");
- }
-
- while (tokenizer.hasMoreTokens())
- {
- String token = tokenizer.nextToken();
-
- if (token.equals(PROPERTY_FIELD_TABLE_CLOSE_XML))
- {
- processing = false;
- finished = true;
- }
- if (token.equals(BYTES_CLOSE_XML))
- {
- processing = false;
- }
-
- if (token.equals(BYTES_CLOSE_XML))
- {
- processing_bytes = false;
- }
-
- if (processing)
- {
- processXMLLine(token);
- }
- else if (processing_bytes)
- {
- processBytesXMLLine(token);
- }
-
- if (token.startsWith(BYTES_OPEN_XML_START))
- {
- processing_bytes = true;
- processing = false;
- }
-
- if (token.equals(PROPERTY_FIELD_TABLE_OPEN_XML) ||
- token.equals(BYTES_CLOSE_XML))
- {
- processing = true;
- }
- }
-
- if (!finished)
- {
- throw new IllegalArgumentException("XML was not in a valid format.");
- }
-
- }
-
- private void processXMLLine(String xmlline)
- {
- // <<type> name='<property>'><value></<type>>
- // <string name='message' >Message 99</string >
-
- String type = xmlline.substring(1, xmlline.indexOf(" "));
-
- String propertyName = xmlline.substring(xmlline.indexOf('\'') + 1,
- xmlline.indexOf('\'', xmlline.indexOf('\'') + 1));
-
- String value = "";
-
- if (!type.equals(BYTES))
- {
- value = xmlline.substring(xmlline.indexOf(">") + 1,
- xmlline.indexOf("</"));
- }
-
- if (type.equals(BOOLEAN))
- {
- setBoolean(propertyName, Boolean.parseBoolean(value));
- }
- if (type.equals(BYTE))
- {
- setByte(propertyName, Byte.parseByte(value));
- }
- if (type.equals(BYTES))
- {
- int headerEnd = xmlline.indexOf('>');
- String bytesHeader = xmlline.substring(0, headerEnd);
-
- //Extract length value
- Integer length = Integer.parseInt(bytesHeader.substring(
- bytesHeader.lastIndexOf("=") + 2
- , bytesHeader.lastIndexOf("'")));
-
-
- byte[] bytes = new byte[length];
- setBytes(propertyName, bytes);
-
- //Check if the line contains all the byte values
- // This is needed as the XMLLine sent across the wire is the bytes value
-
- int byteStart = xmlline.indexOf('<', headerEnd);
-
- //Don't think this is required.
- if (byteStart > 0)
- {
- while (!xmlline.startsWith(BYTES_CLOSE_XML, byteStart))
- {
- //This should be the next byte line
- int bytePrefixEnd = xmlline.indexOf('>', byteStart) + 1;
- int byteEnd = xmlline.indexOf('>', bytePrefixEnd) + 1;
-
- String byteline = xmlline.substring(byteStart, byteEnd);
-
- processBytesXMLLine(byteline);
-
- byteStart = xmlline.indexOf('<', byteEnd);
- }
- }
-
- }
- if (type.equals(SHORT))
- {
- setShort(propertyName, Short.parseShort(value));
- }
- if (type.equals(INT))
- {
- setInteger(propertyName, Integer.parseInt(value));
- }
- if (type.equals(LONG))
- {
- setLong(propertyName, Long.parseLong(value));
- }
- if (type.equals(FLOAT))
- {
- setFloat(propertyName, Float.parseFloat(value));
- }
- if (type.equals(DOUBLE))
- {
- setDouble(propertyName, Double.parseDouble(value));
- }
- if (type.equals(STRING) || type.equals(NULL_STRING))
- {
- if (type.equals(NULL_STRING))
- {
- value = null;
- }
- setString(propertyName, value);
- }
- if (type.equals(CHAR))
- {
- setChar(propertyName, value.charAt(0));
- }
- if (type.equals(UNKNOWN))
- {
- _logger.warn("Ignoring unknown property value:" + xmlline);
- }
- }
-
- // ************************* Byte Buffer Processing
-
- public void writeToBuffer(ByteBuffer buffer)
- {
- final boolean trace = _logger.isTraceEnabled();
-
- if (trace)
- {
- _logger.trace("FieldTable::writeToBuffer: Writing encoded size of " + _encodedSize + "...");
- }
-
- EncodingUtils.writeUnsignedInteger(buffer, _encodedSize);
-
- putDataInBuffer(buffer);
- }
-
- public byte[] getDataAsBytes()
- {
- final ByteBuffer buffer = ByteBuffer.allocate((int) _encodedSize); // FIXME XXX: Is cast a problem?
-
- putDataInBuffer(buffer);
-
- final byte[] result = new byte[(int) _encodedSize];
- buffer.flip();
- buffer.get(result);
- buffer.release();
- return result;
- }
-
-
- public int size()
- {
- return _properties.size();
- }
-
- public boolean isEmpty()
- {
- return _properties.isEmpty();
- }
-
- public boolean containsKey(Object key)
- {
- return _properties.containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return _properties.containsValue(value);
- }
-
- public Object get(Object key)
- {
- return _properties.get(key);
- }
-
-
- public Object put(Object key, Object value)
- {
- return setObject(key.toString(), value);
- }
-
- protected Object put(Prefix type, String propertyName, Object value)
- {
- checkPropertyName(propertyName);
-
- //remove the previous value
- Object previous = remove(propertyName);
-
-
- if (_logger.isTraceEnabled())
- {
- int valueSize = 0;
- if (value != null)
- {
- valueSize = getEncodingSize(type, value);
- }
- _logger.trace("Put:" + propertyName +
- " encoding size Now:" + _encodedSize +
- " name size= " + EncodingUtils.encodedShortStringLength(propertyName) +
- " value size= " + valueSize);
- }
-
- //Add the size of the propertyName plus one for the type identifier
- _encodedSize += EncodingUtils.encodedShortStringLength(propertyName) + 1;
-
- if (value != null)
- {
- //Add the size of the content
- _encodedSize += getEncodingSize(type, value);
- }
-
- //Store new values
- _propertyNamesTypeMap.put(propertyName, type);
- _properties.put(propertyName, value);
-
- return previous;
- }
-
- public Object remove(Object key)
- {
- if (_properties.containsKey(key))
- {
- final Object value = _properties.remove(key);
- Prefix type = _propertyNamesTypeMap.remove(key);
- // plus one for the type
- _encodedSize -= EncodingUtils.encodedShortStringLength(((String) key)) + 1;
-
- // This check is, for now, unnecessary (we don't store null values).
- if (value != null)
- {
- _encodedSize -= getEncodingSize(type, value);
- }
- return value;
- }
- else
- {
- return null;
- }
- }
-
- public void putAll(Map t)
- {
- Iterator it = t.keySet().iterator();
-
- while (it.hasNext())
- {
- Object key = it.next();
- put(key, t.get(key));
- }
- }
-
- public void clear()
- {
- _encodedSize = 0;
- _properties.clear();
- _propertyNamesTypeMap.clear();
- }
-
- public Set keySet()
- {
- return _properties.keySet();
- }
-
- public Collection values()
- {
- return _properties.values();
- }
-
- public Set entrySet()
- {
- return _properties.entrySet();
- }
-
- public long getEncodedSize()
- {
- return _encodedSize;
- }
-
-
- private void putDataInBuffer(ByteBuffer buffer)
- {
-
- final Iterator it = _properties.entrySet().iterator();
-
- //If there are values then write out the encoded Size... could check _encodedSize != 0
- // write out the total length, which we have kept up to date as data is added
-
-
- while (it.hasNext())
- {
- Map.Entry me = (Map.Entry) it.next();
- String propertyName = (String) me.getKey();
-
- //The type value
- Prefix type = _propertyNamesTypeMap.get(propertyName);
-
- Object value = me.getValue();
- try
- {
- if (_logger.isTraceEnabled())
- {
- _logger.trace("Writing Property:" + propertyName +
- " Type:" + type +
- " Value:" + value);
- _logger.trace("Buffer Position:" + buffer.position() +
- " Remaining:" + buffer.remaining());
- }
-
- //Write the actual parameter name
- EncodingUtils.writeShortStringBytes(buffer, propertyName);
-
- switch (type)
- {
- case AMQP_BOOLEAN_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_BOOLEAN_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeBoolean(buffer, (Boolean) value);
- break;
- case AMQP_BYTE_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_BYTE_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeByte(buffer, (Byte) value);
- break;
- case AMQP_SHORT_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_SHORT_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeShort(buffer, (Short) value);
- break;
- case AMQP_INT_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_INT_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeInteger(buffer, (Integer) value);
- break;
- case AMQP_UNSIGNED_INT_PROPERTY_PREFIX: // Currently we don't create these
- buffer.put((byte) Prefix.AMQP_UNSIGNED_INT_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeUnsignedInteger(buffer, (Long) value);
- break;
- case AMQP_LONG_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_LONG_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeLong(buffer, (Long) value);
- break;
- case AMQP_FLOAT_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_FLOAT_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeFloat(buffer, (Float) value);
- break;
- case AMQP_DOUBLE_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_DOUBLE_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeDouble(buffer, (Double) value);
- break;
- case AMQP_NULL_STRING_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_NULL_STRING_PROPERTY_PREFIX.identifier());
- break;
- case AMQP_WIDE_STRING_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_WIDE_STRING_PROPERTY_PREFIX.identifier());
- // FIXME: use proper charset encoder
- EncodingUtils.writeLongStringBytes(buffer, (String) value);
- break;
- case AMQP_ASCII_STRING_PROPERTY_PREFIX:
- //This is a simple ASCII string
- buffer.put((byte) Prefix.AMQP_ASCII_STRING_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeLongStringBytes(buffer, (String) value);
- break;
- case AMQP_ASCII_CHARACTER_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_ASCII_CHARACTER_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeChar(buffer, (Character) value);
- break;
- case AMQP_BINARY_PROPERTY_PREFIX:
- buffer.put((byte) Prefix.AMQP_BINARY_PROPERTY_PREFIX.identifier());
- EncodingUtils.writeBytes(buffer, (byte[]) value);
- break;
- default:
- {
- // Should never get here
- throw new IllegalArgumentException("Key '" + propertyName + "': Unsupported type in field table, type: " + ((value == null) ? "null-object" : value.getClass()));
- }
- }
- }
- catch (Exception e)
- {
- if (_logger.isTraceEnabled())
- {
- _logger.trace("Exception thrown:" + e);
- _logger.trace("Writing Property:" + propertyName +
- " Type:" + type +
- " Value:" + value);
- _logger.trace("Buffer Position:" + buffer.position() +
- " Remaining:" + buffer.remaining());
- }
- throw new RuntimeException(e);
- }
- }
- }
-
-
- public void setFromBuffer(ByteBuffer buffer, long length) throws AMQFrameDecodingException
- {
- final boolean trace = _logger.isTraceEnabled();
-
- int sizeRead = 0;
- while (sizeRead < length)
- {
- int sizeRemaining = buffer.remaining();
- final String key = EncodingUtils.readShortString(buffer);
-
- byte iType = buffer.get();
-
- Character mapKey = new Character((char) iType);
- Prefix type = _reverseTypeMap.get(mapKey);
-
- if (type == null)
- {
- String msg = "Field '" + key + "' - unsupported field table type: " + type + ".";
- //some extra trace information...
- msg += " (" + iType + "), length=" + length + ", sizeRead=" + sizeRead + ", sizeRemaining=" + sizeRemaining;
- throw new AMQFrameDecodingException(msg);
- }
- Object value;
-
- switch (type)
- {
- case AMQP_BOOLEAN_PROPERTY_PREFIX:
- value = EncodingUtils.readBoolean(buffer);
- break;
- case AMQP_BYTE_PROPERTY_PREFIX:
- value = EncodingUtils.readByte(buffer);
- break;
- case AMQP_SHORT_PROPERTY_PREFIX:
- value = EncodingUtils.readShort(buffer);
- break;
- case AMQP_INT_PROPERTY_PREFIX:
- value = EncodingUtils.readInteger(buffer);
- break;
- case AMQP_UNSIGNED_INT_PROPERTY_PREFIX:// This will only fit in a long
- //Change this type for java lookups
- type = Prefix.AMQP_LONG_PROPERTY_PREFIX;
- case AMQP_LONG_PROPERTY_PREFIX:
- value = EncodingUtils.readLong(buffer);
- break;
- case AMQP_FLOAT_PROPERTY_PREFIX:
- value = EncodingUtils.readFloat(buffer);
- break;
- case AMQP_DOUBLE_PROPERTY_PREFIX:
- value = EncodingUtils.readDouble(buffer);
- break;
- case AMQP_WIDE_STRING_PROPERTY_PREFIX:
- // FIXME: use proper charset encoder
- case AMQP_ASCII_STRING_PROPERTY_PREFIX:
- value = EncodingUtils.readLongString(buffer);
- break;
- case AMQP_NULL_STRING_PROPERTY_PREFIX:
- value = null;
- break;
- case AMQP_ASCII_CHARACTER_PROPERTY_PREFIX:
- value = EncodingUtils.readChar((buffer));
- break;
- case AMQP_BINARY_PROPERTY_PREFIX:
- value = EncodingUtils.readBytes(buffer);
- break;
- default:
- String msg = "Internal error, the following type identifier is not handled: " + type;
- throw new AMQFrameDecodingException(msg);
- }
-
- sizeRead += (sizeRemaining - buffer.remaining());
-
- if (trace)
- {
- _logger.trace("FieldTable::PropFieldTable(buffer," + length + "): Read type '" + type + "', key '" + key + "', value '" + value + "' (now read " + sizeRead + " of " + length + " encoded bytes)...");
- }
-
- put(type, key, value);
- }
-
- if (trace)
- {
- _logger.trace("FieldTable::FieldTable(buffer," + length + "): Done.");
- }
- }
-
- /**
- * @param type the type to calucluate encoding for
- * @param value the property value
- * @return integer
- */
- private static int getEncodingSize(Prefix type, Object value)
- {
- int encodingSize = 0;
-
- switch (type)
- {
- case AMQP_BOOLEAN_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedBooleanLength();
- break;
- case AMQP_BYTE_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedByteLength();
- break;
- case AMQP_SHORT_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedShortLength();
- break;
- case AMQP_INT_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedIntegerLength();
- break;
- case AMQP_LONG_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedLongLength();
- break;
- case AMQP_FLOAT_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedFloatLength();
- break;
- case AMQP_DOUBLE_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedDoubleLength();
- break;
- case AMQP_WIDE_STRING_PROPERTY_PREFIX:
- // FIXME: use proper charset encoder
- case AMQP_ASCII_STRING_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedLongStringLength((String) value);
- break;
-// This is not required as this method is never called if the value is null
-// case AMQP_NULL_STRING_PROPERTY_PREFIX:
-// // There is no need for additional size beyond the prefix
-// break;
- case AMQP_ASCII_CHARACTER_PROPERTY_PREFIX:
- encodingSize = EncodingUtils.encodedCharLength();
- break;
- case AMQP_BINARY_PROPERTY_PREFIX:
- encodingSize = 1 + ((byte[]) value).length;
- break;
- default:
- throw new IllegalArgumentException("Unsupported type in field table: " + value.getClass());
- }
-
- // the extra byte for the type indicator is calculated in the name
- return encodingSize;
- }
-}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
index f0d5489527..f2d1a70cdc 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
@@ -146,18 +146,6 @@ public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQData
throw new AMQProtocolInstanceException("Protocol instance " + CURRENT_PROTOCOL_INSTANCE + " was expected; received " +
protocolInstance);
}
- /*
- if (protocolMajor != CURRENT_PROTOCOL_VERSION_MAJOR)
- {
- throw new AMQProtocolVersionException("Protocol major version " + CURRENT_PROTOCOL_VERSION_MAJOR +
- " was expected; received " + protocolMajor);
- }
- if (protocolMinor != CURRENT_PROTOCOL_VERSION_MINOR)
- {
- throw new AMQProtocolVersionException("Protocol minor version " + CURRENT_PROTOCOL_VERSION_MINOR +
- " was expected; received " + protocolMinor);
- }
- */
/* Look through list of available protocol versions */
boolean found = false;
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/pool/Event.java b/qpid/java/common/src/main/java/org/apache/qpid/pool/Event.java
index 7364b9293a..43ff8f6a19 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/pool/Event.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/pool/Event.java
@@ -25,90 +25,66 @@ import org.apache.mina.common.IoFilter;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IdleStatus;
-/**
- * Represents an operation on IoFilter.
- */
-enum EventType
-{
- OPENED, CLOSED, READ, WRITE, WRITTEN, RECEIVED, SENT, IDLE, EXCEPTION
-}
-class Event
+abstract public class Event
{
- private static final Logger _log = Logger.getLogger(Event.class);
-
- private final EventType type;
- private final IoFilter.NextFilter nextFilter;
- private final Object data;
-
- public Event(IoFilter.NextFilter nextFilter, EventType type, Object data)
- {
- this.type = type;
- this.nextFilter = nextFilter;
- this.data = data;
- if (type == EventType.EXCEPTION)
- {
- _log.error("Exception event constructed: " + data, (Throwable) data);
- }
- }
- public Object getData()
+ public Event()
{
- return data;
}
- public IoFilter.NextFilter getNextFilter()
- {
- return nextFilter;
- }
+ abstract public void process(IoSession session);
- public EventType getType()
+ public static final class ReceivedEvent extends Event
{
- return type;
- }
+ private final Object _data;
- void process(IoSession session)
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("Processing " + this);
- }
- if (type == EventType.RECEIVED)
- {
- nextFilter.messageReceived(session, data);
- //ByteBufferUtil.releaseIfPossible( data );
- }
- else if (type == EventType.SENT)
+ private final IoFilter.NextFilter _nextFilter;
+
+ public ReceivedEvent(final IoFilter.NextFilter nextFilter, final Object data)
{
- nextFilter.messageSent(session, data);
- //ByteBufferUtil.releaseIfPossible( data );
+ super();
+ _nextFilter = nextFilter;
+ _data = data;
}
- else if (type == EventType.EXCEPTION)
+
+ public void process(IoSession session)
{
- nextFilter.exceptionCaught(session, (Throwable) data);
+ _nextFilter.messageReceived(session, _data);
}
- else if (type == EventType.IDLE)
+
+ public IoFilter.NextFilter getNextFilter()
{
- nextFilter.sessionIdle(session, (IdleStatus) data);
+ return _nextFilter;
}
- else if (type == EventType.OPENED)
+ }
+
+
+ public static final class WriteEvent extends Event
+ {
+ private final IoFilter.WriteRequest _data;
+ private final IoFilter.NextFilter _nextFilter;
+
+ public WriteEvent(final IoFilter.NextFilter nextFilter, final IoFilter.WriteRequest data)
{
- nextFilter.sessionOpened(session);
+ super();
+ _nextFilter = nextFilter;
+ _data = data;
}
- else if (type == EventType.WRITE)
+
+
+ public void process(IoSession session)
{
- nextFilter.filterWrite(session, (IoFilter.WriteRequest) data);
+ _nextFilter.filterWrite(session, _data);
}
- else if (type == EventType.CLOSED)
+
+ public IoFilter.NextFilter getNextFilter()
{
- nextFilter.sessionClosed(session);
+ return _nextFilter;
}
}
- public String toString()
- {
- return "Event: type " + type + ", data: " + data;
- }
+
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java b/qpid/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
index 38cfa68c78..c0026c1f36 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/pool/PoolingFilter.java
@@ -25,51 +25,39 @@ import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoSession;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.EnumSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionHandler
{
private static final Logger _logger = Logger.getLogger(PoolingFilter.class);
- public static final Set<EventType> READ_EVENTS = new HashSet<EventType>(Arrays.asList(EventType.RECEIVED));
- public static final Set<EventType> WRITE_EVENTS = new HashSet<EventType>(Arrays.asList(EventType.WRITE));
private final ConcurrentMap<IoSession, Job> _jobs = new ConcurrentHashMap<IoSession, Job>();
private final ReferenceCountingExecutorService _poolReference;
- private final Set<EventType> _asyncTypes;
private final String _name;
private final int _maxEvents = Integer.getInteger("amqj.server.read_write_pool.max_events", 10);
- public PoolingFilter(ReferenceCountingExecutorService refCountingPool, Set<EventType> asyncTypes, String name)
+ public PoolingFilter(ReferenceCountingExecutorService refCountingPool, String name)
{
_poolReference = refCountingPool;
- _asyncTypes = asyncTypes;
_name = name;
}
- private void fireEvent(IoSession session, Event event)
+ void fireAsynchEvent(IoSession session, Event event)
{
- if (_asyncTypes.contains(event.getType()))
- {
- Job job = getJobForSession(session);
- job.acquire(); //prevents this job being removed from _jobs
- job.add(event);
+ Job job = getJobForSession(session);
+ job.acquire(); //prevents this job being removed from _jobs
+ job.add(event);
- //Additional checks on pool to check that it hasn't shutdown.
- // The alternative is to catch the RejectedExecutionException that will result from executing on a shutdown pool
- if (job.activate() && _poolReference.getPool() != null && !_poolReference.getPool().isShutdown())
- {
- _poolReference.getPool().execute(job);
- }
- }
- else
+ //Additional checks on pool to check that it hasn't shutdown.
+ // The alternative is to catch the RejectedExecutionException that will result from executing on a shutdown pool
+ if (job.activate() && _poolReference.getPool() != null && !_poolReference.getPool().isShutdown())
{
- event.process(session);
+ _poolReference.getPool().execute(job);
}
+
}
private Job getJobForSession(IoSession session)
@@ -114,45 +102,44 @@ public class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionH
//IoFilter methods that are processed by threads on the pool
- public void sessionOpened(NextFilter nextFilter, IoSession session) throws Exception
+ public void sessionOpened(final NextFilter nextFilter, final IoSession session) throws Exception
{
- fireEvent(session, new Event(nextFilter, EventType.OPENED, null));
+ nextFilter.sessionOpened(session);
}
- public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception
+ public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws Exception
{
- fireEvent(session, new Event(nextFilter, EventType.CLOSED, null));
+ nextFilter.sessionClosed(session);
}
- public void sessionIdle(NextFilter nextFilter, IoSession session,
- IdleStatus status) throws Exception
+ public void sessionIdle(final NextFilter nextFilter, final IoSession session,
+ final IdleStatus status) throws Exception
{
- fireEvent(session, new Event(nextFilter, EventType.IDLE, status));
+ nextFilter.sessionIdle(session, status);
}
- public void exceptionCaught(NextFilter nextFilter, IoSession session,
- Throwable cause) throws Exception
+ public void exceptionCaught(final NextFilter nextFilter, final IoSession session,
+ final Throwable cause) throws Exception
{
- fireEvent(session, new Event(nextFilter, EventType.EXCEPTION, cause));
+ nextFilter.exceptionCaught(session,cause);
}
- public void messageReceived(NextFilter nextFilter, IoSession session,
- Object message) throws Exception
+ public void messageReceived(final NextFilter nextFilter, final IoSession session,
+ final Object message) throws Exception
{
- //ByteBufferUtil.acquireIfPossible( message );
- fireEvent(session, new Event(nextFilter, EventType.RECEIVED, message));
+ nextFilter.messageReceived(session,message);
}
- public void messageSent(NextFilter nextFilter, IoSession session,
- Object message) throws Exception
+ public void messageSent(final NextFilter nextFilter, final IoSession session,
+ final Object message) throws Exception
{
- //ByteBufferUtil.acquireIfPossible( message );
- fireEvent(session, new Event(nextFilter, EventType.SENT, message));
+ nextFilter.messageSent(session, message);
}
- public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
+ public void filterWrite(final NextFilter nextFilter, final IoSession session,
+ final WriteRequest writeRequest) throws Exception
{
- fireEvent(session, new Event(nextFilter, EventType.WRITE, writeRequest));
+ nextFilter.filterWrite(session, writeRequest);
}
//IoFilter methods that are processed on current thread (NOT on pooled thread)
@@ -188,5 +175,52 @@ public class PoolingFilter extends IoFilterAdapter implements Job.JobCompletionH
// when the reference count gets to zero we release the executor service
_poolReference.releaseExecutorService();
}
+
+ public static class AsynchReadPoolingFilter extends PoolingFilter
+ {
+
+ public AsynchReadPoolingFilter(ReferenceCountingExecutorService refCountingPool, String name)
+ {
+ super(refCountingPool, name);
+ }
+
+ public void messageReceived(final NextFilter nextFilter, final IoSession session,
+ final Object message) throws Exception
+ {
+
+ fireAsynchEvent(session, new Event.ReceivedEvent(nextFilter, message));
+ }
+
+
+ }
+
+ public static class AsynchWritePoolingFilter extends PoolingFilter
+ {
+
+ public AsynchWritePoolingFilter(ReferenceCountingExecutorService refCountingPool, String name)
+ {
+ super(refCountingPool, name);
+ }
+
+
+ public void filterWrite(final NextFilter nextFilter, final IoSession session,
+ final WriteRequest writeRequest) throws Exception
+ {
+ fireAsynchEvent(session, new Event.WriteEvent(nextFilter, writeRequest));
+ }
+
+ }
+
+ public static PoolingFilter createAynschReadPoolingFilter(ReferenceCountingExecutorService refCountingPool,String name)
+ {
+ return new AsynchReadPoolingFilter(refCountingPool,name);
+ }
+
+
+ public static PoolingFilter createAynschWritePoolingFilter(ReferenceCountingExecutorService refCountingPool,String name)
+ {
+ return new AsynchWritePoolingFilter(refCountingPool,name);
+ }
+
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/pool/ReadWriteThreadModel.java b/qpid/java/common/src/main/java/org/apache/qpid/pool/ReadWriteThreadModel.java
index d4dbf1309a..84b72bb0dc 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/pool/ReadWriteThreadModel.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/pool/ReadWriteThreadModel.java
@@ -29,11 +29,8 @@ public class ReadWriteThreadModel implements ThreadModel
public void buildFilterChain(IoFilterChain chain) throws Exception
{
ReferenceCountingExecutorService executor = ReferenceCountingExecutorService.getInstance();
- PoolingFilter asyncRead = new PoolingFilter(executor, PoolingFilter.READ_EVENTS,
- "AsynchronousReadFilter");
- PoolingFilter asyncWrite = new PoolingFilter(executor, PoolingFilter.WRITE_EVENTS,
- "AsynchronousWriteFilter");
-
+ PoolingFilter asyncRead = PoolingFilter.createAynschReadPoolingFilter(executor, "AsynchronousReadFilter");
+ PoolingFilter asyncWrite = PoolingFilter.createAynschWritePoolingFilter(executor, "AsynchronousWriteFilter");
chain.addFirst("AsynchronousReadFilter", new ReferenceCountingIoFilter(asyncRead));
chain.addLast("AsynchronousWriteFilter", new ReferenceCountingIoFilter(asyncWrite));
}
diff --git a/qpid/java/common/src/main/xsl/cluster.asl b/qpid/java/common/src/main/xsl/cluster.asl
deleted file mode 100644
index 40ca937904..0000000000
--- a/qpid/java/common/src/main/xsl/cluster.asl
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0"?>
-<!--
- -
- - 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.
- -
- -->
-
-<amqp major="8" minor="0" port="5672" comment="AMQ protocol 0.80">
-
-<class name = "cluster" index = "101">
-
-<doc>
- An extension that allows brokers to communicate in order to
- provide a clustered service to clients.
-</doc>
-
-<method name = "join">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "membership">
- <field name = "members" type = "longstr" />
-</method>
-
-<method name = "synch">
-</method>
-
-<method name = "leave">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "suspect">
- <field name = "broker" type = "shortstr" />
-</method>
-
-<method name = "ping">
- <field name = "broker" type = "shortstr" />
- <field name = "load" type = "long" />
- <field name = "response required" type = "bit" />
-</method>
-
-</class>
-
-</amqp>
diff --git a/qpid/java/common/src/main/xsl/framing.xsl b/qpid/java/common/src/main/xsl/framing.xsl
deleted file mode 100644
index b8ae20aaf5..0000000000
--- a/qpid/java/common/src/main/xsl/framing.xsl
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<xsl:import href="prepare1.xsl"/>
-<xsl:import href="prepare2.xsl"/>
-<xsl:import href="prepare3.xsl"/>
-<xsl:import href="java.xsl"/>
-
-<xsl:output indent="yes"/>
-<xsl:output method="text" indent="yes" name="textFormat"/>
-
-<xsl:template match="/">
- <xsl:variable name="prepare1">
- <xsl:apply-templates mode="prepare1" select="."/>
- </xsl:variable>
-
- <xsl:variable name="prepare2">
- <xsl:apply-templates mode="prepare2" select="$prepare1"/>
- </xsl:variable>
-
- <xsl:variable name="model">
- <xsl:apply-templates mode="prepare3" select="$prepare2"/>
- </xsl:variable>
-
- <xsl:apply-templates mode="generate-multi" select="$model"/>
- <xsl:apply-templates mode="list-registry" select="$model"/>
-
- <!-- dump out the intermediary files for debugging -->
- <!--
- <xsl:result-document href="prepare1.out">
- <xsl:copy-of select="$prepare1"/>
- </xsl:result-document>
-
- <xsl:result-document href="prepare2.out">
- <xsl:copy-of select="$prepare2"/>
- </xsl:result-document>
-
- <xsl:result-document href="model.out">
- <xsl:copy-of select="$model"/>
- </xsl:result-document>
- -->
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/java.xsl b/qpid/java/common/src/main/xsl/java.xsl
deleted file mode 100644
index 948415fc18..0000000000
--- a/qpid/java/common/src/main/xsl/java.xsl
+++ /dev/null
@@ -1,248 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<!-- this class contains the templates for generating java source code for a given framing model -->
-<xsl:import href="utils.xsl"/>
-<xsl:output method="text" indent="yes" name="textFormat"/>
-
-<xsl:param name="major"/>
-<xsl:param name="minor"/>
-<xsl:param name="registry_name"/>
-<xsl:param name="version_list_name"/>
-
-<xsl:template match="/">
- <xsl:apply-templates mode="generate-multi" select="frames"/>
- <xsl:apply-templates mode="generate-registry" select="frames"/>
-</xsl:template>
-
-<!-- processes all frames outputting the classes in a single stream -->
-<!-- (useful for debugging etc) -->
-<xsl:template match="frame" mode="generate-single">
- <xsl:call-template name="generate-class">
- <xsl:with-param name="f" select="."/>
- </xsl:call-template>
-</xsl:template>
-
-<!-- generates seperate file for each class/frame -->
-<xsl:template match="frame" mode="generate-multi">
- <xsl:variable name="uri" select="concat(@name, '.java')"/>
- wrote <xsl:value-of select="$uri"/>
- <xsl:result-document href="{$uri}" format="textFormat">
- <xsl:call-template name="generate-class">
- <xsl:with-param name="f" select="."/>
- </xsl:call-template>
- </xsl:result-document>
-</xsl:template>
-
-<!-- main class generation template -->
-<xsl:template name="generate-class">
- <xsl:param name="f"/>
- <xsl:value-of select="amq:copyright()"/>
-<!-- package org.apache.qpid.framing_<xsl:value-of select="$major"/>_<xsl:value-of select="$minor"/>; -->
-package org.apache.qpid.framing;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.AMQFrameDecodingException;
-import org.apache.qpid.framing.AMQMethodBody;
-import org.apache.qpid.framing.EncodableAMQDataBlock;
-
-/**
- * This class is autogenerated, do not modify. [From <xsl:value-of select="$f/parent::frames/@protocol"/>]
- */
-public class <xsl:value-of select="$f/@name"/> extends AMQMethodBody implements EncodableAMQDataBlock
-{
- public static final int CLASS_ID = <xsl:value-of select="$f/@class-id"/>;
- public static final int METHOD_ID = <xsl:value-of select="$f/@method-id"/>;
-
- <xsl:for-each select="$f/field">
- <xsl:text>public </xsl:text><xsl:value-of select="@java-type"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name"/>;
- </xsl:for-each>
-
- protected int getClazz()
- {
- return <xsl:value-of select="$f/@class-id"/>;
- }
-
- protected int getMethod()
- {
- return <xsl:value-of select="$f/@method-id"/>;
- }
-
- protected int getBodySize()
- {
- <xsl:choose>
- <xsl:when test="$f/field">
- return
- <xsl:for-each select="$f/field">
- <xsl:if test="position() != 1">+
- </xsl:if>
- <xsl:value-of select="amq:field-length(.)"/>
- </xsl:for-each>
- ;
- </xsl:when>
- <xsl:otherwise>return 0;</xsl:otherwise>
- </xsl:choose>
- }
-
- protected void writeMethodPayload(ByteBuffer buffer)
- {
- <xsl:for-each select="$f/field">
- <xsl:if test="@type != 'bit'">
- <xsl:value-of select="amq:encoder(.)"/>;
- </xsl:if>
- <xsl:if test="@type = 'bit' and @boolean-index = 1">
- <xsl:text>EncodingUtils.writeBooleans(buffer, new boolean[]{</xsl:text>
- <xsl:value-of select="$f/field[@type='bit']/@name" separator=", "/>});
- </xsl:if>
- </xsl:for-each>
- }
-
- public void populateMethodBodyFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException
- {
- <xsl:for-each select="$f/field">
- <xsl:value-of select="amq:decoder(.)"/>;
- </xsl:for-each>
- }
-
- public String toString()
- {
- StringBuffer buf = new StringBuffer(super.toString());
- <xsl:for-each select="$f/field">
- <xsl:text>buf.append(" </xsl:text><xsl:value-of select="@name"/>: ").append(<xsl:value-of select="@name"/>);
- </xsl:for-each>
- return buf.toString();
- }
-
- public static AMQFrame createAMQFrame(int channelId<xsl:if test="$f/field">, </xsl:if><xsl:value-of select="$f/field/concat(@java-type, ' ', @name)" separator=", "/>)
- {
- <xsl:value-of select="@name"/> body = new <xsl:value-of select="@name"/>();
- <xsl:for-each select="$f/field">
- <xsl:value-of select="concat('body.', @name, ' = ', @name)"/>;
- </xsl:for-each>
- AMQFrame frame = new AMQFrame();
- frame.channel = channelId;
- frame.bodyFrame = body;
- return frame;
- }
-}
-</xsl:template>
-
-<xsl:template match="/" mode="generate-registry">
- <xsl:text>Matching root for registry mode!</xsl:text>
- <xsl:value-of select="."/>
- <xsl:apply-templates select="frames" mode="generate-registry"/>
-</xsl:template>
-
-<xsl:template match="registries" mode="generate-registry">
-Wrote MethodBodyDecoderRegistry.java
- <xsl:result-document href="MethodBodyDecoderRegistry.java" format="textFormat">
- <xsl:value-of select="amq:copyright()"/>
-<!-- package org.apache.qpid.framing_<xsl:value-of select="$major"/>_<xsl:value-of select="$minor"/>; -->
-package org.apache.qpid.framing;
-
-import java.util.Map;
-import java.util.HashMap;
-import org.apache.log4j.Logger;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQFrameDecodingException;
-import org.apache.qpid.framing.AMQMethodBody;
-
-/**
- * This class is autogenerated, do not modify.
- */
-public final class MethodBodyDecoderRegistry
-{
- private static final Logger _log = Logger.getLogger(MethodBodyDecoderRegistry.class);
-
- private static final Map _classMethodProductToMethodBodyMap = new HashMap();
-
- static
- {
- <xsl:for-each select="registry">
- <xsl:value-of select="concat(@name, '.register(_classMethodProductToMethodBodyMap)')"/>;
- </xsl:for-each>
- }
-
- public static AMQMethodBody get(int clazz, int method) throws AMQFrameDecodingException
- {
- Class bodyClass = (Class) _classMethodProductToMethodBodyMap.get(new Integer(clazz * 1000 + method));
- if (bodyClass != null)
- {
- try
- {
- return (AMQMethodBody) bodyClass.newInstance();
- }
- catch (Exception e)
- {
- throw new AMQFrameDecodingException(_log,
- "Unable to instantiate body class for class " + clazz + " and method " + method + ": " + e, e);
- }
- }
- else
- {
- throw new AMQFrameDecodingException(_log,
- "Unable to find a suitable decoder for class " + clazz + " and method " + method);
- }
- }
-}
-</xsl:result-document>
-</xsl:template>
-
-<xsl:template match="frames" mode="list-registry">
- <xsl:if test="$registry_name">
-
- <xsl:variable name="file" select="concat($registry_name, '.java')"/>
- wrote <xsl:value-of select="$file"/>
- <xsl:result-document href="{$file}" format="textFormat">
- <xsl:value-of select="amq:copyright()"/>
-<!-- package org.apache.qpid.framing_<xsl:value-of select="$major"/>_<xsl:value-of select="$minor"/>; -->
-package org.apache.qpid.framing;
-
-import java.util.Map;
-
-/**
- * This class is autogenerated, do not modify. [From <xsl:value-of select="@protocol"/>]
- */
-class <xsl:value-of select="$registry_name"/>
-{
- static void register(Map map)
- {
- <xsl:for-each select="frame">
- <xsl:text>map.put(new Integer(</xsl:text>
- <xsl:value-of select="@class-id"/>
- <xsl:text> * 1000 + </xsl:text>
- <xsl:value-of select="@method-id"/>
- <xsl:text>), </xsl:text>
- <xsl:value-of select="concat(@name, '.class')"/>);
- </xsl:for-each>
- }
-}
- </xsl:result-document>
-
- </xsl:if>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/prepare1.xsl b/qpid/java/common/src/main/xsl/prepare1.xsl
deleted file mode 100644
index 03e1fa7634..0000000000
--- a/qpid/java/common/src/main/xsl/prepare1.xsl
+++ /dev/null
@@ -1,114 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<xsl:import href="utils.xsl"/>
-
-<xsl:output indent="yes"/>
-<xsl:param name="asl_base"/>
-
-<!-- pre-process, phase 1 -->
-
-<xsl:template match="/">
- <xsl:apply-templates select="protocol" mode="prepare1"/>
-</xsl:template>
-
-<xsl:template match="amqp" mode="prepare1">
- <frames>
- <xsl:attribute name="protocol">
- <xsl:value-of select="@comment"/>
- <xsl:text> (</xsl:text>
- <xsl:text>major=</xsl:text><xsl:value-of select="@major"/>
- <xsl:text>, minor=</xsl:text><xsl:value-of select="@minor"/>
- <xsl:text>)</xsl:text>
- </xsl:attribute>
- <xsl:attribute name="major">
- <xsl:value-of select="@major"/>
- </xsl:attribute>
- <xsl:attribute name="minor">
- <xsl:value-of select="@minor"/>
- </xsl:attribute>
- <xsl:apply-templates mode="prepare1" select="inherit"/>
- <xsl:apply-templates mode="prepare1" select="include"/>
- <xsl:apply-templates mode="prepare1" select="domain"/>
- <xsl:apply-templates mode="prepare1" select="class"/>
- </frames>
-</xsl:template>
-
-<xsl:template match="include" mode="prepare1">
- <xsl:if test="@filename != 'asl_constants.asl'">
- <!-- skip asl_constants.asl, we don't need it and it is not well formed so causes error warnings -->
- <xsl:apply-templates select="document(@filename)" mode="prepare1"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="inherit" mode="prepare1">
- <xsl:variable name="ibase" select="concat('file:///', $asl_base, '/', @name, '.asl')"/>
- <xsl:choose>
- <xsl:when test="document($ibase)">
- <xsl:apply-templates select="document($ibase)" mode="prepare1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message>
- Could not inherit from <xsl:value-of select="$ibase"/>; file not found.
- </xsl:message>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template match="class[@index]" mode="prepare1">
- <xsl:apply-templates select="method" mode="prepare1"/>
-</xsl:template>
-
-<xsl:template match="method" mode="prepare1">
- <xsl:if test="parent::class[@index]"><!-- there is a template class that has no index, which we want to skip -->
- <frame>
- <xsl:attribute name="name"><xsl:value-of select="amq:class-name(parent::class/@name, @name)"/></xsl:attribute>
- <xsl:attribute name="class-id"><xsl:value-of select="parent::class/@index"/></xsl:attribute>
- <xsl:if test="@index">
- <xsl:attribute name="method-id"><xsl:value-of select="@index"/></xsl:attribute>
- </xsl:if>
- <xsl:if test="not(@index)">
- <xsl:attribute name="method-id"><xsl:number count="method"/></xsl:attribute>
- </xsl:if>
-
- <xsl:apply-templates select="field" mode="prepare1"/>
- </frame>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="domain" mode="prepare1">
- <domain>
- <name><xsl:value-of select="@name"/></name>
- <type><xsl:value-of select="@type"/></type>
- </domain>
-</xsl:template>
-
-<xsl:template match="field" mode="prepare1">
- <field>
- <xsl:copy-of select="@name"/>
- <xsl:copy-of select="@type"/>
- <xsl:copy-of select="@domain"/>
- </field>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/prepare2.xsl b/qpid/java/common/src/main/xsl/prepare2.xsl
deleted file mode 100644
index 14f4f33841..0000000000
--- a/qpid/java/common/src/main/xsl/prepare2.xsl
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<xsl:import href="utils.xsl"/>
-
-<xsl:output indent="yes"/>
-
-<!-- pre-process, phase 2 -->
-
-<xsl:key name="domain-lookup" match="domain" use="name"/>
-
-<xsl:template match="/">
- <xsl:apply-templates mode="prepare2" select="frames"/>
-</xsl:template>
-
-<xsl:template match="field[@domain]" mode="prepare2">
- <field>
- <xsl:variable name="t1" select="key('domain-lookup', @domain)/type"/>
- <xsl:attribute name="name"><xsl:value-of select="amq:field-name(@name)"/></xsl:attribute>
- <xsl:attribute name="type"><xsl:value-of select="$t1"/></xsl:attribute>
- </field>
-</xsl:template>
-
-<xsl:template match="field[@type]" mode="prepare2">
- <field>
- <xsl:attribute name="name"><xsl:value-of select="amq:field-name(@name)"/></xsl:attribute>
- <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
- </field>
-</xsl:template>
-
-<xsl:template match="frames" mode="prepare2">
- <frames>
- <xsl:copy-of select="@protocol"/>
- <xsl:copy-of select="@major"/>
- <xsl:copy-of select="@minor"/>
- <xsl:apply-templates mode="prepare2"/>
- </frames>
-</xsl:template>
-
-<xsl:template match="frame" mode="prepare2">
- <xsl:element name="{name()}">
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates mode="prepare2" select="field"/>
- </xsl:element>
-</xsl:template>
-
-<xsl:template match="domain" mode="prepare2"></xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/prepare3.xsl b/qpid/java/common/src/main/xsl/prepare3.xsl
deleted file mode 100644
index f8cf0c8932..0000000000
--- a/qpid/java/common/src/main/xsl/prepare3.xsl
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<xsl:import href="utils.xsl"/>
-
-<xsl:output indent="yes"/>
-
-<!-- final preparation of the model -->
-
-<xsl:template match="/">
- <xsl:apply-templates mode="prepare3"/>
-</xsl:template>
-
-<xsl:template match="frames" mode="prepare3">
- <frames>
- <xsl:copy-of select="@protocol"/>
- <xsl:copy-of select="@major"/>
- <xsl:copy-of select="@minor"/>
- <xsl:apply-templates mode="prepare3"/>
- </frames>
-</xsl:template>
-
-<xsl:template match="frame" mode="prepare3">
- <xsl:element name="frame">
- <xsl:copy-of select="@*"/>
- <xsl:if test="field[@type='bit']"><xsl:attribute name="has-bit-field">true</xsl:attribute></xsl:if>
- <xsl:apply-templates mode="prepare3"/>
- </xsl:element>
-</xsl:template>
-
-
-<xsl:template match="field" mode="prepare3">
- <field>
- <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
- <!-- ensure the field name is processed to be a valid java name -->
- <xsl:attribute name="name"><xsl:value-of select="amq:field-name(@name)"/></xsl:attribute>
- <!-- add some attributes to make code generation easier -->
- <xsl:attribute name="java-type"><xsl:value-of select="amq:java-type(@type)"/></xsl:attribute>
- <xsl:if test="@type='bit'">
- <xsl:attribute name="boolean-index"><xsl:number count="field[@type='bit']"/></xsl:attribute>
- </xsl:if>
- </field>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/readme.txt b/qpid/java/common/src/main/xsl/readme.txt
deleted file mode 100644
index b373055df9..0000000000
--- a/qpid/java/common/src/main/xsl/readme.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-This directory contains the xsl stylesheets used to generate the code from the
-AMQP protocol specification. They require an XSLT2.0 processor, currently
-Saxon 8 is used.
-
-The generation process is controlled by the framing.xsl stylesheet. This performs
-several phases of transformation, using the other stylesheets. The transformation
-in each phase is defined in a separate file, and these are designed to also allow
-then to be run individually.
-
-The generation takes the amq.asl as input, it also requires that the path to the
-directory where the base asl definitions reside (those definitions that the main
-amq.asl defintion inherits from) be passed in via a paramter called asl_base.
-
-The files involved are as follows:
-
- framing.xsl The control file for the entire generation process
-
- prepare1.xsl Resolves the separate files that make up the protocol
- definition, building a single tree containing all the
- information as a set of 'frame' elements, each of which
- has attributes for its name, and ids for the class and
- method it refers to and contains zero or more field
- elements.
-
- A method id is generated based on the order of the
- method elements within the class elements in the original
- specification. The class id is taken from the enclosing
- class element.
-
- prepare2.xsl Resolves domains into their corresponding types. (This is
- much easier when all the information is in a single tree,
- hence the separate frame).
-
- prepare3.xsl Converts names into valid java names and augments the
- tree to include information that makes the subsequent
- generation phase simpler e.g. the index of boolean
- fields as several boolean flags are combined into a
- single byte. (This is easier once the domains have been
- resolved, hence the separate phase).
-
- java.xsl Generates java classes for each frame, and a registry of
- all the frames to a 'magic' number generated from their
- class and method id.
-
- utils.xsl Contains some utility methods for e.g. producing valid
- java names.
-
-For debugging the framing.xsl can output the intermediary files. This can be
-enabled by uncommenting the relevant lines (a comment explaining this is
-provided inline).
-
- \ No newline at end of file
diff --git a/qpid/java/common/src/main/xsl/registry.template b/qpid/java/common/src/main/xsl/registry.template
deleted file mode 100644
index 87c5afcb7b..0000000000
--- a/qpid/java/common/src/main/xsl/registry.template
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0"?>
-<!--
- -
- - 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.
- -
- -->
-<registries>
- <registry name="MainRegistry"/>
- <registry name="ClusterRegistry"/>
-</registries>
diff --git a/qpid/java/common/src/main/xsl/registry.xsl b/qpid/java/common/src/main/xsl/registry.xsl
deleted file mode 100644
index c70dbe21a5..0000000000
--- a/qpid/java/common/src/main/xsl/registry.xsl
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<xsl:import href="java.xsl"/>
-
-<xsl:output method="text" indent="yes" name="textFormat"/>
-
-<xsl:template match="/">
- <xsl:apply-templates mode="generate-registry" select="registries"/>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/main/xsl/utils.xsl b/qpid/java/common/src/main/xsl/utils.xsl
deleted file mode 100644
index 95e15c6e38..0000000000
--- a/qpid/java/common/src/main/xsl/utils.xsl
+++ /dev/null
@@ -1,207 +0,0 @@
-<?xml version='1.0'?>
-<!--
- -
- - 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.
- -
- -->
-<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amq="http://amq.org">
-
-<!-- This file contains functions that are used in the generation of the java classes for framing -->
-
-<!-- create copyright notice for generated files -->
-<xsl:function name="amq:copyright">/**
-*
-* 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.
-*
-*/
-</xsl:function>
-
-<!-- retrieve the java type of a given amq type -->
-<xsl:function name="amq:java-type">
- <xsl:param name="t"/>
- <xsl:choose>
- <xsl:when test="$t='char'">char</xsl:when>
- <xsl:when test="$t='octet'">short</xsl:when>
- <xsl:when test="$t='short'">int</xsl:when>
- <xsl:when test="$t='shortstr'">String</xsl:when>
- <xsl:when test="$t='longstr'">byte[]</xsl:when>
- <xsl:when test="$t='bit'">boolean</xsl:when>
- <xsl:when test="$t='long'">long</xsl:when>
- <xsl:when test="$t='longlong'">long</xsl:when>
- <xsl:when test="$t='table'">FieldTable</xsl:when>
- <xsl:otherwise>Object /*WARNING: undefined type*/</xsl:otherwise>
- </xsl:choose>
-</xsl:function>
-
-<!-- retrieve the code to get the field size of a given amq type -->
-<xsl:function name="amq:field-length">
- <xsl:param name="f"/>
- <xsl:choose>
- <xsl:when test="$f/@type='bit' and $f/@boolean-index=1">
- <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='bit' and $f/@boolean-index &gt; 1">
- <xsl:value-of select="concat('0 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='char'">
- <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='octet'">
- <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='short'">
- <xsl:value-of select="concat('2 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='long'">
- <xsl:value-of select="concat('4 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longlong'">
- <xsl:value-of select="concat('8 /*', $f/@name, '*/')"/>
- </xsl:when>
- <xsl:when test="$f/@type='shortstr'">
- <xsl:value-of select="concat('EncodingUtils.encodedShortStringLength(', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longstr'">
- <xsl:value-of select="concat('4 + (', $f/@name, ' == null ? 0 : ', $f/@name, '.length)')"/>
- </xsl:when>
- <xsl:when test="$f/@type='table'">
- <xsl:value-of select="concat('EncodingUtils.encodedFieldTableLength(', $f/@name, ')')"/>
- </xsl:when>
- <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE FIELD SIZE */</xsl:text></xsl:otherwise>
- </xsl:choose>
-</xsl:function>
-
-<!-- retrieve the code to encode a field of a given amq type -->
-<!-- Note:
- This method will not provide an encoder for a bit field.
- Bit fields should be encoded together separately. -->
-
-<xsl:function name="amq:encoder">
- <xsl:param name="f"/>
- <xsl:choose>
- <xsl:when test="$f/@type='char'">
- <xsl:value-of select="concat('EncodingUtils.writeChar(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='octet'">
- <xsl:value-of select="concat('EncodingUtils.writeUnsignedByte(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='short'">
- <xsl:value-of select="concat('EncodingUtils.writeUnsignedShort(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='long'">
- <xsl:value-of select="concat('EncodingUtils.writeUnsignedInteger(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longlong'">
- <xsl:value-of select="concat('buffer.putLong(', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='shortstr'">
- <xsl:value-of select="concat('EncodingUtils.writeShortStringBytes(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longstr'">
- <xsl:value-of select="concat('EncodingUtils.writeLongstr(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:when test="$f/@type='table'">
- <xsl:value-of select="concat('EncodingUtils.writeFieldTableBytes(buffer, ', $f/@name, ')')"/>
- </xsl:when>
- <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE ENCODER */</xsl:text></xsl:otherwise>
- </xsl:choose>
-</xsl:function>
-
-<!-- retrieve the code to decode a field of a given amq type -->
-<xsl:function name="amq:decoder">
- <xsl:param name="f"/>
- <xsl:choose>
- <xsl:when test="$f/@type='bit'">
- <xsl:if test="$f/@boolean-index = 1">
- <xsl:text>boolean[] bools = EncodingUtils.readBooleans(buffer);</xsl:text>
- </xsl:if>
- <xsl:value-of select="concat($f/@name, ' = bools[', $f/@boolean-index - 1 , ']')"/>
- </xsl:when>
- <xsl:when test="$f/@type='char'">
- <xsl:value-of select="concat($f/@name, ' = buffer.getChar()')"/>
- </xsl:when>
- <xsl:when test="$f/@type='octet'">
- <xsl:value-of select="concat($f/@name, ' = buffer.getUnsigned()')"/>
- </xsl:when>
- <xsl:when test="$f/@type='short'">
- <xsl:value-of select="concat($f/@name, ' = buffer.getUnsignedShort()')"/>
- </xsl:when>
- <xsl:when test="$f/@type='long'">
- <xsl:value-of select="concat($f/@name, ' = buffer.getUnsignedInt()')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longlong'">
- <xsl:value-of select="concat($f/@name, ' = buffer.getLong()')"/>
- </xsl:when>
- <xsl:when test="$f/@type='shortstr'">
- <xsl:value-of select="concat($f/@name, ' = EncodingUtils.readShortString(buffer)')"/>
- </xsl:when>
- <xsl:when test="$f/@type='longstr'">
- <xsl:value-of select="concat($f/@name, ' = EncodingUtils.readLongstr(buffer)')"/>
- </xsl:when>
- <xsl:when test="$f/@type='table'">
- <xsl:value-of select="concat($f/@name, ' = EncodingUtils.readFieldTable(buffer)')"/>
- </xsl:when>
- <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE DECODER */</xsl:text></xsl:otherwise>
- </xsl:choose>
-</xsl:function>
-
-<!-- create the class name for a frame, based on class and method (passed in) -->
-<xsl:function name="amq:class-name">
- <xsl:param name="class"/>
- <xsl:param name="method"/>
- <xsl:value-of select="concat(amq:upper-first($class),amq:upper-first(amq:field-name($method)), 'Body')"/>
-</xsl:function>
-
-<!-- get a valid field name, processing spaces and '-'s where appropriate -->
-<xsl:function name="amq:field-name">
- <xsl:param name="name"/>
- <xsl:choose>
- <xsl:when test="contains($name, ' ')">
- <xsl:value-of select="concat(substring-before($name, ' '), amq:upper-first(substring-after($name, ' ')))"/>
- </xsl:when>
- <xsl:when test="contains($name, '-')">
- <xsl:value-of select="concat(substring-before($name, '-'), amq:upper-first(substring-after($name, '-')))"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$name"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:function>
-
-<!-- convert the first character of the input to upper-case -->
-<xsl:function name="amq:upper-first">
- <xsl:param name="in"/>
- <xsl:value-of select="concat(upper-case(substring($in, 1, 1)), substring($in, 2))"/>
-</xsl:function>
-
-</xsl:stylesheet>
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java b/qpid/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
index 66dd1b10ef..ffbdf730a9 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/framing/BasicContentHeaderPropertiesTest.java
@@ -31,7 +31,7 @@ public class BasicContentHeaderPropertiesTest extends TestCase
{
BasicContentHeaderProperties _testProperties;
- PropertyFieldTable _testTable;
+ FieldTable _testTable;
String _testString = "This is a test string";
int _testint = 666;
@@ -45,11 +45,9 @@ public class BasicContentHeaderPropertiesTest extends TestCase
public void setUp()
{
- HashMap _testMap = new HashMap(10);
- _testMap.put("TestString", _testString);
- _testMap.put("Testint", _testint);
- _testTable = new PropertyFieldTable();
- _testTable.putAll(_testMap);
+ _testTable = new FieldTable();
+ _testTable.setString("TestString", _testString);
+ _testTable.setInteger("Testint", _testint);
_testProperties = new BasicContentHeaderProperties();
_testProperties.setHeaders(_testTable);
}
@@ -57,7 +55,7 @@ public class BasicContentHeaderPropertiesTest extends TestCase
public void testGetPropertyListSize()
{
//needs a better test but at least we're exercising the code !
- // FT size is encoded in an int
+ // FT length is encoded in an int
int expectedSize = EncodingUtils.encodedIntegerLength();
expectedSize += EncodingUtils.encodedShortStringLength("TestInt");
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java b/qpid/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
index 9cad31766b..94c97ef808 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/framing/JMSPropertyFieldTableTest.java
@@ -51,7 +51,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testReplacement() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
//Set a boolean value
table1.setBoolean("value", true);
@@ -73,7 +73,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testRemoval() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
//Set a boolean value
table1.setBoolean("value", true);
@@ -99,7 +99,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testBoolean() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setBoolean("value", true);
Assert.assertTrue(table1.propertyExists("value"));
@@ -184,7 +184,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value will return false
@@ -197,7 +197,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testByte() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setByte("value", Byte.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -243,7 +243,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -266,7 +266,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testShort() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setShort("value", Short.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -323,7 +323,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -345,7 +345,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testDouble() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setDouble("value", Double.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -414,7 +414,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -437,7 +437,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testFloat() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setFloat("value", Float.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -500,7 +500,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -522,7 +522,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testInt() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setInteger("value", Integer.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -586,7 +586,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -608,7 +608,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testLong() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setLong("value", Long.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -679,7 +679,7 @@ public class JMSPropertyFieldTableTest extends TestCase
//but after a remove it doesn't
Assert.assertFalse(table1.propertyExists("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value
@@ -700,7 +700,7 @@ public class JMSPropertyFieldTableTest extends TestCase
* Calls all methods that can be used to check the table is empty
* - getEncodedSize
* - isEmpty
- * - size
+ * - length
*
* @param table to check is empty
*/
@@ -716,7 +716,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testString() throws JMSException
{
- JMSPropertyFieldTable table1 = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table1 = new JMSPropertyFieldTable(new FieldTable());
table1.setString("value", "Hello");
Assert.assertTrue(table1.propertyExists("value"));
@@ -799,7 +799,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testValues() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
table.setBoolean("bool", true);
table.setDouble("double", Double.MAX_VALUE);
table.setFloat("float", Float.MAX_VALUE);
@@ -842,7 +842,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasNull() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
try
{
@@ -862,7 +862,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasEmptyString() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
try
{
@@ -882,7 +882,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNamehasMaxLength() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
StringBuffer longPropertyName = new StringBuffer(129);
@@ -910,7 +910,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsLetter() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -931,7 +931,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameContainsInvalidCharacter() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -953,7 +953,7 @@ public class JMSPropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameIsInvalid() throws JMSException
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
//Try a name that starts with a number
try
@@ -995,7 +995,7 @@ public class JMSPropertyFieldTableTest extends TestCase
public void testSets()
{
- JMSPropertyFieldTable table = new JMSPropertyFieldTable();
+ JMSPropertyFieldTable table = new JMSPropertyFieldTable(new FieldTable());
table.put("n1", "1");
table.put("n2", "2");
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
index 5256c62054..c259d3ee8a 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
@@ -37,39 +37,23 @@ public class PropertyFieldTableTest extends TestCase
private static final Logger _logger = Logger.getLogger(PropertyFieldTableTest.class);
- /**
- * Test that modifying a byte[] after setting property doesn't change property
- */
- public void testByteModification()
- {
- PropertyFieldTable table = new PropertyFieldTable();
- byte[] bytes = {99, 98, 97, 96, 95};
- table.setBytes("bytes", bytes);
- bytes[0] = 1;
- bytes[1] = 2;
- bytes[2] = 3;
- bytes[3] = 4;
- bytes[4] = 5;
-
- assertBytesNotEqual(bytes, table.getBytes("bytes"));
- }
/**
* Test that setting a similar named value replaces any previous value set on that name
*/
public void testReplacement()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
//Set a boolean value
table1.setBoolean("value", true);
- //Check size of table is correct (<Value length> + <type> + <Boolean length>)
+ //Check length of table is correct (<Value length> + <type> + <Boolean length>)
int size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedBooleanLength();
Assert.assertEquals(size, table1.getEncodedSize());
// reset value to an integer
table1.setInteger("value", Integer.MAX_VALUE);
- // Check the size has changed accordingly (<Value length> + <type> + <Integer length>)
+ // Check the length has changed accordingly (<Value length> + <type> + <Integer length>)
size = EncodingUtils.encodedShortStringLength("value") + 1 + EncodingUtils.encodedIntegerLength();
Assert.assertEquals(size, table1.getEncodedSize());
@@ -86,7 +70,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testBoolean()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setBoolean("value", true);
Assert.assertTrue(table1.propertyExists("value"));
@@ -107,19 +91,9 @@ public class PropertyFieldTableTest extends TestCase
//except value as a string
Assert.assertEquals("true", table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BOOLEAN_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getBoolean("value"));
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -132,7 +106,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testByte()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setByte("value", Byte.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -151,20 +125,8 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Byte.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BYTE_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getByte("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -177,7 +139,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testShort()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setShort("value", Short.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -196,20 +158,8 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Short.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_SHORT_PROPERTY_PREFIX, "value", null);
-
- // Should be able to get the null back
- Assert.assertEquals(null, table1.getShort("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
-
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -223,7 +173,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testChar()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setChar("value", 'c');
Assert.assertTrue(table1.propertyExists("value"));
@@ -242,26 +192,9 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("c", table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_ASCII_CHARACTER_PROPERTY_PREFIX, "value", null);
-
- try
- {
- table1.getString("value");
- fail("Should throw NullPointerException");
- }
- catch (NullPointerException npe)
- {
- //Normal Path
- }
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
- //but after a remove it doesn't
- Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -275,7 +208,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testDouble()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setDouble("value", Double.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -293,20 +226,11 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Double.MAX_VALUE, table1.getString("value"));
-
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_DOUBLE_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getDouble("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -320,7 +244,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testFloat()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setFloat("value", Float.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -339,19 +263,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Float.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_FLOAT_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getFloat("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -365,7 +282,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testInt()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setInteger("value", Integer.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -384,19 +301,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Integer.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_INT_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getInteger("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -410,7 +320,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testLong()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setLong("value", Long.MAX_VALUE);
Assert.assertTrue(table1.propertyExists("value"));
@@ -429,19 +339,12 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it.
Assert.assertEquals("" + Long.MAX_VALUE, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_LONG_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getLong("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -457,7 +360,7 @@ public class PropertyFieldTableTest extends TestCase
{
byte[] bytes = {99, 98, 97, 96, 95};
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setBytes("value", bytes);
Assert.assertTrue(table1.propertyExists("value"));
@@ -476,19 +379,11 @@ public class PropertyFieldTableTest extends TestCase
//... and a the string value of it is null
Assert.assertEquals(null, table1.getString("value"));
- //Try setting a null value and read it back
- table1.put(PropertyFieldTable.Prefix.AMQP_BINARY_PROPERTY_PREFIX, "value", null);
-
- Assert.assertEquals(null, table1.getBytes("value"));
-
- //but still contains the value
- Assert.assertTrue(table1.containsKey("value"));
-
table1.remove("value");
//but after a remove it doesn't
Assert.assertFalse(table1.containsKey("value"));
- // Table should now have zero size for encoding
+ // Table should now have zero length for encoding
checkEmpty(table1);
//Looking up an invalid value returns null
@@ -499,19 +394,17 @@ public class PropertyFieldTableTest extends TestCase
* Calls all methods that can be used to check the table is empty
* - getEncodedSize
* - isEmpty
- * - size
+ * - length
*
* @param table to check is empty
*/
- private void checkEmpty(PropertyFieldTable table)
+ private void checkEmpty(FieldTable table)
{
Assert.assertEquals(0, table.getEncodedSize());
Assert.assertTrue(table.isEmpty());
Assert.assertEquals(0, table.size());
Assert.assertEquals(0, table.keySet().size());
- Assert.assertEquals(0, table.values().size());
- Assert.assertEquals(0, table.entrySet().size());
}
@@ -521,7 +414,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testString()
{
- PropertyFieldTable table1 = new PropertyFieldTable();
+ FieldTable table1 = new FieldTable();
table1.setString("value", "Hello");
Assert.assertTrue(table1.propertyExists("value"));
@@ -562,79 +455,11 @@ public class PropertyFieldTableTest extends TestCase
}
- /**
- * Test that the generated XML can be used to create a field table with the same values.
- */
- public void testValidXML()
- {
- PropertyFieldTable table1 = new PropertyFieldTable();
- table1.setBoolean("bool", true);
- table1.setByte("byte", Byte.MAX_VALUE);
- byte[] bytes = {99, 98, 97, 96, 95};
- table1.setBytes("bytes", bytes);
- table1.setChar("char", 'c');
- table1.setDouble("double", Double.MAX_VALUE);
- table1.setFloat("float", Float.MAX_VALUE);
- table1.setInteger("int", Integer.MAX_VALUE);
- table1.setLong("long", Long.MAX_VALUE);
- table1.setShort("short", Short.MAX_VALUE);
- table1.setString("string", "Hello");
- table1.setString("null-string", null);
-
- table1.setObject("object-bool", true);
- table1.setObject("object-byte", Byte.MAX_VALUE);
- table1.setObject("object-bytes", bytes);
- table1.setObject("object-char", 'c');
- table1.setObject("object-double", Double.MAX_VALUE);
- table1.setObject("object-float", Float.MAX_VALUE);
- table1.setObject("object-int", Integer.MAX_VALUE);
- table1.setObject("object-long", Long.MAX_VALUE);
- table1.setObject("object-short", Short.MAX_VALUE);
- table1.setObject("object-string", "Hello");
-
- Assert.assertEquals(21, table1.size());
-
- String table1XML = table1.toString();
-
- PropertyFieldTable table2 = new PropertyFieldTable(table1XML);
-
- Assert.assertEquals(table1XML, table2.toString());
-
- //Check that when bytes is written out as a string with no new line between items that it is read in ok.
-
- }
-
- /**
- * Test that invalid input throws the correct Exception
- */
- public void testInvalidXML()
- {
- try
- {
- _logger.warn("Testing Invalid XML expecting IllegalArgumentException");
- new PropertyFieldTable("Rubbish");
- fail("IllegalArgumentException expected");
- }
- catch (IllegalArgumentException iae)
- {
- //normal path
- }
- try
- {
- _logger.warn("Testing Invalid XML expecting IllegalArgumentException");
- new PropertyFieldTable("");
- fail("IllegalArgumentException expected");
- }
- catch (IllegalArgumentException iae)
- {
- //normal path
- }
- }
-
+
public void testKeyEnumeration()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setLong("one", 1L);
table.setLong("two", 2L);
table.setLong("three", 3L);
@@ -652,7 +477,7 @@ public class PropertyFieldTableTest extends TestCase
public void testValues()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
byte[] bytes = {99, 98, 97, 96, 95};
@@ -707,7 +532,7 @@ public class PropertyFieldTableTest extends TestCase
{
byte[] bytes = {99, 98, 97, 96, 95};
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
@@ -732,7 +557,7 @@ public class PropertyFieldTableTest extends TestCase
try
{
- PropertyFieldTable table2 = new PropertyFieldTable(buffer, length);
+ FieldTable table2 = new FieldTable(buffer, length);
Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
@@ -756,7 +581,7 @@ public class PropertyFieldTableTest extends TestCase
public void testEncodingSize()
{
- PropertyFieldTable result = new PropertyFieldTable();
+ FieldTable result = new FieldTable();
int size = 0;
result.setBoolean("boolean", true);
@@ -847,31 +672,31 @@ public class PropertyFieldTableTest extends TestCase
// public void testEncodingSize1()
// {
// PropertyFieldTable table = new PropertyFieldTable();
-// int size = 0;
+// int length = 0;
// result.put("one", 1L);
-// size = EncodingUtils.encodedShortStringLength("one");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length = EncodingUtils.encodedShortStringLength("one");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("two", 2L);
-// size += EncodingUtils.encodedShortStringLength("two");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("two");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("three", 3L);
-// size += EncodingUtils.encodedShortStringLength("three");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("three");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("four", 4L);
-// size += EncodingUtils.encodedShortStringLength("four");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("four");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// result.put("five", 5L);
-// size += EncodingUtils.encodedShortStringLength("five");
-// size += 1 + EncodingUtils.encodedLongLength();
-// assertEquals(size, result.getEncodedSize());
+// length += EncodingUtils.encodedShortStringLength("five");
+// length += 1 + EncodingUtils.encodedLongLength();
+// assertEquals(length, result.getEncodedSize());
//
// //fixme should perhaps be expanded to incorporate all types.
//
@@ -907,7 +732,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testSetObject()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try setting a non primative object
@@ -920,7 +745,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -929,7 +754,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasNull()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
try
{
@@ -940,7 +765,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -950,7 +775,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameasEmptyString()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
try
{
@@ -961,7 +786,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -971,7 +796,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNamehasMaxLength()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
StringBuffer longPropertyName = new StringBuffer(129);
@@ -989,7 +814,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -999,7 +824,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsLetter()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try a name that starts with a number
try
@@ -1011,7 +836,7 @@ public class PropertyFieldTableTest extends TestCase
{
//normal path
}
- // so size should be zero
+ // so length should be zero
Assert.assertEquals(0, table.getEncodedSize());
}
@@ -1021,7 +846,7 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testCheckPropertyNameStartCharacterIsHashorDollar()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
//Try a name that starts with a number
try
@@ -1041,12 +866,10 @@ public class PropertyFieldTableTest extends TestCase
*/
public void testContents()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.put("StringProperty", "String");
- Assert.assertTrue(table.containsValue("String"));
-
Assert.assertEquals("String", table.get("StringProperty"));
//Test Clear
@@ -1062,7 +885,7 @@ public class PropertyFieldTableTest extends TestCase
public void testSets()
{
- PropertyFieldTable table = new PropertyFieldTable();
+ FieldTable table = new FieldTable();
table.put("n1", "1");
table.put("n2", "2");
@@ -1075,64 +898,10 @@ public class PropertyFieldTableTest extends TestCase
Assert.assertFalse(iterator.hasNext());
- iterator = table.values().iterator();
- Assert.assertEquals("1", iterator.next());
- Assert.assertEquals("2", iterator.next());
- Assert.assertEquals("3", iterator.next());
- Assert.assertFalse(iterator.hasNext());
-
-
- iterator = table.entrySet().iterator();
- Map.Entry entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n1", entry.getKey());
- Assert.assertEquals("1", entry.getValue());
- entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n2", entry.getKey());
- Assert.assertEquals("2", entry.getValue());
- entry = (Map.Entry) iterator.next();
- Assert.assertEquals("n3", entry.getKey());
- Assert.assertEquals("3", entry.getValue());
- Assert.assertFalse(iterator.hasNext());
-
}
- /**
- * Test that all the values are preserved after a putAll
- */
- public void testPutAll()
- {
- Map map = new HashMap();
-
- map.put("char", 'c');
- map.put("double", Double.MAX_VALUE);
- map.put("float", Float.MAX_VALUE);
- map.put("int", Integer.MAX_VALUE);
- map.put("long", Long.MAX_VALUE);
- map.put("short", Short.MAX_VALUE);
-
- PropertyFieldTable table = new PropertyFieldTable();
-
- table.putAll(map);
-
- Assert.assertEquals(6, table.size());
-
- Assert.assertTrue(table.containsKey("char"));
- Assert.assertEquals('c', (char) table.getCharacter("char"));
- Assert.assertTrue(table.containsKey("double"));
- Assert.assertEquals(Double.MAX_VALUE, table.getDouble("double"));
- Assert.assertTrue(table.containsKey("float"));
- Assert.assertEquals(Float.MAX_VALUE, table.getFloat("float"));
- Assert.assertTrue(table.containsKey("int"));
- Assert.assertEquals(Integer.MAX_VALUE, (int) table.getInteger("int"));
- Assert.assertTrue(table.containsKey("long"));
- Assert.assertEquals(Long.MAX_VALUE, (long) table.getLong("long"));
- Assert.assertTrue(table.containsKey("short"));
- Assert.assertEquals(Short.MAX_VALUE, (short) table.getShort("short"));
- Assert.assertEquals(Short.MAX_VALUE, (short) table.getShort("short"));
- }
-
private void assertBytesEqual(byte[] expected, byte[] actual)
{
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/pool/PoolingFilterTest.java b/qpid/java/common/src/test/java/org/apache/qpid/pool/PoolingFilterTest.java
index 972a935257..9a5208662b 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/pool/PoolingFilterTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/pool/PoolingFilterTest.java
@@ -39,7 +39,7 @@ public class PoolingFilterTest extends TestCase
//Create Pool
_executorService = ReferenceCountingExecutorService.getInstance();
_executorService.acquireExecutorService();
- _pool = new PoolingFilter(_executorService, PoolingFilter.WRITE_EVENTS,
+ _pool = PoolingFilter.createAynschWritePoolingFilter(_executorService,
"AsynchronousWriteFilter");
}