You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ar...@apache.org on 2007/08/13 15:59:49 UTC
svn commit: r565354 - in
/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms:
./ message/
Author: arnaudsimon
Date: Mon Aug 13 06:59:48 2007
New Revision: 565354
URL: http://svn.apache.org/viewvc?view=rev&rev=565354
Log:
added constructors
Added:
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java (with props)
Removed:
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessaeImpl.java
Modified:
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/MessageActor.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/SessionImpl.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/BytesMessageImpl.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MapMessageImpl.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageFactory.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/ObjectMessageImpl.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/TextMessageImpl.java
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/MessageActor.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/MessageActor.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/MessageActor.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/MessageActor.java Mon Aug 13 06:59:48 2007
@@ -157,7 +157,7 @@
*
* @return This Actor's Session.
*/
- protected SessionImpl getSession()
+ public SessionImpl getSession()
{
return _session;
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/SessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/SessionImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/SessionImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/SessionImpl.java Mon Aug 13 06:59:48 2007
@@ -975,7 +975,7 @@
*
* @throws JMSException If this method is called on a closed session.
*/
- protected void acknowledge() throws JMSException
+ public void acknowledge() throws JMSException
{
checkNotClosed();
if (getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/BytesMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/BytesMessageImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/BytesMessageImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/BytesMessageImpl.java Mon Aug 13 06:59:48 2007
@@ -51,7 +51,27 @@
*/
protected DataOutputStream _dataOut = new DataOutputStream(_storedData);
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public BytesMessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_BYTESMESSAGE));
+ }
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected BytesMessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
+
+ //--- BytesMessage API
/**
* Gets the number of bytes of the message body when the message
* is in read-only mode.
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MapMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MapMessageImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MapMessageImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MapMessageImpl.java Mon Aug 13 06:59:48 2007
@@ -40,6 +40,27 @@
*/
private Map<String, Object> _map = new HashMap<String, Object>();
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public MapMessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_MAPMESSAGE));
+ }
+
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected MapMessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
+
+ //-- Map Message API
/**
* Indicates whether an key exists in this MapMessage.
*
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageFactory.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageFactory.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageFactory.java Mon Aug 13 06:59:48 2007
@@ -17,10 +17,59 @@
*/
package org.apache.qpidity.jms.message;
+import org.apache.qpidity.QpidException;
+
/**
- *
- *
+ * A factory for JMS messages
*/
public class MessageFactory
{
+ /**
+ * JMS Message hierarchy.
+ */
+ public static final byte JAVAX_JMS_MESSAGE = 1;
+ public static final byte JAVAX_JMS_TEXTMESSAGE = 2;
+ public static final byte JAVAX_JMS_STREAMMESSAGE = 3;
+ public static final byte JAVAX_JMS_BYTESMESSAGE = 4;
+ public static final byte JAVAX_JMS_OBJECTMESSAGE = 5;
+ public static final byte JAVAX_JMS_MAPMESSAGE = 6;
+
+ /**
+ * Create a QpidMessage subclass according to the JMS message type.
+ *
+ * @param message The received qpidity messsage
+ * @return The newly craeted JMS message
+ * @throws QpidException If an appropriate Message class cannot be created.
+ */
+ public static QpidMessage getQpidMessage(org.apache.qpidity.api.Message message) throws QpidException
+ {
+ QpidMessage result = null;
+ byte type = Byte.valueOf(message.getMessageProperties().getType());
+ switch (type)
+ {
+ case JAVAX_JMS_MESSAGE:
+ result = new MessageImpl(message);
+ break;
+ case JAVAX_JMS_TEXTMESSAGE:
+ result = new TextMessageImpl(message);
+ break;
+ case JAVAX_JMS_STREAMMESSAGE:
+ result = new StreamMessageImpl(message);
+ break;
+ case JAVAX_JMS_BYTESMESSAGE:
+ result = new BytesMessageImpl(message);
+ break;
+ case JAVAX_JMS_OBJECTMESSAGE:
+ result = new ObjectMessageImpl(message);
+ break;
+ case JAVAX_JMS_MAPMESSAGE:
+ result = new MapMessageImpl(message);
+ break;
+ default:
+ throw new QpidException(
+ "Message type identifier is not mapped " + "to a Message class in the current factory: " + type,
+ null, null);
+ }
+ return result;
+ }
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java Mon Aug 13 06:59:48 2007
@@ -18,6 +18,7 @@
package org.apache.qpidity.jms.message;
import org.apache.qpidity.jms.ExceptionHelper;
+import org.apache.qpidity.jms.MessageConsumerImpl;
import org.apache.qpidity.QpidException;
import javax.jms.*;
@@ -52,6 +53,31 @@
*/
protected boolean _proertiesReadOnly = false;
+ /**
+ * The message consumer through which this message was received.
+ */
+ private MessageConsumerImpl _messageConsumer;
+
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public MessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_MESSAGE));
+ }
+
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected MessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
+
//---- javax.jms.Message interface
/**
* Get the message ID.
@@ -799,9 +825,18 @@
super.setProperty(name, value);
}
+ /**
+ * Acknowledgment of a message automatically acknowledges all
+ * messages previously received by the session. Clients may
+ * individually acknowledge messages or they may choose to acknowledge
+ * messages in application defined groups (which is done by acknowledging
+ * the last received message in the group).
+ *
+ * @throws JMSException If this method is called on a closed session.
+ */
public void acknowledge() throws JMSException
{
- // TODO
+ _messageConsumer.getSession().acknowledge();
}
/**
@@ -862,5 +897,16 @@
{
throw new MessageNotWriteableException("Cannot update message");
}
+ }
+
+ /**
+ * Set the MessageConsumerImpl through which this message was received.
+ * <p> This method is called after a message is received.
+ *
+ * @param messageConsumer the MessageConsumerImpl reference through which this message was received.
+ */
+ public void setMessageConsumer(MessageConsumerImpl messageConsumer)
+ {
+ _messageConsumer = messageConsumer;
}
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/ObjectMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/ObjectMessageImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/ObjectMessageImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/ObjectMessageImpl.java Mon Aug 13 06:59:48 2007
@@ -43,6 +43,26 @@
*/
private Serializable _object = null;
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public ObjectMessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_OBJECTMESSAGE));
+ }
+
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected ObjectMessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
+
//--- Interface ObjctMessage
/**
* Sets the serializable object containing this message's data.
@@ -140,15 +160,13 @@
catch (IOException ioe)
{
throw new QpidException(
- "Unexpected error during rebuild of message in afterReceive() - " +
- "The Object stored in the message was not a Serializable object.",
+ "Unexpected error during rebuild of message in afterReceive() - " + "The Object stored in the message was not a Serializable object.",
null, ioe);
}
catch (ClassNotFoundException clnfe)
{
throw new QpidException(
- "Unexpected error during rebuild of message in afterReceive() - " +
- "Could not find the required class in classpath.",
+ "Unexpected error during rebuild of message in afterReceive() - " + "Could not find the required class in classpath.",
null, clnfe);
}
}
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java Mon Aug 13 06:59:48 2007
@@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Enumeration;
import java.util.Vector;
+import java.util.HashMap;
import java.nio.ByteBuffer;
@@ -51,13 +52,31 @@
//--- This is required as AMQP delivery modes are different from the JMS ones
public static final short DELIVERY_MODE_PERSISTENT = 2;
public static final short DELIVERY_MODE_NON_PERSISTENT = 1;
- //--- This is the default message type
- public static final String MESSAGE_TYPE = "JMS Message";
+
+
+ //-- Constructors
+
+ /**
+ * Constructor used when JMS messages are created by SessionImpl.
+ */
+ protected QpidMessage()
+ {
+ // TODO we need an implementation class: _qpidityMessage
+ _messageProperties = new HashMap<String, Object>();
+ }
/**
- * The message properties
+ * Constructor used when a Qpid message is received
+ *
+ * @param message The received message
*/
+ protected QpidMessage(org.apache.qpidity.api.Message message)
+ {
+ _qpidityMessage = message;
+ _messageProperties = (Map<String, Object>) message.getMessageProperties().getApplicationHeaders();
+ }
+ //---- getters and setters.
/**
* Get the message ID.
*
@@ -178,7 +197,6 @@
/**
* Get this message type.
- * The default value is {@link QpidMessage#MESSAGE_TYPE}
*
* @return This message type.
*/
Added: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java?view=auto&rev=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java Mon Aug 13 06:59:48 2007
@@ -0,0 +1,1112 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpidity.jms.message;
+
+import javax.jms.*;
+import java.io.IOException;
+import java.io.EOFException;
+
+/**
+ * The JMS spec says:
+ * StreamMessage objects support the following conversion table.
+ * The marked cases must be supported. The unmarked cases must throw a JMSException.
+ * The String-to-primitive conversions may throw a runtime exception if the
+ * primitive's valueOf() method does not accept it as a valid String representation of the primitive.
+ * <p> A value written as the row type can be read as the column type.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |boolean | X X
+ * |byte | X X X X X
+ * |short | X X X X
+ * |char | X X
+ * |int | X X X
+ * |long | X X
+ * |float | X X X
+ * |double | X X
+ * |String | X X X X X X X X
+ * |byte[] | X
+ * |----------------------------------------------------------------------
+ */
+public class StreamMessageImpl extends BytesMessageImpl implements StreamMessage
+{
+ /**
+ * Those statics represent incoming field types. The type of a field is
+ * written first in the stream
+ */
+ private static final byte BOOLEAN = 1;
+ private static final byte BYTE = 2;
+ private static final byte CHAR = 3;
+ private static final byte DOUBLE = 4;
+ private static final byte FLOAT = 5;
+ private static final byte INT = 6;
+ private static final byte LONG = 7;
+ private static final byte SHORT = 8;
+ private static final byte STRING = 9;
+ private static final byte BYTEARRAY = 10;
+ private static final byte NULL = 11;
+
+ /**
+ * The size of the byteArray written in this stream
+ */
+ private int _sizeOfByteArray = 0;
+
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public StreamMessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_STREAMMESSAGE));
+ }
+
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected StreamMessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
+
+ //--- Interface StreamMessage
+ /**
+ * Reads a boolean.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |boolean | X X
+ *
+ * @return The boolean value read
+ * @throws JMSException If reading a boolean fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public boolean readBoolean() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ boolean result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case BOOLEAN:
+ result = super.readBoolean();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = Boolean.valueOf(new String(bArray));
+ break;
+ case NULL:
+ result = false;
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads a byte.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |byte | X X
+ *
+ * @return The byte value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public byte readByte() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ byte result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case BYTE:
+ result = super.readByte();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new Byte(new String(bArray));
+ break;
+ case NULL:
+ result = Byte.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads a short.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |short | X X X
+ *
+ * @return The short value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public short readShort() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ short result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case SHORT:
+ result = super.readShort();
+ break;
+ case BYTE:
+ result = super.readByte();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new Short(new String(bArray));
+ break;
+ case NULL:
+ result = Short.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads a char.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |char | X
+ *
+ * @return The char value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public char readChar() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ char result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case CHAR:
+ result = super.readChar();
+ break;
+ case NULL:
+ _dataIn.reset();
+ throw new NullPointerException();
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an Int.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |int | X X X X
+ *
+ * @return The int value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public int readInt() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ int result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case INT:
+ result = super.readInt();
+ break;
+ case SHORT:
+ result = super.readShort();
+ break;
+ case BYTE:
+ result = super.readByte();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new Integer(new String(bArray));
+ break;
+ case NULL:
+ result = Integer.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an Long.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |long | X X X X X
+ *
+ * @return The long value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public long readLong() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ long result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case LONG:
+ result = super.readLong();
+ break;
+ case INT:
+ result = super.readInt();
+ break;
+ case SHORT:
+ result = super.readShort();
+ break;
+ case BYTE:
+ result = super.readByte();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = (new Long(new String(bArray)));
+ break;
+ case NULL:
+ result = Long.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an Float.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |float | X X
+ *
+ * @return The float value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public float readFloat() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ float result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case FLOAT:
+ result = super.readFloat();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new Float(new String(bArray));
+ break;
+ case NULL:
+ result = Float.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an double.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |double | X X X
+ *
+ * @return The double value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public double readDouble() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ double result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case DOUBLE:
+ result = super.readDouble();
+ break;
+ case FLOAT:
+ result = super.readFloat();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new Double(new String(bArray));
+ break;
+ case NULL:
+ result = Double.valueOf(null);
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an string.
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |double | X X X X X X X X X
+ *
+ * @return The string value read
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public String readString() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ String result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case BOOLEAN:
+ result = Boolean.valueOf(super.readBoolean()).toString();
+ break;
+ case BYTE:
+ result = Byte.valueOf(super.readByte()).toString();
+ break;
+ case SHORT:
+ result = Short.valueOf(super.readShort()).toString();
+ break;
+ case CHAR:
+ result = Character.valueOf(super.readChar()).toString();
+ break;
+ case INT:
+ result = Integer.valueOf(super.readInt()).toString();
+ break;
+ case LONG:
+ result = Long.valueOf(super.readLong()).toString();
+ break;
+ case FLOAT:
+ result = Float.valueOf(super.readFloat()).toString();
+ break;
+ case DOUBLE:
+ result = Double.valueOf(super.readDouble()).toString();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ if (len == 0)
+ {
+ throw new NullPointerException("trying to read a null String");
+ }
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new String(bArray);
+ break;
+ case NULL:
+ result = null;
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an byte[].
+ * <p/>
+ * | | boolean byte short char int long float double String byte[]
+ * |----------------------------------------------------------------------
+ * |byte[] | X
+ * <p> The JMS spec says:
+ * To read the field value, readBytes should be successively called until
+ * it returns a value less than the length
+ * of the read buffer. The value of the bytes in the buffer following the last byte read is undefined.
+ *
+ * @param value The byte array into which the data is read.
+ * @return the total number of bytes read into the array, or -1 if
+ * there is no more data because the end of the byte field has been
+ * reached.
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public int readBytes(byte[] value) throws JMSException
+ {
+ isReadable();
+ int result = -1;
+ try
+ {
+ byte type = BYTEARRAY;
+ if (_sizeOfByteArray == 0)
+ {
+ // we are not in the middle of reading this byte array
+ _dataIn.mark(10);
+ type = _dataIn.readByte();
+ }
+ switch (type)
+ {
+ case BYTEARRAY:
+ if (_sizeOfByteArray == 0)
+ {
+ // we need to read the size of this byte array
+ _sizeOfByteArray = _dataIn.readInt();
+ }
+ result = _dataIn.read(value, 0, value.length);
+ if (result != -1)
+ {
+ _sizeOfByteArray = _sizeOfByteArray - result;
+ }
+ else
+ {
+ _sizeOfByteArray = 0;
+ }
+ case NULL:
+ // result = -1;
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Reads an object from the stream message.
+ * <p> The JMS spec says:
+ * <P>This method can be used to return, in objectified format,
+ * an object in the Java programming language ("Java object") that has
+ * been written to the stream with the equivalent
+ * <CODE>writeObject</CODE> method call, or its equivalent primitive
+ * <CODE>write<I>type</I></CODE> method.
+ * <P>An attempt to call <CODE>readObject</CODE> to read a byte field
+ * value into a new <CODE>byte[]</CODE> object before the full value of the
+ * byte field has been read will throw a
+ * <CODE>MessageFormatException</CODE>.
+ *
+ * @return A Java object from the stream message, in objectified
+ * format
+ * @throws JMSException If reading fails due to some error.
+ * @throws javax.jms.MessageEOFException If unexpected end of message data has been reached.
+ * @throws javax.jms.MessageNotReadableException
+ * If the message is in write-only mode.
+ * @throws MessageFormatException If this type conversion is invalid.
+ */
+ public Object readObject() throws JMSException
+ {
+ isReadableAndNotReadingByteArray();
+ Object result;
+ try
+ {
+ _dataIn.mark(10);
+ byte type = _dataIn.readByte();
+ switch (type)
+ {
+ case BOOLEAN:
+ result = super.readBoolean();
+ break;
+ case BYTE:
+ result = super.readByte();
+ break;
+ case SHORT:
+ result = super.readShort();
+ break;
+ case CHAR:
+ result = super.readChar();
+ break;
+ case INT:
+ result = super.readInt();
+ break;
+ case LONG:
+ result = super.readLong();
+ break;
+ case FLOAT:
+ result = super.readFloat();
+ break;
+ case DOUBLE:
+ result = super.readDouble();
+ break;
+ case STRING:
+ int len = _dataIn.readInt();
+ if (len == 0)
+ {
+ result = null;
+ }
+ else
+ {
+ byte[] bArray = new byte[len];
+ _dataIn.readFully(bArray);
+ result = new String(bArray);
+ }
+ break;
+ case BYTEARRAY:
+ int totalBytes = _dataIn.readInt();
+ byte[] bArray = new byte[totalBytes];
+ _dataIn.read(bArray, 0, totalBytes);
+ result = bArray;
+ break;
+ case NULL:
+ result = null;
+ break;
+ default:
+ _dataIn.reset();
+ throw new MessageFormatException("Invalid Object Type");
+ }
+ }
+ catch (EOFException eof)
+ {
+ throw new MessageEOFException("End of file Reached when reading message");
+ }
+ catch (IOException io)
+ {
+ throw new JMSException("IO exception when reading message");
+ }
+ return result;
+ }
+
+ /**
+ * Writes a boolean to the stream message.
+ *
+ * @param val The boolean value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeBoolean(boolean val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(BOOLEAN);
+ super.writeBoolean(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a byte to the stream message.
+ *
+ * @param val The byte value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeByte(byte val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(BYTE);
+ super.writeByte(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a short to the stream message.
+ *
+ * @param val The short value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeShort(short val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(SHORT);
+ super.writeShort(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a char to the stream message.
+ *
+ * @param val The char value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeChar(char val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(CHAR);
+ super.writeChar(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a int to the stream message.
+ *
+ * @param val The int value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeInt(int val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(INT);
+ super.writeInt(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a long to the stream message.
+ *
+ * @param val The long value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeLong(long val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(LONG);
+ super.writeLong(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a float to the stream message.
+ *
+ * @param val The float value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeFloat(float val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(FLOAT);
+ super.writeFloat(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a double to the stream message.
+ *
+ * @param val The double value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeDouble(double val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(DOUBLE);
+ super.writeDouble(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a string to the stream message.
+ *
+ * @param val The string value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeString(String val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(STRING);
+ if (val == null)
+ {
+ _dataOut.writeInt(0);
+ }
+ else
+ {
+ byte[] bArray = val.getBytes();
+ int len = bArray.length;
+ _dataOut.writeInt(len);
+ _dataOut.write(bArray);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a byte array to the stream message.
+ *
+ * @param val The byte array value to be written
+ * @throws JMSException If writting a boolean fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeBytes(byte[] val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(BYTEARRAY);
+ _dataOut.writeInt(val.length);
+ super.writeBytes(val);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes a portion of byte array to the bytes message.
+ *
+ * @param val The byte array value to be written
+ * @throws JMSException If writting a byte array fails due to some error.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeBytes(byte[] val, int offset, int length) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ _dataOut.writeShort(BYTEARRAY);
+ _dataOut.writeInt(length);
+ super.writeBytes(val, offset, length);
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Writes an Object to the bytes message.
+ * JMS spec says:
+ * <p>This method works only for the objectified primitive
+ * object types Integer, Double, Long, String and byte
+ * arrays.
+ *
+ * @param val The short value to be written
+ * @throws JMSException If writting a short fails due to some error.
+ * @throws NullPointerException if the parameter val is null.
+ * @throws MessageFormatException If the object is of an invalid type.
+ * @throws javax.jms.MessageNotWriteableException
+ * If the message is in read-only mode.
+ */
+ public void writeObject(Object val) throws JMSException
+ {
+ isWriteable();
+ try
+ {
+ if (val == null)
+ {
+ _dataOut.writeShort(NULL);
+ }
+ else if (val instanceof Byte)
+ {
+ writeByte((Byte) val);
+ }
+ else if (val instanceof Boolean)
+ {
+ writeBoolean((Boolean) val);
+ }
+ else if (val instanceof Short)
+ {
+ writeShort((Short) val);
+ }
+ else if (val instanceof Integer)
+ {
+ writeInt((Integer) val);
+ }
+ else if (val instanceof Long)
+ {
+ writeLong((Long) val);
+ }
+ else if (val instanceof Double)
+ {
+ writeDouble((Double) val);
+ }
+ else if (val instanceof Float)
+ {
+ writeFloat((Float) val);
+ }
+ else if (val instanceof Character)
+ {
+ writeChar((Character) val);
+ }
+ else if (val instanceof String)
+ {
+ writeString((String) val);
+ }
+ else if (val instanceof byte[])
+ {
+ writeBytes((byte[]) val);
+ }
+ else
+ {
+ throw new MessageFormatException(
+ "The data type of the object specified as the value to writeObject " + "was of an invalid type.");
+ }
+ }
+ catch (IOException e)
+ {
+ throw new JMSException("IO problem when writting " + e.getLocalizedMessage());
+ }
+ }
+
+ //-- overwritten methods
+ /**
+ * Test whether this message is readable by throwing a MessageNotReadableException if this
+ * message cannot be read.
+ *
+ * @throws javax.jms.MessageNotReadableException
+ * If this message cannot be read.
+ * @throws javax.jms.MessageFormatException
+ * If reading a byte array.
+ */
+ protected void isReadableAndNotReadingByteArray() throws MessageNotReadableException, MessageFormatException
+ {
+ if (_dataIn == null)
+ {
+ throw new MessageNotReadableException("Cannot read this message");
+ }
+ if (_sizeOfByteArray > 0)
+ {
+ throw new MessageFormatException(
+ "Read of object attempted while incomplete byteArray stored in message " + "- finish reading byte array first.");
+ }
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/StreamMessageImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/TextMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/TextMessageImpl.java?view=diff&rev=565354&r1=565353&r2=565354
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/TextMessageImpl.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/jms/message/TextMessageImpl.java Mon Aug 13 06:59:48 2007
@@ -41,8 +41,25 @@
*/
private String _messageText;
- //-- constructor
- // todo
+ //--- Constructor
+ /**
+ * Constructor used by SessionImpl.
+ */
+ public TextMessageImpl()
+ {
+ super();
+ setMessageType(String.valueOf(MessageFactory.JAVAX_JMS_STREAMMESSAGE));
+ }
+
+ /**
+ * Constructor used by MessageFactory
+ *
+ * @param message The new qpid message.
+ */
+ protected TextMessageImpl(org.apache.qpidity.api.Message message)
+ {
+ super(message);
+ }
//--- interface TextMessage