[jboss-cvs] JBoss Messaging SVN: r3515 - in trunk/src/main/org/jboss: messaging/newcore and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 17 10:58:08 EST 2007
Author: timfox
Date: 2007-12-17 10:58:08 -0500 (Mon, 17 Dec 2007)
New Revision: 3515
Added:
trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
trunk/src/main/org/jboss/jms/message/JBossMessage.java
trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
trunk/src/main/org/jboss/messaging/newcore/Destination.java
trunk/src/main/org/jboss/messaging/newcore/impl/DestinationImpl.java
Log:
Missing files
Added: trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,663 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MessageEOFException;
+import javax.jms.MessageFormatException;
+
+import org.jboss.jms.exception.MessagingJMSException;
+
+/**
+ * This class implements javax.jms.BytesMessage.
+ *
+ * @author Norbert Lataille (Norbert.Lataille at m4x.org)
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ *
+ * @version $Revision: 3412 $
+ *
+ * $Id: JBossBytesMessage.java 3412 2007-12-05 19:41:47Z timfox $
+ */
+public class JBossBytesMessage extends JBossMessage implements BytesMessage
+{
+ // Static -------------------------------------------------------
+
+ public static final byte TYPE = 4;
+
+ // Attributes ----------------------------------------------------
+
+ // TODO - use abstraction of MINA byte buffer to write directly and avoid
+ // unnecessary copying
+
+ private ByteArrayOutputStream baos;
+ private DataOutputStream dos;
+
+ private ByteArrayInputStream bais;
+ private DataInputStream dis;
+
+ private byte[] data;
+
+ // Constructor ---------------------------------------------------
+
+ /*
+ * This constructor is used to construct messages prior to sending
+ */
+ public JBossBytesMessage()
+ {
+ super(JBossBytesMessage.TYPE);
+ }
+
+ public JBossBytesMessage(org.jboss.messaging.newcore.Message message,
+ long deliveryID, int deliveryCount)
+ {
+ super(message, deliveryID, deliveryCount);
+ }
+
+ public JBossBytesMessage(BytesMessage foreign) throws JMSException
+ {
+ super(foreign, JBossBytesMessage.TYPE);
+
+ foreign.reset();
+
+ baos = new ByteArrayOutputStream();
+ dos = new DataOutputStream(baos);
+
+ byte[] buffer = new byte[1024];
+ int n = foreign.readBytes(buffer);
+ while (n != -1)
+ {
+ writeBytes(buffer, 0, n);
+ n = foreign.readBytes(buffer);
+ }
+ }
+
+ // BytesMessage implementation -----------------------------------
+
+ public boolean readBoolean() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readBoolean();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public byte readByte() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readByte();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public int readUnsignedByte() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readUnsignedByte();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public short readShort() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readShort();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public int readUnsignedShort() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readUnsignedShort();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public char readChar() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readChar();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public int readInt() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readInt();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public long readLong() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readLong();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public float readFloat() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readFloat();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public double readDouble() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readDouble();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public String readUTF() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.readUTF();
+ }
+ catch (EOFException e)
+ {
+ throw new MessageEOFException("");
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public int readBytes(byte[] value) throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.read(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public int readBytes(byte[] value, int length) throws JMSException
+ {
+ checkRead();
+ try
+ {
+ return dis.read(value, 0, length);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeBoolean(boolean value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeBoolean(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeByte(byte value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeByte(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeShort(short value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeShort(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeChar(char value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeChar(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeInt(int value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeInt(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeLong(long value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeLong(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeFloat(float value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeFloat(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeDouble(double value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeDouble(value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeUTF(String value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.writeUTF((String) value);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeBytes(byte[] value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.write(value, 0, value.length);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeBytes(byte[] value, int offset, int length)
+ throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ dos.write(value, offset, length);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void writeObject(Object value) throws JMSException
+ {
+ checkWrite();
+ try
+ {
+ if (value == null) { throw new NullPointerException(
+ "Attempt to write a new value"); }
+ if (value instanceof String)
+ {
+ dos.writeUTF((String) value);
+ }
+ else if (value instanceof Boolean)
+ {
+ dos.writeBoolean(((Boolean) value).booleanValue());
+ }
+ else if (value instanceof Byte)
+ {
+ dos.writeByte(((Byte) value).byteValue());
+ }
+ else if (value instanceof Short)
+ {
+ dos.writeShort(((Short) value).shortValue());
+ }
+ else if (value instanceof Integer)
+ {
+ dos.writeInt(((Integer) value).intValue());
+ }
+ else if (value instanceof Long)
+ {
+ dos.writeLong(((Long) value).longValue());
+ }
+ else if (value instanceof Float)
+ {
+ dos.writeFloat(((Float) value).floatValue());
+ }
+ else if (value instanceof Double)
+ {
+ dos.writeDouble(((Double) value).doubleValue());
+ }
+ else if (value instanceof byte[])
+ {
+ dos.write((byte[]) value, 0, ((byte[]) value).length);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid object for properties");
+ }
+ }
+ catch (IOException e)
+ {
+ throw new MessagingJMSException("IOException", e);
+ }
+ }
+
+ public void reset() throws JMSException
+ {
+ try
+ {
+ if (baos != null)
+ {
+ dos.flush();
+
+ data = baos.toByteArray();
+
+ baos.close();
+ }
+ baos = null;
+ bais = null;
+ dis = null;
+ dos = null;
+ }
+ catch (Exception e)
+ {
+ JMSException e2 = new JMSException(e.getMessage());
+ e2.setStackTrace(e.getStackTrace());
+ throw e2;
+ }
+
+ readOnly = true;
+ }
+
+ // JBossMessage overrides ----------------------------------------
+
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+
+ try
+ {
+ if (baos != null)
+ {
+ baos.close();
+ }
+ else
+ {
+ if (bais != null)
+ {
+ bais.close();
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // don't throw an exception
+ }
+
+ baos = new ByteArrayOutputStream();
+ dos = new DataOutputStream(baos);
+ data = null;
+ bais = null;
+ dis = null;
+ }
+
+ public long getBodyLength() throws JMSException
+ {
+ checkRead();
+
+ if (data != null)
+ {
+ return data.length;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+
+
+ // Public --------------------------------------------------------
+
+ public byte getType()
+ {
+ return JBossBytesMessage.TYPE;
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ reset();
+
+ beforeSend();
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ beforeReceive();
+ }
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void checkRead() throws JMSException
+ {
+ super.checkRead();
+
+ if (bais == null)
+ {
+ bais = new ByteArrayInputStream(data);
+ dis = new DataInputStream(bais);
+ }
+ }
+
+ protected void checkWrite() throws JMSException
+ {
+ super.checkWrite();
+
+ if (baos == null)
+ {
+ baos = new ByteArrayOutputStream();
+ dos = new DataOutputStream(baos);
+ }
+ }
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ if (data == null)
+ {
+ daos.writeInt(0);
+ }
+ else
+ {
+ daos.writeInt(data.length);
+
+ daos.write(data);
+ }
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ int length = dais.readInt();
+
+ data = new byte[length];
+
+ dais.read(data);
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Added: trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMapMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossMapMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,470 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.MessageFormatException;
+
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * This class implements javax.jms.MapMessage
+ *
+ * @author Norbert Lataille (Norbert.Lataille at m4x.org)
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ *
+ * @version $Revision: 3412 $
+ *
+ * $Id: JBossMapMessage.java 3412 2007-12-05 19:41:47Z timfox $
+ */
+public class JBossMapMessage extends JBossMessage implements MapMessage
+{
+ // Constants -----------------------------------------------------
+
+ public static final byte TYPE = 5;
+
+ // Attributes ----------------------------------------------------
+
+ private Map<String, Object> map = new HashMap<String, Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ /*
+ * This constructor is used to construct messages prior to sending
+ */
+ public JBossMapMessage()
+ {
+ super(JBossMapMessage.TYPE);
+ }
+
+ public JBossMapMessage(org.jboss.messaging.newcore.Message message, long deliveryID, int deliveryCount)
+ {
+ super(message, deliveryID, deliveryCount);
+ }
+
+ /**
+ *
+ * Constructor for a foreign MapMessage
+ * @param foreign
+ * @throws JMSException
+ */
+ public JBossMapMessage(MapMessage foreign) throws JMSException
+ {
+ super(foreign, JBossMapMessage.TYPE);
+ Enumeration names = foreign.getMapNames();
+ while (names.hasMoreElements())
+ {
+ String name = (String)names.nextElement();
+ Object obj = foreign.getObject(name);
+ this.setObject(name, obj);
+ }
+ }
+
+ // Public --------------------------------------------------------
+
+ public byte getType()
+ {
+ return JBossMapMessage.TYPE;
+ }
+
+ // MapMessage implementation -------------------------------------
+
+ public void setBoolean(String name, boolean value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Boolean.valueOf(value));
+ }
+
+ public void setByte(String name, byte value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Byte.valueOf(value));
+ }
+
+ public void setShort(String name, short value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Short.valueOf(value));
+ }
+
+ public void setChar(String name, char value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Character.valueOf(value));
+ }
+
+ public void setInt(String name, int value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Integer.valueOf(value));
+ }
+
+ public void setLong(String name, long value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Long.valueOf(value));
+ }
+
+ public void setFloat(String name, float value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Float.valueOf(value));
+ }
+
+ public void setDouble(String name, double value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, Double.valueOf(value));
+ }
+
+ public void setString(String name, String value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, value);
+ }
+
+ public void setBytes(String name, byte[] value) throws JMSException
+ {
+ checkName(name);
+ map.put(name, value.clone());
+ }
+
+ public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
+ {
+ checkName(name);
+ if (offset + length > value.length)
+ {
+ throw new JMSException("Invalid offset/length");
+ }
+ byte[] newBytes = new byte[length];
+ System.arraycopy(value, offset, newBytes, 0, length);
+ map.put(name, newBytes);
+ }
+
+ public void setObject(String name, Object value) throws JMSException
+ {
+ checkName(name);
+ if (value instanceof Boolean)
+ map.put(name, value);
+ else if (value instanceof Byte)
+ map.put(name, value);
+ else if (value instanceof Short)
+ map.put(name, value);
+ else if (value instanceof Character)
+ map.put(name, value);
+ else if (value instanceof Integer)
+ map.put(name, value);
+ else if (value instanceof Long)
+ map.put(name, value);
+ else if (value instanceof Float)
+ map.put(name, value);
+ else if (value instanceof Double)
+ map.put(name, value);
+ else if (value instanceof String)
+ map.put(name, value);
+ else if (value instanceof byte[])
+ map.put(name, ((byte[]) value).clone());
+ else
+ throw new MessageFormatException("Invalid object type.");
+ }
+
+ public boolean getBoolean(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Boolean.valueOf(null).booleanValue();
+
+ if (value instanceof Boolean)
+ return ((Boolean) value).booleanValue();
+ else if (value instanceof String)
+ return Boolean.valueOf((String) value).booleanValue();
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public byte getByte(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Byte.parseByte(null);
+
+ if (value instanceof Byte)
+ return ((Byte) value).byteValue();
+ else if (value instanceof String)
+ return Byte.parseByte((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public short getShort(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Short.parseShort(null);
+
+ if (value instanceof Byte)
+ return ((Byte) value).shortValue();
+ else if (value instanceof Short)
+ return ((Short) value).shortValue();
+ else if (value instanceof String)
+ return Short.parseShort((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public char getChar(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ throw new NullPointerException("Invalid conversion");
+
+ if (value instanceof Character)
+ return ((Character) value).charValue();
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public int getInt(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Integer.parseInt(null);
+
+ if (value instanceof Byte)
+ return ((Byte) value).intValue();
+ else if (value instanceof Short)
+ return ((Short) value).intValue();
+ else if (value instanceof Integer)
+ return ((Integer) value).intValue();
+ else if (value instanceof String)
+ return Integer.parseInt((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public long getLong(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Long.parseLong(null);
+
+ if (value instanceof Byte)
+ return ((Byte) value).longValue();
+ else if (value instanceof Short)
+ return ((Short) value).longValue();
+ else if (value instanceof Integer)
+ return ((Integer) value).longValue();
+ else if (value instanceof Long)
+ return ((Long) value).longValue();
+ else if (value instanceof String)
+ return Long.parseLong((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public float getFloat(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Float.parseFloat(null);
+
+ if (value instanceof Float)
+ return ((Float) value).floatValue();
+ else if (value instanceof String)
+ return Float.parseFloat((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public double getDouble(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return Double.parseDouble(null);
+
+ if (value instanceof Float)
+ return ((Float) value).doubleValue();
+ else if (value instanceof Double)
+ return ((Double) value).doubleValue();
+ else if (value instanceof String)
+ return Double.parseDouble((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public String getString(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return null;
+
+ if (value instanceof Boolean)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Byte)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Short)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Character)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Integer)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Long)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Float)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Double)
+ {
+ return value.toString();
+ }
+ else if (value instanceof String)
+ {
+ return (String) value;
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+ }
+
+ public byte[] getBytes(String name) throws JMSException
+ {
+ Object value = map.get(name);
+
+ if (value == null)
+ return null;
+ if (value instanceof byte[])
+ return (byte[]) value;
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public Object getObject(String name) throws JMSException
+ {
+ return map.get(name);
+ }
+
+ public Enumeration getMapNames() throws JMSException
+ {
+ return Collections.enumeration(new HashSet<String>(map.keySet()));
+ }
+
+ public boolean itemExists(String name) throws JMSException
+ {
+ return map.containsKey(name);
+ }
+
+ // JBossMessage overrides ----------------------------------------
+
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+
+ map.clear();
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ beforeSend();
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ beforeReceive();
+ }
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ StreamUtils.writeMap(daos, map, false);
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ map = StreamUtils.readMap(dais, false);
+ }
+
+ // Private -------------------------------------------------------
+
+ /**
+ * Check the name
+ *
+ * @param name the name
+ */
+ private void checkName(String name) throws JMSException
+ {
+ checkWrite();
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException("Name must not be null.");
+ }
+
+ if (name.equals(""))
+ {
+ throw new IllegalArgumentException("Name must not be an empty String.");
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
+
Added: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,921 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.exception.MessagingJMSException;
+import org.jboss.logging.Logger;
+import org.jboss.messaging.newcore.impl.MessageImpl;
+import org.jboss.util.Primitives;
+import org.jboss.util.Strings;
+
+/**
+ *
+ * Implementation of a JMS Message
+ *
+ * JMS Messages only live on the client side - the server only deals with MessageImpl instances
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:bershath at yahoo.com">Tyronne Wickramarathne</a>
+ *
+ * Partially ported from JBossMQ implementation originally written by:
+ * @author Norbert Lataille (Norbert.Lataille at m4x.org)
+ * @author Hiram Chirino (Cojonudo14 at hotmail.com)
+ * @author David Maplesden (David.Maplesden at orion.co.nz)
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ *
+ * $Id: JBossMessage.java 3466 2007-12-10 18:44:52Z timfox $
+ */
+public class JBossMessage implements javax.jms.Message
+{
+ // Constants -----------------------------------------------------
+
+ private static final char PROPERTY_PREFIX_CHAR = 'P';
+
+ private static final String PROPERTY_PREFIX = "P";
+
+ private static final String DESTINATION_HEADER_NAME = "H.DEST";
+
+ private static final String REPLYTO_HEADER_NAME = "H.REPLYTO";
+
+ private static final String CORRELATIONID_HEADER_NAME = "H.CORRELATIONID";
+
+ // When the message is sent through the cluster, it needs to keep the original messageID
+ private static final String JBM_MESSAGE_ID = "JBM_MESSAGE_ID";
+
+ private static final String CORRELATIONIDBYTES_HEADER_NAME = "H.CORRELATIONIDBYTES";
+
+ private static final String TYPE_HEADER_NAME = "H.TYPE";
+
+ public static final String JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME = "JMS_JBOSS_SCHEDULED_DELIVERY";
+
+ //Used when sending a message to the DLQ
+ public static final String JBOSS_MESSAGING_ORIG_DESTINATION = "JBM_ORIG_DESTINATION";
+
+ //Used when sending a message to the DLQ
+ public static final String JBOSS_MESSAGING_ORIG_MESSAGE_ID = "JBM_ORIG_MESSAGE_ID";
+
+ //Used when sending a mesage to the DLQ
+ public static final String JBOSS_MESSAGING_ACTUAL_EXPIRY_TIME = "JBM_ACTUAL_EXPIRY";
+
+ //Used when bridging a message
+ public static final String JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST = "JBM_BRIDGE_MSG_ID_LIST";
+
+ protected static final byte NULL = 0;
+
+ protected static final byte NOT_NULL = 1;
+
+ private static final int TYPE = 0;
+
+ // Static --------------------------------------------------------
+
+ private static final HashSet<String> reservedIdentifiers = new HashSet<String>();
+ static
+ {
+ reservedIdentifiers.add("NULL");
+ reservedIdentifiers.add("TRUE");
+ reservedIdentifiers.add("FALSE");
+ reservedIdentifiers.add("NOT");
+ reservedIdentifiers.add("AND");
+ reservedIdentifiers.add("OR");
+ reservedIdentifiers.add("BETWEEN");
+ reservedIdentifiers.add("LIKE");
+ reservedIdentifiers.add("IN");
+ reservedIdentifiers.add("IS");
+ reservedIdentifiers.add("ESCAPE");
+ }
+
+ private static final Logger log = Logger.getLogger(JBossMessage.class);
+
+
+ public static JBossMessage createMessage(org.jboss.messaging.newcore.Message message,
+ long deliveryID, int deliveryCount)
+ {
+ int type = message.getType();
+
+ switch(type)
+ {
+ case JBossMessage.TYPE:
+ return new JBossMessage(message, deliveryID, deliveryCount);
+ case JBossBytesMessage.TYPE:
+ return new JBossBytesMessage(message, deliveryID, deliveryCount);
+ case JBossMapMessage.TYPE:
+ return new JBossMapMessage(message, deliveryID, deliveryCount);
+ case JBossObjectMessage.TYPE:
+ return new JBossObjectMessage(message, deliveryID, deliveryCount);
+ case JBossStreamMessage.TYPE:
+ return new JBossStreamMessage(message, deliveryID, deliveryCount);
+ case JBossTextMessage.TYPE:
+ return new JBossTextMessage(message, deliveryID, deliveryCount);
+ default:
+ throw new IllegalArgumentException("Invalid message type " + type);
+ }
+ }
+
+ // Attributes ----------------------------------------------------
+
+ //The underlying message
+ protected org.jboss.messaging.newcore.Message message;
+
+ //The SessionDelegate - we need this when acknowledging the message directly
+ private SessionDelegate delegate;
+
+ //From a connection consumer?
+ private boolean cc;
+
+ //The delivery count
+ private int deliveryCount;
+
+ //The delivery id
+ private long deliveryID;
+
+ //Read-only?
+ protected boolean readOnly;
+
+ // Constructors --------------------------------------------------
+
+ protected JBossMessage(int type)
+ {
+ message =
+ new MessageImpl(-1, type, true, 0, System.currentTimeMillis(), (byte)4);
+ }
+
+ public JBossMessage()
+ {
+ this (JBossMessage.TYPE);
+ }
+
+ /**
+ * Constructor for when receiving a message from the server
+ */
+ public JBossMessage(org.jboss.messaging.newcore.Message message, long deliveryID, int deliveryCount)
+ {
+ this.message = message;
+
+ this.deliveryID = deliveryID;
+
+ this.deliveryCount = deliveryCount;
+
+ this.readOnly = true;
+ }
+
+ /*
+ * A constructor that takes a foreign message
+ */
+ public JBossMessage(Message foreign) throws JMSException
+ {
+ this(foreign, JBossMessage.TYPE);
+ }
+
+ protected JBossMessage(Message foreign, int type) throws JMSException
+ {
+ this(type);
+
+ setJMSTimestamp(foreign.getJMSTimestamp());
+
+ try
+ {
+ byte[] corrIDBytes = foreign.getJMSCorrelationIDAsBytes();
+ setJMSCorrelationIDAsBytes(corrIDBytes);
+ }
+ catch(JMSException e)
+ {
+ // specified as String
+ String corrIDString = foreign.getJMSCorrelationID();
+ if (corrIDString != null)
+ {
+ setJMSCorrelationID(corrIDString);
+ }
+ }
+
+ setJMSReplyTo(foreign.getJMSReplyTo());
+ setJMSDestination(foreign.getJMSDestination());
+ setJMSDeliveryMode(foreign.getJMSDeliveryMode());
+ setJMSExpiration(foreign.getJMSExpiration());
+ setJMSPriority(foreign.getJMSPriority());
+ setJMSType(foreign.getJMSType());
+
+ //We can't avoid a cast warning here since getPropertyNames() is on the JMS API
+ for (Enumeration<String> props = foreign.getPropertyNames(); props.hasMoreElements(); )
+ {
+ String name = (String)props.nextElement();
+
+ Object prop = foreign.getObjectProperty(name);
+
+ this.setObjectProperty(name, prop);
+ }
+ }
+
+ // javax.jmx.Message implementation ------------------------------
+
+ public String getJMSMessageID()
+ {
+ String id = (String)message.getHeader(JBM_MESSAGE_ID);
+
+ if (id == null)
+ {
+ id = "ID:JBM-" + message.getMessageID();
+
+ //We cache the JMSMessageID in the header - this is because when moving a message between clusters
+ //the underlying message id can change but we want to preserve the JMSMessageID
+ message.putHeader(JBM_MESSAGE_ID, id);
+ }
+
+ return id;
+ }
+
+ public void setJMSMessageID(String jmsMessageID) throws JMSException
+ {
+ if (jmsMessageID != null && !jmsMessageID.startsWith("ID:"))
+ {
+ throw new JMSException("JMSMessageID must start with ID:");
+ }
+ if (jmsMessageID == null)
+ {
+ message.removeHeader(JBM_MESSAGE_ID);
+ }
+ else
+ {
+ message.putHeader(JBM_MESSAGE_ID, jmsMessageID);
+ }
+ }
+
+ public long getJMSTimestamp() throws JMSException
+ {
+ return message.getTimestamp();
+ }
+
+ public void setJMSTimestamp(long timestamp) throws JMSException
+ {
+ message.setTimestamp(timestamp);
+ }
+
+ public byte[] getJMSCorrelationIDAsBytes() throws JMSException
+ {
+ return (byte[]) message.getHeader(CORRELATIONIDBYTES_HEADER_NAME);
+ }
+
+ public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
+ {
+ if (correlationID == null || correlationID.length == 0)
+ {
+ throw new JMSException("Please specify a non-zero length byte[]");
+ }
+ message.putHeader(CORRELATIONIDBYTES_HEADER_NAME, correlationID);
+
+ message.removeHeader(CORRELATIONID_HEADER_NAME);
+ }
+
+ public void setJMSCorrelationID(String correlationID) throws JMSException
+ {
+ message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
+
+ message.removeHeader(CORRELATIONIDBYTES_HEADER_NAME);
+ }
+
+ public String getJMSCorrelationID() throws JMSException
+ {
+ return (String)message.getHeader(CORRELATIONID_HEADER_NAME);
+ }
+
+ public Destination getJMSReplyTo() throws JMSException
+ {
+ return (Destination)message.getHeader(REPLYTO_HEADER_NAME);
+ }
+
+ public void setJMSReplyTo(Destination replyTo) throws JMSException
+ {
+ message.putHeader(REPLYTO_HEADER_NAME, replyTo);
+ }
+
+ public Destination getJMSDestination() throws JMSException
+ {
+ return (Destination)message.getHeader(DESTINATION_HEADER_NAME);
+ }
+
+ public void setJMSDestination(Destination destination) throws JMSException
+ {
+ message.putHeader(DESTINATION_HEADER_NAME, destination);
+ }
+
+ public int getJMSDeliveryMode() throws JMSException
+ {
+ return message.isReliable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
+ }
+
+ public void setJMSDeliveryMode(int deliveryMode) throws JMSException
+ {
+ if (deliveryMode == DeliveryMode.PERSISTENT)
+ {
+ message.setReliable(true);
+ }
+ else if (deliveryMode == DeliveryMode.NON_PERSISTENT)
+ {
+ message.setReliable(false);
+ }
+ else
+ {
+ throw new MessagingJMSException("Delivery mode must be either DeliveryMode.PERSISTENT "
+ + "or DeliveryMode.NON_PERSISTENT");
+ }
+ }
+
+ public boolean getJMSRedelivered() throws JMSException
+ {
+ return deliveryCount >= 2;
+ }
+
+ public void setJMSRedelivered(boolean redelivered) throws JMSException
+ {
+ if (deliveryCount == 1)
+ {
+ deliveryCount++;
+ }
+ else
+ {
+ //do nothing
+ }
+ }
+
+ /**
+ * @return The JMSType header
+ * @throws JMSException
+ */
+ public String getJMSType() throws JMSException
+ {
+ return (String)message.getHeader(TYPE_HEADER_NAME);
+ }
+
+ /**
+ *
+ * @param type
+ * @throws JMSException
+ */
+ public void setJMSType(String type) throws JMSException
+ {
+ message.putHeader(TYPE_HEADER_NAME, type);
+ }
+
+ public long getJMSExpiration() throws JMSException
+ {
+ return message.getExpiration();
+ }
+
+ public void setJMSExpiration(long expiration) throws JMSException
+ {
+ message.setExpiration(expiration);
+ }
+
+ public int getJMSPriority() throws JMSException
+ {
+ return message.getPriority();
+ }
+
+ public void setJMSPriority(int priority) throws JMSException
+ {
+ message.setPriority((byte)priority);
+ }
+
+ public void clearProperties() throws JMSException
+ {
+ Iterator<String> iter = message.getHeaders().keySet().iterator();
+
+ while (iter.hasNext())
+ {
+ String propName = iter.next();
+
+ if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
+ {
+ iter.remove();
+ }
+ }
+ }
+
+ public void clearBody() throws JMSException
+ {
+ readOnly = false;
+ }
+
+ public boolean propertyExists(String name) throws JMSException
+ {
+ return message.containsHeader(PROPERTY_PREFIX + name)
+ || name.equals("JMSXDeliveryCount");
+ }
+
+ public boolean getBooleanProperty(String name) throws JMSException
+ {
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ return Boolean.valueOf(null).booleanValue();
+
+ if (value instanceof Boolean)
+ return ((Boolean) value).booleanValue();
+ else if (value instanceof String)
+ return Boolean.valueOf((String) value).booleanValue();
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public byte getByteProperty(String name) throws JMSException
+ {
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ throw new NumberFormatException("Message property '" + name + "' not set.");
+
+ if (value instanceof Byte)
+ return ((Byte) value).byteValue();
+ else if (value instanceof String)
+ return Byte.parseByte((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public short getShortProperty(String name) throws JMSException
+ {
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ throw new NumberFormatException("Message property '" + name + "' not set.");
+
+ if (value instanceof Byte)
+ return ((Byte) value).shortValue();
+ else if (value instanceof Short)
+ return ((Short) value).shortValue();
+ else if (value instanceof String)
+ return Short.parseShort((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public int getIntProperty(String name) throws JMSException
+ {
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return deliveryCount;
+ }
+
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+
+ if (value == null)
+ {
+ throw new NumberFormatException("Message property '" + name + "' not set.");
+ }
+
+ if (value instanceof Byte)
+ {
+ return ((Byte) value).intValue();
+ }
+ else if (value instanceof Short)
+ {
+ return ((Short) value).intValue();
+ }
+ else if (value instanceof Integer)
+ {
+ return ((Integer) value).intValue();
+ }
+ else if (value instanceof String)
+ {
+ return Integer.parseInt((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+ }
+
+ public long getLongProperty(String name) throws JMSException
+ {
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return deliveryCount;
+ }
+
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+
+ if (value == null)
+ {
+ throw new NumberFormatException("Message property '" + name + "' not set.");
+ }
+
+ if (value instanceof Byte)
+ {
+ return ((Byte) value).longValue();
+ }
+ else if (value instanceof Short)
+ {
+ return ((Short) value).longValue();
+ }
+ else if (value instanceof Integer)
+ {
+ return ((Integer) value).longValue();
+ }
+ else if (value instanceof Long)
+ {
+ return ((Long) value).longValue();
+ }
+ else if (value instanceof String)
+ {
+ return Long.parseLong((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+ }
+
+ public float getFloatProperty(String name) throws JMSException
+ {
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ return Float.valueOf(null).floatValue();
+
+ if (value instanceof Float)
+ return ((Float) value).floatValue();
+ else if (value instanceof String)
+ return Float.parseFloat((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public double getDoubleProperty(String name) throws JMSException
+ {
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ return Double.valueOf(null).doubleValue();
+
+ if (value instanceof Float)
+ return ((Float) value).doubleValue();
+ else if (value instanceof Double)
+ return ((Double) value).doubleValue();
+ else if (value instanceof String)
+ return Double.parseDouble((String) value);
+ else
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ public String getStringProperty(String name) throws JMSException
+ {
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return Integer.toString(deliveryCount);
+ }
+
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
+ if (value == null)
+ return null;
+
+ if (value instanceof Boolean)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Byte)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Short)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Integer)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Long)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Float)
+ {
+ return value.toString();
+ }
+ else if (value instanceof Double)
+ {
+ return value.toString();
+ }
+ else if (value instanceof String)
+ {
+ return (String) value;
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+ }
+
+ public Object getObjectProperty(String name) throws JMSException
+ {
+ return message.getHeader(PROPERTY_PREFIX + name);
+ }
+
+ public Enumeration getPropertyNames() throws JMSException
+ {
+ HashSet<String> set = new HashSet<String>();
+
+ for (String propName: message.getHeaders().keySet())
+ {
+ if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
+ {
+ String name = propName.substring(1);
+ set.add(name);
+ }
+ }
+
+ return Collections.enumeration(set);
+ }
+
+ public void setBooleanProperty(String name, boolean value) throws JMSException
+ {
+ Boolean b = Primitives.valueOf(value);
+ checkProperty(name, b);
+ message.putHeader(PROPERTY_PREFIX + name, b);
+ }
+
+ public void setByteProperty(String name, byte value) throws JMSException
+ {
+ Byte b = new Byte(value);
+ checkProperty(name, b);
+ message.putHeader(PROPERTY_PREFIX + name, b);
+ }
+
+ public void setShortProperty(String name, short value) throws JMSException
+ {
+ Short s = new Short(value);
+ checkProperty(name, s);
+ message.putHeader(PROPERTY_PREFIX + name, s);
+ }
+
+ public void setIntProperty(String name, int value) throws JMSException
+ {
+ Integer i = new Integer(value);
+ checkProperty(name, i);
+ message.putHeader(PROPERTY_PREFIX + name, i);
+ }
+
+ public void setLongProperty(String name, long value) throws JMSException
+ {
+ Long l = new Long(value);
+ checkProperty(name, l);
+ message.putHeader(PROPERTY_PREFIX + name, l);
+ }
+
+ public void setFloatProperty(String name, float value) throws JMSException
+ {
+ Float f = new Float(value);
+ checkProperty(name, f);
+ message.putHeader(PROPERTY_PREFIX + name, f);
+ }
+
+ public void setDoubleProperty(String name, double value) throws JMSException
+ {
+ Double d = new Double(value);
+ checkProperty(name, d);
+ message.putHeader(PROPERTY_PREFIX + name, d);
+ }
+
+ public void setStringProperty(String name, String value) throws JMSException
+ {
+ checkProperty(name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+
+ public void setObjectProperty(String name, Object value) throws JMSException
+ {
+ checkProperty(name, value);
+
+ if (value instanceof Boolean)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Byte)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Short)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Integer)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Long)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Float)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof Double)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value instanceof String)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, value);
+ }
+ else if (value == null)
+ {
+ message.putHeader(PROPERTY_PREFIX + name, null);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid object type");
+ }
+ }
+
+ public void acknowledge() throws JMSException
+ {
+ if (!cc)
+ {
+ //Only acknowledge for client ack if is not in connection consumer
+ delegate.acknowledgeAll();
+ }
+ }
+
+ // Public --------------------------------------------------------
+
+ public org.jboss.messaging.newcore.Message getCoreMessage()
+ {
+ return message;
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ //NOOP
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ //NOOP
+ }
+
+ protected void beforeSend() throws Exception
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+
+ DataOutputStream daos = new DataOutputStream(baos);
+
+ writePayload(daos);
+
+ daos.close();
+
+ message.setPayload(baos.toByteArray());
+ }
+
+ protected void beforeReceive() throws Exception
+ {
+ DataInputStream dais = new DataInputStream(new ByteArrayInputStream(message.getPayload()));
+
+ readPayload(dais);
+ }
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ }
+
+ public byte getType()
+ {
+ return JBossMessage.TYPE;
+ }
+
+ public void setSessionDelegate(SessionDelegate sd, boolean isConnectionConsumer)
+ {
+ this.delegate = sd;
+ this.cc = isConnectionConsumer;
+ }
+
+ public SessionDelegate getSessionDelegate()
+ {
+ return delegate;
+ }
+
+ public int getDeliveryCount()
+ {
+ return deliveryCount;
+ }
+
+ public void incDeliveryCount()
+ {
+ this.deliveryCount++;
+ }
+
+ public long getDeliveryId()
+ {
+ return deliveryID;
+ }
+
+ public void copyMessage()
+ {
+ message = message.copy();
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer("JBossMessage[");
+ sb.append("");
+ sb.append(getJMSMessageID());
+ sb.append("]:");
+ sb.append(message.isReliable() ? "PERSISTENT" : "NON-PERSISTENT");
+ return sb.toString();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void checkWrite() throws JMSException
+ {
+ if (readOnly)
+ {
+ throw new MessageNotWriteableException("Message is read-only");
+ }
+ }
+
+ protected void checkRead() throws JMSException
+ {
+ if (!readOnly)
+ {
+ throw new MessageNotReadableException("Message is write-only");
+ }
+ }
+
+ // Private ------------------------------------------------------------
+
+ private void checkProperty(String name, Object value) throws JMSException
+ {
+ checkWrite();
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException("The name of a property must not be null.");
+ }
+
+ if (name.equals(""))
+ {
+ throw new IllegalArgumentException("The name of a property must not be an empty String.");
+ }
+
+ if (!Strings.isValidJavaIdentifier(name))
+ {
+ throw new IllegalArgumentException("The property name '" + name +
+ "' is not a valid java identifier.");
+ }
+
+ if (reservedIdentifiers.contains(name))
+ {
+ throw new IllegalArgumentException("The property name '" + name +
+ "' is reserved due to selector syntax.");
+ }
+
+ if (name.startsWith("JMSX") &&
+ !name.equals("JMSXGroupID") &&
+ !name.equals("JMSXGroupSeq") &&
+ !name.equals("JMSXDeliveryCount"))
+ {
+ throw new JMSException("Can only set JMSXGroupId, JMSXGroupSeq, JMSXDeliveryCount");
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+}
Added: trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * This class implements javax.jms.ObjectMessage
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ *
+ * @version $Revision: 3412 $
+ *
+ * $Id: JBossObjectMessage.java 3412 2007-12-05 19:41:47Z timfox $
+ */
+public class JBossObjectMessage extends JBossMessage implements ObjectMessage
+{
+ // Constants -----------------------------------------------------
+
+ public static final byte TYPE = 2;
+
+ // Attributes ----------------------------------------------------
+
+ private Serializable object;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ /*
+ * This constructor is used to construct messages prior to sending
+ */
+ public JBossObjectMessage()
+ {
+ super(JBossObjectMessage.TYPE);
+ }
+
+ public JBossObjectMessage(org.jboss.messaging.newcore.Message message, long deliveryID, int deliveryCount)
+ {
+ super(message, deliveryID, deliveryCount);
+ }
+
+ /**
+ * A copy constructor for foreign JMS ObjectMessages.
+ */
+ public JBossObjectMessage(ObjectMessage foreign) throws JMSException
+ {
+ super(foreign, JBossObjectMessage.TYPE);
+
+ setObject(foreign.getObject());
+ }
+
+ // Public --------------------------------------------------------
+
+ public byte getType()
+ {
+ return JBossObjectMessage.TYPE;
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ beforeSend();
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ beforeReceive();
+ }
+
+
+ // ObjectMessage implementation ----------------------------------
+
+ public void setObject(Serializable object) throws JMSException
+ {
+ checkWrite();
+
+ this.object = object;
+ }
+
+ public Serializable getObject() throws JMSException
+ {
+ return object;
+ }
+
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+
+ object = null;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(daos);
+ oos.writeObject(object);
+ oos.flush();
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ ObjectInputStream ois = new ObjectInputStream(dais);
+ object = (Serializable)ois.readObject();
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Added: trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,739 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.MessageEOFException;
+import javax.jms.MessageFormatException;
+import javax.jms.StreamMessage;
+
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * This class implements javax.jms.StreamMessage.
+ *
+ * @author Norbert Lataille (Norbert.Lataille at m4x.org)
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ *
+ * @version $Revision: 3412 $
+ *
+ * $Id: JBossStreamMessage.java 3412 2007-12-05 19:41:47Z timfox $
+ */
+public class JBossStreamMessage extends JBossMessage implements StreamMessage
+{
+ // Constants -----------------------------------------------------
+
+ public static final byte TYPE = 6;
+
+ // Attributes ----------------------------------------------------
+
+ private int position;
+
+ private int offset;
+
+ //private int size;
+
+ private List<Object> list = new ArrayList<Object>();
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ /*
+ * This constructor is used to construct messages prior to sending
+ */
+ public JBossStreamMessage()
+ {
+ super(JBossStreamMessage.TYPE);
+ }
+
+ public JBossStreamMessage(org.jboss.messaging.newcore.Message message, long deliveryID, int deliveryCount)
+ {
+ super(message, deliveryID, deliveryCount);
+ }
+
+ public JBossStreamMessage(StreamMessage foreign) throws JMSException
+ {
+ super(foreign, JBossStreamMessage.TYPE);
+
+ foreign.reset();
+
+ try
+ {
+ while (true)
+ {
+ Object obj = foreign.readObject();
+ this.writeObject(obj);
+ }
+ }
+ catch (MessageEOFException e)
+ {
+ //Ignore
+ }
+ }
+
+ // Public --------------------------------------------------------
+
+ public byte getType()
+ {
+ return JBossStreamMessage.TYPE;
+ }
+
+ // StreamMessage implementation ----------------------------------
+
+ public boolean readBoolean() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ offset = 0;
+
+ boolean result;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Boolean)
+ {
+ result = ((Boolean)value).booleanValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Boolean.valueOf((String) value).booleanValue();
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+
+ }
+
+ public byte readByte() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ offset = 0;
+
+ byte result;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Byte)
+ {
+ result = ((Byte) value).byteValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Byte.parseByte((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public short readShort() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ short result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Byte)
+ {
+ result = ((Byte) value).shortValue();
+ }
+ else if (value instanceof Short)
+ {
+ result = ((Short) value).shortValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Short.parseShort((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public char readChar() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ char result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Character)
+ {
+ result = ((Character) value).charValue();
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public int readInt() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ int result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Byte)
+ {
+ result = ((Byte) value).intValue();
+ }
+ else if (value instanceof Short)
+ {
+ result = ((Short) value).intValue();
+ }
+ else if (value instanceof Integer)
+ {
+ result = ((Integer) value).intValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Integer.parseInt((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public long readLong() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ long result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Byte)
+ {
+ result = ((Byte) value).longValue();
+ }
+ else if (value instanceof Short)
+ {
+ result = ((Short) value).longValue();
+ }
+ else if (value instanceof Integer)
+ {
+ result = ((Integer) value).longValue();
+ }
+ else if (value instanceof Long)
+ {
+ result = ((Long) value).longValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Long.parseLong((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public float readFloat() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ float result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Float)
+ {
+ result = ((Float) value).floatValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Float.parseFloat((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public double readDouble() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ offset = 0;
+
+ double result;
+
+ if (value == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+ else if (value instanceof Float)
+ {
+ result = ((Float) value).doubleValue();
+ }
+ else if (value instanceof Double)
+ {
+ result = ((Double) value).doubleValue();
+ }
+ else if (value instanceof String)
+ {
+ result = Double.parseDouble((String) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public String readString() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+
+ String result;
+
+ offset = 0;
+
+ if (value == null)
+ {
+ result = null;
+ }
+ else if (value instanceof Boolean)
+ {
+ result = ((Boolean) value).toString();
+ }
+ else if (value instanceof Byte)
+ {
+ result = ((Byte) value).toString();
+ }
+ else if (value instanceof Short)
+ {
+ result = ((Short) value).toString();
+ }
+ else if (value instanceof Character)
+ {
+ result = ((Character) value).toString();
+ }
+ else if (value instanceof Integer)
+ {
+ result = ((Integer) value).toString();
+ }
+ else if (value instanceof Long)
+ {
+ result = ((Long) value).toString();
+ }
+ else if (value instanceof Float)
+ {
+ result = ((Float) value).toString();
+ }
+ else if (value instanceof Double)
+ {
+ result = ((Double) value).toString();
+ }
+ else if (value instanceof String)
+ {
+ result = (String) value;
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public int readBytes(byte[] value) throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object myObj = list.get(position);
+
+ if (myObj == null)
+ {
+ throw new NullPointerException("Value is null");
+ }
+
+ if (!(myObj instanceof byte[]))
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+
+ byte[] obj = (byte[]) myObj;
+
+ if (obj.length == 0)
+ {
+ position++;
+ offset = 0;
+ return 0;
+ }
+
+ if (offset >= obj.length)
+ {
+ position++;
+ offset = 0;
+ return -1;
+ }
+
+ if (obj.length - offset < value.length)
+ {
+ for (int i = 0; i < obj.length; i++)
+ value[i] = obj[i + offset];
+
+ position++;
+ offset = 0;
+
+ return obj.length - offset;
+ }
+ else
+ {
+ for (int i = 0; i < value.length; i++)
+ value[i] = obj[i + offset];
+ offset += value.length;
+
+ return value.length;
+ }
+
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public Object readObject() throws JMSException
+ {
+ checkRead();
+ try
+ {
+ Object value = list.get(position);
+ position++;
+ offset = 0;
+
+ return value;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MessageEOFException("");
+ }
+ }
+
+ public void writeBoolean(boolean value) throws JMSException
+ {
+ checkWrite();
+ list.add(Boolean.valueOf(value));
+ }
+
+ public void writeByte(byte value) throws JMSException
+ {
+ checkWrite();
+ list.add(Byte.valueOf(value));
+ }
+
+ public void writeShort(short value) throws JMSException
+ {
+ checkWrite();
+ list.add(Short.valueOf(value));
+ }
+
+ public void writeChar(char value) throws JMSException
+ {
+ checkWrite();
+ list.add(Character.valueOf(value));
+ }
+
+ public void writeInt(int value) throws JMSException
+ {
+ checkWrite();
+ list.add(Integer.valueOf(value));
+ }
+
+ public void writeLong(long value) throws JMSException
+ {
+ checkWrite();
+ list.add(Long.valueOf(value));
+ }
+
+ public void writeFloat(float value) throws JMSException
+ {
+ checkWrite();
+ list.add(Float.valueOf(value));
+ }
+
+ public void writeDouble(double value) throws JMSException
+ {
+ checkWrite();
+ list.add(Double.valueOf(value));
+ }
+
+ public void writeString(String value) throws JMSException
+ {
+ checkWrite();
+ if (value == null)
+ {
+ list.add(null);
+ }
+ else
+ {
+ list.add(value);
+ }
+ }
+
+ public void writeBytes(byte[] value) throws JMSException
+ {
+ checkWrite();
+ list.add(value.clone());
+ }
+
+ public void writeBytes(byte[] value, int offset, int length) throws JMSException
+ {
+ checkWrite();
+ if (offset + length > value.length)
+ {
+ throw new JMSException("Invalid offset/length");
+ }
+
+ byte[] newBytes = new byte[length];
+
+ System.arraycopy(value, offset, newBytes, 0, length);
+
+ list.add(newBytes);
+ }
+
+ public void writeObject(Object value) throws JMSException
+ {
+ checkWrite();
+ if (value == null)
+ list.add(null);
+ else if (value instanceof Boolean)
+ list.add(value);
+ else if (value instanceof Byte)
+ list.add(value);
+ else if (value instanceof Short)
+ list.add(value);
+ else if (value instanceof Character)
+ list.add(value);
+ else if (value instanceof Integer)
+ list.add(value);
+ else if (value instanceof Long)
+ list.add(value);
+ else if (value instanceof Float)
+ list.add(value);
+ else if (value instanceof Double)
+ list.add(value);
+ else if (value instanceof String)
+ list.add(value);
+ else if (value instanceof byte[])
+ list.add(((byte[]) value).clone());
+ else
+ throw new MessageFormatException("Invalid object type");
+ }
+
+ public void reset() throws JMSException
+ {
+ position = 0;
+ offset = 0;
+ readOnly = true;
+ }
+
+ // JBossMessage overrides ----------------------------------------
+
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+
+ list.clear();
+ position = 0;
+ offset = 0;
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ reset();
+
+ beforeSend();
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ beforeReceive();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ StreamUtils.writeList(daos, list);
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ list = StreamUtils.readList(dais);
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Added: trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossTextMessage.java (rev 0)
+++ trunk/src/main/org/jboss/jms/message/JBossTextMessage.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.message;
+
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.util.SafeUTF;
+
+/**
+ * This class implements javax.jms.TextMessage ported from SpyTextMessage in JBossMQ.
+ *
+ * @author Norbert Lataille (Norbert.Lataille at m4x.org)
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ *
+ * @version $Revision: 3412 $
+ *
+ * $Id: JBossTextMessage.java 3412 2007-12-05 19:41:47Z timfox $
+ */
+public class JBossTextMessage extends JBossMessage implements TextMessage
+{
+ // Constants -----------------------------------------------------
+
+ public static final byte TYPE = 3;
+
+ public static final Logger log = Logger.getLogger(JBossTextMessage.class);
+
+ // Attributes ----------------------------------------------------
+
+ private String text;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ /*
+ * This constructor is used to construct messages prior to sending
+ */
+ public JBossTextMessage()
+ {
+ super(JBossTextMessage.TYPE);
+ }
+
+ public JBossTextMessage(org.jboss.messaging.newcore.Message message, long deliveryID, int deliveryCount)
+ {
+ super(message, deliveryID, deliveryCount);
+ }
+
+ /**
+ * A copy constructor for non-JBoss Messaging JMS TextMessages.
+ */
+ public JBossTextMessage(TextMessage foreign) throws JMSException
+ {
+ super(foreign, JBossTextMessage.TYPE);
+
+ text = foreign.getText();
+ }
+
+ // Public --------------------------------------------------------
+
+ public byte getType()
+ {
+ return JBossTextMessage.TYPE;
+ }
+
+ public void doBeforeSend() throws Exception
+ {
+ beforeSend();
+ }
+
+ public void doBeforeReceive() throws Exception
+ {
+ beforeReceive();
+ }
+
+ // TextMessage implementation ------------------------------------
+
+ public void setText(String text) throws JMSException
+ {
+ checkWrite();
+
+ this.text = text;
+ }
+
+ public String getText() throws JMSException
+ {
+ return text;
+ }
+
+ public void clearBody() throws JMSException
+ {
+ super.clearBody();
+
+ text = null;
+ }
+
+ // JBossMessage override -----------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void writePayload(DataOutputStream daos) throws Exception
+ {
+ //TODO - if send strings in plain format as opposed to UTF-8 then we can calculate the size
+ //in advance more easily - so we can allocate a byte buffer - as opposed to using a stream
+
+ if (text == null)
+ {
+ daos.writeByte(NULL);
+ }
+ else
+ {
+ daos.writeByte(NOT_NULL);
+
+ SafeUTF.safeWriteUTF(daos, text);
+ }
+ }
+
+ protected void readPayload(DataInputStream dais) throws Exception
+ {
+ byte b = dais.readByte();
+
+ if (b == NULL)
+ {
+ text = null;
+ }
+ else
+ {
+ text = SafeUTF.safeReadUTF(dais);
+ }
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ // Public --------------------------------------------------------
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/messaging/newcore/Destination.java
===================================================================
--- trunk/src/main/org/jboss/messaging/newcore/Destination.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/newcore/Destination.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,19 @@
+package org.jboss.messaging.newcore;
+
+import org.jboss.messaging.util.Streamable;
+
+/**
+ *
+ * A Destination
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface Destination extends Streamable
+{
+ String getType();
+
+ String getName();
+
+ boolean isTemporary();
+}
Added: trunk/src/main/org/jboss/messaging/newcore/impl/DestinationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/newcore/impl/DestinationImpl.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/newcore/impl/DestinationImpl.java 2007-12-17 15:58:08 UTC (rev 3515)
@@ -0,0 +1,72 @@
+package org.jboss.messaging.newcore.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.Serializable;
+
+import org.jboss.messaging.newcore.Destination;
+
+/**
+ *
+ * A DestinationImpl
+ *
+ * TODO remove serializable once SendPacket has destination and scheduled delivery time
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class DestinationImpl implements Destination, Serializable
+{
+ private String type;
+
+ private String name;
+
+ private boolean temporary;
+
+ public DestinationImpl()
+ {
+ }
+
+ public DestinationImpl(String type, String name, boolean temporary)
+ {
+ this.type = type;
+
+ this.name = name;
+
+ this.temporary = temporary;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean isTemporary()
+ {
+ return temporary;
+ }
+
+ public void read(DataInputStream in) throws Exception
+ {
+ type = in.readUTF();
+
+ name = in.readUTF();
+
+ temporary = in.readBoolean();
+ }
+
+ public void write(DataOutputStream out) throws Exception
+ {
+ out.writeUTF(type);
+
+ out.writeUTF(name);
+
+ out.writeBoolean(temporary);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list