messageimpl.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 893 行 · 第 1/2 页
JAVA
893 行
{ return ObjectConverter.toLong(getObjectProperty(name)); } /** * Returns a property as a float */ public float getFloatProperty(String name) throws JMSException { return ObjectConverter.toFloat(getObjectProperty(name)); } /** * Returns a property as a double */ public double getDoubleProperty(String name) throws JMSException { return ObjectConverter.toDouble(getObjectProperty(name)); } /** * Returns a string property. */ public String getStringProperty(String name) throws JMSException { Object prop = getObjectProperty(name); if (prop == null) return null; return String.valueOf(prop); } /** * Returns a string property. */ public Object getObjectProperty(String name) throws JMSException { if (_properties == null || name == null) return null; else return _properties.get(name); } /** * Returns an enumeration of the message's properties. */ public Enumeration getPropertyNames() throws JMSException { if (_properties == null) return NullEnumeration.create(); else return Collections.enumeration(_properties.keySet()); } /** * Sets a boolean property. * * @param name the property name * @param value the property's value */ public void setBooleanProperty(String name, boolean value) throws JMSException { setObjectProperty(name, new Boolean(value)); } /** * Sets a byte property. * * @param name the property name * @param value the property's value */ public void setByteProperty(String name, byte value) throws JMSException { setObjectProperty(name, new Byte(value)); } /** * Sets a short property. * * @param name the property name * @param value the property's value */ public void setShortProperty(String name, short value) throws JMSException { setObjectProperty(name, new Short(value)); } /** * Sets an integer property. * * @param name the property name * @param value the property's value */ public void setIntProperty(String name, int value) throws JMSException { setObjectProperty(name, new Integer(value)); } /** * Sets a long property. * * @param name the property name * @param value the property's value */ public void setLongProperty(String name, long value) throws JMSException { setObjectProperty(name, new Long(value)); } /** * Sets a float property. * * @param name the property name * @param value the property's value */ public void setFloatProperty(String name, float value) throws JMSException { setObjectProperty(name, new Float(value)); } /** * Sets a double property. * * @param name the property name * @param value the property's value */ public void setDoubleProperty(String name, double value) throws JMSException { setObjectProperty(name, new Double(value)); } /** * Sets a string property. * * @param name the property name * @param value the property's value */ public void setStringProperty(String name, String value) throws JMSException { setObjectProperty(name, value); } /** * Sets an object property. * * @param name the property name * @param value the property's value */ public void setObjectProperty(String name, Object value) throws JMSException { checkPropertyWriteable(); if (name == null) throw new NullPointerException(); else if ("".equals(name)) throw new IllegalArgumentException(); if (isReserved(name)) throw new JMSException(L.l("'{0}' is a reserved property name.", name)); if (! (value == null || value instanceof Number || value instanceof String || value instanceof Boolean)) throw new MessageFormatException(L.l("{0} is an illegal object property value", value.getClass().getName())); if (_properties == null) _properties = new HashMap<String,Object>(); _properties.put(name, value); } /** * Acknowledge receipt of this message. */ public void acknowledge() throws JMSException { WeakReference<JmsSession> sessionRef = _sessionRef; _sessionRef = null; JmsSession session; if (sessionRef != null && (session = sessionRef.get()) != null) { session.acknowledge(); } } /** * Clears the body, setting write mode. */ public void clearBody() throws JMSException { _isBodyWriteable = true; } /** * Sets the body for reading. */ public void setReceive() throws JMSException { _isHeaderWriteable = false; _isBodyWriteable = false; } /** * Sets the body for reading. */ protected void setBodyReadOnly() { _isBodyWriteable = false; } /** * Returns the properties. */ public HashMap<String,Object> getProperties() { return _properties; } public long getSequence() { return _sequence; } public void setSequence(long seq) { _sequence = seq; } public MessageImpl copy() { MessageImpl msg = new MessageImpl(); copy(msg); return msg; } /** * Serialize the properties to an input stream. */ public InputStream propertiesToInputStream() throws IOException { if (_properties == null || _properties.size() == 0) return null; TempOutputStream out = new TempOutputStream(); writeProperties(out); out.close(); return out.openRead(); } /** * Serialize the properties to an input stream. */ public void writeProperties(OutputStream os) throws IOException { if (_properties == null || _properties.size() == 0) return; Hessian2Output out = new Hessian2Output(os); out.writeString(_messageId); out.writeBoolean(_isRedelivered); out.writeInt(_priority); out.writeLong(_timestamp); out.writeInt(_deliveryMode); if (_destination instanceof java.io.Serializable) out.writeObject(_destination); else out.writeObject(null); if (_replyTo instanceof java.io.Serializable) out.writeObject(_replyTo); else out.writeObject(null); for (Map.Entry<String,Object> entry : _properties.entrySet()) { out.writeString(entry.getKey()); out.writeObject(entry.getValue()); } out.close(); } /** * Read the properties from an input stream. */ public void readProperties(InputStream is) throws IOException, JMSException { if (is == null) return; Hessian2Input in = new Hessian2Input(is); _messageId = in.readString(); _isRedelivered = in.readBoolean(); _priority = in.readInt(); _timestamp = in.readLong(); _deliveryMode = in.readInt(); _destination = (Destination) in.readObject(); _replyTo = (Destination) in.readObject(); while (! in.isEnd()) { String key = in.readString(); Object value = in.readObject(); setObjectProperty(key, value); } in.close(); } /** * Serialize the body to an input stream. */ public InputStream bodyToInputStream() throws IOException { return null; } /** * Serialize the body to an output stream. */ public void writeBody(OutputStream os) throws IOException { } /** * Read the body from an input stream. */ public void readBody(InputStream is) throws IOException, JMSException { } protected void checkHeaderWriteable() throws JMSException { if (! _isHeaderWriteable) throw new MessageNotWriteableException(L.l("received messages can't be written.")); } protected void checkPropertyWriteable() throws JMSException { if (! _isHeaderWriteable) throw new MessageNotWriteableException(L.l("properties for received messages are read-only.")); } protected void checkBodyWriteable() throws JMSException { if (! _isBodyWriteable) throw new MessageNotWriteableException(L.l("received messages can't be written.")); } protected void checkBodyReadable() throws JMSException { if (_isBodyWriteable) throw new MessageNotReadableException(L.l("write-only messages can't be read until reset() is called.")); } protected void copy(MessageImpl newMsg) { if (_properties != null) { newMsg._properties = new HashMap<String,Object>(_properties); } newMsg._messageId = _messageId; newMsg._correlationId = _correlationId; newMsg._timestamp = _timestamp; newMsg._expiration = _expiration; newMsg._destination = _destination; newMsg._replyTo = _replyTo; newMsg._deliveryMode = _deliveryMode; newMsg._isRedelivered = _isRedelivered; newMsg._messageType = _messageType; newMsg._priority = _priority; } public String toString() { if (_messageId != null) return getClass().getSimpleName() + "[" + _messageId + "]"; else if (Alarm.isTest()) return getClass().getSimpleName() + "[]"; else return getClass().getSimpleName() + "@" + System.identityHashCode(this); } public static boolean isReserved(String name) { return _reserved.contains(name.toUpperCase()); } static { _reserved = new HashSet<String>(); _reserved.add("TRUE"); _reserved.add("FALSE"); _reserved.add("NULL"); _reserved.add("NOT"); _reserved.add("AND"); _reserved.add("OR"); _reserved.add("BETWEEN"); _reserved.add("LIKE"); _reserved.add("IN"); _reserved.add("IS"); _reserved.add("ESCAPE"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?