http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/BooleanType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/BooleanType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/BooleanType.java deleted file mode 100644 index d87dd19..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/BooleanType.java +++ /dev/null @@ -1,273 +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; - -import java.util.Arrays; -import java.util.Collection; - -public final class BooleanType extends AbstractPrimitiveType<Boolean> -{ - - private static final byte BYTE_0 = (byte) 0; - private static final byte BYTE_1 = (byte) 1; - - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _trueEncoder; - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _falseEncoder; - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _booleanEncoder; - - public static interface BooleanEncoding extends PrimitiveTypeEncoding<Boolean> - { - void write(boolean b); - void writeValue(boolean b); - - boolean readPrimitiveValue(); - } - - BooleanType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _trueEncoder = new TrueEncoding(encoder, decoder); - _falseEncoder = new FalseEncoding(encoder, decoder); - _booleanEncoder = new AllBooleanEncoding(encoder, decoder); - - encoder.register(Boolean.class, this); - decoder.register(this); - } - - public Class<Boolean> getTypeClass() - { - return Boolean.class; - } - - public BooleanEncoding getEncoding(final Boolean val) - { - return val ? _trueEncoder : _falseEncoder; - } - - public BooleanEncoding getEncoding(final boolean val) - { - return val ? _trueEncoder : _falseEncoder; - } - - public void writeValue(final boolean val) - { - getEncoding(val).write(val); - } - - - - - public BooleanEncoding getCanonicalEncoding() - { - return _booleanEncoder; - } - - public Collection<BooleanEncoding> getAllEncodings() - { - return Arrays.asList(_trueEncoder, _falseEncoder, _booleanEncoder); - } - - private class TrueEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements BooleanEncoding - { - - public TrueEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN_TRUE; - } - - public BooleanType getType() - { - return BooleanType.this; - } - - public void writeValue(final Boolean val) - { - } - - public void write(final boolean b) - { - writeConstructor(); - } - - public void writeValue(final boolean b) - { - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return encoding == this; - } - - public Boolean readValue() - { - return Boolean.TRUE; - } - - public boolean readPrimitiveValue() - { - return true; - } - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - - private class FalseEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements org.apache.qpid.proton.codec.BooleanType.BooleanEncoding - { - - public FalseEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN_FALSE; - } - - public BooleanType getType() - { - return BooleanType.this; - } - - public void writeValue(final Boolean val) - { - } - - public void write(final boolean b) - { - writeConstructor(); - } - - public void writeValue(final boolean b) - { - } - - public boolean readPrimitiveValue() - { - return false; - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return encoding == this; - } - - public Boolean readValue() - { - return Boolean.FALSE; - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - private class AllBooleanEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements BooleanEncoding - { - - public AllBooleanEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public BooleanType getType() - { - return BooleanType.this; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN; - } - - public void writeValue(final Boolean val) - { - getEncoder().writeRaw(val ? BYTE_1 : BYTE_0); - } - - public void write(final boolean val) - { - writeConstructor(); - getEncoder().writeRaw(val ? BYTE_1 : BYTE_0); - } - - public void writeValue(final boolean b) - { - getEncoder().writeRaw(b ? BYTE_1 : BYTE_0); - } - - public boolean readPrimitiveValue() - { - - return getDecoder().readRawByte() != BYTE_0; - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return (getType() == encoding.getType()); - } - - public Boolean readValue() - { - return readPrimitiveValue() ? Boolean.TRUE : Boolean.FALSE; - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferDecoder.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferDecoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferDecoder.java deleted file mode 100644 index 39718b7..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferDecoder.java +++ /dev/null @@ -1,30 +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; - -import java.nio.ByteBuffer; - -public interface ByteBufferDecoder extends Decoder -{ - public void setByteBuffer(ByteBuffer buffer); - - public int getByteBufferRemaining(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferEncoder.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferEncoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferEncoder.java deleted file mode 100644 index b773279..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteBufferEncoder.java +++ /dev/null @@ -1,28 +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; - -import java.nio.ByteBuffer; - -public interface ByteBufferEncoder extends Encoder -{ - public void setByteBuffer(ByteBuffer buf); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteType.java deleted file mode 100644 index b35f4f1..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ByteType.java +++ /dev/null @@ -1,129 +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; - -import java.util.Collection; -import java.util.Collections; - -public class ByteType extends AbstractPrimitiveType<Byte> -{ - private ByteEncoding _byteEncoding; - - ByteType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _byteEncoding = new ByteEncoding(encoder, decoder); - encoder.register(Byte.class, this); - decoder.register(this); - } - - public Class<Byte> getTypeClass() - { - return Byte.class; - } - - public ByteEncoding getEncoding(final Byte val) - { - return _byteEncoding; - } - - - public ByteEncoding getCanonicalEncoding() - { - return _byteEncoding; - } - - public Collection<ByteEncoding> getAllEncodings() - { - return Collections.singleton(_byteEncoding); - } - - public void writeType(byte b) - { - _byteEncoding.write(b); - } - - - public class ByteEncoding extends FixedSizePrimitiveTypeEncoding<Byte> - { - - public ByteEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BYTE; - } - - public ByteType getType() - { - return ByteType.this; - } - - public void writeValue(final Byte val) - { - getEncoder().writeRaw(val); - } - - - public void write(final byte val) - { - writeConstructor(); - getEncoder().writeRaw(val); - } - - public void writeValue(final byte val) - { - getEncoder().writeRaw(val); - } - - public boolean encodesSuperset(final TypeEncoding<Byte> encoding) - { - return (getType() == encoding.getType()); - } - - public Byte readValue() - { - return readPrimitiveValue(); - } - - public byte readPrimitiveValue() - { - return getDecoder().readRawByte(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/CharacterType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/CharacterType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/CharacterType.java deleted file mode 100644 index 8084495..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/CharacterType.java +++ /dev/null @@ -1,127 +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; - -import java.util.Collection; -import java.util.Collections; - -public class CharacterType extends AbstractPrimitiveType<Character> -{ - private CharacterEncoding _characterEncoding; - - CharacterType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _characterEncoding = new CharacterEncoding(encoder, decoder); - encoder.register(Character.class, this); - decoder.register(this); - } - - public Class<Character> getTypeClass() - { - return Character.class; - } - - public CharacterEncoding getEncoding(final Character val) - { - return _characterEncoding; - } - - - public CharacterEncoding getCanonicalEncoding() - { - return _characterEncoding; - } - - public Collection<CharacterEncoding> getAllEncodings() - { - return Collections.singleton(_characterEncoding); - } - - public void write(char c) - { - _characterEncoding.write(c); - } - - public class CharacterEncoding extends FixedSizePrimitiveTypeEncoding<Character> - { - - public CharacterEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.CHAR; - } - - public CharacterType getType() - { - return CharacterType.this; - } - - public void writeValue(final Character val) - { - getEncoder().writeRaw((int)val.charValue() & 0xffff); - } - - public void writeValue(final char val) - { - getEncoder().writeRaw((int)val & 0xffff); - } - - public void write(final char c) - { - writeConstructor(); - getEncoder().writeRaw((int)c & 0xffff); - - } - - public boolean encodesSuperset(final TypeEncoding<Character> encoding) - { - return (getType() == encoding.getType()); - } - - public Character readValue() - { - return readPrimitiveValue(); - } - - public char readPrimitiveValue() - { - return (char) (getDecoder().readRawInt() & 0xffff); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Codec.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Codec.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Codec.java deleted file mode 100644 index 1aa2143..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Codec.java +++ /dev/null @@ -1,40 +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; - -/** - * Codec - * - */ - -public final class Codec -{ - - private Codec() - { - } - - public static Data data(long capacity) - { - return Data.Factory.create(); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeWritableBuffer.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeWritableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeWritableBuffer.java deleted file mode 100644 index 5786924..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/CompositeWritableBuffer.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.apache.qpid.proton.codec; -/* - * - * 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. - * -*/ - - -import java.nio.ByteBuffer; - -public class CompositeWritableBuffer implements WritableBuffer -{ - private final WritableBuffer _first; - private final WritableBuffer _second; - - public CompositeWritableBuffer(WritableBuffer first, WritableBuffer second) - { - _first = first; - _second = second; - } - - public void put(byte b) - { - (_first.hasRemaining() ? _first : _second).put(b); - } - - public void putFloat(float f) - { - putInt(Float.floatToRawIntBits(f)); - } - - public void putDouble(double d) - { - putLong(Double.doubleToRawLongBits(d)); - } - - public void putShort(short s) - { - int remaining = _first.remaining(); - if(remaining >= 2) - { - _first.putShort(s); - } - else if(remaining ==0 ) - { - _second.putShort(s); - } - else - { - ByteBuffer wrap = ByteBuffer.wrap(new byte[2]); - wrap.putShort(s); - wrap.flip(); - put(wrap); - } - } - - public void putInt(int i) - { - int remaining = _first.remaining(); - if(remaining >= 4) - { - _first.putInt(i); - } - else if(remaining ==0 ) - { - _second.putInt(i); - } - else - { - ByteBuffer wrap = ByteBuffer.wrap(new byte[4]); - wrap.putInt(i); - wrap.flip(); - put(wrap); - } - } - - public void putLong(long l) - { - int remaining = _first.remaining(); - if(remaining >= 8) - { - _first.putLong(l); - } - else if(remaining ==0 ) - { - _second.putLong(l); - } - else - { - ByteBuffer wrap = ByteBuffer.wrap(new byte[8]); - wrap.putLong(l); - wrap.flip(); - put(wrap); - } - } - - public boolean hasRemaining() - { - return _first.hasRemaining() || _second.hasRemaining(); - } - - public int remaining() - { - return _first.remaining()+_second.remaining(); - } - - public int position() - { - return _first.position()+_second.position(); - } - - public int limit() - { - return _first.limit() + _second.limit(); - } - - public void position(int position) - { - int first_limit = _first.limit(); - if( position <= first_limit ) - { - _first.position(position); - _second.position(0); - } - else - { - _first.position(first_limit); - _second.position(position - first_limit); - } - } - - public void put(byte[] src, int offset, int length) - { - final int firstRemaining = _first.remaining(); - if(firstRemaining > 0) - { - if(firstRemaining >= length) - { - _first.put(src, offset, length); - return; - } - else - { - _first.put(src,offset, firstRemaining); - } - } - _second.put(src, offset+firstRemaining, length-firstRemaining); - } - - public void put(ByteBuffer payload) - { - int firstRemaining = _first.remaining(); - if(firstRemaining > 0) - { - if(firstRemaining >= payload.remaining()) - { - _first.put(payload); - return; - } - else - { - int limit = payload.limit(); - payload.limit(payload.position()+firstRemaining); - _first.put(payload); - payload.limit(limit); - } - } - _second.put(payload); - } - - @Override - public String toString() - { - return _first.toString() + " + "+_second.toString(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Data.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Data.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Data.java deleted file mode 100644 index 9d9fd94..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Data.java +++ /dev/null @@ -1,182 +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; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; - -import org.apache.qpid.proton.codec.impl.DataImpl; - -public interface Data -{ - - public static final class Factory { - - public static Data create() { - return new DataImpl(); - } - - } - - - enum DataType - { - NULL, - BOOL, - UBYTE, - BYTE, - USHORT, - SHORT, - UINT, - INT, - CHAR, - ULONG, - LONG, - TIMESTAMP, - FLOAT, - DOUBLE, - DECIMAL32, - DECIMAL64, - DECIMAL128, - UUID, - BINARY, - STRING, - SYMBOL, - DESCRIBED, - ARRAY, - LIST, - MAP - } - - void free(); -// int errno(); -// String error(); - - void clear(); - long size(); - void rewind(); - DataType next(); - DataType prev(); - boolean enter(); - boolean exit(); - boolean lookup(String name); - - DataType type(); - -// int print(); -// int format(ByteBuffer buf); - Binary encode(); - long encodedSize(); - long encode(ByteBuffer buf); - long decode(ByteBuffer buf); - - void putList(); - void putMap(); - void putArray(boolean described, DataType type); - void putDescribed(); - void putNull(); - void putBoolean(boolean b); - void putUnsignedByte(UnsignedByte ub); - void putByte(byte b); - void putUnsignedShort(UnsignedShort us); - void putShort(short s); - void putUnsignedInteger(UnsignedInteger ui); - void putInt(int i); - void putChar(int c); - void putUnsignedLong(UnsignedLong ul); - void putLong(long l); - void putTimestamp(Date t); - void putFloat(float f); - void putDouble(double d); - void putDecimal32(Decimal32 d); - void putDecimal64(Decimal64 d); - void putDecimal128(Decimal128 d); - void putUUID(UUID u); - void putBinary(Binary bytes); - void putBinary(byte[] bytes); - void putString(String string); - void putSymbol(Symbol symbol); - void putObject(Object o); - void putJavaMap(Map<Object, Object> map); - void putJavaList(List<Object> list); - void putJavaArray(Object[] array); - void putDescribedType(DescribedType dt); - - long getList(); - long getMap(); - long getArray(); - boolean isArrayDescribed(); - DataType getArrayType(); - boolean isDescribed(); - boolean isNull(); - boolean getBoolean(); - UnsignedByte getUnsignedByte(); - byte getByte(); - UnsignedShort getUnsignedShort(); - short getShort(); - UnsignedInteger getUnsignedInteger(); - int getInt(); - int getChar(); - UnsignedLong getUnsignedLong(); - long getLong(); - Date getTimestamp(); - float getFloat(); - double getDouble(); - Decimal32 getDecimal32(); - Decimal64 getDecimal64(); - Decimal128 getDecimal128(); - UUID getUUID(); - Binary getBinary(); - String getString(); - Symbol getSymbol(); - Object getObject(); - Map<Object, Object> getJavaMap(); - List<Object> getJavaList(); - Object[] getJavaArray(); - DescribedType getDescribedType(); - //pnAtomT getAtom(); - - void copy(Data src); - void append(Data src); - void appendn(Data src, int limit); - void narrow(); - void widen(); - - String format(); - - // void dump(); - - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal128Type.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal128Type.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal128Type.java deleted file mode 100644 index c871247..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal128Type.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; - -import org.apache.qpid.proton.amqp.Decimal128; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal128Type extends AbstractPrimitiveType<Decimal128> -{ - private Decimal128Encoding _decimal128Encoder; - - Decimal128Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal128Encoder = new Decimal128Encoding(encoder, decoder); - encoder.register(Decimal128.class, this); - decoder.register(this); - } - - public Class<Decimal128> getTypeClass() - { - return Decimal128.class; - } - - public Decimal128Encoding getEncoding(final Decimal128 val) - { - return _decimal128Encoder; - } - - - public Decimal128Encoding getCanonicalEncoding() - { - return _decimal128Encoder; - } - - public Collection<Decimal128Encoding> getAllEncodings() - { - return Collections.singleton(_decimal128Encoder); - } - - private class Decimal128Encoding extends FixedSizePrimitiveTypeEncoding<Decimal128> - { - - public Decimal128Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 16; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL128; - } - - public Decimal128Type getType() - { - return Decimal128Type.this; - } - - public void writeValue(final Decimal128 val) - { - getEncoder().writeRaw(val.getMostSignificantBits()); - getEncoder().writeRaw(val.getLeastSignificantBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal128> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal128 readValue() - { - long msb = getDecoder().readRawLong(); - long lsb = getDecoder().readRawLong(); - return new Decimal128(msb, lsb); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal32Type.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal32Type.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal32Type.java deleted file mode 100644 index 5ea5ee5..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal32Type.java +++ /dev/null @@ -1,100 +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; - -import org.apache.qpid.proton.amqp.Decimal32; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal32Type extends AbstractPrimitiveType<Decimal32> -{ - private Decimal32Encoding _decimal32Encoder; - - Decimal32Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal32Encoder = new Decimal32Encoding(encoder, decoder); - encoder.register(Decimal32.class, this); - decoder.register(this); - } - - public Class<Decimal32> getTypeClass() - { - return Decimal32.class; - } - - public Decimal32Encoding getEncoding(final Decimal32 val) - { - return _decimal32Encoder; - } - - - public Decimal32Encoding getCanonicalEncoding() - { - return _decimal32Encoder; - } - - public Collection<Decimal32Encoding> getAllEncodings() - { - return Collections.singleton(_decimal32Encoder); - } - - private class Decimal32Encoding extends FixedSizePrimitiveTypeEncoding<Decimal32> - { - - public Decimal32Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL32; - } - - public Decimal32Type getType() - { - return Decimal32Type.this; - } - - public void writeValue(final Decimal32 val) - { - getEncoder().writeRaw(val.getBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal32> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal32 readValue() - { - return new Decimal32(getDecoder().readRawInt()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal64Type.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal64Type.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal64Type.java deleted file mode 100644 index 26df547..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decimal64Type.java +++ /dev/null @@ -1,100 +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; - -import org.apache.qpid.proton.amqp.Decimal64; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal64Type extends AbstractPrimitiveType<Decimal64> -{ - private Decimal64Encoding _decimal64Encoder; - - Decimal64Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal64Encoder = new Decimal64Encoding(encoder, decoder); - encoder.register(Decimal64.class, this); - decoder.register(this); - } - - public Class<Decimal64> getTypeClass() - { - return Decimal64.class; - } - - public Decimal64Encoding getEncoding(final Decimal64 val) - { - return _decimal64Encoder; - } - - - public Decimal64Encoding getCanonicalEncoding() - { - return _decimal64Encoder; - } - - public Collection<Decimal64Encoding> getAllEncodings() - { - return Collections.singleton(_decimal64Encoder); - } - - private class Decimal64Encoding extends FixedSizePrimitiveTypeEncoding<Decimal64> - { - - public Decimal64Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL64; - } - - public Decimal64Type getType() - { - return Decimal64Type.this; - } - - public void writeValue(final Decimal64 val) - { - getEncoder().writeRaw(val.getBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal64> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal64 readValue() - { - return new Decimal64(getDecoder().readRawLong()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DecodeException.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecodeException.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DecodeException.java deleted file mode 100644 index 213e614..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecodeException.java +++ /dev/null @@ -1,44 +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; - -public class DecodeException extends RuntimeException -{ - public DecodeException() - { - } - - public DecodeException(String message) - { - super(message); - } - - public DecodeException(String message, Throwable cause) - { - super(message, cause); - } - - public DecodeException(Throwable cause) - { - super(cause); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Decoder.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Decoder.java deleted file mode 100644 index 6053479..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Decoder.java +++ /dev/null @@ -1,149 +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; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; - -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public interface Decoder -{ - public static interface ListProcessor<T> - { - T process(int count, Encoder encoder); - } - - - Boolean readBoolean(); - Boolean readBoolean(Boolean defaultVal); - boolean readBoolean(boolean defaultVal); - - Byte readByte(); - Byte readByte(Byte defaultVal); - byte readByte(byte defaultVal); - - Short readShort(); - Short readShort(Short defaultVal); - short readShort(short defaultVal); - - Integer readInteger(); - Integer readInteger(Integer defaultVal); - int readInteger(int defaultVal); - - Long readLong(); - Long readLong(Long defaultVal); - long readLong(long defaultVal); - - UnsignedByte readUnsignedByte(); - UnsignedByte readUnsignedByte(UnsignedByte defaultVal); - - UnsignedShort readUnsignedShort(); - UnsignedShort readUnsignedShort(UnsignedShort defaultVal); - - UnsignedInteger readUnsignedInteger(); - UnsignedInteger readUnsignedInteger(UnsignedInteger defaultVal); - - UnsignedLong readUnsignedLong(); - UnsignedLong readUnsignedLong(UnsignedLong defaultVal); - - Character readCharacter(); - Character readCharacter(Character defaultVal); - char readCharacter(char defaultVal); - - Float readFloat(); - Float readFloat(Float defaultVal); - float readFloat(float defaultVal); - - Double readDouble(); - Double readDouble(Double defaultVal); - double readDouble(double defaultVal); - - UUID readUUID(); - UUID readUUID(UUID defaultValue); - - Decimal32 readDecimal32(); - Decimal32 readDecimal32(Decimal32 defaultValue); - - Decimal64 readDecimal64(); - Decimal64 readDecimal64(Decimal64 defaultValue); - - Decimal128 readDecimal128(); - Decimal128 readDecimal128(Decimal128 defaultValue); - - Date readTimestamp(); - Date readTimestamp(Date defaultValue); - - Binary readBinary(); - Binary readBinary(Binary defaultValue); - - Symbol readSymbol(); - Symbol readSymbol(Symbol defaultValue); - - String readString(); - String readString(String defaultValue); - - List readList(); - <T> void readList(ListProcessor<T> processor); - - Map readMap(); - - <T> T[] readArray(Class<T> clazz); - - Object[] readArray(); - - boolean[] readBooleanArray(); - byte[] readByteArray(); - short[] readShortArray(); - int[] readIntegerArray(); - long[] readLongArray(); - float[] readFloatArray(); - double[] readDoubleArray(); - char[] readCharacterArray(); - - <T> T[] readMultiple(Class<T> clazz); - - Object[] readMultiple(); - byte[] readByteMultiple(); - short[] readShortMultiple(); - int[] readIntegerMultiple(); - long[] readLongMultiple(); - float[] readFloatMultiple(); - double[] readDoubleMultiple(); - char[] readCharacterMultiple(); - - Object readObject(); - Object readObject(Object defaultValue); - - void register(final Object descriptor, final DescribedTypeConstructor dtc); - - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java deleted file mode 100644 index dd68f6a..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DecoderImpl.java +++ /dev/null @@ -1,999 +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; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; - -import java.lang.reflect.Array; -import java.nio.ByteBuffer; -import java.util.*; - -public class DecoderImpl implements ByteBufferDecoder -{ - - private ByteBuffer _buffer; - private PrimitiveTypeEncoding[] _constructors = new PrimitiveTypeEncoding[256]; - private Map<Object, DescribedTypeConstructor> _dynamicTypeConstructors = - new HashMap<Object, DescribedTypeConstructor>(); - - - public DecoderImpl() - { - } - - - DecoderImpl(final ByteBuffer buffer) - { - _buffer = buffer; - } - - TypeConstructor readConstructor() - { - int code = ((int)readRawByte()) & 0xff; - if(code == EncodingCodes.DESCRIBED_TYPE_INDICATOR) - { - final Object descriptor = readObject(); - TypeConstructor nestedEncoding = readConstructor(); - DescribedTypeConstructor dtc = _dynamicTypeConstructors.get(descriptor); - if(dtc == null) - { - dtc = new DescribedTypeConstructor() - { - - public DescribedType newInstance(final Object described) - { - return new UnknownDescribedType(descriptor, described); - } - - public Class getTypeClass() - { - return UnknownDescribedType.class; - } - }; - register(descriptor, dtc); - } - return new DynamicTypeConstructor(dtc, nestedEncoding); - } - else - { - return _constructors[code]; - } - } - - public void register(final Object descriptor, final DescribedTypeConstructor dtc) - { - _dynamicTypeConstructors.put(descriptor, dtc); - } - - private ClassCastException unexpectedType(final Object val, Class clazz) - { - return new ClassCastException("Unexpected type " - + val.getClass().getName() - + ". Expected " - + clazz.getName() +"."); - } - - - public Boolean readBoolean() - { - return readBoolean(null); - } - - public Boolean readBoolean(final Boolean defaultVal) - { - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Boolean) - { - return (Boolean) val; - } - throw unexpectedType(val, Boolean.class); - } - - public boolean readBoolean(final boolean defaultVal) - { - TypeConstructor constructor = readConstructor(); - if(constructor instanceof BooleanType.BooleanEncoding) - { - return ((BooleanType.BooleanEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Boolean.class); - } - } - } - - public Byte readByte() - { - return readByte(null); - } - - public Byte readByte(final Byte defaultVal) - { - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Byte) - { - return (Byte) val; - } - throw unexpectedType(val, Byte.class); - } - - public byte readByte(final byte defaultVal) - { - TypeConstructor constructor = readConstructor(); - if(constructor instanceof ByteType.ByteEncoding) - { - return ((ByteType.ByteEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Byte.class); - } - } - } - - public Short readShort() - { - return readShort(null); - } - - public Short readShort(final Short defaultVal) - { - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Short) - { - return (Short) val; - } - throw unexpectedType(val, Short.class); - - } - - public short readShort(final short defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof ShortType.ShortEncoding) - { - return ((ShortType.ShortEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Short.class); - } - } - } - - public Integer readInteger() - { - return readInteger(null); - } - - public Integer readInteger(final Integer defaultVal) - { - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Integer) - { - return (Integer) val; - } - throw unexpectedType(val, Integer.class); - - } - - public int readInteger(final int defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof IntegerType.IntegerEncoding) - { - return ((IntegerType.IntegerEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Integer.class); - } - } - } - - public Long readLong() - { - return readLong(null); - } - - public Long readLong(final Long defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Long) - { - return (Long) val; - } - throw unexpectedType(val, Long.class); - - } - - public long readLong(final long defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof LongType.LongEncoding) - { - return ((LongType.LongEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Long.class); - } - } - } - - public UnsignedByte readUnsignedByte() - { - return readUnsignedByte(null); - } - - public UnsignedByte readUnsignedByte(final UnsignedByte defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof UnsignedByte) - { - return (UnsignedByte) val; - } - throw unexpectedType(val, UnsignedByte.class); - - } - - public UnsignedShort readUnsignedShort() - { - return readUnsignedShort(null); - } - - public UnsignedShort readUnsignedShort(final UnsignedShort defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof UnsignedShort) - { - return (UnsignedShort) val; - } - throw unexpectedType(val, UnsignedShort.class); - - } - - public UnsignedInteger readUnsignedInteger() - { - return readUnsignedInteger(null); - } - - public UnsignedInteger readUnsignedInteger(final UnsignedInteger defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof UnsignedInteger) - { - return (UnsignedInteger) val; - } - throw unexpectedType(val, UnsignedInteger.class); - - } - - public UnsignedLong readUnsignedLong() - { - return readUnsignedLong(null); - } - - public UnsignedLong readUnsignedLong(final UnsignedLong defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof UnsignedLong) - { - return (UnsignedLong) val; - } - throw unexpectedType(val, UnsignedLong.class); - - } - - public Character readCharacter() - { - return readCharacter(null); - } - - public Character readCharacter(final Character defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Character) - { - return (Character) val; - } - throw unexpectedType(val, Character.class); - - } - - public char readCharacter(final char defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof CharacterType.CharacterEncoding) - { - return ((CharacterType.CharacterEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Character.class); - } - } - } - - public Float readFloat() - { - return readFloat(null); - } - - public Float readFloat(final Float defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Float) - { - return (Float) val; - } - throw unexpectedType(val, Float.class); - - } - - public float readFloat(final float defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof FloatType.FloatEncoding) - { - return ((FloatType.FloatEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Float.class); - } - } - } - - public Double readDouble() - { - return readDouble(null); - } - - public Double readDouble(final Double defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof Double) - { - return (Double) val; - } - throw unexpectedType(val, Double.class); - - } - - public double readDouble(final double defaultVal) - { - - TypeConstructor constructor = readConstructor(); - if(constructor instanceof DoubleType.DoubleEncoding) - { - return ((DoubleType.DoubleEncoding)constructor).readPrimitiveValue(); - } - else - { - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else - { - throw unexpectedType(val, Double.class); - } - } - } - - public UUID readUUID() - { - return readUUID(null); - } - - public UUID readUUID(final UUID defaultVal) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultVal; - } - else if(val instanceof UUID) - { - return (UUID) val; - } - throw unexpectedType(val, UUID.class); - - } - - public Decimal32 readDecimal32() - { - return readDecimal32(null); - } - - public Decimal32 readDecimal32(final Decimal32 defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Decimal32) - { - return (Decimal32) val; - } - throw unexpectedType(val, Decimal32.class); - - } - - public Decimal64 readDecimal64() - { - return readDecimal64(null); - } - - public Decimal64 readDecimal64(final Decimal64 defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Decimal64) - { - return (Decimal64) val; - } - throw unexpectedType(val, Decimal64.class); - } - - public Decimal128 readDecimal128() - { - return readDecimal128(null); - } - - public Decimal128 readDecimal128(final Decimal128 defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Decimal128) - { - return (Decimal128) val; - } - throw unexpectedType(val, Decimal128.class); - } - - public Date readTimestamp() - { - return readTimestamp(null); - } - - public Date readTimestamp(final Date defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Date) - { - return (Date) val; - } - throw unexpectedType(val, Date.class); - } - - public Binary readBinary() - { - return readBinary(null); - } - - public Binary readBinary(final Binary defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Binary) - { - return (Binary) val; - } - throw unexpectedType(val, Binary.class); - } - - public Symbol readSymbol() - { - return readSymbol(null); - } - - public Symbol readSymbol(final Symbol defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof Symbol) - { - return (Symbol) val; - } - throw unexpectedType(val, Symbol.class); - } - - public String readString() - { - return readString(null); - } - - public String readString(final String defaultValue) - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return defaultValue; - } - else if(val instanceof String) - { - return (String) val; - } - throw unexpectedType(val, String.class); - } - - public List readList() - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return null; - } - else if(val instanceof List) - { - return (List) val; - } - throw unexpectedType(val, List.class); - } - - public <T> void readList(final ListProcessor<T> processor) - { - //TODO. - } - - public Map readMap() - { - - TypeConstructor constructor = readConstructor(); - Object val = constructor.readValue(); - if(val == null) - { - return null; - } - else if(val instanceof Map) - { - return (Map) val; - } - throw unexpectedType(val, Map.class); - } - - public <T> T[] readArray(final Class<T> clazz) - { - return null; //TODO. - } - - public Object[] readArray() - { - return (Object[]) readConstructor().readValue(); - - } - - public boolean[] readBooleanArray() - { - return (boolean[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public byte[] readByteArray() - { - return (byte[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public short[] readShortArray() - { - return (short[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public int[] readIntegerArray() - { - return (int[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public long[] readLongArray() - { - return (long[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public float[] readFloatArray() - { - return (float[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public double[] readDoubleArray() - { - return (double[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public char[] readCharacterArray() - { - return (char[]) ((ArrayType.ArrayEncoding)readConstructor()).readValueArray(); - } - - public <T> T[] readMultiple(final Class<T> clazz) - { - Object val = readObject(); - if(val == null) - { - return null; - } - else if(val.getClass().isArray()) - { - if(clazz.isAssignableFrom(val.getClass().getComponentType())) - { - return (T[]) val; - } - else - { - throw unexpectedType(val, Array.newInstance(clazz, 0).getClass()); - } - } - else if(clazz.isAssignableFrom(val.getClass())) - { - T[] array = (T[]) Array.newInstance(clazz, 1); - array[0] = (T) val; - return array; - } - else - { - throw unexpectedType(val, Array.newInstance(clazz, 0).getClass()); - } - } - - public Object[] readMultiple() - { - Object val = readObject(); - if(val == null) - { - return null; - } - else if(val.getClass().isArray()) - { - return (Object[]) val; - } - else - { - Object[] array = (Object[]) Array.newInstance(val.getClass(), 1); - array[0] = val; - return array; - } - } - - public byte[] readByteMultiple() - { - return new byte[0]; //TODO. - } - - public short[] readShortMultiple() - { - return new short[0]; //TODO. - } - - public int[] readIntegerMultiple() - { - return new int[0]; //TODO. - } - - public long[] readLongMultiple() - { - return new long[0]; //TODO. - } - - public float[] readFloatMultiple() - { - return new float[0]; //TODO. - } - - public double[] readDoubleMultiple() - { - return new double[0]; //TODO. - } - - public char[] readCharacterMultiple() - { - return new char[0]; //TODO. - } - - public Object readObject() - { - TypeConstructor constructor = readConstructor(); - if(constructor== null) - { - throw new DecodeException("Unknown constructor"); - } - return constructor instanceof ArrayType.ArrayEncoding - ? ((ArrayType.ArrayEncoding)constructor).readValueArray() - : constructor.readValue(); - } - - public Object readObject(final Object defaultValue) - { - Object val = readObject(); - return val == null ? defaultValue : val; - } - - <V> void register(PrimitiveType<V> type) - { - Collection<? extends PrimitiveTypeEncoding<V>> encodings = type.getAllEncodings(); - - for(PrimitiveTypeEncoding<V> encoding : encodings) - { - _constructors[((int) encoding.getEncodingCode()) & 0xFF ] = encoding; - } - - } - - byte readRawByte() - { - return _buffer.get(); - } - - int readRawInt() - { - return _buffer.getInt(); - } - - long readRawLong() - { - return _buffer.getLong(); - } - - short readRawShort() - { - return _buffer.getShort(); - } - - float readRawFloat() - { - return _buffer.getFloat(); - } - - double readRawDouble() - { - return _buffer.getDouble(); - } - - void readRaw(final byte[] data, final int offset, final int length) - { - _buffer.get(data, offset, length); - } - - - <V> V readRaw(TypeDecoder<V> decoder, int size) - { - V decode = decoder.decode((ByteBuffer) _buffer.slice().limit(size)); - _buffer.position(_buffer.position()+size); - return decode; - } - - public void setByteBuffer(final ByteBuffer buffer) - { - _buffer = buffer; - } - - interface TypeDecoder<V> - { - V decode(ByteBuffer buf); - } - - private static class UnknownDescribedType implements DescribedType - { - private final Object _descriptor; - private final Object _described; - - public UnknownDescribedType(final Object descriptor, final Object described) - { - _descriptor = descriptor; - _described = described; - } - - public Object getDescriptor() - { - return _descriptor; - } - - public Object getDescribed() - { - return _described; - } - - - @Override - public boolean equals(Object obj) - { - - return obj instanceof DescribedType - && _descriptor == null ? ((DescribedType) obj).getDescriptor() == null - : _descriptor.equals(((DescribedType) obj).getDescriptor()) - && _described == null ? ((DescribedType) obj).getDescribed() == null - : _described.equals(((DescribedType) obj).getDescribed()); - - } - - } - - public int getByteBufferRemaining() { - return _buffer.remaining(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DescribedTypeConstructor.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DescribedTypeConstructor.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DescribedTypeConstructor.java deleted file mode 100644 index 9df97a0..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DescribedTypeConstructor.java +++ /dev/null @@ -1,28 +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; - -public interface DescribedTypeConstructor<V> -{ - V newInstance(Object described); - - Class getTypeClass(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DoubleType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DoubleType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DoubleType.java deleted file mode 100644 index 8c6c84c..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DoubleType.java +++ /dev/null @@ -1,127 +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; - -import java.util.Collection; -import java.util.Collections; - -public class DoubleType extends AbstractPrimitiveType<Double> -{ - private DoubleEncoding _doubleEncoding; - - DoubleType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _doubleEncoding = new DoubleEncoding(encoder, decoder); - encoder.register(Double.class, this); - decoder.register(this); - } - - public Class<Double> getTypeClass() - { - return Double.class; - } - - public DoubleEncoding getEncoding(final Double val) - { - return _doubleEncoding; - } - - - public DoubleEncoding getCanonicalEncoding() - { - return _doubleEncoding; - } - - public Collection<DoubleEncoding> getAllEncodings() - { - return Collections.singleton(_doubleEncoding); - } - - public void write(double d) - { - _doubleEncoding.write(d); - } - - public class DoubleEncoding extends FixedSizePrimitiveTypeEncoding<Double> - { - - public DoubleEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DOUBLE; - } - - public DoubleType getType() - { - return DoubleType.this; - } - - public void writeValue(final Double val) - { - getEncoder().writeRaw(val.doubleValue()); - } - - public void writeValue(final double val) - { - getEncoder().writeRaw(val); - } - - public void write(final double d) - { - writeConstructor(); - getEncoder().writeRaw(d); - - } - - public boolean encodesSuperset(final TypeEncoding<Double> encoding) - { - return (getType() == encoding.getType()); - } - - public Double readValue() - { - return readPrimitiveValue(); - } - - public double readPrimitiveValue() - { - return getDecoder().readRawDouble(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DroppingWritableBuffer.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DroppingWritableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DroppingWritableBuffer.java deleted file mode 100644 index a6949b5..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DroppingWritableBuffer.java +++ /dev/null @@ -1,107 +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; - -import java.nio.ByteBuffer; - -public class DroppingWritableBuffer implements WritableBuffer -{ - private int _pos = 0; - - @Override - public boolean hasRemaining() - { - return true; - } - - @Override - public void put(byte b) - { - _pos += 1; - } - - @Override - public void putFloat(float f) - { - _pos += 4; - } - - @Override - public void putDouble(double d) - { - _pos += 8; - } - - @Override - public void put(byte[] src, int offset, int length) - { - _pos += length; - } - - @Override - public void putShort(short s) - { - _pos += 2; - } - - @Override - public void putInt(int i) - { - _pos += 4; - } - - @Override - public void putLong(long l) - { - _pos += 8; - } - - @Override - public int remaining() - { - return Integer.MAX_VALUE - _pos; - } - - @Override - public int position() - { - return _pos; - } - - @Override - public void position(int position) - { - _pos = position; - } - - @Override - public void put(ByteBuffer payload) - { - _pos += payload.remaining(); - payload.position(payload.limit()); - } - - @Override - public int limit() - { - return Integer.MAX_VALUE; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicDescribedType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicDescribedType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicDescribedType.java deleted file mode 100644 index d6ffaf7..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicDescribedType.java +++ /dev/null @@ -1,144 +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; - -import org.apache.qpid.proton.amqp.DescribedType; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class DynamicDescribedType implements AMQPType<DescribedType> -{ - - private final EncoderImpl _encoder; - private final Map<TypeEncoding, TypeEncoding> _encodings = new HashMap<TypeEncoding, TypeEncoding>(); - private final Object _descriptor; - - public DynamicDescribedType(EncoderImpl encoder, final Object descriptor) - { - _encoder = encoder; - _descriptor = descriptor; - } - - - public Class<DescribedType> getTypeClass() - { - return DescribedType.class; - } - - public TypeEncoding<DescribedType> getEncoding(final DescribedType val) - { - TypeEncoding underlyingEncoding = _encoder.getType(val.getDescribed()).getEncoding(val.getDescribed()); - TypeEncoding encoding = _encodings.get(underlyingEncoding); - if(encoding == null) - { - encoding = new DynamicDescribedTypeEncoding(underlyingEncoding); - _encodings.put(underlyingEncoding, encoding); - } - - return encoding; - } - - public TypeEncoding<DescribedType> getCanonicalEncoding() - { - return null; - } - - public Collection<TypeEncoding<DescribedType>> getAllEncodings() - { - Collection values = _encodings.values(); - Collection unmodifiable = Collections.unmodifiableCollection(values); - return (Collection<TypeEncoding<DescribedType>>) unmodifiable; - } - - public void write(final DescribedType val) - { - TypeEncoding<DescribedType> encoding = getEncoding(val); - encoding.writeConstructor(); - encoding.writeValue(val); - } - - private class DynamicDescribedTypeEncoding implements TypeEncoding - { - private final TypeEncoding _underlyingEncoding; - private final TypeEncoding _descriptorType; - private final int _constructorSize; - - - public DynamicDescribedTypeEncoding(final TypeEncoding underlyingEncoding) - { - _underlyingEncoding = underlyingEncoding; - _descriptorType = _encoder.getType(_descriptor).getEncoding(_descriptor); - _constructorSize = 1 + _descriptorType.getConstructorSize() - + _descriptorType.getValueSize(_descriptor) - + _underlyingEncoding.getConstructorSize(); - } - - public AMQPType getType() - { - return DynamicDescribedType.this; - } - - public void writeConstructor() - { - _encoder.writeRaw(EncodingCodes.DESCRIBED_TYPE_INDICATOR); - _descriptorType.writeConstructor(); - _descriptorType.writeValue(_descriptor); - _underlyingEncoding.writeConstructor(); - } - - public int getConstructorSize() - { - return _constructorSize; - } - - public void writeValue(final Object val) - { - _underlyingEncoding.writeValue(((DescribedType)val).getDescribed()); - } - - public int getValueSize(final Object val) - { - return _underlyingEncoding.getValueSize(((DescribedType) val).getDescribed()); - } - - public boolean isFixedSizeVal() - { - return _underlyingEncoding.isFixedSizeVal(); - } - - public boolean encodesSuperset(final TypeEncoding encoding) - { - return (getType() == encoding.getType()) - && (_underlyingEncoding.encodesSuperset(((DynamicDescribedTypeEncoding)encoding) - ._underlyingEncoding)); - } - - @Override - public boolean encodesJavaPrimitive() - { - return false; - } - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicTypeConstructor.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicTypeConstructor.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicTypeConstructor.java deleted file mode 100644 index 0cee927..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/DynamicTypeConstructor.java +++ /dev/null @@ -1,60 +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; - -public class DynamicTypeConstructor implements TypeConstructor -{ - private final DescribedTypeConstructor _describedTypeConstructor; - private final TypeConstructor _underlyingEncoding; - - public DynamicTypeConstructor(final DescribedTypeConstructor dtc, - final TypeConstructor underlyingEncoding) - { - _describedTypeConstructor = dtc; - _underlyingEncoding = underlyingEncoding; - } - - public Object readValue() - { - try - { - return _describedTypeConstructor.newInstance(_underlyingEncoding.readValue()); - } - catch (NullPointerException npe) - { - throw new DecodeException("Unexpected null value - mandatory field not set? ("+npe.getMessage()+")", npe); - } - catch (ClassCastException cce) - { - throw new DecodeException("Incorrect type used", cce); - } - } - - public boolean encodesJavaPrimitive() - { - return false; - } - - public Class getTypeClass() - { - return _describedTypeConstructor.getTypeClass(); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
