You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cm...@apache.org on 2010/01/19 02:52:14 UTC
svn commit: r900642 - in
/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src:
handcoded/org/apache/activemq/amqp/generator/handcoded/
handcoded/org/apache/activemq/amqp/generator/handcoded/types/
main/java/org/apache/activemq/amqp/gener...
Author: cmacnaug
Date: Tue Jan 19 01:52:11 2010
New Revision: 900642
URL: http://svn.apache.org/viewvc?rev=900642&view=rev
Log:
Adding CommandHandler interfaces + some bug fixes.
Added:
activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpCommand.java
activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDefinition.java
Removed:
activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/resources/org/apache/activemq/amqp/generator/handcoded/types/
Modified:
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/AmqpType.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/AmqpDoc.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
Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpCommand.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpCommand.java?rev=900642&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpCommand.java (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpCommand.java Tue Jan 19 01:52:11 2010
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.amqp.generator.handcoded;
+
+public interface AmqpCommand {
+
+ public void handle(AmqpCommandHandler handler) throws Exception;
+}
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFrame.java Tue Jan 19 01:52:11 2010
@@ -1,3 +1,19 @@
+/**
+ * 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.
+ */
package org.apache.activemq.amqp.generator.handcoded;
/**
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpFramingException.java Tue Jan 19 01:52:11 2010
@@ -1,3 +1,19 @@
+/**
+ * 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.
+ */
package org.apache.activemq.amqp.generator.handcoded;
import java.io.IOException;
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpMarshaller.java Tue Jan 19 01:52:11 2010
@@ -1,7 +1,23 @@
+/**
+ * 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.
+ */
package org.apache.activemq.amqp.generator.handcoded;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
@@ -12,19 +28,19 @@
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;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpType;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpBinary;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpBoolean;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpList;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpMap;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpString;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpSymbol;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpBinary.BINARY_ENCODING;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpBoolean.BOOLEAN_ENCODING;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpList.LIST_ENCODING;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpMap.MAP_ENCODING;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpString.STRING_ENCODING;
+import org.apache.activemq.amqp.generator.handcoded.types.AmqpSymbol.SYMBOL_ENCODING;
public class AmqpMarshaller {
@@ -160,33 +176,33 @@
return val.length();
}
- public static final byte[] readBinary(AmqpBinary.BINARY_ENCODING encoding, int length, int count, DataInputStream dis) throws IOException {
+ public static final byte[] readBinary(AmqpBinary.BINARY_ENCODING encoding, int length, int count, DataInput 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 byte readByte(DataInput dis) throws IOException {
+ return (byte) dis.readByte();
}
- public static final int readChar(DataInputStream dis) throws IOException {
+ public static final int readChar(DataInput dis) throws IOException {
return dis.readInt();
}
- public static final double readDouble(DataInputStream dis) throws IOException {
+ public static final double readDouble(DataInput dis) throws IOException {
return dis.readDouble();
}
- public static final float readFloat(DataInputStream dis) throws IOException {
+ public static final float readFloat(DataInput dis) throws IOException {
return dis.readFloat();
}
- public static final int readInt(DataInputStream dis) throws IOException {
+ public static final int readInt(DataInput dis) throws IOException {
return dis.readInt();
}
- public static final List<AmqpType> readList(AmqpList.LIST_ENCODING encoding, int size, int count, DataInputStream dis) throws IOException {
+ public static final List<AmqpType> readList(AmqpList.LIST_ENCODING encoding, int size, int count, DataInput dis) throws IOException {
List<AmqpType> rc = new ArrayList<AmqpType>(count);
for (int i = 0; i < count; i++) {
rc.set(i, readType(dis));
@@ -194,11 +210,11 @@
return rc;
}
- public static final long readLong(DataInputStream dis) throws IOException {
+ public static final long readLong(DataInput 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 {
+ public static final HashMap<AmqpType, AmqpType> readMap(AmqpMap.MAP_ENCODING encoding, int size, int count, DataInput dis) throws IOException {
HashMap<AmqpType, AmqpType> rc = new HashMap<AmqpType, AmqpType>();
for (int i = 0; i < count; i++) {
rc.put(readType(dis), readType(dis));
@@ -206,11 +222,11 @@
return rc;
}
- public static final short readShort(DataInputStream dis) throws IOException {
+ public static final short readShort(DataInput dis) throws IOException {
return dis.readShort();
}
- public static final String readString(AmqpString.STRING_ENCODING encoding, int size, int count, DataInputStream dis) throws IOException {
+ public static final String readString(AmqpString.STRING_ENCODING encoding, int size, int count, DataInput dis) throws IOException {
byte[] str = new byte[size];
dis.readFully(str);
switch (encoding) {
@@ -225,21 +241,21 @@
}
}
- public static final String readSymbol(AmqpSymbol.SYMBOL_ENCODING encoding, int size, int count, DataInputStream dis) throws IOException {
+ public static final String readSymbol(AmqpSymbol.SYMBOL_ENCODING encoding, int size, int count, DataInput 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 {
+ public static final Date readTimestamp(DataInput dis) throws IOException {
return new Date(dis.readInt());
}
- public static final short readUbyte(DataInputStream dis) throws IOException {
+ public static final short readUbyte(DataInput dis) throws IOException {
return (short) (0xFF & (short) dis.readByte());
}
- public static final long readUint(DataInputStream dis) throws IOException {
+ public static final long readUint(DataInput dis) throws IOException {
long rc = 0;
rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 24));
rc = rc | (0xFFFFFFFFL & (((long) dis.readByte()) << 16));
@@ -249,14 +265,14 @@
return rc;
}
- public static final BigInteger readUlong(DataInputStream dis) throws IOException {
+ public static final BigInteger readUlong(DataInput 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 {
+ public static final int readUshort(DataInput dis) throws IOException {
int rc = 0;
rc = rc | ((int) 0xFFFF & (((int) dis.readByte()) << 8));
rc = rc | ((int) 0xFFFF & (int) dis.readByte());
@@ -264,36 +280,36 @@
return rc;
}
- public static final UUID readUuid(DataInputStream dis) throws IOException {
+ public static final UUID readUuid(DataInput 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 {
+ public static final void writeBinary(byte[] val, AmqpBinary.BINARY_ENCODING encoding, DataOutput dos) throws IOException {
dos.write(val);
}
- public static final void writeByte(byte val, DataOutputStream dos) throws IOException {
+ public static final void writeByte(byte val, DataOutput dos) throws IOException {
dos.writeByte(val);
}
- public static final void writeChar(int val, DataOutputStream dos) throws IOException {
+ public static final void writeChar(int val, DataOutput dos) throws IOException {
dos.writeInt(val);
}
- public static final void writeDouble(double val, DataOutputStream dos) throws IOException {
+ public static final void writeDouble(double val, DataOutput dos) throws IOException {
dos.writeLong(Double.doubleToLongBits(val));
}
- public static final void writeFloat(float val, DataOutputStream dos) throws IOException {
+ public static final void writeFloat(float val, DataOutput dos) throws IOException {
dos.writeInt(Float.floatToIntBits(val));
}
- public static final void writeInt(int val, DataOutputStream dos) throws IOException {
+ public static final void writeInt(int val, DataOutput dos) throws IOException {
dos.writeInt(val);
}
- public static final void writeList(List<AmqpType> val, AmqpList.LIST_ENCODING encoding, DataOutputStream dos) throws IOException {
+ public static final void writeList(List<AmqpType> val, AmqpList.LIST_ENCODING encoding, DataOutput dos) throws IOException {
switch (encoding) {
case ARRAY32:
case ARRAY8: {
@@ -314,22 +330,22 @@
}
}
- public static final void writeLong(long val, DataOutputStream dos) throws IOException {
+ public static final void writeLong(long val, DataOutput dos) throws IOException {
dos.writeLong(val);
}
- public static final void writeMap(HashMap<AmqpType, AmqpType> val, AmqpMap.MAP_ENCODING encoding, DataOutputStream dos) throws IOException {
+ public static final void writeMap(HashMap<AmqpType, AmqpType> val, AmqpMap.MAP_ENCODING encoding, DataOutput 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 {
+ public static final void writeShort(short val, DataOutput dos) throws IOException {
dos.writeShort(val);
}
- public static final void writeString(String val, AmqpString.STRING_ENCODING encoding, DataOutputStream dos) throws IOException {
+ public static final void writeString(String val, AmqpString.STRING_ENCODING encoding, DataOutput dos) throws IOException {
switch (encoding) {
case STR32_UTF16:
case STR8_UTF16: {
@@ -345,26 +361,26 @@
}
- public static final void writeSymbol(String val, SYMBOL_ENCODING encoding, DataOutputStream dos) throws IOException {
+ public static final void writeSymbol(String val, SYMBOL_ENCODING encoding, DataOutput dos) throws IOException {
dos.write(val.getBytes("ascii"));
}
- public static final void writeTimestamp(Date val, DataOutputStream dos) throws IOException {
+ public static final void writeTimestamp(Date val, DataOutput dos) throws IOException {
dos.writeInt((int) val.getTime());
}
- public static final void writeUbyte(short val, DataOutputStream dos) throws IOException {
+ public static final void writeUbyte(short val, DataOutput dos) throws IOException {
dos.write(val);
}
- public static final void writeUint(long val, DataOutputStream dos) throws IOException {
+ public static final void writeUint(long val, DataOutput dos) throws IOException {
dos.writeInt((int) val);
}
- public static final void writeUlong(BigInteger val, DataOutputStream dos) throws IOException {
+ public static final void writeUlong(BigInteger val, DataOutput dos) throws IOException {
byte[] b = val.toByteArray();
if (b.length > 8) {
for (int i = 0; i < b.length - 8; i++) {
@@ -376,16 +392,16 @@
dos.write(b, b.length - 8, 8);
}
- public static final void writeUshort(int val, DataOutputStream dos) throws IOException {
+ public static final void writeUshort(int val, DataOutput dos) throws IOException {
dos.writeShort((short) val);
}
- public static final void writeUuid(UUID val, DataOutputStream dos) throws IOException {
+ public static final void writeUuid(UUID val, DataOutput dos) throws IOException {
dos.writeLong(val.getMostSignificantBits());
dos.writeLong(val.getLeastSignificantBits());
}
- public static final AmqpType readType(DataInputStream dis) throws IOException
+ public static final AmqpType readType(DataInput dis) throws IOException
{
//TODO
return null;
@@ -395,7 +411,7 @@
// AmqpMarshaller marshaller = new AmqpMarshaller();
//
// ByteArrayOutputStream baos = new ByteArrayOutputStream(30);
- // DataOutputStream dos = new DataOutputStream(baos);
+ // DataOutput dos = new DataOutput(baos);
//
// try {
// BigInteger unsigned = new BigInteger("" + Long.MAX_VALUE).multiply(new
@@ -405,7 +421,7 @@
//
// byte[] b = baos.toByteArray();
// ByteArrayInputStream bais = new ByteArrayInputStream(b);
- // DataInputStream dis = new DataInputStream(bais);
+ // DataInput dis = new DataInput(bais);
// BigInteger read = marshaller.readUlong(dis);
// if (read != unsigned) {
// throw new Exception();
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/AmqpSessionFrame.java Tue Jan 19 01:52:11 2010
@@ -1,3 +1,19 @@
+/**
+ * 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.
+ */
package org.apache.activemq.amqp.generator.handcoded;
public class AmqpSessionFrame extends AmqpFrame {
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java Tue Jan 19 01:52:11 2010
@@ -1,3 +1,19 @@
+/**
+ * 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.
+ */
package org.apache.activemq.amqp.generator.handcoded;
public class BitUtils {
Modified: 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=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/types/AmqpType.java Tue Jan 19 01:52:11 2010
@@ -1,5 +1,3 @@
-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
@@ -16,9 +14,10 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
+package org.apache.activemq.amqp.generator.handcoded.types;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
public abstract class AmqpType {
@@ -114,7 +113,7 @@
}
}
- public final void marshalFormatHeader(AmqpType type, DataOutputStream dos) throws IOException {
+ public final void marshalFormatHeader(AmqpType type, DataOutput dos) throws IOException {
if (category == FormatCategory.FIXED) {
return;
}
@@ -136,7 +135,7 @@
}
}
- public final void unmarshalFormatHeader(AmqpType type, DataInputStream dis) throws IOException {
+ public final void unmarshalFormatHeader(AmqpType type, DataInput dis) throws IOException {
if (category == FormatCategory.FIXED) {
return;
}
@@ -171,11 +170,11 @@
public abstract int getEncodedCount() throws IOException;
- public abstract void unmarshal(DataInputStream dis) throws IOException;
+ public abstract void unmarshal(DataInput dis) throws IOException;
- public abstract void marshal(DataOutputStream dos) throws IOException;
+ public abstract void marshal(DataOutput dos) throws IOException;
- public abstract void marshalConstructor(DataOutputStream dos) throws IOException;
+ public abstract void marshalConstructor(DataOutput dos) throws IOException;
- public abstract void marshalData(DataOutputStream dos) throws IOException;
+ public abstract void marshalData(DataOutput dos) throws IOException;
}
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpClass.java Tue Jan 19 01:52:11 2010
@@ -16,18 +16,20 @@
import java.util.TreeSet;
import org.apache.activemq.amqp.generator.TypeRegistry.JavaTypeMapping;
+import org.apache.activemq.amqp.generator.jaxb.schema.Amqp;
import org.apache.activemq.amqp.generator.jaxb.schema.Choice;
import org.apache.activemq.amqp.generator.jaxb.schema.Descriptor;
import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
import org.apache.activemq.amqp.generator.jaxb.schema.Encoding;
import org.apache.activemq.amqp.generator.jaxb.schema.Field;
+import org.apache.activemq.amqp.generator.jaxb.schema.Section;
import org.apache.activemq.amqp.generator.jaxb.schema.Type;
public class AmqpClass {
protected String name;
protected String label;
- protected AmqpDoc doc;
+ protected AmqpDoc doc = new AmqpDoc();
protected AmqpChoice choice;
protected AmqpException exception;
protected AmqpDescriptor descriptor;
@@ -36,6 +38,7 @@
protected boolean restricted;
protected boolean primitive;
+ protected boolean isCommand;
LinkedHashMap<String, AmqpField> fields = new LinkedHashMap<String, AmqpField>();
public boolean handcoded;
@@ -45,10 +48,11 @@
// Java mapping of the value that this type holds (if any)
public TypeRegistry.JavaTypeMapping valueMapping;
- public void parseFromType(Generator generator, String source, Type type) throws UnknownTypeException {
+ public void parseFromType(Generator generator, Amqp source, Section section, Type type) throws UnknownTypeException {
this.name = type.getName();
this.restrictedType = type.getSource();
this.label = type.getLabel();
+ isCommand = Generator.COMMANDS.contains(name) || Generator.CONTROLS.contains(name);
for (Object typeAttribute : type.getEncodingOrDescriptorOrFieldOrChoiceOrExceptionOrDoc()) {
if (typeAttribute instanceof Field) {
@@ -64,7 +68,6 @@
}
choice.parseFromChoice((Choice) typeAttribute);
} else if (typeAttribute instanceof Doc) {
- doc = new AmqpDoc();
doc.parseFromDoc((Doc) typeAttribute);
} else if (typeAttribute instanceof Encoding) {
if (encodings == null) {
@@ -79,6 +82,10 @@
}
}
+ if (label != null) {
+ doc.setLabel("Represents a " + label);
+ }
+
if (type.getClazz().equalsIgnoreCase("primitive")) {
setPrimitive(true);
}
@@ -89,7 +96,7 @@
this.restricted = true;
}
- typeMapping = new JavaTypeMapping(name, generator.getPackagePrefix() + "." + source + "." + "Amqp" + capFirst(toJavaName(name)));
+ typeMapping = new JavaTypeMapping(name, generator.getPackagePrefix() + "." + source.getName() + "." + "Amqp" + capFirst(toJavaName(name)));
}
public void generate(Generator generator) throws IOException, UnknownTypeException {
@@ -128,6 +135,10 @@
} else if (isRestricted()) {
writer.write(" extends " + resolveRestrictedType().getTypeMapping().getShortName());
}
+
+ if (isCommand()) {
+ writer.write(" implements AmqpCommand");
+ }
}
writer.write(" {");
@@ -166,17 +177,22 @@
}
}
+ if (isCommand()) {
+ imports.add(generator.getPackagePrefix() + ".AmqpCommandHandler");
+ imports.add(generator.getPackagePrefix() + ".AmqpCommand");
+ }
+
if (isPrimitive() || descriptor != null) {
imports.add(generator.getPackagePrefix() + ".types.AmqpType");
- imports.add("java.io.DataOutputStream");
- imports.add("java.io.DataInputStream");
+ imports.add("java.io.DataOutput");
+ imports.add("java.io.DataInput");
imports.add("java.io.IOException");
}
if (isPrimitive()) {
filterOrAddImport(imports, resolveValueMapping());
- //Need the AmqpMarshaller to help with encodings:
+ // Need the AmqpMarshaller to help with encodings:
if (hasNonZeroEncoding() || encodings.size() > 1) {
imports.add(generator.getPackagePrefix() + ".AmqpMarshaller");
}
@@ -301,11 +317,7 @@
for (Choice constant : choice.choices) {
i++;
if (constant.getDoc() != null) {
- AmqpDoc docs = new AmqpDoc();
- for (Doc doc : constant.getDoc()) {
- docs.parseFromDoc(doc);
- }
- docs.writeJavaDoc(writer, 1);
+ new AmqpDoc(constant.getDoc()).writeJavaDoc(writer, 1);
}
writer.write(tab(1) + toJavaConstant(constant.getName()) + "((" + amqpType.resolveValueMapping().getJavaType() + ") " + constant.getValue() + ")");
@@ -391,7 +403,7 @@
// writer.newLine();
// writer.write(tab(1) + "public static final " +
// getTypeMapping().getJavaType() +
- // " createFromStream(DataInputStream dis) throws IOException {");
+ // " createFromStream(DataInput dis) throws IOException {");
// writer.newLine();
// writer.write(tab(2) + " return get(" +
// amqpType.getTypeMapping().getJavaType() +
@@ -587,9 +599,7 @@
// Setter:
writer.newLine();
- if (field.getDoc() != null) {
- field.getDoc().writeJavaDoc(writer, 1);
- }
+ field.writeJavaDoc(writer, 1);
writer.write(tab(1) + "public final void set" + capFirst(field.getJavaName()) + "(" + amqpType.resolveValueType() + " " + toJavaName(field.getName()) + ") {");
writer.newLine();
if (amqpType.isPrimitive() && !amqpType.getName().equals("*")) {
@@ -602,9 +612,7 @@
writer.newLine();
writer.newLine();
// Getter:
- if (field.getDoc() != null) {
- field.getDoc().writeJavaDoc(writer, 1);
- }
+ field.writeJavaDoc(writer, 1);
writer.write(tab(1) + "public final " + amqpType.resolveValueType() + " get" + capFirst(field.getJavaName()) + "() {");
writer.newLine();
if (amqpType.isPrimitive() && !amqpType.getName().equals("*")) {
@@ -657,7 +665,7 @@
ret = true;
writer.newLine();
- writer.write(tab(1) + "public static final " + typeMapping.javaType + " createFromStream(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public static final " + typeMapping.javaType + " createFromStream(DataInput dis) throws IOException {");
writer.newLine();
writer.write(tab(2) + typeMapping.javaType + " rc = new " + typeMapping.javaType + "();");
writer.newLine();
@@ -669,7 +677,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshal(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshal(DataOutput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "marshalConstructor(dos);");
writer.newLine();
@@ -679,7 +687,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshal(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshal(DataInput dis) throws IOException {");
writer.newLine();
writer.write(tab(2) + "unmarshalConstructor(dis);");
writer.newLine();
@@ -712,7 +720,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalConstructor(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalConstructor(DataOutput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "dos.writeByte(FORMAT_CODE);");
writer.newLine();
@@ -720,7 +728,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalConstructor(DataInput dis) throws IOException {");
writer.newLine();
writer.write(tab(2) + "byte fc = dis.readByte();");
writer.newLine();
@@ -734,7 +742,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalData(DataOutput dos) throws IOException {");
writer.newLine();
if (hasNonZeroEncoding()) {
@@ -745,7 +753,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalData(DataInput dis) throws IOException {");
writer.newLine();
if (hasNonZeroEncoding()) {
writer.write(tab(2) + "value = AmqpMarshaller.read" + capFirst(toJavaName(name)) + "(dis);");
@@ -801,7 +809,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalConstructor(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalConstructor(DataOutput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "chooseEncoding();");
writer.newLine();
@@ -811,7 +819,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalConstructor(DataInput dis) throws IOException {");
writer.newLine();
writer.write(tab(2) + "encoding = " + getEncodingName(false) + ".getEncoding(dis.readByte());");
writer.newLine();
@@ -819,7 +827,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalData(DataOutput dos) throws IOException {");
if (hasNonZeroEncoding()) {
writer.newLine();
writer.write(tab(2) + "encoding.CATEGORY.marshalFormatHeader(this, dos);");
@@ -831,7 +839,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalData(DataInput dis) throws IOException {");
if (hasNonZeroEncoding()) {
writer.newLine();
writer.write(tab(2) + "value = AmqpMarshaller.read" + capFirst(toJavaName(name)) + "(encoding, encodedSize, encodedCount, dis);");
@@ -842,6 +850,16 @@
}
}
+ if (isCommand()) {
+ writer.newLine();
+ writer.write(tab(1) + "public final void handle(AmqpCommandHandler handler) throws Exception {");
+ writer.newLine();
+ writer.write(tab(2) + "handler.handle" + capFirst(toJavaName(name)) + "(this);");
+ writer.newLine();
+ writer.write(tab(1) + "}");
+ writer.newLine();
+ }
+
if (descriptor != null) {
writer.newLine();
@@ -861,7 +879,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalConstructor(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalConstructor(DataOutput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "dos.write(CONSTRUCTOR);");
writer.newLine();
@@ -871,7 +889,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void marshalData(DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void marshalData(DataOutput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "value.marshalData(dos);");
writer.newLine();
@@ -879,7 +897,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalConstructor(DataInputStream dos) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalConstructor(DataInput dos) throws IOException {");
writer.newLine();
writer.write(tab(2) + "//TODO");
writer.newLine();
@@ -887,7 +905,7 @@
writer.newLine();
writer.newLine();
- writer.write(tab(1) + "public final void unmarshalData(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public final void unmarshalData(DataInput dis) throws IOException {");
writer.newLine();
if (descriptor.getDescribedType().equals("list")) {
writer.write(tab(2) + "value = new " + TypeRegistry.resolveAmqpClass(descriptor.getDescribedType()).getJavaType() + "();");
@@ -981,6 +999,10 @@
return restricted;
}
+ public boolean isCommand() {
+ return isCommand;
+ }
+
public String getRestrictedType() {
return restrictedType;
}
Added: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDefinition.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDefinition.java?rev=900642&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDefinition.java (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDefinition.java Tue Jan 19 01:52:11 2010
@@ -0,0 +1,41 @@
+package org.apache.activemq.amqp.generator;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+import org.apache.activemq.amqp.generator.jaxb.schema.Definition;
+
+public class AmqpDefinition {
+
+ Definition definition;
+ AmqpDoc doc;
+
+ AmqpDefinition(Definition definition) {
+ parseFromDefinition(definition);
+ }
+
+ public void parseFromDefinition(Definition definition) {
+ this.definition = definition;
+ if (definition.getDoc() != null || definition.getDoc() != null) {
+ doc = new AmqpDoc(definition.getDoc());
+ doc.setLabel(definition.getLabel());
+ }
+ }
+
+ public String getLabel() {
+ return definition.getLabel();
+ }
+
+ public void writeJavaDoc(BufferedWriter writer, int indent) throws IOException {
+ doc.writeJavaDoc(writer, indent);
+ }
+
+ public String getValue() {
+ return definition.getValue();
+ }
+
+ public String getName() {
+ return definition.getName();
+ }
+
+}
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpDoc.java Tue Jan 19 01:52:11 2010
@@ -10,14 +10,39 @@
public class AmqpDoc {
List<Doc> docs = new LinkedList<Doc>();
+ String label;
+
+ AmqpDoc() {
+
+ }
+
+ AmqpDoc(Doc doc) {
+ parseFromDoc(doc);
+ }
+
+ AmqpDoc(List<Doc> docs) {
+ parseFromDoc(docs);
+ }
public void parseFromDoc(Doc doc) {
this.docs.add(doc);
}
+ public void parseFromDoc(List<Doc> docs) {
+
+ this.docs.addAll(docs);
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
public void writeJavaDoc(BufferedWriter writer, int indent) throws IOException {
String comment = "";
+ if (label != null) {
+ comment = label + "\n";
+ }
for (Doc doc : docs) {
for (Object docType : doc.getPOrUlOrOlOrDlOrPicture()) {
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpField.java Tue Jan 19 01:52:11 2010
@@ -2,12 +2,15 @@
import static org.apache.activemq.amqp.generator.Utils.toJavaName;
+import java.io.BufferedWriter;
+import java.io.IOException;
+
import org.apache.activemq.amqp.generator.jaxb.schema.Doc;
import org.apache.activemq.amqp.generator.jaxb.schema.Field;
public class AmqpField {
- AmqpDoc doc;
+ AmqpDoc doc = new AmqpDoc();
String name;
String defaultValue;
String label;
@@ -22,12 +25,10 @@
multiple = new Boolean(field.getMultiple()).booleanValue();
required = new Boolean(field.getRequired()).booleanValue();
type = field.getType();
-
+ doc.setLabel(label);
+
for (Object object : field.getDocOrException()) {
if (object instanceof Doc) {
- if (doc == null) {
- doc = new AmqpDoc();
- }
doc.parseFromDoc((Doc) object);
} else {
// TODO handle exception:
@@ -100,6 +101,10 @@
return ampqClass;
}
+ public void writeJavaDoc(BufferedWriter writer, int indent) throws IOException {
+ doc.writeJavaDoc(writer, indent);
+ }
+
public String getJavaName() {
return toJavaName(name);
}
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/AmqpMarshallerGen.java Tue Jan 19 01:52:11 2010
@@ -123,7 +123,7 @@
writer.newLine();
writeJavaComment(writer, 1, "Writes a " + javaType + " with the given encoding");
writer.write(tab(1) + "public static final void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, " + amqpClass.getEncodingName(true)
- + " encoding, DataOutputStream dos) throws IOException {");
+ + " encoding, DataOutput dos) throws IOException {");
writeUnimplementedMethodBody(writer, 1);
writer.newLine();
@@ -131,11 +131,11 @@
if(amqpClass.hasCompoundEncoding() || amqpClass.hasArrayEncoding() || amqpClass.hasVariableEncoding())
{
writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getEncodingName(true)
- + " encoding, int size, int count, DataInputStream dis) throws IOException {");
+ + " encoding, int size, int count, DataInput dis) throws IOException {");
}
else {
writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getEncodingName(true)
- + " encoding, DataInputStream dis) throws IOException {");
+ + " encoding, DataInput dis) throws IOException {");
}
writeUnimplementedMethodBody(writer, 1);
}
@@ -146,15 +146,15 @@
writer.newLine();
writeJavaComment(writer, 1, "Writes a " + javaType + " encoded as " + encoding.getLabel());
- writer.write(tab(1) + "public static final void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, DataOutputStream dos) throws IOException {");
+ writer.write(tab(1) + "public static final void write" + capFirst(toJavaName(amqpClass.name)) + "(" + javaType + " val, DataOutput dos) throws IOException {");
writeUnimplementedMethodBody(writer, 1);
writer.newLine();
writeJavaComment(writer, 1, "Reads a " + javaType + " encoded as " + encoding.getLabel());
if (amqpClass.hasNonFixedEncoding()) {
- writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(int size, int count, DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(int size, int count, DataInput dis) throws IOException {");
} else {
- writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(DataInputStream dis) throws IOException {");
+ writer.write(tab(1) + "public static final " + javaType + " read" + capFirst(toJavaName(amqpClass.name)) + "(DataInput dis) throws IOException {");
}
writeUnimplementedMethodBody(writer, 1);
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Generator.java Tue Jan 19 01:52:11 2010
@@ -1,10 +1,16 @@
package org.apache.activemq.amqp.generator;
+import static org.apache.activemq.amqp.generator.Utils.*;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.StringTokenizer;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -13,6 +19,7 @@
import javax.xml.transform.sax.SAXSource;
import org.apache.activemq.amqp.generator.jaxb.schema.Amqp;
+import org.apache.activemq.amqp.generator.jaxb.schema.Definition;
import org.apache.activemq.amqp.generator.jaxb.schema.Section;
import org.apache.activemq.amqp.generator.jaxb.schema.Type;
import org.xml.sax.InputSource;
@@ -25,6 +32,10 @@
private String sourceDirectory;
private String packagePrefix;
+ public static final HashSet<String> CONTROLS = new HashSet<String>();
+ public static final HashSet<String> COMMANDS = new HashSet<String>();
+ public static final LinkedList<AmqpDefinition> DEFINITIONS = new LinkedList<AmqpDefinition>();
+
public String[] getInputFile() {
return inputFiles;
}
@@ -44,7 +55,7 @@
public void setSourceDirectory(String sourceDirectory) {
this.sourceDirectory = sourceDirectory;
}
-
+
public String getPackagePrefix() {
return packagePrefix;
}
@@ -58,25 +69,51 @@
JAXBContext jc = JAXBContext.newInstance(Amqp.class.getPackage().getName());
for (String inputFile : inputFiles) {
+
+ // Firstly, scan the file for command and control defs:
+ BufferedReader reader = new BufferedReader(new FileReader(new File(inputFile)));
+ String line = reader.readLine();
+ while (line != null) {
+ line = line.trim();
+ if (line.startsWith("<!-- -")) {
+ StringTokenizer tok = new StringTokenizer(line, "- ");
+ while (tok.hasMoreTokens()) {
+ String token = tok.nextToken();
+ if (token.equals("Control:")) {
+ CONTROLS.add(tok.nextToken());
+ break;
+ } else if (token.equals("Command:")) {
+ COMMANDS.add(tok.nextToken());
+ break;
+ }
+ }
+ }
+ line = reader.readLine();
+ }
+ reader.close();
+
// JAXB has some namespace handling problems:
Unmarshaller unmarshaller = jc.createUnmarshaller();
SAXParserFactory parserFactory;
parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(false);
- XMLReader reader = parserFactory.newSAXParser().getXMLReader();
- Source er = new SAXSource(reader, new InputSource(inputFile));
+ XMLReader xmlreader = parserFactory.newSAXParser().getXMLReader();
+ Source er = new SAXSource(xmlreader, new InputSource(inputFile));
// Amqp amqp = (Amqp) unmarshaller.unmarshal(new StreamSource(new
// File(inputFile)), Amqp.class).getValue();
Amqp amqp = (Amqp) unmarshaller.unmarshal(er);
-
+
// Scan document:
for (Object docOrSection : amqp.getDocOrSection()) {
if (docOrSection instanceof Section) {
Section section = (Section) docOrSection;
+
System.out.println("Scanning: " + section.getName());
for (Object docOrDefinitionOrType : section.getDocOrDefinitionOrType()) {
if (docOrDefinitionOrType instanceof Type) {
- generateClassFromType(amqp.getName(), (Type) docOrDefinitionOrType);
+ generateClassFromType(amqp, section, (Type) docOrDefinitionOrType);
+ } else if (docOrDefinitionOrType instanceof Definition) {
+ DEFINITIONS.add(new AmqpDefinition((Definition) docOrDefinitionOrType));
}
}
}
@@ -88,9 +125,12 @@
String outputPackage = packagePrefix.replace(".", File.separator);
File sourceDir = new File(sourceDirectory + File.separator + handCodedSource);
for (File javaFile : Utils.findFiles(sourceDir)) {
+ if (!javaFile.getName().endsWith(".java")) {
+ continue;
+ }
javaFile.setWritable(true);
BufferedReader reader = new BufferedReader(new FileReader(javaFile));
- File out = new File(outputDirectory + File.separator + outputPackage + File.separator + javaFile.getCanonicalPath().substring((int)sourceDir.getCanonicalPath().length()));
+ File out = new File(outputDirectory + File.separator + outputPackage + File.separator + javaFile.getCanonicalPath().substring((int) sourceDir.getCanonicalPath().length()));
out.getParentFile().mkdirs();
String line = reader.readLine();
BufferedWriter writer = new BufferedWriter(new FileWriter(out));
@@ -110,14 +150,74 @@
amqpClass.generate(this);
}
+ generateCommandHandler();
+ writeDefinitions();
+ }
+
+ private void generateCommandHandler() throws IOException {
+ String outputPackage = packagePrefix.replace(".", File.separator);
+ File out = new File(outputDirectory + File.separator + outputPackage + File.separator + "AmqpCommandHandler.java");
+
+ BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+ writeJavaCopyWrite(writer);
+ writer.write("package " + packagePrefix + ";");
+ writer.newLine();
+ writer.newLine();
+
+ for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+ if (amqpClass.isCommand()) {
+ writer.write("import " + amqpClass.getTypeMapping().getImport() + ";");
+ writer.newLine();
+ }
+ }
+
+ writer.write("public interface AmqpCommandHandler {");
+ writer.newLine();
+ // Generate Handler methods:
+ for (AmqpClass amqpClass : TypeRegistry.getGeneratedTypes()) {
+ if (amqpClass.isCommand()) {
+ writer.newLine();
+ writer.write(tab(1) + "public void handle" + capFirst(toJavaName(amqpClass.name)) + "(" + amqpClass.getJavaType() + " " + toJavaName(amqpClass.name) + ") throws Exception;");
+ writer.newLine();
+ }
+ }
+ writer.write("}");
+ writer.flush();
+ writer.close();
+ }
+
+ private void writeDefinitions() throws IOException {
+ String outputPackage = packagePrefix.replace(".", File.separator);
+ File out = new File(outputDirectory + File.separator + outputPackage + File.separator + "Definitions.java");
+
+ BufferedWriter writer = new BufferedWriter(new FileWriter(out));
+
+ writeJavaCopyWrite(writer);
+ writer.write("package " + packagePrefix + ";");
+ writer.newLine();
+ writer.newLine();
+
+ writer.write("public interface Definitions {");
+ writer.newLine();
+ // Generate Handler methods:
+ for (AmqpDefinition def : DEFINITIONS) {
+ writer.newLine();
+ def.writeJavaDoc(writer, 1);
+ writer.write(tab(1) + "public static final String " + capFirst(toJavaConstant(def.getName())) + " = \"" + def.getValue() + "\";");
+ writer.newLine();
+ }
+
+ writer.write("}");
+ writer.flush();
+ writer.close();
}
- private void generateClassFromType(String source, Type type) throws Exception {
+ private void generateClassFromType(Amqp source, Section section, Type type) throws Exception {
AmqpClass amqpClass = new AmqpClass();
- amqpClass.parseFromType(this, source, type);
+ amqpClass.parseFromType(this, source, section, type);
TypeRegistry.addType(amqpClass);
System.out.println("Found: " + amqpClass);
}
-
}
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java?rev=900642&r1=900641&r2=900642&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/main/java/org/apache/activemq/amqp/generator/Main.java Tue Jan 19 01:52:11 2010
@@ -7,8 +7,8 @@
Generator gen = new Generator();
gen.setInputFiles("C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/transport.xml", "C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/messaging.xml",
"C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/types.xml", "C:/dev/fuse/amq6.0/activemq-amqp-generator/specification/1.0-PR2/security.xml");
- gen.setPackagePrefix("org.apache.activemq.amqp.v1pr2");
- gen.setOutputDirectory("C:/dev/fuse/amq6.0/activemq-amqp-generator/src/main/java");
+ gen.setPackagePrefix("org.apache.activemq.amqp.protocol.v1pr2");
+ gen.setOutputDirectory("C:/dev/fuse/amq6.0/activemq-amqp/src/main/java");
gen.setSourceDirectory("C:/dev/fuse/amq6.0/activemq-amqp-generator/src/handcoded");
try {
gen.generate();