You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2011/08/14 19:15:08 UTC
svn commit: r1157566 [6/23] - in /qpid:
branches/rg-amqp-1-0-sandbox/qpid/java/
branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/
branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/
branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/s...
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/jms/impl/TopicSubscriberImpl.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.amqp_1_0.jms.impl;
+
+import org.apache.qpid.amqp_1_0.client.Receiver;
+import org.apache.qpid.amqp_1_0.jms.Topic;
+import org.apache.qpid.amqp_1_0.jms.TopicSubscriber;
+
+import javax.jms.JMSException;
+
+public class TopicSubscriberImpl extends MessageConsumerImpl implements TopicSubscriber
+{
+ TopicSubscriberImpl(final Topic destination,
+ final SessionImpl session,
+ final String selector,
+ final boolean noLocal)
+ throws JMSException
+ {
+ super(destination, session, selector, noLocal);
+ }
+
+ public TopicImpl getTopic() throws JMSException
+ {
+ return (TopicImpl) getDestination();
+ }
+
+
+ protected Receiver createClientReceiver()
+ {
+ return getSession().getClientSession().createCopyingReceiver(getDestination().getAddress());
+ }
+
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/build.xml
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/build.xml?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/build.xml (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/build.xml Sun Aug 14 17:14:51 2011
@@ -0,0 +1,27 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<project name="AMQP 1.0 Common" default="build">
+
+ <property name="module.genpom" value="true"/>
+
+ <import file="../module.xml"/>
+
+</project>
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractDescribedTypeWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractDescribedTypeWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractDescribedTypeWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractDescribedTypeWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,188 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class AbstractDescribedTypeWriter<V> implements ValueWriter<V>
+{
+ private int _length;
+ private Registry _registry;
+ private static final int LARGE_COMPOUND_THRESHOLD_COUNT = 10;
+ private ValueWriter _delegate;
+ private static final byte DESCRIBED_TYPE = (byte)0;
+
+ public AbstractDescribedTypeWriter(final Registry registry)
+ {
+ _registry = registry;
+ }
+
+ enum State {
+ FORMAT_CODE,
+ DESCRIPTOR,
+ DESCRIBED,
+ DONE
+ }
+
+ private State _state = State.FORMAT_CODE;
+
+ public int writeToBuffer(ByteBuffer buffer)
+ {
+ final int length = _length;
+
+ if(length == -1)
+ {
+ writeFirstPass(buffer);
+ }
+ else
+ {
+
+ State state = _state;
+
+ switch(state)
+ {
+ case FORMAT_CODE:
+ if(buffer.hasRemaining())
+ {
+ buffer.put(DESCRIBED_TYPE);
+ state = State.DESCRIPTOR;
+ _delegate = createDescriptorWriter();
+ }
+ else
+ {
+ break;
+ }
+
+ case DESCRIPTOR:
+ if(buffer.hasRemaining())
+ {
+ _delegate.writeToBuffer(buffer);
+ if(_delegate.isComplete())
+ {
+ state = State.DESCRIBED;
+ _delegate = createDescribedWriter();
+ }
+ else
+ {
+ break;
+ }
+ }
+ case DESCRIBED:
+ if(buffer.hasRemaining())
+ {
+ _delegate.writeToBuffer(buffer);
+ if(_delegate.isComplete())
+ {
+ state = State.DONE;
+ _delegate = null;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ }
+
+ _state = state;
+
+ }
+
+ return _length;
+ }
+
+ private void writeFirstPass(ByteBuffer buffer)
+ {
+
+ int length = 1;
+ State state = State.FORMAT_CODE;
+
+ ValueWriter descriptorWriter = createDescriptorWriter();
+ if(buffer.hasRemaining())
+ {
+ buffer.put(DESCRIBED_TYPE);
+ state = State.DESCRIPTOR;
+ _delegate = descriptorWriter;
+ }
+ length += descriptorWriter.writeToBuffer(buffer);
+
+ ValueWriter describedWriter = createDescribedWriter();
+
+ if(descriptorWriter.isComplete())
+ {
+ state = State.DESCRIBED;
+ _delegate = describedWriter;
+ }
+
+ length += describedWriter.writeToBuffer(buffer);
+
+ if(describedWriter.isComplete())
+ {
+ _delegate = null;
+ state = State.DONE;
+ }
+
+ _state = state;
+ _length = length;
+ }
+
+ public void setValue(V value)
+ {
+ _length = -1;
+ _delegate = null;
+ _state = State.FORMAT_CODE;
+ onSetValue(value);
+ }
+
+ public void setRegistry(Registry registry)
+ {
+ _registry = registry;
+ }
+
+ protected Registry getRegistry()
+ {
+ return _registry;
+ }
+
+ protected abstract void onSetValue(final V value);
+
+ protected abstract void clear();
+
+ protected abstract ValueWriter createDescribedWriter();
+
+ protected abstract Object getDescriptor();
+
+ protected final ValueWriter createDescriptorWriter()
+ {
+ return getRegistry().getValueWriter(getDescriptor());
+ }
+
+ public boolean isComplete()
+ {
+ return _state == State.DONE;
+ }
+
+ public boolean isCacheable()
+ {
+ return false;
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractListWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractListWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractListWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractListWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public abstract class AbstractListWriter<V> extends CompoundWriter<V>
+{
+ public AbstractListWriter(final Registry registry)
+ {
+ super(registry);
+ }
+
+ @Override
+ protected byte getFourOctetEncodingCode()
+ {
+ return (byte)0xd0;
+ }
+
+ @Override
+ protected byte getSingleOctetEncodingCode()
+ {
+ return (byte)0xc0;
+ }
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractMapWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractMapWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractMapWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/AbstractMapWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,95 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public abstract class AbstractMapWriter<V> extends CompoundWriter<V>
+{
+ private boolean onKey;
+
+ public AbstractMapWriter(Registry registry)
+ {
+ super(registry);
+ }
+
+ @Override
+ protected byte getFourOctetEncodingCode()
+ {
+ return (byte)0xd1;
+ }
+
+ @Override
+ protected byte getSingleOctetEncodingCode()
+ {
+ return (byte)0xc1;
+ }
+
+ @Override
+ protected final int getCount()
+ {
+ return 2 * getMapCount();
+ }
+
+ protected abstract int getMapCount();
+
+ @Override
+ protected final boolean hasNext()
+ {
+ return onKey || hasMapNext();
+ }
+
+ protected abstract boolean hasMapNext();
+
+ @Override
+ protected final Object next()
+ {
+ if(onKey = !onKey)
+ {
+ return nextKey();
+ }
+ else
+ {
+ return nextValue();
+ }
+ }
+
+ protected abstract Object nextValue();
+
+ protected abstract Object nextKey();
+
+ @Override
+ protected final void clear()
+ {
+ onKey = false;
+ onClear();
+ }
+
+ protected abstract void onClear();
+
+ @Override
+ protected final void reset()
+ {
+ onKey = false;
+ onReset();
+ }
+
+ protected abstract void onReset();
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,113 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.AmqpError;
+
+import java.lang.reflect.Array;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ArrayTypeConstructor implements TypeConstructor<Object[]>
+{
+
+
+
+ public Object[] construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ int size = read(in);
+ if(in.remaining() < size)
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Insufficient data to decode array - requires %d octects, only %d remaining.",
+ size, in.remaining());
+ }
+ ByteBuffer dup = in.slice();
+ dup.limit(size);
+ in.position(in.position()+size);
+ int count = read(dup);
+ TypeConstructor t = handler.readConstructor(dup);
+ List rval = new ArrayList(count);
+ for(int i = 0; i < count; i++)
+ {
+ rval.add(t.construct(dup, handler));
+ }
+ if(dup.hasRemaining())
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR,
+ "Array incorrectly encoded, %d bytes remaining after decoding %d elements",
+ dup.remaining(), count);
+ }
+ if(rval.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+
+
+ return rval.toArray((Object[])Array.newInstance(rval.get(0).getClass(), rval.size()));
+ }
+ }
+
+
+ abstract int read(ByteBuffer in) throws AmqpErrorException;
+
+
+ private static final ArrayTypeConstructor ONE_BYTE_SIZE_ARRAY = new ArrayTypeConstructor()
+ {
+
+ @Override int read(final ByteBuffer in) throws AmqpErrorException
+ {
+ if(!in.hasRemaining())
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode array");
+ }
+ return ((int)in.get()) & 0xff;
+ }
+
+ };
+
+ private static final ArrayTypeConstructor FOUR_BYTE_SIZE_ARRAY = new ArrayTypeConstructor()
+ {
+
+ @Override int read(final ByteBuffer in) throws AmqpErrorException
+ {
+ if(in.remaining()<4)
+ {
+ throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode array");
+ }
+ return in.getInt();
+ }
+
+ };
+
+ public static ArrayTypeConstructor getOneByteSizeTypeConstructor()
+ {
+ return ONE_BYTE_SIZE_ARRAY;
+ }
+
+ public static ArrayTypeConstructor getFourByteSizeTypeConstructor()
+ {
+ return FOUR_BYTE_SIZE_ARRAY;
+ }
+
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ArrayWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,82 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class ArrayWriter implements ValueWriter<Object[]>
+{
+ private Object[] _list;
+ private int _position = 0;
+ private final Registry _registry;
+ private ValueWriter valueWriter;
+
+ public ArrayWriter(final Registry registry)
+ {
+ _registry = registry;
+ }
+
+
+ protected void onSetValue(final Object[] value)
+ {
+
+ Class clazz = value.getClass().getComponentType();
+ //valueWriter = _registry.getValueWriterByClass(clazz);
+
+
+ }
+
+
+
+
+ private static Factory<Object[]> FACTORY = new Factory<Object[]>()
+ {
+
+ public ValueWriter<Object[]> newInstance(Registry registry)
+ {
+ return new ArrayWriter(registry);
+ }
+ };
+
+ public static void register(Registry registry)
+ {
+ //registry.register(List.class, FACTORY);
+ }
+
+ public int writeToBuffer(final ByteBuffer buffer)
+ {
+ return 0; //TODO change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setValue(final Object[] frameBody)
+ {
+ //TODO change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isComplete()
+ {
+ return false; //TODO change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isCacheable()
+ {
+ return false; //TODO change body of implemented methods use File | Settings | File Templates.
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryString.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryString.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryString.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryString.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,68 @@
+package org.apache.qpid.amqp_1_0.codec;
+
+
+final class BinaryString
+{
+
+ private byte[] _data;
+ private int _offset;
+ private int _size;
+ private int _hashCode;
+
+ BinaryString(final byte[] data, final int offset, final int size)
+ {
+
+ setData(data, offset, size);
+ }
+
+ BinaryString()
+ {
+ }
+
+ void setData(byte[] data, int offset, int size)
+ {
+ _data = data;
+ _offset = offset;
+ _size = size;
+ int hc = 0;
+ for (int i = 0; i < size; i++)
+ {
+ hc = 31*hc + (0xFF & data[offset + i]);
+ }
+ _hashCode = hc;
+ }
+
+
+ public final int hashCode()
+ {
+ return _hashCode;
+ }
+
+ public final boolean equals(Object o)
+ {
+ BinaryString buf = (BinaryString) o;
+ final int size = _size;
+ if (size != buf._size)
+ {
+ return false;
+ }
+
+ final byte[] myData = _data;
+ final byte[] theirData = buf._data;
+ int myOffset = _offset;
+ int theirOffset = buf._offset;
+ final int myLimit = myOffset + size;
+
+ while(myOffset < myLimit)
+ {
+ if (myData[myOffset++] != theirData[theirOffset++])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,80 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.Binary;
+
+import java.nio.ByteBuffer;
+
+public class BinaryTypeConstructor extends VariableWidthTypeConstructor
+{
+ private static final BinaryTypeConstructor INSTANCE_1 = new BinaryTypeConstructor(1);
+ private static final BinaryTypeConstructor INSTANCE_4 = new BinaryTypeConstructor(4);
+
+ public static BinaryTypeConstructor getInstance(int i)
+ {
+ return i == 1 ? INSTANCE_1 : INSTANCE_4;
+ }
+
+
+ private BinaryTypeConstructor(int size)
+ {
+ super(size);
+ }
+
+ @Override
+ public Object construct(final ByteBuffer in, boolean isCopy, ValueHandler handler) throws AmqpErrorException
+ {
+ int size;
+
+ if(getSize() == 1)
+ {
+ size = in.get() & 0xFF;
+ }
+ else
+ {
+ size = in.getInt();
+ }
+
+ ByteBuffer inDup = in.slice();
+ inDup.limit(inDup.position()+size);
+
+ Binary binary;
+/* if(isCopy && inDup.hasArray())
+ {
+ binary= new Binary(inDup.array(), inDup.arrayOffset()+inDup.position(),size);
+ }
+ else
+ {*/
+ byte[] buf = new byte[size];
+ inDup.get(buf);
+ binary = new Binary(buf);
+ /* }*/
+
+ in.position(in.position()+size);
+
+
+ return binary;
+
+ }
+
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BinaryWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.Binary;
+
+public class BinaryWriter extends SimpleVariableWidthWriter<Binary>
+{
+ private int _offset;
+ private int _length;
+
+ @Override
+ protected byte getFourOctetEncodingCode()
+ {
+ return (byte)0xb0;
+ }
+
+ @Override
+ protected byte getSingleOctetEncodingCode()
+ {
+ return (byte)0xa0;
+ }
+
+ @Override
+ protected byte[] getByteArray(Binary value)
+ {
+ _offset = value.getArrayOffset();
+ _length = value.getLength();
+ return value.getArray();
+ }
+
+ @Override
+ protected int getOffset()
+ {
+ return _offset;
+ }
+
+ @Override protected int getLength()
+ {
+ return _length;
+ }
+
+ private static Factory<Binary> FACTORY = new Factory<Binary>()
+ {
+
+ public ValueWriter<Binary> newInstance(Registry registry)
+ {
+ return new BinaryWriter();
+ }
+ };
+
+ public static void register(Registry registry)
+ {
+ registry.register(Binary.class, FACTORY);
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.*;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class BooleanConstructor
+{
+ private static final TypeConstructor<Boolean> TRUE_INSTANCE = new TypeConstructor<Boolean>()
+ {
+ public Boolean construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ return Boolean.TRUE;
+ }
+ };
+
+ private static final TypeConstructor<Boolean> FALSE_INSTANCE = new TypeConstructor<Boolean>()
+ {
+ public Boolean construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ return Boolean.FALSE;
+ }
+ };
+ private static final TypeConstructor<Boolean> BYTE_INSTANCE = new TypeConstructor<Boolean>()
+ {
+ public Boolean construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ if(in.hasRemaining())
+ {
+ byte b = in.get();
+ return b != (byte) 0;
+ }
+ else
+ {
+ org.apache.qpid.amqp_1_0.type.transport.Error error = new Error();
+ error.setCondition(ConnectionError.FRAMING_ERROR);
+ error.setDescription("Cannot construct boolean: insufficient input data");
+ throw new AmqpErrorException(error);
+ }
+ }
+
+ };
+
+
+ public static TypeConstructor<Boolean> getTrueInstance()
+ {
+ return TRUE_INSTANCE;
+ }
+
+ public static TypeConstructor<Boolean> getFalseInstance()
+ {
+ return FALSE_INSTANCE;
+ }
+
+ public static TypeConstructor<Boolean> getByteInstance()
+ {
+ return BYTE_INSTANCE;
+ }
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/BooleanWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class BooleanWriter implements ValueWriter<Boolean>
+{
+ private boolean _complete = true;
+ private boolean _value;
+
+ public int writeToBuffer(ByteBuffer buffer)
+ {
+ if(!_complete & buffer.hasRemaining())
+ {
+ buffer.put(_value ? (byte)0x41 : (byte)0x42);
+ _complete = true;
+ }
+ return 1;
+ }
+
+ public void setValue(Boolean value)
+ {
+ _complete = false;
+ _value = value.booleanValue();
+ }
+
+ public boolean isCacheable()
+ {
+ return true;
+ }
+
+ public boolean isComplete()
+ {
+ return _complete;
+ }
+
+ private static Factory<Boolean> FACTORY = new Factory<Boolean>()
+ {
+
+ public ValueWriter<Boolean> newInstance(Registry registry)
+ {
+ return new BooleanWriter();
+ }
+ };
+
+ public static void register(ValueWriter.Registry registry)
+ {
+ registry.register(Boolean.class, FACTORY);
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteArrayWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteArrayWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteArrayWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteArrayWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public class ByteArrayWriter extends SimpleVariableWidthWriter<byte[]>
+{
+
+ @Override
+ protected byte getFourOctetEncodingCode()
+ {
+ return (byte)0xb0;
+ }
+
+ @Override
+ protected byte getSingleOctetEncodingCode()
+ {
+ return (byte)0xa0;
+ }
+
+ @Override
+ protected byte[] getByteArray(byte[] value)
+ {
+ return value;
+ }
+
+
+ @Override
+ protected int getOffset()
+ {
+ return 0;
+ }
+
+ private static Factory<byte[]> FACTORY = new Factory<byte[]>()
+ {
+
+ public ValueWriter<byte[]> newInstance(Registry registry)
+ {
+ return new ByteArrayWriter();
+ }
+ };
+
+ public static void register(ValueWriter.Registry registry)
+ {
+ registry.register(byte[].class, FACTORY);
+ }
+
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteBufferWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteBufferWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteBufferWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteBufferWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class ByteBufferWriter extends SimpleVariableWidthWriter<ByteBuffer>
+{
+
+ @Override
+ protected byte getFourOctetEncodingCode()
+ {
+ return (byte)0xb0;
+ }
+
+ @Override
+ protected byte getSingleOctetEncodingCode()
+ {
+ return (byte)0xa0;
+ }
+
+ @Override
+ protected byte[] getByteArray(ByteBuffer value)
+ {
+ if(value.hasArray() && value.arrayOffset() == 0 && value.remaining() == value.array().length)
+ {
+ return value.array();
+ }
+ else
+ {
+ byte[] copy = new byte[value.remaining()];
+ value.duplicate().get(copy);
+ return copy;
+ }
+ }
+
+ @Override
+ protected int getOffset()
+ {
+ return 0;
+ }
+
+ private static Factory<ByteBuffer> FACTORY = new Factory<ByteBuffer>()
+ {
+
+ public ValueWriter<ByteBuffer> newInstance(Registry registry)
+ {
+ return new ByteBufferWriter();
+ }
+ };
+
+ public static void register(Registry registry)
+ {
+ registry.register(ByteBuffer.class, FACTORY);
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class ByteTypeConstructor implements TypeConstructor
+{
+ private static final ByteTypeConstructor INSTANCE = new ByteTypeConstructor();
+
+ public static ByteTypeConstructor getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private ByteTypeConstructor()
+ {
+ }
+
+ public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+ {
+ if(in.hasRemaining())
+ {
+ return in.get();
+ }
+ else
+ {
+ Error error = new Error();
+ error.setCondition(ConnectionError.FRAMING_ERROR);
+ error.setDescription("Cannot construct byte: insufficient input data");
+ throw new AmqpErrorException(error);
+
+ }
+
+ }
+
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ByteWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class ByteWriter implements ValueWriter<Byte>
+{
+ private int _written = 2;
+ private byte _value;
+
+ public int writeToBuffer(ByteBuffer buffer)
+ {
+
+ switch(_written)
+ {
+ case 0:
+ if(buffer.hasRemaining())
+ {
+ buffer.put((byte)0x51);
+ }
+ else
+ {
+ break;
+ }
+ case 1:
+ if(buffer.hasRemaining())
+ {
+ buffer.put(_value);
+ _written = 2;
+ }
+ else
+ {
+ _written = 1;
+ }
+
+ }
+
+ return 2;
+ }
+
+ public void setValue(Byte value)
+ {
+ _written = 0;
+ _value = value.byteValue();
+ }
+
+ public boolean isComplete()
+ {
+ return _written == 2;
+ }
+
+ public boolean isCacheable()
+ {
+ return true;
+ }
+
+ private static Factory<Byte> FACTORY = new Factory<Byte>()
+ {
+
+ public ValueWriter<Byte> newInstance(Registry registry)
+ {
+ return new ByteWriter();
+ }
+ };
+
+ public static void register(ValueWriter.Registry registry)
+ {
+ registry.register(Byte.class, FACTORY);
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.*;
+
+import java.nio.ByteBuffer;
+
+public class CharTypeConstructor implements TypeConstructor
+{
+ private static final CharTypeConstructor INSTANCE = new CharTypeConstructor();
+
+
+ public static CharTypeConstructor getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private CharTypeConstructor()
+ {
+ }
+
+ public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+ {
+ if(in.remaining()>=4)
+ {
+ int codePoint = in.getInt();
+ char[] chars = Character.toChars(codePoint);
+ if(chars.length == 1)
+ {
+ return chars[0];
+ }
+ else
+ {
+ return chars;
+ }
+ }
+ else
+ {
+ org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+ error.setCondition(ConnectionError.FRAMING_ERROR);
+ error.setDescription("Cannot construct char: insufficient input data");
+ throw new AmqpErrorException(error);
+
+ }
+ }
+
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CharWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,53 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public class CharWriter extends FixedFourWriter<Character>
+{
+ private static final byte FORMAT_CODE = (byte)0x73;
+
+ @Override
+ byte getFormatCode()
+ {
+ return FORMAT_CODE;
+ }
+
+ @Override
+ int convertValueToInt(Character value)
+ {
+ return (int) value.charValue();
+ }
+
+ private static Factory<Character> FACTORY = new Factory<Character>()
+ {
+
+ public ValueWriter<Character> newInstance(Registry registry)
+ {
+ return new CharWriter();
+ }
+ };
+
+ public static void register(ValueWriter.Registry registry)
+ {
+ registry.register(Character.class, FACTORY);
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeAssembler.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeAssembler.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeAssembler.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeAssembler.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+
+public interface CompoundTypeAssembler
+{
+
+ public static interface Factory
+ {
+ CompoundTypeAssembler newInstance();
+ }
+
+ void init(int count) throws AmqpErrorException;
+ void addItem(Object obj) throws AmqpErrorException;
+ Object complete() throws AmqpErrorException;
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,192 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.*;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CompoundTypeConstructor extends VariableWidthTypeConstructor
+{
+ private final CompoundTypeAssembler.Factory _assemblerFactory;
+
+ public static final CompoundTypeAssembler.Factory LIST_ASSEMBLER_FACTORY =
+ new CompoundTypeAssembler.Factory()
+ {
+
+ public CompoundTypeAssembler newInstance()
+ {
+ return new ListAssembler();
+ }
+ };
+
+
+
+ private static class ListAssembler implements CompoundTypeAssembler
+ {
+ private List _list;
+
+ public void init(final int count) throws AmqpErrorException
+ {
+ _list = new ArrayList(count);
+ }
+
+ public void addItem(final Object obj) throws AmqpErrorException
+ {
+ _list.add(obj);
+ }
+
+ public Object complete() throws AmqpErrorException
+ {
+ return _list;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ListAssembler{" +
+ "_list=" + _list +
+ '}';
+ }
+ }
+
+
+ public static final CompoundTypeAssembler.Factory MAP_ASSEMBLER_FACTORY =
+ new CompoundTypeAssembler.Factory()
+ {
+
+ public CompoundTypeAssembler newInstance()
+ {
+ return new MapAssembler();
+ }
+ };
+
+ private static class MapAssembler implements CompoundTypeAssembler
+ {
+ private Map _map;
+ private Object _lastKey;
+ private static final Object NOT_A_KEY = new Object();
+
+
+ public void init(final int count) throws AmqpErrorException
+ {
+ // Can't have an odd number of elements in a map
+ if((count & 0x1) == 1)
+ {
+ Error error = new Error();
+ error.setCondition(AmqpError.DECODE_ERROR);
+ Formatter formatter = new Formatter();
+ formatter.format("map cannot have odd number of elements: %d", count);
+ error.setDescription(formatter.toString());
+ throw new AmqpErrorException(error);
+ }
+ _map = new HashMap(count);
+ _lastKey = NOT_A_KEY;
+ }
+
+ public void addItem(final Object obj) throws AmqpErrorException
+ {
+ if(_lastKey != NOT_A_KEY)
+ {
+ if(_map.put(_lastKey, obj) != null)
+ {
+ Error error = new Error();
+ error.setCondition(AmqpError.DECODE_ERROR);
+ Formatter formatter = new Formatter();
+ formatter.format("map cannot have duplicate keys: %s has values (%s, %s)", _lastKey, _map.get(_lastKey), obj);
+ error.setDescription(formatter.toString());
+
+ throw new AmqpErrorException(error);
+ }
+ _lastKey = NOT_A_KEY;
+ }
+ else
+ {
+ _lastKey = obj;
+ }
+
+ }
+
+ public Object complete() throws AmqpErrorException
+ {
+ return _map;
+ }
+ }
+
+
+ public static CompoundTypeConstructor getInstance(int i,
+ CompoundTypeAssembler.Factory assemblerFactory)
+ {
+ return new CompoundTypeConstructor(i, assemblerFactory);
+ }
+
+
+ private CompoundTypeConstructor(int size,
+ final CompoundTypeAssembler.Factory assemblerFactory)
+ {
+ super(size);
+ _assemblerFactory = assemblerFactory;
+ }
+
+ @Override
+ public Object construct(final ByteBuffer in, boolean isCopy, ValueHandler delegate) throws AmqpErrorException
+ {
+ int size;
+ int count;
+
+ if(getSize() == 1)
+ {
+ size = in.get() & 0xFF;
+ count = in.get() & 0xFF;
+ }
+ else
+ {
+ size = in.getInt();
+ count = in.getInt();
+ }
+
+ ByteBuffer data;
+
+ ByteBuffer inDup = in.slice();
+ inDup.limit(size-getSize());
+
+ CompoundTypeAssembler assembler = _assemblerFactory.newInstance();
+
+ assembler.init(count);
+
+ for(int i = 0; i < count; i++)
+ {
+ assembler.addItem(delegate.parse(in));
+ }
+
+ return assembler.complete();
+
+ }
+
+
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/CompoundWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,420 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class CompoundWriter<V> implements ValueWriter<V>
+{
+ private int _length;
+ private Registry _registry;
+ private static final int LARGE_COMPOUND_THRESHOLD_COUNT = 25;
+ private ValueWriter _delegate;
+ private Map<Class, ValueWriter> _writerCache = new HashMap<Class, ValueWriter>();
+
+ public CompoundWriter(final Registry registry)
+ {
+ _registry = registry;
+ }
+
+ enum State {
+ FORMAT_CODE,
+ SIZE_0,
+ SIZE_1,
+ SIZE_2,
+ SIZE_3,
+ COUNT_0,
+ COUNT_1,
+ COUNT_2,
+ COUNT_3,
+ DELEGATING,
+ DONE
+ }
+
+ private State _state = State.FORMAT_CODE;
+
+ public int writeToBuffer(ByteBuffer buffer)
+ {
+ return writeToBuffer(buffer, false);
+ }
+
+ public int writeToBuffer(ByteBuffer buffer, boolean large)
+ {
+ final int length = _length;
+
+ if(length == -1)
+ {
+ writeFirstPass(buffer, (large || getCount() > LARGE_COMPOUND_THRESHOLD_COUNT) ? 4 : 1);
+ if(_delegate != null && _delegate.isComplete())
+ {
+ _delegate = null;
+ }
+ }
+ else
+ {
+ //
+
+ final int size = (length & 0xFFFFFF00) == 0 ? 1 : 4;
+ final int count = getCount();
+ final int typeLength = length - (1+size);
+
+ State state = _state;
+
+ switch(state)
+ {
+ case FORMAT_CODE:
+ if(buffer.hasRemaining())
+ {
+ buffer.put(size == 1 ? getSingleOctetEncodingCode(): getFourOctetEncodingCode());
+ state = State.SIZE_0;
+ }
+ else
+ {
+ break;
+ }
+
+ case SIZE_0:
+ if(size == 4)
+ {
+ if(buffer.remaining()>=4)
+ {
+ buffer.putInt(typeLength);
+ state = State.COUNT_0;
+ }
+ }
+ else if(size == 1)
+ {
+ if(buffer.hasRemaining())
+ {
+ buffer.put((byte)(typeLength));
+ state = State.COUNT_0;
+ }
+ else
+ {
+ break;
+ }
+
+ }
+ case SIZE_1:
+ case SIZE_2:
+ if(state != State.COUNT_0 && buffer.remaining() >= 2)
+ {
+ buffer.putShort((short)(((typeLength) >> ((3-state.ordinal())<<3)) & 0xFFFF ));
+ state = (state == State.SIZE_0)
+ ? State.SIZE_2
+ : (state == State.SIZE_1)
+ ? State.SIZE_3
+ : State.COUNT_0;
+ }
+ case SIZE_3:
+ if(state != State.COUNT_0 && buffer.hasRemaining())
+ {
+ buffer.put((byte)(((typeLength) >> ((4-state.ordinal())<<3)) & 0xFF ));
+ state = (state == State.SIZE_0)
+ ? State.SIZE_1
+ : (state == State.SIZE_1)
+ ? State.SIZE_2
+ : (state == State.SIZE_2)
+ ? State.SIZE_3
+ : State.COUNT_0;
+ }
+ case COUNT_0:
+ if(size == 4)
+ {
+ if(buffer.remaining()>=4)
+ {
+ buffer.putInt(count);
+ state = State.DELEGATING;
+ }
+ }
+ else if(size == 1)
+ {
+ if(buffer.hasRemaining())
+ {
+ buffer.put((byte)count);
+ state = State.DELEGATING;
+ }
+ else
+ {
+ break;
+ }
+
+ }
+
+ case COUNT_1:
+ case COUNT_2:
+ if(state != State.DELEGATING && buffer.remaining() >= 2)
+ {
+ buffer.putShort((short)((count >> ((7-state.ordinal())<<3)) & 0xFFFF ));
+ state = state == State.COUNT_0
+ ? State.COUNT_2
+ : state == State.COUNT_1
+ ? State.COUNT_3
+ : State.DELEGATING;
+ }
+ case COUNT_3:
+ if(state != State.DELEGATING && buffer.hasRemaining())
+ {
+ buffer.put((byte)((count >> ((8-state.ordinal())<<3)) & 0xFF ));
+ state = state == State.COUNT_0
+ ? State.COUNT_1
+ : state == State.COUNT_1
+ ? State.COUNT_2
+ : state == State.COUNT_2
+ ? State.COUNT_3
+ : State.DELEGATING;
+ }
+ case DELEGATING:
+ while(state == State.DELEGATING && buffer.hasRemaining())
+ {
+ if(_delegate == null || _delegate.isComplete())
+ {
+ if(hasNext())
+ {
+ Object val = next();
+ _delegate = _registry.getValueWriter(val);
+ }
+ else
+ {
+ state = State.DONE;
+ break;
+ }
+ }
+ _delegate.writeToBuffer(buffer);
+ }
+ }
+
+ _state = state;
+
+ }
+
+ return _length;
+ }
+
+ private void writeFirstPass(ByteBuffer buffer, int size)
+ {
+
+ State state = State.FORMAT_CODE;
+ /*ByteBuffer origBuffer = buffer;
+ buffer = buffer.duplicate();*/
+ int origPosition = buffer.position();
+ int length ;
+
+
+ if(size == 4)
+ {
+ if(buffer.hasRemaining())
+ {
+ buffer.put(getFourOctetEncodingCode());
+
+ // Skip the size - we will come back and patch this
+ if(buffer.remaining() >= 4 )
+ {
+ buffer.position(buffer.position()+4);
+ state = State.COUNT_0;
+ }
+ else
+ {
+ state = State.values()[buffer.remaining()+1];
+ buffer.position(buffer.limit());
+ }
+
+
+ switch(buffer.remaining())
+ {
+ case 0:
+ break;
+ case 1:
+ buffer.put((byte)((getCount() >> 24) & 0xFF));
+ state = State.COUNT_1;
+ break;
+ case 2:
+ buffer.putShort((short)((getCount() >> 16) & 0xFFFF));
+ state = State.COUNT_2;
+ break;
+ case 3:
+ buffer.putShort((short)((getCount() >> 16) & 0xFFFF));
+ buffer.put((byte)((getCount() >> 8) & 0xFF));
+ state = State.COUNT_3;
+ break;
+ default:
+ buffer.putInt(getCount());
+ state = State.DELEGATING;
+ }
+
+
+
+ }
+ length = 9;
+
+
+
+ }
+ else
+ {
+ if(buffer.hasRemaining())
+ {
+ buffer.put(getSingleOctetEncodingCode());
+ if(buffer.hasRemaining())
+ {
+ // Size - we will come back and patch this
+ buffer.put((byte) 0);
+
+ if(buffer.hasRemaining())
+ {
+ buffer.put((byte)getCount());
+ state = State.DELEGATING;
+ }
+ else
+ {
+ state = State.COUNT_0;
+ }
+ }
+ else
+ {
+ state = State.SIZE_0;
+ }
+ }
+ length = 3;
+
+ }
+
+
+ int iterPos = -1;
+ for(int i = 0; i < getCount(); i++)
+ {
+ Object val = next();
+ ValueWriter writer = _registry.getValueWriter(val, _writerCache);
+ if(writer == null)
+ {
+ // TODO
+ System.out.println("no writer for " + val);
+ }
+ length += writer.writeToBuffer(buffer);
+ if(iterPos == -1 && !writer.isComplete())
+ {
+ iterPos = i;
+ _delegate = writer;
+ }
+
+ if(size == 1 && length > 255)
+ {
+ reset();
+ buffer.position(origPosition);
+ writeFirstPass(buffer, 4);
+ return;
+ }
+
+ }
+
+ // TODO - back-patch size
+ if(buffer.limit() - origPosition >= 2)
+ {
+ buffer.position(origPosition+1);
+ if(size == 1)
+ {
+ buffer.put((byte)((length & 0xFF)-2));
+ }
+ else
+ {
+ switch(buffer.remaining())
+ {
+ case 1:
+ buffer.put((byte)(((length-5) >> 24) & 0xFF));
+ break;
+ case 2:
+ buffer.putShort((short)(((length-5) >> 16) & 0xFFFF));
+ break;
+ case 3:
+ buffer.putShort((short)(((length-5) >> 16) & 0xFFFF));
+ buffer.put((byte)(((length-5) >> 8) & 0xFF));
+ break;
+ default:
+ buffer.putInt(length-5);
+ }
+ }
+ }
+
+ if(buffer.limit() - origPosition >= length)
+ {
+ buffer.position(origPosition+length);
+ state = State.DONE;
+ }
+ else
+ {
+ reset();
+ while(iterPos-- >= 0)
+ {
+ next();
+ }
+ buffer.position(buffer.limit());
+ }
+ _state = state;
+ _length = length;
+ }
+
+ protected abstract byte getFourOctetEncodingCode();
+
+ protected abstract byte getSingleOctetEncodingCode();
+
+ public void setValue(V value)
+ {
+ _length = -1;
+ _delegate = null;
+ _state = State.FORMAT_CODE;
+ onSetValue(value);
+ }
+
+ public void setRegistry(Registry registry)
+ {
+ _registry = registry;
+ }
+
+ public Registry getRegistry()
+ {
+ return _registry;
+ }
+
+ protected abstract void onSetValue(final V value);
+
+ protected abstract int getCount();
+
+ protected abstract boolean hasNext();
+
+ protected abstract Object next();
+
+ protected abstract void clear();
+
+ protected abstract void reset();
+
+ public boolean isCacheable()
+ {
+ return false;
+ }
+
+ public boolean isComplete()
+ {
+ return _state == State.DONE;
+ }
+}
\ No newline at end of file
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DecimalConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DecimalConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DecimalConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DecimalConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,230 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+
+public abstract class DecimalConstructor implements TypeConstructor<BigDecimal>
+{
+
+ private static final DecimalConstructor DECIMAL_32 = new DecimalConstructor()
+ {
+
+ public BigDecimal construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+
+
+ int val;
+
+ if(in.remaining()>=4)
+ {
+ val = in.getInt();
+ }
+ else
+ {
+ throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal32: insufficient input data");
+ }
+
+ return constructFrom32(val);}
+
+ };
+
+
+ private static final DecimalConstructor DECIMAL_64 = new DecimalConstructor()
+ {
+
+ public BigDecimal construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ long val;
+
+ if(in.remaining()>=8)
+ {
+ val = in.getLong();
+ }
+ else
+ {
+ throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal64: insufficient input data");
+ }
+
+ return constructFrom64(val);
+
+ }
+
+ };
+
+
+ private static final DecimalConstructor DECIMAL_128 = new DecimalConstructor()
+ {
+
+ public BigDecimal construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+ {
+ long high;
+ long low;
+
+ if(in.remaining()>=16)
+ {
+ high = in.getLong();
+ low = in.getLong();
+ }
+ else
+ {
+ throw new AmqpErrorException(ConnectionError.FRAMING_ERROR, "Cannot construct decimal128: insufficient input data");
+ }
+
+ return constructFrom128(high, low);
+
+ }
+
+ };
+
+ private static final BigDecimal TWO_TO_THE_SIXTY_FOUR = new BigDecimal(2).pow(64);
+
+ private static BigDecimal constructFrom128(long high, long low)
+ {
+ int sign = ((high & 0x8000000000000000l) == 0) ? 1 : -1;
+
+ int exponent = 0;
+ long significand = high;
+
+ if((high & 0x6000000000000000l) != 0x6000000000000000l)
+ {
+ exponent = ((int) ((high & 0x7FFE000000000000l) >> 49)) - 6176;
+ significand = high & 0x0001ffffffffffffl;
+ }
+ else if((high & 0x7800000000000000l) != 0x7800000000000000l)
+ {
+ exponent = ((int)((high & 0x1fff800000000000l)>>47)) - 6176;
+ significand = (0x00007fffffffffffl & high) | 0x0004000000000000l;
+ }
+ else
+ {
+ // NaN or infinite
+ return null;
+ }
+
+
+ BigDecimal bigDecimal = new BigDecimal(significand).multiply(TWO_TO_THE_SIXTY_FOUR);
+ if(low >=0)
+ {
+ bigDecimal = bigDecimal.add(new BigDecimal(low));
+ }
+ else
+ {
+ bigDecimal = bigDecimal.add(TWO_TO_THE_SIXTY_FOUR.add(new BigDecimal(low)));
+ }
+ if(((high & 0x8000000000000000l) != 0))
+ {
+ bigDecimal = bigDecimal.negate();
+ }
+ bigDecimal = bigDecimal.scaleByPowerOfTen(exponent);
+ return bigDecimal;
+ }
+
+
+ private static BigDecimal constructFrom64(final long val)
+ {
+ int sign = ((val & 0x8000000000000000l) == 0) ? 1 : -1;
+
+ int exponent = 0;
+ long significand = val;
+
+ if((val & 0x6000000000000000l) != 0x6000000000000000l)
+ {
+ exponent = ((int) ((val & 0x7FE0000000000000l) >> 53)) - 398;
+ significand = val & 0x001fffffffffffffl;
+ }
+ else if((val & 0x7800000000000000l) != 0x7800000000000000l)
+ {
+ exponent = ((int)((val & 0x1ff8000000000000l)>>51)) - 398;
+ significand = (0x0007ffffffffffffl & val) | 0x0020000000000000l;
+ }
+ else
+ {
+ // NaN or infinite
+ return null;
+ }
+
+ BigDecimal bigDecimal = new BigDecimal(sign * significand);
+ bigDecimal = bigDecimal.scaleByPowerOfTen(exponent);
+ return bigDecimal;
+ }
+
+ private static BigDecimal constructFrom32(final int val)
+ {
+ int sign = ((val & 0x80000000) == 0) ? 1 : -1;
+
+ int exponent = 0;
+ int significand = val;
+
+ if((val & 0x60000000) != 0x60000000)
+ {
+ exponent = ((int) ((val & 0x7F800000) >> 23)) - 101;
+ significand = val & 0x007fffffff;
+ }
+ else if((val & 0x78000000) != 0x78000000)
+ {
+ exponent = ((int)((val & 0x1fe00000)>>21)) - 101;
+ significand = (0x001fffff & val) | 0x00800000;
+ }
+ else
+ {
+ // NaN or infinite
+ return null;
+ }
+
+ BigDecimal bigDecimal = new BigDecimal(sign * significand);
+ bigDecimal = bigDecimal.scaleByPowerOfTen(exponent);
+ return bigDecimal;
+ }
+
+/*
+
+ public static void main(String[] args)
+ {
+ System.out.println(constructFrom128(0l,0l));
+ System.out.println(constructFrom128(0x3041ED09BEAD87C0l,0x378D8E63FFFFFFFFl));
+ System.out.println(constructFrom64(0l));
+ System.out.println(constructFrom64(0x5fe0000000000001l));
+ System.out.println(constructFrom64(0xec7386F26FC0FFFFl));
+ System.out.println(constructFrom32(0));
+ System.out.println(constructFrom32(0x6cb8967f));
+
+ }
+*/
+
+ public static TypeConstructor getDecimal32Instance()
+ {
+ return DECIMAL_32;
+ }
+
+ public static TypeConstructor getDecimal64Instance()
+ {
+ return DECIMAL_64;
+ }
+
+ public static TypeConstructor getDecimal128Instance()
+ {
+ return DECIMAL_128;
+ }
+}
Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DefaultDescribedTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DefaultDescribedTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DefaultDescribedTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DefaultDescribedTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class DefaultDescribedTypeConstructor extends DescribedTypeConstructor
+{
+ private Object _descriptor;
+
+ public DefaultDescribedTypeConstructor(final Object descriptor)
+ {
+ _descriptor = descriptor;
+ }
+
+ public Object construct(final Object underlying)
+ {
+ return new DescribedType(_descriptor, underlying);
+ }
+
+
+ public static void main(String[] args) throws IOException, ParseException
+ {
+ LineNumberReader reader = new LineNumberReader(new InputStreamReader(System.in));
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
+ String line;
+ Pattern pattern = Pattern.compile("^\\d+ (\\d{4}-\\d{2}-\\d{2} \\d\\d:\\d\\d:\\d\\d,\\d\\d\\d)");
+
+ long prevTime = Long.MAX_VALUE;
+
+ while((line = reader.readLine()) != null)
+ {
+ Matcher m = pattern.matcher(line);
+ if(m.matches())
+ {
+ String timeStr = m.group(1);
+ long time = df.parse(timeStr).getTime();
+ if(time - prevTime > 20000)
+ {
+ System.out.println(df.format(prevTime) + " - " + df.format(time));
+ }
+ prevTime = time;
+ }
+ }
+ }
+}
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org