activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmacn...@apache.org
Subject svn commit: r900531 [1/2] - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src: handcoded/ handcoded/org/ handcoded/org/apache/ handcoded/org/apache/activemq/ handcoded/org/apache/activemq/amqp/ handcoded/org/apache/activemq/amqp/ge...
Date Mon, 18 Jan 2010 20:12:49 GMT
Author: cmacnaug
Date: Mon Jan 18 20:12:47 2010
New Revision: 900531

URL: http://svn.apache.org/viewvc?rev=900531&view=rev
Log:
Generator updates

Added:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java
Removed:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.jtemp
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/AmqpType.jtemp
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/AmqpAny.jtemp
Modified:
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpChoice.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDescriptor.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpEncoding.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/TypeRegistry.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/UnknownTypeException.java
    activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Utils.java

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,172 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+/**
+ * <p>
+ * Frames are divided into two distinct areas: a fixed width frame header, and a
+ * variable width frame body.
+ * </p>
+ * <p>
+ * <![CDATA[ +--------------+------------+ | frame header | frame body |
+ * +--------------+------------+ 24 bytes *variable* ]]>
+ * </p>
+ * <dl>
+ * <dt>frame header</dt>
+ * <dd>
+ * <p>
+ * The frame header is a fixed size (24 byte) structure that precedes each
+ * frame. The frame header includes information required to parse the rest of
+ * the frame.
+ * </p>
+ * </dd>
+ * <dt>frame body</dt>
+ * <dd>
+ * <p>
+ * The frame body is a variable width sequence of bytes whose interpretation
+ * depends on the frame type. For Connection and Session frames, this will, when
+ * non-empty, contain an encoded control or command.
+ * </p>
+ * </dd>
+ * </dl>
+ * <p>
+ * <b>Frame Header</b>
+ * <p>
+ * The first 8 bytes of the frame header are formatted identically for all frame
+ * types. The semantics of the frame flags, and the format of the last 16 bytes
+ * of the frame header are dependent on the specific type of frame as indicated
+ * by the value of the type field. There are two frame types defined: Connection
+ * frames and Session frames.
+ * </p>
+ * <p>
+ * 
+ * <pre>
+ *      +0         +1         +2         +3
+ *      +-------------------------------------------+ -.
+ *    0 |                   size                    |  |
+ *      +-------------------------------------------+  |
+ *    4 |  type  |   flags    |       channel       |  |
+ *      +-------------------------------------------+  |
+ *    8 |             type-dependent                |  |
+ *      +-------------------------------------------+  |---> frame header
+ *   12 |             type-dependent                |  |      (24 bytes)
+ *      +-------------------------------------------+  |
+ *   16 |             type-dependent                |  |
+ *      +-------------------------------------------+  |
+ *   20 |             type-dependent                |  |
+ *      +-------------------------------------------+ -'
+ *      +-------------------------------------------+ -.
+ *      |                    ...                    |  |
+ *      .                                           .  |
+ *      .                                           .  |---> frame body
+ *      .                                           .  |  (size - 24) bytes
+ *      |                    ...                    |  |
+ *      +-------------------------------------------+ -'
+ * </pre>
+ * 
+ * </p>
+ * <dl>
+ * <dt>size</dt>
+ * <dd>
+ * <p>
+ * Bytes 0-3 of the frame header contain the frame size. This is an unsigned
+ * 32-bit integer that MUST contain the total frame size including the frame
+ * header. The frame is malformed if the size is less than the the size of the
+ * header (24 bytes).
+ * </p>
+ * </dd>
+ * <dt>type</dt>
+ * <dd>
+ * <p>
+ * Byte 4 of the frame header is a type code. The type code indicates the format
+ * and purpose of the frame. A type code of 0x00 indicates that the frame is a
+ * Connection frame. A type code of 0x01 indicates that the frame is a Session
+ * frame. The subsequent bytes in the frame header may be interpreted
+ * differently depending on the type of the frame.
+ * </p>
+ * </dd>
+ * <dt>flags</dt>
+ * <dd>
+ * <p>
+ * Byte 5 of the frame header is reserved for frame flags. The semantics of the
+ * frame flags are determined by the frame type.
+ * </p>
+ * </dd>
+ * <dt>channel</dt>
+ * <dd>
+ * <p>
+ * Bytes 6 and 7 of the frame header contain the channel number. The channel
+ * number uniquely identifies one of the Sessions associated with the
+ * Connection.
+ * </p>
+ * </dd>
+ * </dl>
+ * 
+ * <b>Frame Body</b>
+ * <p>
+ * The frame body contains a variable number of octets, anywhere from zero, up
+ * to the maximum frame size minus 24 bytes for the header. Prior to any
+ * explicit negotiation, the maximum frame size is <xref
+ * name="MIN-MAX-FRAME-SIZE"/>. For Connection and Session frames, the frame
+ * body, if non-empty, will consist of a command or control operation encoded as
+ * a compound value (see <xref name="compound-types"/>). The complete set of
+ * compound type definitions for the core AMQP protocol commands and controls
+ * are defined in the "commands"and "controls" sections respectively.
+ * </p>
+ */
+
+public class AmqpFrame {
+
+    protected byte[] frameHeader;
+
+    protected static final int SIZE_OFFSET = 0;
+    protected static final int TYPE_OFFSET = 4;
+    protected static final int FLAGS_OFFSET = 5;
+    protected static final int CHANNEL_OFFSET = 6;
+
+    public static final byte CONNECTION_TYPE = 0x00;
+    public static final byte SESSION_TYPE = 0x01;
+
+    public static enum FrameType {
+
+        CONNECTION(CONNECTION_TYPE), SESSION(SESSION_TYPE);
+        final byte type;
+
+        FrameType(byte type) {
+            this.type = type;
+        }
+
+        public static FrameType getFrameType(AmqpFrame f) throws AmqpFramingException {
+            switch (f.frameHeader[TYPE_OFFSET]) {
+            case CONNECTION_TYPE:
+                return CONNECTION;
+            case SESSION_TYPE:
+                return SESSION;
+            default:
+                throw new AmqpFramingException("Unknown Frame Type: " + f.frameHeader[TYPE_OFFSET]);
+            }
+        }
+    }
+
+    public final FrameType getFrameType() throws AmqpFramingException {
+        return FrameType.getFrameType(this);
+    }
+
+    public final void setSize(long size) {
+        BitUtils.setUInt(frameHeader, SIZE_OFFSET, size);
+    }
+
+    public long getSize() {
+        return BitUtils.getUInt(frameHeader, SIZE_OFFSET);
+    }
+
+    protected void setFlags(byte flags) {
+        frameHeader[FLAGS_OFFSET] = flags;
+    }
+
+    public final void setChannel(int channel) {
+        BitUtils.setUShort(frameHeader, CHANNEL_OFFSET, channel);
+    }
+    
+    public final int getChannel() {
+        return BitUtils.getUShort(frameHeader, CHANNEL_OFFSET);
+    }
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,18 @@
+package org.apache.activemq.amqp.v1pr2;
+
+import java.io.IOException;
+
+public class AmqpFramingException extends IOException{
+
+    private static final long serialVersionUID = 1L;
+
+    public AmqpFramingException(String msg)
+    {
+        super(msg);
+    }
+    
+    public AmqpFramingException(String msg, Throwable cause)
+    {
+        super(msg, cause);
+    }
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,417 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.activemq.amqp.v1pr2.types.AmqpType;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBinary;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBoolean;
+import org.apache.activemq.amqp.v1pr2.types.AmqpList;
+import org.apache.activemq.amqp.v1pr2.types.AmqpMap;
+import org.apache.activemq.amqp.v1pr2.types.AmqpString;
+import org.apache.activemq.amqp.v1pr2.types.AmqpSymbol;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBinary.BINARY_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpBoolean.BOOLEAN_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpList.LIST_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpMap.MAP_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpString.STRING_ENCODING;
+import org.apache.activemq.amqp.v1pr2.types.AmqpSymbol.SYMBOL_ENCODING;
+
+public class AmqpMarshaller {
+
+    public static final AmqpBinary.BINARY_ENCODING chooseBinaryEncoding(byte[] val) throws
IOException {
+        if (val.length > 255) {
+            return AmqpBinary.BINARY_ENCODING.VBIN32;
+        }
+        return AmqpBinary.BINARY_ENCODING.VBIN8;
+    }
+
+    public static final AmqpBoolean.BOOLEAN_ENCODING chooseBooleanEncoding(boolean val) throws
IOException {
+        if (val) {
+            return AmqpBoolean.BOOLEAN_ENCODING.TRUE;
+        }
+        return AmqpBoolean.BOOLEAN_ENCODING.FALSE;
+    }
+
+    public static final AmqpList.LIST_ENCODING chooseListEncoding(List<AmqpType> val)
throws IOException {
+        if (val.size() > 255) {
+            return AmqpList.LIST_ENCODING.LIST32;
+        }
+        for (AmqpType le : val) {
+            int size = le.getEncodedSize();
+            if (size > 255) {
+                return AmqpList.LIST_ENCODING.LIST32;
+            }
+        }
+        return AmqpList.LIST_ENCODING.LIST8;
+    }
+
+    public static final AmqpMap.MAP_ENCODING chooseMapEncoding(HashMap<AmqpType, AmqpType>
val) throws IOException {
+        for (Map.Entry<AmqpType, AmqpType> me : val.entrySet()) {
+            int size = me.getKey().getEncodedSize() + me.getValue().getEncodedSize();
+            if (size > 255) {
+                return AmqpMap.MAP_ENCODING.MAP32;
+            }
+        }
+        return AmqpMap.MAP_ENCODING.MAP8;
+    }
+
+    public static final AmqpString.STRING_ENCODING chooseStringEncoding(String val) throws
IOException {
+        if (val.length() > 255 || val.getBytes("utf-16").length > 255) {
+            return AmqpString.STRING_ENCODING.STR32_UTF16;
+        }
+
+        return AmqpString.STRING_ENCODING.STR32_UTF16;
+    }
+
+    public static final AmqpSymbol.SYMBOL_ENCODING chooseSymbolEncoding(String val) throws
IOException {
+        if (val.length() > 255 || val.getBytes("ascii").length > 255) {
+            return AmqpSymbol.SYMBOL_ENCODING.SYM32;
+        }
+        return AmqpSymbol.SYMBOL_ENCODING.SYM8;
+    }
+
+    public static int getEncodedCounfOfList(List<AmqpType> val, LIST_ENCODING listENCODING)
{
+        return val.size();
+    }
+
+    public static int getEncodedCounfOfMap(HashMap<AmqpType, AmqpType> val, MAP_ENCODING
mapENCODING) {
+        return val.size() * 2;
+    }
+
+    public static final int getEncodedSizeOfBinary(byte[] val, BINARY_ENCODING encoding)
throws IOException {
+        return val.length;
+    }
+
+    public static final int getEncodedSizeOfBoolean(boolean val, BOOLEAN_ENCODING encoding)
throws IOException {
+        return 0;
+    }
+
+    public static final int getEncodedSizeOfList(List<AmqpType> val, LIST_ENCODING
encoding) throws IOException {
+        int size = 0;
+        switch (encoding) {
+        case ARRAY32: {
+            size = 4;
+            for (AmqpType le : val) {
+                size += le.getEncodedSize();
+            }
+            return size;
+        }
+        case ARRAY8: {
+            size = 1;
+            for (AmqpType le : val) {
+                size += le.getEncodedSize();
+            }
+            return size;
+        }
+        case LIST32: {
+            size = 8;
+            for (AmqpType le : val) {
+                size += le.getEncodedSize();
+            }
+            return size;
+        }
+        case LIST8: {
+            size = 8;
+            for (AmqpType le : val) {
+                size += le.getEncodedSize();
+            }
+            return size;
+        }
+        default: {
+            throw new UnsupportedEncodingException();
+        }
+        }
+    }
+
+    public static final int getEncodedSizeOfMap(HashMap<AmqpType, AmqpType> val, MAP_ENCODING
encoding) throws IOException {
+        int size = 0;
+        for (Map.Entry<AmqpType, AmqpType> me : val.entrySet()) {
+            size += me.getKey().getEncodedSize() + me.getValue().getEncodedSize();
+        }
+        return size;
+    }
+
+    public static final int getEncodedSizeOfString(String val, STRING_ENCODING encoding)
throws IOException {
+        switch (encoding) {
+        case STR32_UTF16:
+        case STR8_UTF16: {
+            return val.getBytes("utf-16").length;
+        }
+        case STR32_UTF8:
+        case STR8_UTF8: {
+            return val.getBytes("utf-8").length;
+        }
+        default:
+            throw new UnsupportedEncodingException(encoding.name());
+        }
+    }
+
+    public static final int getEncodedSizeOfSymbol(String val, SYMBOL_ENCODING encoding)
throws IOException {
+        return val.length();
+    }
+
+    public static final byte[] readBinary(AmqpBinary.BINARY_ENCODING encoding, int length,
int count, DataInputStream dis) throws IOException {
+        byte[] rc = new byte[length];
+        dis.readFully(rc);
+        return rc;
+    }
+
+    public static final byte readByte(DataInputStream dis) throws IOException {
+        return (byte) dis.read();
+    }
+
+    public static final int readChar(DataInputStream dis) throws IOException {
+        return dis.readInt();
+    }
+
+    public static final double readDouble(DataInputStream dis) throws IOException {
+        return dis.readDouble();
+    }
+
+    public static final float readFloat(DataInputStream dis) throws IOException {
+        return dis.readFloat();
+    }
+
+    public static final int readInt(DataInputStream dis) throws IOException {
+        return dis.readInt();
+    }
+
+    public static final List<AmqpType> readList(AmqpList.LIST_ENCODING encoding, int
size, int count, DataInputStream dis) throws IOException {
+        List<AmqpType> rc = new ArrayList<AmqpType>(count);
+        for (int i = 0; i < count; i++) {
+            rc.set(i, readType(dis));
+        }
+        return rc;
+    }
+
+    public static final long readLong(DataInputStream dis) throws IOException {
+        return dis.readLong();
+    }
+
+    public static final HashMap<AmqpType, AmqpType> readMap(AmqpMap.MAP_ENCODING encoding,
int size, int count, DataInputStream dis) throws IOException {
+        HashMap<AmqpType, AmqpType> rc = new HashMap<AmqpType, AmqpType>();
+        for (int i = 0; i < count; i++) {
+            rc.put(readType(dis), readType(dis));
+        }
+        return rc;
+    }
+
+    public static final short readShort(DataInputStream dis) throws IOException {
+        return dis.readShort();
+    }
+
+    public static final String readString(AmqpString.STRING_ENCODING encoding, int size,
int count, DataInputStream dis) throws IOException {
+        byte[] str = new byte[size];
+        dis.readFully(str);
+        switch (encoding) {
+        case STR32_UTF16:
+        case STR8_UTF16:
+            return new String(str, "utf-16");
+        case STR32_UTF8:
+        case STR8_UTF8:
+            return new String(str, "utf-8");
+        default:
+            throw new UnsupportedEncodingException(encoding.name());
+        }
+    }
+
+    public static final String readSymbol(AmqpSymbol.SYMBOL_ENCODING encoding, int size,
int count, DataInputStream dis) throws IOException {
+        byte[] str = new byte[size];
+        dis.readFully(str);
+        return new String(str, "ascii");
+    }
+
+    public static final Date readTimestamp(DataInputStream dis) throws IOException {
+        return new Date(dis.readInt());
+    }
+
+    public static final short readUbyte(DataInputStream dis) throws IOException {
+        return (short) (0xFF & (short) dis.readByte());
+    }
+
+    public static final long readUint(DataInputStream dis) throws IOException {
+        long rc = 0;
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 24));
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 16));
+        rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 8));
+        rc = rc | (0xFFFFFFFFL & (long) dis.readByte());
+
+        return rc;
+    }
+
+    public static final BigInteger readUlong(DataInputStream dis) throws IOException {
+        byte[] rc = new byte[9];
+        rc[0] = 0;
+        dis.readFully(rc, 1, 8);
+        return new BigInteger(rc);
+    }
+
+    public static final int readUshort(DataInputStream dis) throws IOException {
+        int rc = 0;
+        rc = rc | ((int) 0xFFFF & (((int) dis.readByte()) << 8));
+        rc = rc | ((int) 0xFFFF & (int) dis.readByte());
+
+        return rc;
+    }
+
+    public static final UUID readUuid(DataInputStream dis) throws IOException {
+        return new UUID(dis.readLong(), dis.readLong());
+    }
+
+    public static final void writeBinary(byte[] val, AmqpBinary.BINARY_ENCODING encoding,
DataOutputStream dos) throws IOException {
+        dos.write(val);
+    }
+
+    public static final void writeByte(byte val, DataOutputStream dos) throws IOException
{
+        dos.writeByte(val);
+    }
+
+    public static final void writeChar(int val, DataOutputStream dos) throws IOException
{
+        dos.writeInt(val);
+
+    }
+
+    public static final void writeDouble(double val, DataOutputStream dos) throws IOException
{
+        dos.writeLong(Double.doubleToLongBits(val));
+    }
+
+    public static final void writeFloat(float val, DataOutputStream dos) throws IOException
{
+        dos.writeInt(Float.floatToIntBits(val));
+    }
+
+    public static final void writeInt(int val, DataOutputStream dos) throws IOException {
+        dos.writeInt(val);
+    }
+
+    public static final void writeList(List<AmqpType> val, AmqpList.LIST_ENCODING encoding,
DataOutputStream dos) throws IOException {
+        switch (encoding) {
+        case ARRAY32:
+        case ARRAY8: {
+            val.get(0).marshalConstructor(dos);
+            for (AmqpType le : val) {
+                le.marshalData(dos);
+            }
+        }
+        case LIST32:
+        case LIST8: {
+            for (AmqpType le : val) {
+                le.marshal(dos);
+            }
+        }
+        default: {
+            throw new UnsupportedEncodingException();
+        }
+        }
+    }
+
+    public static final void writeLong(long val, DataOutputStream dos) throws IOException
{
+        dos.writeLong(val);
+    }
+
+    public static final void writeMap(HashMap<AmqpType, AmqpType> val, AmqpMap.MAP_ENCODING
encoding, DataOutputStream dos) throws IOException {
+        for (Map.Entry<AmqpType, AmqpType> me : val.entrySet()) {
+            me.getKey().marshal(dos);
+            me.getValue().marshal(dos);
+        }
+    }
+
+    public static final void writeShort(short val, DataOutputStream dos) throws IOException
{
+        dos.writeShort(val);
+    }
+
+    public static final void writeString(String val, AmqpString.STRING_ENCODING encoding,
DataOutputStream dos) throws IOException {
+        switch (encoding) {
+        case STR32_UTF16:
+        case STR8_UTF16: {
+            dos.write(val.getBytes("utf-16"));
+        }
+        case STR32_UTF8:
+        case STR8_UTF8: {
+            dos.write(val.getBytes("utf-8"));
+        }
+        default:
+            throw new UnsupportedEncodingException(encoding.name());
+        }
+
+    }
+
+    public static final void writeSymbol(String val, SYMBOL_ENCODING encoding, DataOutputStream
dos) throws IOException {
+        dos.write(val.getBytes("ascii"));
+    }
+
+    public static final void writeTimestamp(Date val, DataOutputStream dos) throws IOException
{
+        dos.writeInt((int) val.getTime());
+
+    }
+
+    public static final void writeUbyte(short val, DataOutputStream dos) throws IOException
{
+        dos.write(val);
+
+    }
+
+    public static final void writeUint(long val, DataOutputStream dos) throws IOException
{
+        dos.writeInt((int) val);
+
+    }
+
+    public static final void writeUlong(BigInteger val, DataOutputStream dos) throws IOException
{
+        byte[] b = val.toByteArray();
+        if (b.length > 8) {
+            for (int i = 0; i < b.length - 8; i++) {
+                if (b[i] > 0) {
+                    throw new UnsupportedEncodingException("Unsigned long too large");
+                }
+            }
+        }
+        dos.write(b, b.length - 8, 8);
+    }
+
+    public static final void writeUshort(int val, DataOutputStream dos) throws IOException
{
+        dos.writeShort((short) val);
+    }
+
+    public static final void writeUuid(UUID val, DataOutputStream dos) throws IOException
{
+        dos.writeLong(val.getMostSignificantBits());
+        dos.writeLong(val.getLeastSignificantBits());
+    }
+    
+    public static final AmqpType readType(DataInputStream dis) throws IOException
+    {
+        //TODO 
+        return null;
+    }
+
+    // public static final void main(String[] arg) {
+    // AmqpMarshaller marshaller = new AmqpMarshaller();
+    //
+    // ByteArrayOutputStream baos = new ByteArrayOutputStream(30);
+    // DataOutputStream dos = new DataOutputStream(baos);
+    //
+    // try {
+    // BigInteger unsigned = new BigInteger("" + Long.MAX_VALUE).multiply(new
+    // BigInteger("2"));
+    // marshaller.writeUlong(unsigned, dos);
+    // dos.flush();
+    //
+    // byte[] b = baos.toByteArray();
+    // ByteArrayInputStream bais = new ByteArrayInputStream(b);
+    // DataInputStream dis = new DataInputStream(bais);
+    // BigInteger read = marshaller.readUlong(dis);
+    // if (read != unsigned) {
+    // throw new Exception();
+    // }
+    // } catch (Exception e) {
+    // e.printStackTrace();
+    // }
+    // }
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,81 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+public class AmqpSessionFrame extends AmqpFrame {
+
+    private static final byte COMMAND_MASK = 0x01;
+    private static final byte NO_EXECUTED_MASK = 0x02;
+    private static final byte SYNC_MASK = 0x04;
+
+    private static final int ACKNOWLEDGED_OFFSET = 8;
+    private static final int NO_EXECUTED_OFFSET = 12;
+    private static final int CAPACITY_OFFSET = 16;
+    private static final int COMMAND_ID_OFFSET = 20;
+
+    public void setCommand(boolean isCommand) {
+        if (isCommand) {
+            frameHeader[FLAGS_OFFSET] |= COMMAND_MASK;
+        } else {
+            frameHeader[FLAGS_OFFSET] &= ~COMMAND_MASK;
+        }
+    }
+
+    public boolean isCommand() {
+        return (frameHeader[FLAGS_OFFSET] & COMMAND_MASK) != 0;
+    }
+
+    public void setNoExecuted(boolean isNoExecuted) {
+        if (isNoExecuted) {
+            frameHeader[FLAGS_OFFSET] |= NO_EXECUTED_MASK;
+        } else {
+            frameHeader[FLAGS_OFFSET] &= ~NO_EXECUTED_MASK;
+        }
+    }
+
+    public boolean isNoExecuted() {
+        return (frameHeader[FLAGS_OFFSET] & NO_EXECUTED_MASK) != 0;
+    }
+
+    public void setSync(boolean isSync) {
+        if (isSync) {
+            frameHeader[FLAGS_OFFSET] |= SYNC_MASK;
+        } else {
+            frameHeader[FLAGS_OFFSET] &= ~SYNC_MASK;
+        }
+    }
+
+    public boolean isSync() {
+        return (frameHeader[FLAGS_OFFSET] & SYNC_MASK) != 0;
+    }
+
+    public void setAcknowledged(long acknowledged) {
+        BitUtils.setUInt(frameHeader, ACKNOWLEDGED_OFFSET, acknowledged);
+    }
+
+    public long getAcknowledged() {
+        return BitUtils.getUInt(frameHeader, ACKNOWLEDGED_OFFSET);
+    }
+
+    public void setNoExecuted(long noExecuted) {
+        BitUtils.setUInt(frameHeader, NO_EXECUTED_OFFSET, noExecuted);
+    }
+
+    public long getNoExecuted() {
+        return BitUtils.getUInt(frameHeader, NO_EXECUTED_OFFSET);
+    }
+
+    public void setCapacity(long capacity) {
+        BitUtils.setUInt(frameHeader, CAPACITY_OFFSET, capacity);
+    }
+
+    public long getCapacity() {
+        return BitUtils.getUInt(frameHeader, CAPACITY_OFFSET);
+    }
+    
+    public void setCommandId(long commandId) {
+        BitUtils.setUInt(frameHeader, COMMAND_ID_OFFSET, commandId);
+    }
+
+    public long getCommandId() {
+        return BitUtils.getUInt(frameHeader, COMMAND_ID_OFFSET);
+    }
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,47 @@
+package org.apache.activemq.amqp.generator.handcoded;
+
+public class BitUtils {
+
+    public static final void setUShort(final byte[] target, final int offset, final long
value) {
+        target[offset + 0] = (byte) ((value >> 1) & 0xff);
+        target[offset + 1] = (byte) ((value >> 0) & 0xff);
+    }
+    
+    public static final int getUShort(final byte[] target, final int offset) {
+        return target[offset + 0] << 1 & 0xff | target[offset + 1];
+    }
+    
+    public static final void setShort(final byte[] target, final int offset, final short
value) {
+        target[offset + 0] = (byte) ((value >> 1) & 0xff);
+        target[offset + 1] = (byte) ((value >> 0) & 0xff);
+    }
+    
+    public static final short getShort(final byte[] target, final int offset) {
+        return (short) (target[offset + 0] << 1 & 0xff | target[offset + 1]);
+    }
+    
+    public static final void setUInt(final byte[] target, final int offset, final long value)
{
+        assert value < Integer.MAX_VALUE * 2 + 1;
+        target[offset + 0] = (byte) (value >> 3 & 0xff);
+        target[offset + 1] = (byte) (value >> 2 & 0xff);
+        target[offset + 2] = (byte) (value >> 1 & 0xff);
+        target[offset + 3] = (byte) (value >> 0 & 0xff);
+    }
+
+    public static final long getUInt(final byte[] target, final int offset) {
+        return target[offset + 0] << 3 | target[offset + 1] << 2 | target[offset
+ 2] << 1 | target[offset + 3];
+    }
+    
+    public static final void setInt(final byte[] target, final int offset, final int value)
{
+        assert value < Integer.MAX_VALUE * 2 + 1;
+        target[offset + 0] = (byte) (value >> 3 & 0xff);
+        target[offset + 1] = (byte) (value >> 2 & 0xff);
+        target[offset + 2] = (byte) (value >> 1 & 0xff);
+        target[offset + 3] = (byte) (value >> 0 & 0xff);
+    }
+
+    public static final int getInt(final byte[] target, final int offset) {
+        return target[offset + 0] << 3 | target[offset + 1] << 2 | target[offset
+ 2] << 1 | target[offset + 3];
+    }
+
+}

Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java?rev=900531&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java
(added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java
Mon Jan 18 20:12:47 2010
@@ -0,0 +1,181 @@
+package org.apache.activemq.amqp.generator.handcoded.types;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with his 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.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public abstract class AmqpType {
+
+    protected int encodedSize;
+    protected int encodedCount;
+    
+    public static enum FormatCategory {
+        FIXED(false, false), VARIABLE(false, false), COMPOUND(false, false), ARRAY(false,
false);
+
+        private final boolean encodesSize;
+        private final boolean encodesCount;
+
+        FormatCategory(boolean encodesSize, boolean encodesCount) {
+            this.encodesSize = encodesSize;
+            this.encodesCount = encodesCount;
+        }
+
+        public static FormatCategory getCategory(byte formatCode) throws IllegalArgumentException
{
+            switch ((byte) (formatCode | 0xF0)) {
+            case (byte) 0x40:
+            case (byte) 0x50:
+            case (byte) 0x60:
+            case (byte) 0x70:
+            case (byte) 0x80:
+            case (byte) 0x90:
+                return FIXED;
+            case (byte) 0xA0:
+            case (byte) 0xB0:
+                return VARIABLE;
+            case (byte) 0xC0:
+            case (byte) 0xD0:
+                return COMPOUND;
+            case (byte) 0xE0:
+            case (byte) 0xF0:
+                return ARRAY;
+            default:
+                throw new IllegalArgumentException("" + formatCode);
+            }
+        }
+
+        public final boolean encodesSize() {
+            return encodesSize;
+        }
+
+        public final boolean encodesCount() {
+            return encodesCount;
+        }
+    }
+
+    public static enum FormatSubCategory {
+        FIXED_0((byte) 0x40, 0), FIXED_1((byte) 0x50, 1), FIXED_2((byte) 0x60, 2), FIXED_4((byte)
0x70, 4), FIXED_8((byte) 0x80, 8), FIXED_16((byte) 0x90, 16), VARIABLE_1((byte) 0xA0, 1),
VARIABLE_4(
+                (byte) 0xB0, 4), COMPOUND_1((byte) 0xC0, 1), COMPOUND_4((byte) 0xD0, 4),
ARRAY_1((byte) 0xE0, 1), ARRAY_4((byte) 0xF0, 4);
+
+        private final FormatCategory category;
+        private final byte subCategory;
+        public final int WIDTH;
+
+        FormatSubCategory(byte subCategory, int width) {
+            this.subCategory = subCategory;
+            category = FormatCategory.getCategory(this.subCategory);
+            this.WIDTH = width;
+        }
+
+        public static FormatSubCategory getCategory(byte formatCode) throws IllegalArgumentException
{
+            switch ((byte) (formatCode | 0xF0)) {
+            case (byte) 0x40:
+                return FIXED_0;
+            case (byte) 0x50:
+                return FIXED_1;
+            case (byte) 0x60:
+                return FIXED_2;
+            case (byte) 0x70:
+                return FIXED_4;
+            case (byte) 0x80:
+                return FIXED_8;
+            case (byte) 0x90:
+                return FIXED_16;
+            case (byte) 0xA0:
+                return VARIABLE_1;
+            case (byte) 0xB0:
+                return VARIABLE_4;
+            case (byte) 0xC0:
+                return COMPOUND_1;
+            case (byte) 0xD0:
+                return COMPOUND_4;
+            case (byte) 0xE0:
+                return ARRAY_1;
+            case (byte) 0xF0:
+                return ARRAY_4;
+            default:
+                throw new IllegalArgumentException("" + formatCode);
+            }
+        }
+
+        public final void marshalFormatHeader(AmqpType type, DataOutputStream dos) throws
IOException {
+            if (category == FormatCategory.FIXED) {
+                return;
+            }
+
+            if (category.encodesSize()) {
+                if (WIDTH == 1) {
+                    dos.writeByte(type.getEncodedSize());
+                } else {
+                    dos.writeInt(type.getEncodedCount());
+                }
+            }
+
+            if (category.encodesCount()) {
+                if (WIDTH == 1) {
+                    dos.writeByte(type.getEncodedCount());
+                } else {
+                    dos.writeInt(type.getEncodedCount());
+                }
+            }
+        }
+
+        public final void unmarshalFormatHeader(AmqpType type, DataInputStream dis) throws
IOException {
+            if (category == FormatCategory.FIXED) {
+                return;
+            }
+
+            if (category.encodesSize()) {
+                if (WIDTH == 1) {
+                    type.setEncodedSize(dis.readByte());
+                } else {
+                    type.setEncodedCount(dis.readInt());
+                }
+            }
+
+            if (category.encodesCount()) {
+                if (WIDTH == 1) {
+                    type.setEncodedCount(dis.readByte());
+                } else {
+                    type.setEncodedCount(dis.readInt());
+                }
+            }
+        }
+    }
+    
+    protected void setEncodedSize(int size) {
+        encodedSize = size;
+    }
+
+    protected void setEncodedCount(int count) throws IOException {
+        encodedCount = count;
+    }
+
+    public abstract int getEncodedSize() throws IOException;
+
+    public abstract int getEncodedCount() throws IOException;
+
+    public abstract void unmarshal(DataInputStream dis) throws IOException;
+    
+    public abstract void marshal(DataOutputStream dos) throws IOException;
+
+    public abstract void marshalConstructor(DataOutputStream dos) throws IOException;
+
+    public abstract void marshalData(DataOutputStream dos) throws IOException;
+}

Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpChoice.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpChoice.java?rev=900531&r1=900530&r2=900531&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpChoice.java
(original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpChoice.java
Mon Jan 18 20:12:47 2010
@@ -1,6 +1,6 @@
 package org.apache.activemq.amqp.generator;
 
-import java.util.LinkedHashMap;
+import java.util.LinkedList;
 
 import org.apache.activemq.amqp.generator.jaxb.schema.Choice;
 
@@ -9,9 +9,9 @@
     private AmqpDoc doc;
     private String name;
     
-    LinkedHashMap<String, String> choices = new LinkedHashMap<String, String>();
+    LinkedList<Choice> choices = new LinkedList<Choice>();
     public void parseFromChoice(Choice choice) {
-        choices.put(choice.getName(), choice.getValue());
+        choices.add(choice);
         //TODO choice.getDoc();
     }
 }



Mime
View raw message