Home » activemq-parent-5.3.1-source-release » org.apache.activemq.console.command.store.amq » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.console.command.store.amq;
   18   
   19   import javax.jms.JMSException;
   20   
   21   import org.apache.activemq.command.ActiveMQBlobMessage;
   22   import org.apache.activemq.command.ActiveMQBytesMessage;
   23   import org.apache.activemq.command.ActiveMQMapMessage;
   24   import org.apache.activemq.command.ActiveMQMessage;
   25   import org.apache.activemq.command.ActiveMQObjectMessage;
   26   import org.apache.activemq.command.ActiveMQStreamMessage;
   27   import org.apache.activemq.command.ActiveMQTextMessage;
   28   import org.apache.activemq.util.ByteSequence;
   29   
   30   public class MessageBodyFormatter {
   31   	final ActiveMQMessage message;
   32   	
   33   	public MessageBodyFormatter(ActiveMQMessage message) {
   34   		this.message=message;
   35   	}
   36   
   37   	@Override
   38   	public String toString() {
   39   		try {
   40   			switch (message.getDataStructureType()) {
   41   			case ActiveMQMessage.DATA_STRUCTURE_TYPE:
   42   				return "";
   43   			case ActiveMQBlobMessage.DATA_STRUCTURE_TYPE:
   44   				ActiveMQBlobMessage blob = (ActiveMQBlobMessage) message;
   45   				return blob.getRemoteBlobUrl();
   46   			case ActiveMQMapMessage.DATA_STRUCTURE_TYPE:
   47   				ActiveMQMapMessage map = (ActiveMQMapMessage)message;
   48   				return map.getContentMap().toString();			
   49   			case ActiveMQTextMessage.DATA_STRUCTURE_TYPE:
   50   				ActiveMQTextMessage text = (ActiveMQTextMessage)message;
   51   				return text.getText();
   52   			case ActiveMQBytesMessage.DATA_STRUCTURE_TYPE:
   53   			case ActiveMQObjectMessage.DATA_STRUCTURE_TYPE:
   54   			case ActiveMQStreamMessage.DATA_STRUCTURE_TYPE:
   55   				ByteSequence data = message.getContent();
   56   				return "binary payload {length="+data.getLength()+", compressed="+message.isCompressed()+"}";
   57   			}
   58   		} catch (JMSException e) {
   59   		}
   60   		return "";
   61   	}
   62   }

Home » activemq-parent-5.3.1-source-release » org.apache.activemq.console.command.store.amq » [javadoc | source]