⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messageimpl.java

📁 Java实现的Socket框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Project:ms4j (Message Server for Java)
 * Date:2007-2-21 
 * Authoer : jobsun@gmail.com
 *
 * 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.
 *
 */
package com.sunjob.ms4j.client;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.jms.BytesMessage;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;

/**
 * @author sunjob
 *
 */
public class MessageImpl implements BytesMessage, MapMessage, Message,
		ObjectMessage, StreamMessage, TextMessage, Serializable {
//header
	//send or publish method
	private Destination JMSDestination;
	private int JMSDeliveryMode;
	private long JMSExpiration;
	private int JMSPriority;
	private String JMSMessageID;
	private long JMSTimestamp;
	//Client
	private String JMSCorrelationID;
	private Destination JMSReplyTo;
	private String JMSType;
	//JMS provider
	private boolean JMSRedelivered;
// header end
	
    private Hashtable hmProps = new Hashtable();
    private Object body = null;
    ////////////
    private boolean acknowledge = false;
	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#getBodyLength()
	 */
	public long getBodyLength() throws JMSException {
		return ( (byte[]) body).length;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readBoolean()
	 */
	public boolean readBoolean() throws JMSException {
		return ((Boolean) body).booleanValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readByte()
	 */
	public byte readByte() throws JMSException {
		return ((Byte) body).byteValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readBytes(byte[])
	 */
	public int readBytes(byte[] arg0) throws JMSException {
		byte[] bsrc = (byte[]) this.body;
		int i = 0 ;
		if(bsrc.length > arg0.length)
		{
			i = arg0.length;
			
		}else
		{
			i = bsrc.length;
		}
		System.arraycopy(bsrc, 0, arg0, 0, i);
		return i;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readBytes(byte[], int)
	 */
	public int readBytes(byte[] arg0, int length) throws JMSException {
		byte[] bsrc = (byte[]) this.body;
		int i = 0 ;
		if(bsrc.length > length)
		{
			i = length;
			
		}else
		{
			i = bsrc.length;
		}
		System.arraycopy(bsrc, 0, arg0, 0, i);
		return i;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readChar()
	 */
	public char readChar() throws JMSException {
		return ((Character)this.body).charValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readDouble()
	 */
	public double readDouble() throws JMSException {
		return ((Double)this.body).doubleValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readFloat()
	 */
	public float readFloat() throws JMSException {
		return ((Float)this.body).floatValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readInt()
	 */
	public int readInt() throws JMSException {
		return ((Integer)this.body).intValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readLong()
	 */
	public long readLong() throws JMSException {
		return ((Long)this.body).longValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readShort()
	 */
	public short readShort() throws JMSException {
		return ((Short)this.body).shortValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readUTF()
	 */
	public String readUTF() throws JMSException {
		return (String)this.body;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readUnsignedByte()
	 */
	public int readUnsignedByte() throws JMSException {
		return ((Integer)this.body).intValue();
    }

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#readUnsignedShort()
	 */
	public int readUnsignedShort() throws JMSException {
		return ((Short)this.body).shortValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#reset()
	 */
	public void reset() throws JMSException {
//        this.hmHeader.clear();
        this.hmProps.clear();
        this.body = null;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeBoolean(boolean)
	 */
	public void writeBoolean(boolean arg0) throws JMSException {
	    this.body = new Boolean(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeByte(byte)
	 */
	public void writeByte(byte arg0) throws JMSException {
		this.body = new Byte(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeBytes(byte[])
	 */
	public void writeBytes(byte[] arg0) throws JMSException {
		this.body = arg0;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeBytes(byte[], int, int)
	 */
	public void writeBytes(byte[] arg0, int offset, int length) throws JMSException {
		if(length > arg0.length)
		{
			length = arg0.length;
		}
		byte[] b = new byte[length];
		System.arraycopy(arg0,0 , b, 0, length);
		this.body = b;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeChar(char)
	 */
	public void writeChar(char arg0) throws JMSException {
		this.body = new Character(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeDouble(double)
	 */
	public void writeDouble(double arg0) throws JMSException {
		this.body = new Double(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeFloat(float)
	 */
	public void writeFloat(float arg0) throws JMSException {
		this.body = new Float(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeInt(int)
	 */
	public void writeInt(int arg0) throws JMSException {
		this.body = new Integer(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeLong(long)
	 */
	public void writeLong(long arg0) throws JMSException {
		this.body = new Long(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeObject(java.lang.Object)
	 */
	public void writeObject(Object arg0) throws JMSException {
		this.body = arg0;
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeShort(short)
	 */
	public void writeShort(short arg0) throws JMSException {
		this.body = new Short(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.BytesMessage#writeUTF(java.lang.String)
	 */
	public void writeUTF(String arg0) throws JMSException {
		try
		{
		this.body = new String(arg0.getBytes(),"UTF-8");
		}catch(Exception e)
		{
			throw new JMSException(e.getLocalizedMessage());
		}
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#acknowledge()
	 */
	public void acknowledge() throws JMSException {
		this.acknowledge = true;
	}
	
	public boolean isAcknowledge()
	{
		return this.acknowledge;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#clearBody()
	 */
	public void clearBody() throws JMSException {
		this.body = null;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#clearProperties()
	 */
	public void clearProperties() throws JMSException {
		this.hmProps.clear();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getBooleanProperty(java.lang.String)
	 */
	public boolean getBooleanProperty(String arg0) throws JMSException {
		return ((Boolean)this.hmProps.get(arg0)).booleanValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getByteProperty(java.lang.String)
	 */
	public byte getByteProperty(String arg0) throws JMSException {
		return ((Byte)this.hmProps.get(arg0)).byteValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getDoubleProperty(java.lang.String)
	 */
	public double getDoubleProperty(String arg0) throws JMSException {
		return ((Double)this.hmProps.get(arg0)).doubleValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getFloatProperty(java.lang.String)
	 */
	public float getFloatProperty(String arg0) throws JMSException {
		return ((Float)this.hmProps.get(arg0)).floatValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getIntProperty(java.lang.String)
	 */
	public int getIntProperty(String arg0) throws JMSException {
		return ((Integer)this.hmProps.get(arg0)).intValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSCorrelationID()
	 */
	public String getJMSCorrelationID() throws JMSException {
		return this.JMSCorrelationID;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSCorrelationIDAsBytes()
	 */
	public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
		return this.JMSCorrelationID.getBytes();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSDeliveryMode()
	 */
	public int getJMSDeliveryMode() throws JMSException {
		return this.JMSDeliveryMode;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSDestination()
	 */
	public Destination getJMSDestination() throws JMSException {
		return this.JMSDestination;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSExpiration()
	 */
	public long getJMSExpiration() throws JMSException {
		return this.JMSExpiration;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSMessageID()
	 */
	public String getJMSMessageID() throws JMSException {
		return this.JMSMessageID;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSPriority()
	 */
	public int getJMSPriority() throws JMSException {
		return this.JMSPriority;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSRedelivered()
	 */
	public boolean getJMSRedelivered() throws JMSException {
		return this.JMSRedelivered;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSReplyTo()
	 */
	public Destination getJMSReplyTo() throws JMSException {
		return this.JMSReplyTo;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSTimestamp()
	 */
	public long getJMSTimestamp() throws JMSException {
		return this.JMSTimestamp;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getJMSType()
	 */
	public String getJMSType() throws JMSException {
		return this.JMSType;
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getLongProperty(java.lang.String)
	 */
	public long getLongProperty(String arg0) throws JMSException {
		return ((Long) this.hmProps.get(arg0)).longValue();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getObjectProperty(java.lang.String)
	 */
	public Object getObjectProperty(String arg0) throws JMSException {
		return this.hmProps.get(arg0);
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getPropertyNames()
	 */
	public Enumeration getPropertyNames() throws JMSException {
		return this.hmProps.keys();
	}

	/* (non-Javadoc)
	 * @see javax.jms.Message#getShortProperty(java.lang.String)
	 */
	public short getShortProperty(String arg0) throws JMSException {
		return ((Short)this.hmProps.get(arg0)).shortValue();
	}

	/* (non-Javadoc)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -