📄 message.java
字号:
* @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid. */ public void setFloatProperty(String name, float value) throws JMSException { doSetProperty(name, new Float(value)); } /** * API method. * * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid. */ public void setIntProperty(String name, int value) throws JMSException { doSetProperty(name, new Integer(value)); } /** * API method. * * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid. */ public void setLongProperty(String name, long value) throws JMSException { doSetProperty(name, new Long(value)); } /** * API method. * * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid, or if the * object is invalid. */ public void setObjectProperty(String name, Object value) throws JMSException { doSetProperty(name, value); } /** * API method. * * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid. */ public void setShortProperty(String name, short value) throws JMSException { doSetProperty(name, new Short(value)); } /** * API method. * * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the property name is invalid. */ public void setStringProperty(String name, String value) throws JMSException { doSetProperty(name, value); } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public boolean getBooleanProperty(String name) throws JMSException { try { return ConversionHelper.toBoolean(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public byte getByteProperty(String name) throws JMSException { try { return ConversionHelper.toByte(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public double getDoubleProperty(String name) throws JMSException { try { return ConversionHelper.toDouble(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public float getFloatProperty(String name) throws JMSException { try { return ConversionHelper.toFloat(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public int getIntProperty(String name) throws JMSException { try { return ConversionHelper.toInt(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public long getLongProperty(String name) throws JMSException { try { return ConversionHelper.toLong(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception JMSException If the name is invalid. */ public Object getObjectProperty(String name) throws JMSException { return doGetProperty(name); } /** * API method. * * @exception MessageFormatException If the property type is invalid. * @exception JMSException If the name is invalid. */ public short getShortProperty(String name) throws JMSException { try { return ConversionHelper.toShort(doGetProperty(name)); } catch (MessageValueException mE) { throw new MessageFormatException(mE.getMessage()); } } /** * API method. * * @exception JMSException If the name is invalid. */ public String getStringProperty(String name) throws JMSException { return ConversionHelper.toString(doGetProperty(name)); } /** * Method actually setting a new property. * * @param name The property name. * @param value The property value. * * @exception MessageFormatException If the property type is invalid. * @exception MessageNotWriteableException If the message is read-only. * @exception JMSException If the name is invalid. * @exception IllegalArgumentException If the name string is null or empty. */ private void doSetProperty(String name, Object value) throws JMSException { if (name == null || name.equals("")) throw new IllegalArgumentException("Invalid property name: " + name); try { if (name.startsWith("JMSX")) { if (name.equals("JMSXGroupID")) momMsg.setOptionalHeader(name, ConversionHelper.toString(value)); else if (name.equals("JMSXGroupSeq")) momMsg.setOptionalHeader(name, new Integer(ConversionHelper.toInt(value))); else throw new JMSException("Property names with prefix 'JMSX' are" + " reserved."); } else if (name.startsWith("JMS_")) throw new JMSException("Property names with prefix 'JMS_' are" + " reserved."); else if (name.startsWith("JMS")) throw new JMSException("Property names with prefix 'JMS' are" + " reserved."); else if (name.equalsIgnoreCase("NULL") || name.equalsIgnoreCase("TRUE") || name.equalsIgnoreCase("FALSE") || name.equalsIgnoreCase("NOT") || name.equalsIgnoreCase("AND") || name.equalsIgnoreCase("OR") || name.equalsIgnoreCase("BETWEEN") || name.equalsIgnoreCase("LIKE") || name.equalsIgnoreCase("IN") || name.equalsIgnoreCase("IS") || name.equalsIgnoreCase("ESCAPE")) throw new JMSException("Invalid property name: " + name + " is a" + " SQL terminal."); else momMsg.setObjectProperty(name, value); } catch (MessageException mE) { if (mE instanceof MessageValueException) throw new MessageFormatException(mE.getMessage()); if (mE instanceof MessageROException) throw new MessageNotWriteableException(mE.getMessage()); } } /** * Method actually getting a property. * * @param name The property name. */ private Object doGetProperty(String name) { if (name == null || name.equals("")) throw new IllegalArgumentException("Invalid property name: " + name); Object value = null; if (name.startsWith("JMSX")) { if (name.equals("JMSXDeliveryCount")) value = new Integer(momMsg.deliveryCount); else value = momMsg.getOptionalHeader(name); } else if (name.startsWith("JMS_JORAM")) { if (name.equals("JMS_JORAM_DELETEDDEST")) value = new Boolean(momMsg.deletedDest); else if (name.equals("JMS_JORAM_NOTWRITABLE")) value = new Boolean(momMsg.notWriteable); else if (name.equals("JMS_JORAM_EXPIRED")) value = new Boolean(momMsg.expired); else if (name.equals("JMS_JORAM_UNDELIVERABLE")) value = new Boolean(momMsg.undeliverable); } else value = momMsg.getObjectProperty(name); return value; } /** * Method called by message producers for getting the wrapped MOM message * they actually send. * * @exception MessageFormatException If the data could not be serialized. */ org.objectweb.joram.shared.messages.Message getMomMessage() throws MessageFormatException { try { prepare(); return momMsg; } catch (Exception e) { MessageFormatException jE = new MessageFormatException("The message body could not be" + " serialized."); jE.setLinkedException(e); throw jE; } } /** * Wraps a given MOM message in the appropriate Joram message. * <p> * This method is actually called by a session consuming a MOM message * for wrapping it in a Joram message before handing it to the consumer. * * @exception JMSException If an error occurs while building the message. */ public static Message wrapMomMessage(Session sess, org.objectweb.joram.shared.messages.Message momMsg) throws JMSException { Message msg = null; if (momMsg.getType() == MessageType.SIMPLE) msg = new Message(sess, momMsg); else if (momMsg.getType() == MessageType.TEXT) msg = new TextMessage(sess, momMsg); else if (momMsg.getType() == MessageType.MAP) msg = new MapMessage(sess, momMsg); else if (momMsg.getType() == MessageType.OBJECT) msg = new ObjectMessage(sess, momMsg); else if (momMsg.getType() == MessageType.STREAM) msg = new StreamMessage(sess, momMsg); else if (momMsg.getType() == MessageType.BYTES) msg = new BytesMessage(sess, momMsg); return msg; } /** * Converts a non-Joram JMS message into a Joram message. * * @exception JMSException If an error occurs while building the message. */ static Message convertJMSMessage(javax.jms.Message jmsMsg) throws JMSException { Message msg = null; if (jmsMsg instanceof javax.jms.TextMessage) { msg = new TextMessage(); ((javax.jms.TextMessage) msg).setText(((javax.jms.TextMessage) jmsMsg).getText()); } else if (jmsMsg instanceof javax.jms.ObjectMessage) { msg = new ObjectMessage(); ((javax.jms.ObjectMessage) msg).setObject(((javax.jms.ObjectMessage) jmsMsg).getObject()); } else if (jmsMsg instanceof javax.jms.StreamMessage) { msg = new StreamMessage(); try { ((javax.jms.StreamMessage) jmsMsg).reset(); while (true) ((StreamMessage) msg).writeObject(((javax.jms.StreamMessage) jmsMsg).readObject()); } catch (Exception mE) {} } else if (jmsMsg instanceof javax.jms.BytesMessage) { msg = new BytesMessage(); try { ((javax.jms.BytesMessage) jmsMsg).reset(); while (true) ((BytesMessage) msg).writeByte(((javax.jms.BytesMessage) jmsMsg).readByte()); } catch (Exception mE) {} } else if (jmsMsg instanceof javax.jms.MapMessage) { msg = new MapMessage(); Enumeration mapNames = ((javax.jms.MapMessage) jmsMsg).getMapNames(); String mapName; while (mapNames.hasMoreElements()) { mapName = (String) mapNames.nextElement(); ((javax.jms.MapMessage) msg).setObject(mapName, ((javax.jms.MapMessage) jmsMsg).getObject(mapName)); } } else { msg = new Message(); } msg.setJMSCorrelationID(jmsMsg.getJMSCorrelationID()); msg.setJMSReplyTo(jmsMsg.getJMSReplyTo()); msg.setJMSType(jmsMsg.getJMSType()); msg.setJMSMessageID(jmsMsg.getJMSMessageID()); Enumeration names = jmsMsg.getPropertyNames(); if (names != null) { String name; while (names.hasMoreElements()) { name = (String) names.nextElement(); try { msg.setObjectProperty(name, jmsMsg.getObjectProperty(name)); } catch (JMSException e) { // Joram not support other Optional JMSX, just ignore. if (! name.startsWith("JMSX")) throw e; } } } return msg; } /** * Method preparing the message for sending; resets header values, and * serializes the body (done in subclasses). * * @exception Exception If an error occurs while serializing. */ protected void prepare() throws Exception { momMsg.denied = false; momMsg.deletedDest = false; momMsg.expired = false; momMsg.notWriteable = false; momMsg.undeliverable = false; } public String toString() { StringBuffer strbuf = new StringBuffer(); try { strbuf.append('(').append(super.toString()); strbuf.append(",messageID=").append(getJMSMessageID()); strbuf.append(",destination=").append(getJMSDestination()); strbuf.append(",correlationId=").append(getJMSCorrelationID()); strbuf.append(",deliveryMode=").append(getJMSDeliveryMode()); strbuf.append(",expiration=").append(getJMSExpiration()); strbuf.append(",priority=").append(getJMSPriority()); strbuf.append(",redelivered=").append(getJMSRedelivered()); strbuf.append(",replyTo=").append(getJMSReplyTo()); strbuf.append(",timestamp=").append(getJMSTimestamp()); strbuf.append(",type=").append(getJMSType()); strbuf.append(')'); } catch (JMSException exc) { JoramTracing.dbgClient.log(BasicLevel.ERROR, "Message.toString()", exc); return super.toString(); } return strbuf.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -