Author: rajith
Date: Fri Jun 15 17:21:42 2012
New Revision: 1350706

URL: http://svn.apache.org/viewvc?rev=1350706&view=rev
Log:
QPID-4027 Added sub interfaces for Message class to retrieve specific
content types.
Added a MessageFactory to create concrete Message objects with given
content. It can also decode a generic message object in a specific
content type such as String, Map or List. This is useful if you don't
want to cast your message into a specific sub interface type.

Added:
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
Removed:
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/TextMessage.java
Modified:
    
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java

Added: 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java?rev=1350706&view=auto
==============================================================================
--- 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
 (added)
+++ 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/ListMessage.java
 Fri Jun 15 17:21:42 2012
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.messaging;
+
+import java.util.List;
+
+public interface ListMessage extends Message
+{
+    public List<Object> getList() throws MessageEncodingException;
+}

Added: 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java?rev=1350706&view=auto
==============================================================================
--- 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
 (added)
+++ 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MapMessage.java
 Fri Jun 15 17:21:42 2012
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.messaging;
+
+import java.util.Map;
+
+public interface MapMessage extends Message
+{
+    public Map<String,Object> getMap() throws MessageEncodingException;
+}

Modified: 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java?rev=1350706&r1=1350705&r2=1350706&view=diff
==============================================================================
--- 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
 (original)
+++ 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Message.java
 Fri Jun 15 17:21:42 2012
@@ -17,14 +17,39 @@
  */
 package org.apache.qpid.messaging;
 
+import java.nio.ByteBuffer;
 import java.util.Map;
 
 /**
  * Representation of a message.
+ * The getters/setters are for the message headers.
+ *
+ * To get the content of a message you need to either,
+ * (1) use the generic method @see Message#getContent() which returns a 
ByteBuffer,
+ *
+ * (2) cast a generic Message, to a specific sub interface type and invoke the 
specific method.
+ * @see StringMessage#getString()
+ * @see MapMessage#getMap()
+ * @see ListMessage#getList()
+ *
+ * (2) Or use one of the convenience methods provided by the MessageFactory.
+ * @see MessageFactory#getContentAsString(Message)
+ * @see MessageFactory#getContentAsMap(Message)
+ * @see MessageFactory#getContentAsList(Message)
+ *
+ * To create a specific a concrete Message with a specific content type
+ * you need to use one of the following methods from the @see MessageFactory
+ * @see MessageFactory#createMessage(String)
+ * @see MessageFactory#createMessage(byte[])
+ * @see MessageFactory#createMessage(java.nio.ByteBuffer)
+ * @see MessageFactory#createMessage(java.util.Map)
+ * @see MessageFactory#createMessage(java.util.List)
  */
 public interface Message
 {
-    public Object getContent() throws MessagingException;
+    public final static String QPID_SUBJECT = "qpid.subject";
+
+    public ByteBuffer getContent();
 
     public String getMessageId() throws MessagingException;
 

Added: 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java?rev=1350706&view=auto
==============================================================================
--- 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
 (added)
+++ 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/MessageFactory.java
 Fri Jun 15 17:21:42 2012
@@ -0,0 +1,50 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.messaging;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *  The message factory is responsible for returning
+ *  a concrete implementation of the message interface
+ *  with the given content.
+ *
+ *  A reference to the Message Factory can be obtained via
+ *  the Connection object.
+ *  @see Connection#getMessageFactory()
+ */
+public interface MessageFactory
+{
+    Message createMessage(String text) throws MessageEncodingException;
+
+    Message createMessage(byte[] bytes) throws MessageEncodingException;
+
+    Message createMessage(ByteBuffer buf) throws MessageEncodingException;
+
+    Message createMessage(Map<String,Object> map) throws 
MessageEncodingException;
+
+    Message createMessage(List<Object> list) throws MessageEncodingException;
+
+    String getContentAsString(Message m) throws MessageEncodingException;
+
+    Map<String,Object> getContentAsMap(Message m) throws 
MessageEncodingException;
+
+    List<Object> getContentAsList(Message m) throws MessageEncodingException;
+}

Added: 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java?rev=1350706&view=auto
==============================================================================
--- 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
 (added)
+++ 
qpid/branches/address-refactor2/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/StringMessage.java
 Fri Jun 15 17:21:42 2012
@@ -0,0 +1,23 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.messaging;
+
+public interface StringMessage extends Message
+{
+    public String getString() throws MessageEncodingException;
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to