http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java deleted file mode 100644 index 71199bb..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java +++ /dev/null @@ -1,1074 +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.proton.codec.impl; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.Date; -import java.util.UUID; - -import org.apache.qpid.proton.amqp.*; -import org.apache.qpid.proton.codec.Data; - -class DataDecoder -{ - - private static final Charset ASCII = Charset.forName("US-ASCII"); - private static final Charset UTF_8 = Charset.forName("UTF-8"); - - private static final TypeConstructor[] _constructors = new TypeConstructor[256]; - - static - { - - _constructors[0x00] = new DescribedTypeConstructor(); - - _constructors[0x40] = new NullConstructor(); - _constructors[0x41] = new TrueConstructor(); - _constructors[0x42] = new FalseConstructor(); - _constructors[0x43] = new UInt0Constructor(); - _constructors[0x44] = new ULong0Constructor(); - _constructors[0x45] = new EmptyListConstructor(); - - _constructors[0x50] = new UByteConstructor(); - _constructors[0x51] = new ByteConstructor(); - _constructors[0x52] = new SmallUIntConstructor(); - _constructors[0x53] = new SmallULongConstructor(); - _constructors[0x54] = new SmallIntConstructor(); - _constructors[0x55] = new SmallLongConstructor(); - _constructors[0x56] = new BooleanConstructor(); - - _constructors[0x60] = new UShortConstructor(); - _constructors[0x61] = new ShortConstructor(); - - _constructors[0x70] = new UIntConstructor(); - _constructors[0x71] = new IntConstructor(); - _constructors[0x72] = new FloatConstructor(); - _constructors[0x73] = new CharConstructor(); - _constructors[0x74] = new Decimal32Constructor(); - - _constructors[0x80] = new ULongConstructor(); - _constructors[0x81] = new LongConstructor(); - _constructors[0x82] = new DoubleConstructor(); - _constructors[0x83] = new TimestampConstructor(); - _constructors[0x84] = new Decimal64Constructor(); - - _constructors[0x94] = new Decimal128Constructor(); - _constructors[0x98] = new UUIDConstructor(); - - _constructors[0xa0] = new SmallBinaryConstructor(); - _constructors[0xa1] = new SmallStringConstructor(); - _constructors[0xa3] = new SmallSymbolConstructor(); - - _constructors[0xb0] = new BinaryConstructor(); - _constructors[0xb1] = new StringConstructor(); - _constructors[0xb3] = new SymbolConstructor(); - - _constructors[0xc0] = new SmallListConstructor(); - _constructors[0xc1] = new SmallMapConstructor(); - - - _constructors[0xd0] = new ListConstructor(); - _constructors[0xd1] = new MapConstructor(); - - _constructors[0xe0] = new SmallArrayConstructor(); - _constructors[0xf0] = new ArrayConstructor(); - - } - - private interface TypeConstructor - { - Data.DataType getType(); - - int size(ByteBuffer b); - - void parse(ByteBuffer b, Data data); - } - - - static int decode(ByteBuffer b, Data data) - { - if(b.hasRemaining()) - { - int position = b.position(); - TypeConstructor c = readConstructor(b); - final int size = c.size(b); - if(b.remaining() >= size) - { - c.parse(b, data); - return 1+size; - } - else - { - b.position(position); - return -4; - } - } - return 0; - } - - private static TypeConstructor readConstructor(ByteBuffer b) - { - int index = b.get() & 0xff; - TypeConstructor tc = _constructors[index]; - if(tc == null) - { - throw new IllegalArgumentException("No constructor for type " + index); - } - return tc; - } - - - private static class NullConstructor implements TypeConstructor - { - @Override - public Data.DataType getType() - { - return Data.DataType.NULL; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putNull(); - } - } - - private static class TrueConstructor implements TypeConstructor - { - @Override - public Data.DataType getType() - { - return Data.DataType.BOOL; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putBoolean(true); - } - } - - - private static class FalseConstructor implements TypeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.BOOL; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putBoolean(false); - } - } - - private static class UInt0Constructor implements TypeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.UINT; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedInteger(UnsignedInteger.ZERO); - } - } - - private static class ULong0Constructor implements TypeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.ULONG; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedLong(UnsignedLong.ZERO); - } - } - - - private static class EmptyListConstructor implements TypeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.LIST; - } - - @Override - public int size(ByteBuffer b) - { - return 0; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putList(); - } - } - - - private static abstract class Fixed0SizeConstructor implements TypeConstructor - { - @Override - public final int size(ByteBuffer b) - { - return 0; - } - } - - private static abstract class Fixed1SizeConstructor implements TypeConstructor - { - @Override - public int size(ByteBuffer b) - { - return 1; - } - } - - private static abstract class Fixed2SizeConstructor implements TypeConstructor - { - @Override - public int size(ByteBuffer b) - { - return 2; - } - } - - private static abstract class Fixed4SizeConstructor implements TypeConstructor - { - @Override - public int size(ByteBuffer b) - { - return 4; - } - } - - private static abstract class Fixed8SizeConstructor implements TypeConstructor - { - @Override - public int size(ByteBuffer b) - { - return 8; - } - } - - private static abstract class Fixed16SizeConstructor implements TypeConstructor - { - @Override - public int size(ByteBuffer b) - { - return 16; - } - } - - private static class UByteConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.UBYTE; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedByte(UnsignedByte.valueOf(b.get())); - } - } - - private static class ByteConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.BYTE; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putByte(b.get()); - } - } - - private static class SmallUIntConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.UINT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedInteger(UnsignedInteger.valueOf(((int) b.get()) & 0xff)); - } - } - - private static class SmallIntConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.INT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putInt(b.get()); - } - } - - private static class SmallULongConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.ULONG; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedLong(UnsignedLong.valueOf(((int) b.get()) & 0xff)); - } - } - - private static class SmallLongConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.LONG; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putLong(b.get()); - } - } - - private static class BooleanConstructor extends Fixed1SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.BOOL; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int i = b.get(); - if(i != 0 && i != 1) - { - throw new IllegalArgumentException("Illegal value " + i + " for boolean"); - } - data.putBoolean(i == 1); - } - } - - private static class UShortConstructor extends Fixed2SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.USHORT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedShort(UnsignedShort.valueOf(b.getShort())); - } - } - - private static class ShortConstructor extends Fixed2SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.SHORT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putShort(b.getShort()); - } - } - - private static class UIntConstructor extends Fixed4SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.UINT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedInteger(UnsignedInteger.valueOf(b.getInt())); - } - } - - private static class IntConstructor extends Fixed4SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.INT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putInt(b.getInt()); - } - } - - private static class FloatConstructor extends Fixed4SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.FLOAT; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putFloat(b.getFloat()); - } - } - - private static class CharConstructor extends Fixed4SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.CHAR; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putChar(b.getInt()); - } - } - - private static class Decimal32Constructor extends Fixed4SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.DECIMAL32; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putDecimal32(new Decimal32(b.getInt())); - } - } - - private static class ULongConstructor extends Fixed8SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.ULONG; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUnsignedLong(UnsignedLong.valueOf(b.getLong())); - } - } - - private static class LongConstructor extends Fixed8SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.LONG; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putLong(b.getLong()); - } - } - - private static class DoubleConstructor extends Fixed8SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.DOUBLE; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putDouble(b.getDouble()); - } - } - - private static class TimestampConstructor extends Fixed8SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.TIMESTAMP; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putTimestamp(new Date(b.getLong())); - } - } - - private static class Decimal64Constructor extends Fixed8SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.DECIMAL64; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putDecimal64(new Decimal64(b.getLong())); - } - } - - private static class Decimal128Constructor extends Fixed16SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.DECIMAL128; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putDecimal128(new Decimal128(b.getLong(), b.getLong())); - } - } - - private static class UUIDConstructor extends Fixed16SizeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.UUID; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putUUID(new UUID(b.getLong(), b.getLong())); - } - } - - private static abstract class SmallVariableConstructor implements TypeConstructor - { - - @Override - public int size(ByteBuffer b) - { - int position = b.position(); - if(b.hasRemaining()) - { - int size = b.get() & 0xff; - b.position(position); - - return size+1; - } - else - { - return 1; - } - } - - } - - private static abstract class VariableConstructor implements TypeConstructor - { - - @Override - public int size(ByteBuffer b) - { - int position = b.position(); - if(b.remaining()>=4) - { - int size = b.getInt(); - b.position(position); - - return size+4; - } - else - { - return 4; - } - } - - } - - - private static class SmallBinaryConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.BINARY; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.get() & 0xff; - byte[] bytes = new byte[size]; - b.get(bytes); - data.putBinary(bytes); - } - } - - private static class SmallSymbolConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.SYMBOL; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.get() & 0xff; - byte[] bytes = new byte[size]; - b.get(bytes); - data.putSymbol(Symbol.valueOf(new String(bytes, ASCII))); - } - } - - - private static class SmallStringConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.STRING; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.get() & 0xff; - byte[] bytes = new byte[size]; - b.get(bytes); - data.putString(new String(bytes, UTF_8)); - } - } - - private static class BinaryConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.BINARY; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.getInt(); - byte[] bytes = new byte[size]; - b.get(bytes); - data.putBinary(bytes); - } - } - - private static class SymbolConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.SYMBOL; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.getInt(); - byte[] bytes = new byte[size]; - b.get(bytes); - data.putSymbol(Symbol.valueOf(new String(bytes, ASCII))); - } - } - - - private static class StringConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.STRING; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.getInt(); - byte[] bytes = new byte[size]; - b.get(bytes); - data.putString(new String(bytes, UTF_8)); - } - } - - - private static class SmallListConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.LIST; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.get() & 0xff; - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.get() & 0xff; - data.putList(); - parseChildren(data, buf, count); - } - } - - - private static class SmallMapConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.MAP; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.get() & 0xff; - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.get() & 0xff; - data.putMap(); - parseChildren(data, buf, count); - } - } - - - private static class ListConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.LIST; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.getInt(); - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.getInt(); - data.putList(); - parseChildren(data, buf, count); - } - } - - - private static class MapConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.MAP; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - int size = b.getInt(); - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.getInt(); - data.putMap(); - parseChildren(data, buf, count); - } - } - - - private static void parseChildren(Data data, ByteBuffer buf, int count) - { - data.enter(); - for(int i = 0; i < count; i++) - { - TypeConstructor c = readConstructor(buf); - final int size = c.size(buf); - final int remaining = buf.remaining(); - if(size <= remaining) - { - c.parse(buf, data); - } - else - { - throw new IllegalArgumentException("Malformed data"); - } - - } - data.exit(); - } - - private static class DescribedTypeConstructor implements TypeConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.DESCRIBED; - } - - @Override - public int size(ByteBuffer b) - { - ByteBuffer buf = b.slice(); - if(buf.hasRemaining()) - { - TypeConstructor c = readConstructor(buf); - int size = c.size(buf); - if(buf.remaining()>size) - { - buf.position(size + 1); - c = readConstructor(buf); - return size + 2 + c.size(buf); - } - else - { - return size + 2; - } - } - else - { - return 1; - } - - } - - @Override - public void parse(ByteBuffer b, Data data) - { - data.putDescribed(); - data.enter(); - TypeConstructor c = readConstructor(b); - c.parse(b, data); - c = readConstructor(b); - c.parse(b, data); - data.exit(); - } - } - - private static class SmallArrayConstructor extends SmallVariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.ARRAY; - } - - @Override - public void parse(ByteBuffer b, Data data) - { - - int size = b.get() & 0xff; - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.get() & 0xff; - parseArray(data, buf, count); - } - - } - - private static class ArrayConstructor extends VariableConstructor - { - - @Override - public Data.DataType getType() - { - return Data.DataType.ARRAY; - } - - - @Override - public void parse(ByteBuffer b, Data data) - { - - int size = b.getInt(); - ByteBuffer buf = b.slice(); - buf.limit(size); - b.position(b.position()+size); - int count = buf.getInt(); - parseArray(data, buf, count); - } - } - - private static void parseArray(Data data, ByteBuffer buf, int count) - { - byte type = buf.get(); - boolean isDescribed = type == (byte)0x00; - int descriptorPosition = buf.position(); - if(isDescribed) - { - TypeConstructor descriptorTc = readConstructor(buf); - buf.position(buf.position()+descriptorTc.size(buf)); - type = buf.get(); - if(type == (byte)0x00) - { - throw new IllegalArgumentException("Malformed array data"); - } - - } - TypeConstructor tc = _constructors[type&0xff]; - - data.putArray(isDescribed, tc.getType()); - data.enter(); - if(isDescribed) - { - int position = buf.position(); - buf.position(descriptorPosition); - TypeConstructor descriptorTc = readConstructor(buf); - descriptorTc.parse(buf,data); - buf.position(position); - } - for(int i = 0; i<count; i++) - { - tc.parse(buf,data); - } - - data.exit(); - } - -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java deleted file mode 100644 index 5f430ba..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java +++ /dev/null @@ -1,928 +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.proton.codec.impl; - -import java.nio.ByteBuffer; -import java.util.*; - -import org.apache.qpid.proton.ProtonUnsupportedOperationException; -import org.apache.qpid.proton.amqp.*; -import org.apache.qpid.proton.codec.Data; - - -public class DataImpl implements Data -{ - - private Element _first; - private Element _current; - private Element _parent; - - - public DataImpl() - { - } - - @Override - public void free() - { - _first = null; - _current = null; - - } - - @Override - public void clear() - { - _first=null; - _current=null; - _parent=null; - } - - @Override - public long size() - { - return _first == null ? 0 : _first.size(); - } - - @Override - public void rewind() - { - _current = null; - _parent = null; - } - - @Override - public DataType next() - { - Element next = _current == null ? (_parent == null ? _first : _parent.child()) : _current.next(); - - if(next != null) - { - _current = next; - } - return next == null ? null : next.getDataType(); - } - - @Override - public DataType prev() - { - Element prev = _current == null ? null : _current.prev(); - - _current = prev; - return prev == null ? null : prev.getDataType(); - } - - @Override - public boolean enter() - { - if(_current != null && _current.canEnter()) - { - - _parent = _current; - _current = null; - return true; - } - return false; - } - - @Override - public boolean exit() - { - if(_parent != null) - { - Element parent = _parent; - _current = parent; - _parent = _current.parent(); - return true; - - } - return false; - } - - @Override - public boolean lookup(String name) - { - // TODO - throw new ProtonUnsupportedOperationException(); - - } - - @Override - public DataType type() - { - return _current == null ? null : _current.getDataType(); - } - - @Override - public long encodedSize() - { - int size = 0; - Element elt = _first; - while(elt != null) - { - size += elt.size(); - elt = elt.next(); - } - return size; - } - - @Override - public Binary encode() - { - byte[] data = new byte[(int)encodedSize()]; - ByteBuffer buf = ByteBuffer.wrap(data); - encode(buf); - - return new Binary(data); - } - - @Override - public long encode(ByteBuffer buf) - { - Element elt = _first; - int size = 0; - while(elt != null ) - { - final int eltSize = elt.size(); - if(eltSize <= buf.remaining()) - { - size += elt.encode(buf); - } - else - { - size+= eltSize; - } - elt = elt.next(); - } - return size; - } - - @Override - public long decode(ByteBuffer buf) - { - return DataDecoder.decode(buf, this); - } - - - private void putElement(Element element) - { - if(_first == null) - { - _first = element; - } - else - { - if(_current == null) - { - if (_parent == null) { - _first = _first.replaceWith(element); - element = _first; - } else { - element = _parent.addChild(element); - } - } - else - { - if(_parent!=null) - { - element = _parent.checkChild(element); - } - _current.setNext(element); - } - } - - _current = element; - } - - @Override - public void putList() - { - putElement(new ListElement(_parent, _current)); - } - - @Override - public void putMap() - { - putElement(new MapElement(_parent, _current)); - } - - @Override - public void putArray(boolean described, DataType type) - { - putElement(new ArrayElement(_parent, _current, described, type)); - - } - - @Override - public void putDescribed() - { - putElement(new DescribedTypeElement(_parent, _current)); - } - - @Override - public void putNull() - { - putElement(new NullElement(_parent, _current)); - - } - - @Override - public void putBoolean(boolean b) - { - putElement(new BooleanElement(_parent, _current, b)); - } - - @Override - public void putUnsignedByte(UnsignedByte ub) - { - putElement(new UnsignedByteElement(_parent, _current, ub)); - - } - - @Override - public void putByte(byte b) - { - putElement(new ByteElement(_parent, _current, b)); - } - - @Override - public void putUnsignedShort(UnsignedShort us) - { - putElement(new UnsignedShortElement(_parent, _current, us)); - - } - - @Override - public void putShort(short s) - { - putElement(new ShortElement(_parent, _current, s)); - } - - @Override - public void putUnsignedInteger(UnsignedInteger ui) - { - putElement(new UnsignedIntegerElement(_parent, _current, ui)); - } - - @Override - public void putInt(int i) - { - putElement(new IntegerElement(_parent, _current, i)); - } - - @Override - public void putChar(int c) - { - putElement(new CharElement(_parent, _current, c)); - } - - @Override - public void putUnsignedLong(UnsignedLong ul) - { - putElement(new UnsignedLongElement(_parent, _current, ul)); - } - - @Override - public void putLong(long l) - { - putElement(new LongElement(_parent, _current, l)); - } - - @Override - public void putTimestamp(Date t) - { - putElement(new TimestampElement(_parent,_current,t)); - } - - @Override - public void putFloat(float f) - { - putElement(new FloatElement(_parent,_current,f)); - } - - @Override - public void putDouble(double d) - { - putElement(new DoubleElement(_parent,_current,d)); - } - - @Override - public void putDecimal32(Decimal32 d) - { - putElement(new Decimal32Element(_parent,_current,d)); - } - - @Override - public void putDecimal64(Decimal64 d) - { - putElement(new Decimal64Element(_parent,_current,d)); - } - - @Override - public void putDecimal128(Decimal128 d) - { - putElement(new Decimal128Element(_parent,_current,d)); - } - - @Override - public void putUUID(UUID u) - { - putElement(new UUIDElement(_parent,_current,u)); - } - - @Override - public void putBinary(Binary bytes) - { - putElement(new BinaryElement(_parent, _current, bytes)); - } - - @Override - public void putBinary(byte[] bytes) - { - putBinary(new Binary(bytes)); - } - - @Override - public void putString(String string) - { - putElement(new StringElement(_parent,_current,string)); - } - - @Override - public void putSymbol(Symbol symbol) - { - putElement(new SymbolElement(_parent,_current,symbol)); - } - - @Override - public void putObject(Object o) - { - if(o == null) - { - putNull(); - } - else if(o instanceof Boolean) - { - putBoolean((Boolean) o); - } - else if(o instanceof UnsignedByte) - { - putUnsignedByte((UnsignedByte)o); - } - else if(o instanceof Byte) - { - putByte((Byte)o); - } - else if(o instanceof UnsignedShort) - { - putUnsignedShort((UnsignedShort)o); - } - else if(o instanceof Short) - { - putShort((Short)o); - } - else if(o instanceof UnsignedInteger) - { - putUnsignedInteger((UnsignedInteger)o); - } - else if(o instanceof Integer) - { - putInt((Integer)o); - } - else if(o instanceof Character) - { - putChar((Character)o); - } - else if(o instanceof UnsignedLong) - { - putUnsignedLong((UnsignedLong)o); - } - else if(o instanceof Long) - { - putLong((Long)o); - } - else if(o instanceof Date) - { - putTimestamp((Date)o); - } - else if(o instanceof Float) - { - putFloat((Float)o); - } - else if(o instanceof Double) - { - putDouble((Double)o); - } - else if(o instanceof Decimal32) - { - putDecimal32((Decimal32)o); - } - else if(o instanceof Decimal64) - { - putDecimal64((Decimal64)o); - } - else if(o instanceof Decimal128) - { - putDecimal128((Decimal128)o); - } - else if(o instanceof UUID) - { - putUUID((UUID)o); - } - else if(o instanceof Binary) - { - putBinary((Binary)o); - } - else if(o instanceof String) - { - putString((String)o); - } - else if(o instanceof Symbol) - { - putSymbol((Symbol)o); - } - else if(o instanceof DescribedType) - { - putDescribedType((DescribedType)o); - } - else if(o instanceof Symbol[]) - { - putArray(false, Data.DataType.SYMBOL); - enter(); - for(Symbol s : (Symbol[]) o) - { - putSymbol(s); - } - exit(); - } - else if(o instanceof Object[]) - { - putJavaArray((Object[]) o); - } - else if(o instanceof List) - { - putJavaList((List)o); - } - else if(o instanceof Map) - { - putJavaMap((Map)o); - } - else - { - throw new IllegalArgumentException("Unknown type " + o.getClass().getSimpleName()); - } - } - - @Override - public void putJavaMap(Map<Object, Object> map) - { - putMap(); - enter(); - for(Map.Entry<Object, Object> entry : map.entrySet()) - { - putObject(entry.getKey()); - putObject(entry.getValue()); - } - exit(); - - } - - @Override - public void putJavaList(List<Object> list) - { - putList(); - enter(); - for(Object o : list) - { - putObject(o); - } - exit(); - } - - @Override - public void putJavaArray(Object[] array) - { - // TODO - throw new ProtonUnsupportedOperationException(); - } - - @Override - public void putDescribedType(DescribedType dt) - { - putElement(new DescribedTypeElement(_parent,_current)); - enter(); - putObject(dt.getDescriptor()); - putObject(dt.getDescribed()); - exit(); - } - - @Override - public long getList() - { - if(_current instanceof ListElement) - { - return ((ListElement)_current).count(); - } - throw new IllegalStateException("Current value not list"); - } - - @Override - public long getMap() - { - if(_current instanceof MapElement) - { - return ((MapElement)_current).count(); - } - throw new IllegalStateException("Current value not map"); - } - - @Override - public long getArray() - { - if(_current instanceof ArrayElement) - { - return ((ArrayElement)_current).count(); - } - throw new IllegalStateException("Current value not array"); - } - - @Override - public boolean isArrayDescribed() - { - if(_current instanceof ArrayElement) - { - return ((ArrayElement)_current).isDescribed(); - } - throw new IllegalStateException("Current value not array"); - } - - @Override - public DataType getArrayType() - { - if(_current instanceof ArrayElement) - { - return ((ArrayElement)_current).getArrayDataType(); - } - throw new IllegalStateException("Current value not array"); - } - - @Override - public boolean isDescribed() - { - return _current != null && _current.getDataType() == DataType.DESCRIBED; - } - - @Override - public boolean isNull() - { - return _current != null && _current.getDataType() == DataType.NULL; - } - - @Override - public boolean getBoolean() - { - if(_current instanceof BooleanElement) - { - return ((BooleanElement)_current).getValue(); - } - throw new IllegalStateException("Current value not boolean"); - } - - @Override - public UnsignedByte getUnsignedByte() - { - - if(_current instanceof UnsignedByteElement) - { - return ((UnsignedByteElement)_current).getValue(); - } - throw new IllegalStateException("Current value not unsigned byte"); - } - - @Override - public byte getByte() - { - if(_current instanceof ByteElement) - { - return ((ByteElement)_current).getValue(); - } - throw new IllegalStateException("Current value not byte"); - } - - @Override - public UnsignedShort getUnsignedShort() - { - if(_current instanceof UnsignedShortElement) - { - return ((UnsignedShortElement)_current).getValue(); - } - throw new IllegalStateException("Current value not unsigned short"); - } - - @Override - public short getShort() - { - if(_current instanceof ShortElement) - { - return ((ShortElement)_current).getValue(); - } - throw new IllegalStateException("Current value not short"); - } - - @Override - public UnsignedInteger getUnsignedInteger() - { - if(_current instanceof UnsignedIntegerElement) - { - return ((UnsignedIntegerElement)_current).getValue(); - } - throw new IllegalStateException("Current value not unsigned integer"); - } - - @Override - public int getInt() - { - if(_current instanceof IntegerElement) - { - return ((IntegerElement)_current).getValue(); - } - throw new IllegalStateException("Current value not integer"); - } - - @Override - public int getChar() - { - if(_current instanceof CharElement) - { - return ((CharElement)_current).getValue(); - } - throw new IllegalStateException("Current value not char"); - } - - @Override - public UnsignedLong getUnsignedLong() - { - if(_current instanceof UnsignedLongElement) - { - return ((UnsignedLongElement)_current).getValue(); - } - throw new IllegalStateException("Current value not unsigned long"); - } - - @Override - public long getLong() - { - if(_current instanceof LongElement) - { - return ((LongElement)_current).getValue(); - } - throw new IllegalStateException("Current value not long"); - } - - @Override - public Date getTimestamp() - { - if(_current instanceof TimestampElement) - { - return ((TimestampElement)_current).getValue(); - } - throw new IllegalStateException("Current value not timestamp"); - } - - @Override - public float getFloat() - { - if(_current instanceof FloatElement) - { - return ((FloatElement)_current).getValue(); - } - throw new IllegalStateException("Current value not float"); - } - - @Override - public double getDouble() - { - if(_current instanceof DoubleElement) - { - return ((DoubleElement)_current).getValue(); - } - throw new IllegalStateException("Current value not double"); - } - - @Override - public Decimal32 getDecimal32() - { - if(_current instanceof Decimal32Element) - { - return ((Decimal32Element)_current).getValue(); - } - throw new IllegalStateException("Current value not decimal32"); - } - - @Override - public Decimal64 getDecimal64() - { - if(_current instanceof Decimal64Element) - { - return ((Decimal64Element)_current).getValue(); - } - throw new IllegalStateException("Current value not decimal32"); - } - - @Override - public Decimal128 getDecimal128() - { - if(_current instanceof Decimal128Element) - { - return ((Decimal128Element)_current).getValue(); - } - throw new IllegalStateException("Current value not decimal32"); - } - - @Override - public UUID getUUID() - { - if(_current instanceof UUIDElement) - { - return ((UUIDElement)_current).getValue(); - } - throw new IllegalStateException("Current value not uuid"); - } - - @Override - public Binary getBinary() - { - if(_current instanceof BinaryElement) - { - return ((BinaryElement)_current).getValue(); - } - throw new IllegalStateException("Current value not binary"); - } - - @Override - public String getString() - { - if (_current instanceof StringElement) - { - return ((StringElement) _current).getValue(); - } - throw new IllegalStateException("Current value not string"); - } - - @Override - public Symbol getSymbol() - { - if(_current instanceof SymbolElement) - { - return ((SymbolElement)_current).getValue(); - } - throw new IllegalStateException("Current value not symbol"); - } - - @Override - public Object getObject() - { - return _current == null ? null : _current.getValue(); - } - - @Override - public Map<Object, Object> getJavaMap() - { - if(_current instanceof MapElement) - { - return ((MapElement)_current).getValue(); - } - throw new IllegalStateException("Current value not map"); - } - - @Override - public List<Object> getJavaList() - { - if(_current instanceof ListElement) - { - return ((ListElement)_current).getValue(); - } - throw new IllegalStateException("Current value not list"); - } - - @Override - public Object[] getJavaArray() - { - if(_current instanceof ArrayElement) - { - return ((ArrayElement)_current).getValue(); - } - throw new IllegalStateException("Current value not array"); - } - - @Override - public DescribedType getDescribedType() - { - if(_current instanceof DescribedTypeElement) - { - return ((DescribedTypeElement)_current).getValue(); - } - throw new IllegalStateException("Current value not described type"); - } - - @Override - public void copy(Data src) - { - // TODO - - throw new ProtonUnsupportedOperationException(); - } - - @Override - public void append(Data src) - { - // TODO - - throw new ProtonUnsupportedOperationException(); - } - - @Override - public void appendn(Data src, int limit) - { - // TODO - - throw new ProtonUnsupportedOperationException(); - } - - @Override - public void narrow() - { - // TODO - - throw new ProtonUnsupportedOperationException(); - } - - @Override - public void widen() - { - // TODO - - throw new ProtonUnsupportedOperationException(); - } - - - @Override - public String format() - { - StringBuilder sb = new StringBuilder(); - Element el = _first; - boolean first = true; - while (el != null) { - if (first) { - first = false; - } else { - sb.append(", "); - } - el.render(sb); - el = el.next(); - } - - return sb.toString(); - } - - private void render(StringBuilder sb, Element el) - { - if (el == null) return; - sb.append(" ").append(el).append("\n"); - if (el.canEnter()) { - render(sb, el.child()); - } - render(sb, el.next()); - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(); - render(sb, _first); - return String.format("Data[current=%h, parent=%h]{%n%s}", - System.identityHashCode(_current), - System.identityHashCode(_parent), - sb); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java deleted file mode 100644 index 433c10b..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java +++ /dev/null @@ -1,77 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.codec.Data; - -class Decimal128Element extends AtomicElement<Decimal128> -{ - - private final Decimal128 _value; - - Decimal128Element(Element parent, Element prev, Decimal128 d) - { - super(parent, prev); - _value = d; - } - - @Override - public int size() - { - return isElementOfArray() ? 16 : 17; - } - - @Override - public Decimal128 getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.DECIMAL128; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()>=size) - { - if(size == 17) - { - b.put((byte)0x94); - } - b.putLong(_value.getMostSignificantBits()); - b.putLong(_value.getLeastSignificantBits()); - return size; - } - else - { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal32Element.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal32Element.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal32Element.java deleted file mode 100644 index 4859a78..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal32Element.java +++ /dev/null @@ -1,76 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.codec.Data; - -class Decimal32Element extends AtomicElement<Decimal32> -{ - - private final Decimal32 _value; - - Decimal32Element(Element parent, Element prev, Decimal32 d) - { - super(parent, prev); - _value = d; - } - - @Override - public int size() - { - return isElementOfArray() ? 4 : 5; - } - - @Override - public Decimal32 getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.DECIMAL32; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()>=size) - { - if(size == 5) - { - b.put((byte)0x74); - } - b.putInt(_value.getBits()); - return size; - } - else - { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal64Element.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal64Element.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal64Element.java deleted file mode 100644 index cd8ce45..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Decimal64Element.java +++ /dev/null @@ -1,76 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.codec.Data; - -class Decimal64Element extends AtomicElement<Decimal64> -{ - - private final Decimal64 _value; - - Decimal64Element(Element parent, Element prev, Decimal64 d) - { - super(parent, prev); - _value = d; - } - - @Override - public int size() - { - return isElementOfArray() ? 8 : 9; - } - - @Override - public Decimal64 getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.DECIMAL64; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()>=size) - { - if(size == 9) - { - b.put((byte)0x84); - } - b.putLong(_value.getBits()); - return size; - } - else - { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeElement.java deleted file mode 100644 index 432cd21..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeElement.java +++ /dev/null @@ -1,176 +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.proton.codec.impl; - -import java.nio.ByteBuffer; -import java.util.AbstractSequentialList; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.codec.Data; - -class DescribedTypeElement extends AbstractElement<DescribedType> -{ - private Element _first; - - DescribedTypeElement(Element parent, Element prev) - { - super(parent, prev); - } - - - - - @Override - public int size() - { - int count = 0; - int size = 0; - Element elt = _first; - while(elt != null) - { - count++; - size += elt.size(); - elt = elt.next(); - } - - if(isElementOfArray()) - { - throw new IllegalArgumentException("Cannot add described type members to an array"); - } - else if(count > 2) - { - throw new IllegalArgumentException("Too many elements in described type"); - } - else if(count == 0) - { - size = 3; - } - else if(count == 1) - { - size += 2; - } - else - { - size+=1; - } - - return size; - } - - @Override - public DescribedType getValue() - { - final Object descriptor = _first == null ? null : _first.getValue(); - Element second = _first == null ? null : _first.next(); - final Object described = second == null ? null : second.getValue(); - return new DescribedTypeImpl(descriptor,described); - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.DESCRIBED; - } - - @Override - public int encode(ByteBuffer b) - { - int encodedSize = size(); - - if(encodedSize > b.remaining()) - { - return 0; - } - else - { - b.put((byte) 0); - if(_first == null) - { - b.put((byte)0x40); - b.put((byte)0x40); - } - else - { - _first.encode(b); - if(_first.next() == null) - { - b.put((byte)0x40); - } - else - { - _first.next().encode(b); - } - } - } - return encodedSize; - } - - @Override - public boolean canEnter() - { - return true; - } - - @Override - public Element child() - { - return _first; - } - - @Override - public void setChild(Element elt) - { - _first = elt; - } - - @Override - public Element checkChild(Element element) - { - if(element.prev() != _first) - { - throw new IllegalArgumentException("Described Type may only have two elements"); - } - return element; - - } - - @Override - public Element addChild(Element element) - { - _first = element; - return element; - } - - @Override - String startSymbol() { - return "("; - } - - @Override - String stopSymbol() { - return ")"; - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeImpl.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeImpl.java deleted file mode 100644 index a16595a..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeImpl.java +++ /dev/null @@ -1,90 +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.proton.codec.impl; - -import org.apache.qpid.proton.amqp.DescribedType; - -class DescribedTypeImpl implements DescribedType -{ - private final Object _descriptor; - private final Object _described; - - public DescribedTypeImpl(final Object descriptor, final Object described) - { - _descriptor = descriptor; - _described = described; - } - - @Override - public Object getDescriptor() - { - return _descriptor; - } - - @Override - public Object getDescribed() - { - return _described; - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - if (o == null || ! (o instanceof DescribedType)) - { - return false; - } - - DescribedType that = (DescribedType) o; - - if (_described != null ? !_described.equals(that.getDescribed()) : that.getDescribed() != null) - { - return false; - } - if (_descriptor != null ? !_descriptor.equals(that.getDescriptor()) : that.getDescriptor() != null) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - int result = _descriptor != null ? _descriptor.hashCode() : 0; - result = 31 * result + (_described != null ? _described.hashCode() : 0); - return result; - } - - @Override - public String toString() - { - return "{" + _descriptor + - ": " + _described + - '}'; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DoubleElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DoubleElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DoubleElement.java deleted file mode 100644 index b4c56bc..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DoubleElement.java +++ /dev/null @@ -1,75 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class DoubleElement extends AtomicElement<Double> -{ - - private final double _value; - - DoubleElement(Element parent, Element prev, double d) - { - super(parent, prev); - _value = d; - } - - @Override - public int size() - { - return isElementOfArray() ? 8 : 9; - } - - @Override - public Double getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.DOUBLE; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()>=size) - { - if(size == 9) - { - b.put((byte)0x82); - } - b.putDouble(_value); - return size; - } - else - { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Element.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Element.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Element.java deleted file mode 100644 index 492008d..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/Element.java +++ /dev/null @@ -1,53 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -interface Element<T> -{ - int size(); - T getValue(); - Data.DataType getDataType(); - int encode(ByteBuffer b); - Element next(); - Element prev(); - Element child(); - Element parent(); - - void setNext(Element elt); - void setPrev(Element elt); - void setParent(Element elt); - void setChild(Element elt); - - Element replaceWith(Element elt); - - Element addChild(Element element); - Element checkChild(Element element); - - boolean canEnter(); - - void render(StringBuilder sb); - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/FloatElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/FloatElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/FloatElement.java deleted file mode 100644 index d8c13c2..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/FloatElement.java +++ /dev/null @@ -1,75 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class FloatElement extends AtomicElement<Float> -{ - - private final float _value; - - FloatElement(Element parent, Element prev, float f) - { - super(parent, prev); - _value = f; - } - - @Override - public int size() - { - return isElementOfArray() ? 4 : 5; - } - - @Override - public Float getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.FLOAT; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()>=size) - { - if(size == 5) - { - b.put((byte)0x72); - } - b.putFloat(_value); - return size; - } - else - { - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/IntegerElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/IntegerElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/IntegerElement.java deleted file mode 100644 index 8e4f435..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/IntegerElement.java +++ /dev/null @@ -1,106 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class IntegerElement extends AtomicElement<Integer> -{ - - private final int _value; - - IntegerElement(Element parent, Element prev, int i) - { - super(parent, prev); - _value = i; - } - - @Override - public int size() - { - if(isElementOfArray()) - { - final ArrayElement parent = (ArrayElement) parent(); - if(parent.constructorType() == ArrayElement.SMALL) - { - if(-128 <= _value && _value <= 127) - { - return 1; - } - else - { - parent.setConstructorType(ArrayElement.LARGE); - return 4; - } - } - else - { - return 4; - } - } - else - { - return (-128 <= _value && _value <= 127) ? 2 : 5; - } - - } - - @Override - public Integer getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.INT; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(size <= b.remaining()) - { - switch(size) - { - case 2: - b.put((byte)0x54); - case 1: - b.put((byte)_value); - break; - - case 5: - b.put((byte)0x71); - case 4: - b.putInt(_value); - - } - - return size; - } - return 0; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ListElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ListElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ListElement.java deleted file mode 100644 index 6b2dde1..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ListElement.java +++ /dev/null @@ -1,237 +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.proton.codec.impl; - -import java.nio.ByteBuffer; -import java.util.*; - -import org.apache.qpid.proton.codec.Data; - -class ListElement extends AbstractElement<List<Object>> -{ - private Element _first; - - ListElement(Element parent, Element prev) - { - super(parent, prev); - } - - public int count() - { - int count = 0; - Element elt = _first; - while(elt != null) - { - count++; - elt = elt.next(); - } - return count; - } - - - @Override - public int size() - { - int count = 0; - int size = 0; - Element elt = _first; - while(elt != null) - { - count++; - size += elt.size(); - elt = elt.next(); - } - if(isElementOfArray()) - { - ArrayElement parent = (ArrayElement) parent(); - if(parent.constructorType() == ArrayElement.TINY) - { - if(count != 0) - { - parent.setConstructorType(ArrayElement.ConstructorType.SMALL); - size += 2; - } - } - else if(parent.constructorType() == ArrayElement.SMALL) - { - if(count > 255 || size > 254) - { - parent.setConstructorType(ArrayElement.ConstructorType.LARGE); - size += 8; - } - else - { - size += 2; - } - } - size += 8; - - } - else - { - if(count == 0) - { - size = 1; - } - else if(count <= 255 && size <= 254) - { - size += 3; - } - else - { - size+=9; - } - } - - return size; - } - - @Override - public List<Object> getValue() - { - List<Object> list = new ArrayList<Object>(); - Element elt = _first; - while(elt != null) - { - list.add(elt.getValue()); - elt = elt.next(); - } - - return Collections.unmodifiableList(list); - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.LIST; - } - - @Override - public int encode(ByteBuffer b) - { - int encodedSize = size(); - - int count = 0; - int size = 0; - Element elt = _first; - while(elt != null) - { - count++; - size += elt.size(); - elt = elt.next(); - } - - if(encodedSize > b.remaining()) - { - return 0; - } - else - { - if(isElementOfArray()) - { - switch(((ArrayElement)parent()).constructorType()) - { - case TINY: - break; - case SMALL: - b.put((byte)(size+1)); - b.put((byte)count); - break; - case LARGE: - b.putInt((size+4)); - b.putInt(count); - } - } - else - { - if(count == 0) - { - b.put((byte)0x45); - } - else if(size <= 254 && count <=255) - { - b.put((byte)0xc0); - b.put((byte)(size+1)); - b.put((byte)count); - } - else - { - b.put((byte)0xd0); - b.putInt((size+4)); - b.putInt(count); - } - - } - - elt = _first; - while(elt != null) - { - elt.encode(b); - elt = elt.next(); - } - - return encodedSize; - } - } - - @Override - public boolean canEnter() - { - return true; - } - - @Override - public Element child() - { - return _first; - } - - @Override - public void setChild(Element elt) - { - _first = elt; - } - - @Override - public Element checkChild(Element element) - { - return element; - } - - @Override - public Element addChild(Element element) - { - _first = element; - return element; - } - - @Override - String startSymbol() { - return "["; - } - - @Override - String stopSymbol() { - return "]"; - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/LongElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/LongElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/LongElement.java deleted file mode 100644 index e2e832d..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/LongElement.java +++ /dev/null @@ -1,103 +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.proton.codec.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class LongElement extends AtomicElement<Long> -{ - - private final long _value; - - LongElement(Element parent, Element prev, long l) - { - super(parent, prev); - _value = l; - } - - @Override - public int size() - { - if(isElementOfArray()) - { - final ArrayElement parent = (ArrayElement) parent(); - - if(parent.constructorType() == ArrayElement.SMALL) - { - if(-128l <= _value && _value <= 127l) - { - return 1; - } - else - { - parent.setConstructorType(ArrayElement.LARGE); - } - } - - return 8; - - } - else - { - return (-128l <= _value && _value <= 127l) ? 2 : 9; - } - - } - - @Override - public Long getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.LONG; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(size > b.remaining()) - { - return 0; - } - switch(size) - { - case 2: - b.put((byte)0x55); - case 1: - b.put((byte)_value); - break; - case 9: - b.put((byte)0x81); - case 8: - b.putLong(_value); - - } - return size; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/MapElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/MapElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/MapElement.java deleted file mode 100644 index 710e9f0..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/MapElement.java +++ /dev/null @@ -1,231 +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.proton.codec.impl; - -import java.nio.ByteBuffer; -import java.util.*; - -import org.apache.qpid.proton.codec.Data; - -class MapElement extends AbstractElement<Map<Object,Object>> -{ - private Element _first; - - MapElement(Element parent, Element prev) - { - super(parent, prev); - } - - - public int count() - { - int count = 0; - Element elt = _first; - while(elt != null) - { - count++; - elt = elt.next(); - } - return count; - } - - @Override - public int size() - { - int count = 0; - int size = 0; - Element elt = _first; - while(elt != null) - { - count++; - size += elt.size(); - elt = elt.next(); - } - if(isElementOfArray()) - { - ArrayElement parent = (ArrayElement) parent(); - - if(parent.constructorType() == ArrayElement.SMALL) - { - if(count > 255 || size > 254) - { - parent.setConstructorType(ArrayElement.ConstructorType.LARGE); - size += 8; - } - else - { - size += 2; - } - } - size += 8; - - } - else - { - if(count <= 255 && size <= 254) - { - size += 3; - } - else - { - size+=9; - } - } - - return size; - } - - @Override - public Map<Object,Object> getValue() - { - LinkedHashMap<Object,Object> map = new LinkedHashMap<Object,Object>(); - Element elt = _first; - while(elt != null) - { - Object key = elt.getValue(); - Object value; - elt = elt.next(); - if(elt != null) - { - value = elt.getValue(); - elt = elt.next(); - } - else - { - value = null; - } - map.put(key,value); - } - - return Collections.unmodifiableMap(map); - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.MAP; - } - - @Override - public int encode(ByteBuffer b) - { - int encodedSize = size(); - - int count = 0; - int size = 0; - Element elt = _first; - while(elt != null) - { - count++; - size += elt.size(); - elt = elt.next(); - } - - if(encodedSize > b.remaining()) - { - return 0; - } - else - { - if(isElementOfArray()) - { - switch(((ArrayElement)parent()).constructorType()) - { - case SMALL: - b.put((byte)(size+1)); - b.put((byte)count); - break; - case LARGE: - b.putInt((size+4)); - b.putInt(count); - } - } - else - { - if(size <= 254 && count <=255) - { - b.put((byte)0xc1); - b.put((byte)(size+1)); - b.put((byte)count); - } - else - { - b.put((byte)0xd1); - b.putInt((size+4)); - b.putInt(count); - } - - } - - elt = _first; - while(elt != null) - { - elt.encode(b); - elt = elt.next(); - } - - return encodedSize; - } - } - - @Override - public boolean canEnter() - { - return true; - } - - @Override - public Element child() - { - return _first; - } - - @Override - public void setChild(Element elt) - { - _first = elt; - } - - @Override - public Element checkChild(Element element) - { - return element; - } - - @Override - public Element addChild(Element element) - { - _first = element; - return element; - } - - @Override - String startSymbol() { - return "{"; - } - - @Override - String stopSymbol() { - return "}"; - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
