📄 message.java
字号:
public byte getByteProperty(String name) throws MessageValueException { if (properties == null) throw new RuntimeException("getByteProperty properties = null"); return ConversionHelper.toByte(properties.get(name)); } /** * Returns a property as a double value. * * @param name The property name. * * @exception MessageValueException If the property type is invalid. */// public double getDoubleProperty(String name) throws MessageValueException// {// if (properties == null)// return Double.valueOf(null).doubleValue();// return ConversionHelper.toDouble(properties.get(name));// } /** * Returns a property as a float value. * * @param name The property name. * * @exception MessageValueException If the property type is invalid. */// public float getFloatProperty(String name) throws MessageValueException// {// if (properties == null)// return Float.valueOf(null).floatValue();// return ConversionHelper.toFloat(properties.get(name));// } /** * Returns a property as a int value. * * @param name The property name. * * @exception MessageValueException If the property type is invalid. */ public int getIntProperty(String name) throws MessageValueException { if (properties == null) return Integer.valueOf(null).intValue(); return ConversionHelper.toInt(properties.get(name)); } /** * Returns a property as a long value. * * @param name The property name. * * @exception MessageValueException If the property type is invalid. */ public long getLongProperty(String name) throws MessageValueException { if (properties == null) throw new RuntimeException("getLongProperty properties = null"); return ConversionHelper.toLong(properties.get(name)); } /** * Returns a property as an object. * * @param name The property name. */ public Object getObjectProperty(String name) { if (properties == null) return null; return properties.get(name); } /** * Returns a property as a short value. * * @param name The property name. * * @exception MessageValueException If the property type is invalid. */ public short getShortProperty(String name) throws MessageValueException { if (properties == null) throw new RuntimeException("getShortProperty properties = null"); return ConversionHelper.toShort(properties.get(name)); } /** * Returns a property as a String. * * @param name The property name. */ public String getStringProperty(String name) { if (properties == null) return null; return ConversionHelper.toString(properties.get(name)); } /** * Returns <code>true</code> if a given property exists. * * @param name The name of the property to check. */ public boolean propertyExists(String name) { if (properties == null) return false; return properties.containsKey(name); } /** Returns an enumeration of the properties names. */ public Enumeration getPropertyNames() { if (properties == null) return (new Hashtable()).keys(); return properties.keys(); } /** Empties the properties table. */ public void clearProperties() { propertiesRO = false; if (properties == null) return; properties.clear(); properties = null; } /** * Sets a map as the body of the message. * * @exception IOException In case of an error while setting the map. * @exception MessageROException If the message body is read-only. */ public void setMap(Hashtable map) throws Exception { if (bodyRO) throw new MessageROException("Can't set the body as it is READ-ONLY."); body_map = map; type = MessageType.MAP; } /** * Sets a String as the body of the message. * * @exception MessageROException If the message body is read-only. */ public void setText(String text) throws MessageROException { if (bodyRO) throw new MessageROException("Can't set the body as it is READ-ONLY."); body_text = text; type = MessageType.TEXT; } /** * Sets the message body as a stream of bytes. * * @exception MessageROException If the message body is read-only. */ public void setStream(byte[] bytes) throws MessageROException { if (bodyRO) throw new MessageROException("Can't set the body as it is READ-ONLY."); body_bytes = bytes; type = MessageType.STREAM; } /** * Sets the message body as an array of bytes. * * @exception MessageROException If the message body is read-only. */ public void setBytes(byte[] bytes) throws MessageROException { if (bodyRO) throw new MessageROException("Can't set the body as it is READ-ONLY."); body_bytes = bytes; type = MessageType.BYTES; } /** * Returns the map body of the message. */ public Hashtable getMap() { return body_map; } /** Gets the String body of the message. */ public String getText() { return body_text; } /** Returns the stream of bytes body of the message. */ public byte[] getStream() { if (type != MessageType.STREAM) return null; return body_bytes; } /** Returns the array of bytes body of the message. */ public byte[] getBytes() { if (type != MessageType.BYTES) return null; return body_bytes; } /** * Method clearing the message body. */ public void clearBody() { body_bytes = null; body_map = null; body_text = null; bodyRO = false; } /** Returns <code>true</code> if the message is valid. */ public boolean isValid() { if (expiration == 0) return true; return ((expiration - System.currentTimeMillis()) > 0); } /** Clones the message. */ public Object clone() { Message clone = new Message(); clone.type = type; clone.persistent = persistent; clone.id = id; clone.priority = priority; clone.expiration = expiration; clone.timestamp = timestamp; clone.toId = toId; clone.toQueue = toQueue; clone.correlationId = correlationId; clone.replyToId = replyToId; clone.replyToQueue = replyToQueue; clone.body_text = body_text; clone.bodyRO = bodyRO; clone.propertiesRO = propertiesRO; clone.deliveryCount = deliveryCount; clone.denied = denied; clone.deletedDest = deletedDest; clone.expired = expired; clone.notWriteable = notWriteable; clone.undeliverable = undeliverable; clone.acksCounter = acksCounter; clone.durableAcksCounter = durableAcksCounter; if (body_bytes != null) { byte[] b = new byte[body_bytes.length]; for (int i = 0; i < body_bytes.length; i++) b[i] = body_bytes[i]; clone.body_bytes = b; } if (body_map != null) { clone.body_map = new Hashtable(); for (Enumeration e = body_map.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); clone.body_map.put(key,body_map.get(key)); } } if (optionalHeader != null) { clone.optionalHeader = new Hashtable(); for (Enumeration e = optionalHeader.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); clone.optionalHeader.put(key,optionalHeader.get(key)); } } if (properties != null) { clone.properties = new Hashtable(); for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); clone.properties.put(key,properties.get(key)); } } return clone; } /** * Transforms this message into a vector of primitive values that can * be vehiculated through the SOAP protocol. */ public Hashtable soapCode() { Hashtable h = new Hashtable(); // Building a hashtable containg the fields values: Hashtable fieldsTb = new Hashtable(); fieldsTb.put("type", new Integer(type)); fieldsTb.put("id", id); fieldsTb.put("persistent", new Boolean(persistent)); fieldsTb.put("priority", new Integer(priority)); fieldsTb.put("expiration", new Long(expiration)); fieldsTb.put("timestamp", new Long(timestamp)); fieldsTb.put("toId", toId); fieldsTb.put("toQueue", new Boolean(toQueue)); if (correlationId != null) fieldsTb.put("correlationId", correlationId); if (replyToId != null) { fieldsTb.put("replyToId", replyToId); fieldsTb.put("replyToQueue", new Boolean(replyToQueue)); } if (body_bytes != null) fieldsTb.put("body_bytes", body_bytes); else if (body_map != null) fieldsTb.put("body_map", body_map); else if (body_text != null) fieldsTb.put("body_text", body_text); fieldsTb.put("bodyRO", new Boolean(bodyRO)); fieldsTb.put("propertiesRO", new Boolean(propertiesRO)); fieldsTb.put("deliveryCount", new Integer(deliveryCount)); fieldsTb.put("denied", new Boolean(denied)); fieldsTb.put("deletedDest", new Boolean(deletedDest)); fieldsTb.put("expired", new Boolean(expired)); fieldsTb.put("notWriteable", new Boolean(notWriteable)); fieldsTb.put("undeliverable", new Boolean(undeliverable)); h.put("fieldsTb",fieldsTb); // Adding the hashtable of optional headers: if (optionalHeader != null) h.put("optionalHeader",optionalHeader); // Adding the hashtable of properties: if (properties != null) h.put("properties",properties); return h; } /** * Transforms a vector of primitive values into a <code>Message</code> * instance. */ public static Message soapDecode(Hashtable h) { if (h == null) return null; Hashtable fieldsTb = (Hashtable) h.get("fieldsTb"); Message msg = new Message(); try { msg.type = ConversionHelper.toInt(fieldsTb.get("type")); msg.id = (String) fieldsTb.get("id"); msg.persistent = ConversionHelper.toBoolean(fieldsTb.get("persistent")); msg.priority = ConversionHelper.toInt(fieldsTb.get("priority")); msg.expiration = ConversionHelper.toLong(fieldsTb.get("expiration")); msg.timestamp = ConversionHelper.toLong(fieldsTb.get("timestamp")); msg.toId = (String) fieldsTb.get("toId"); msg.toQueue = ConversionHelper.toBoolean(fieldsTb.get("toQueue")); msg.correlationId = (String) fieldsTb.get("correlationId"); msg.replyToId = (String) fieldsTb.get("replyToId"); if (msg.replyToId != null) { msg.replyToQueue = ConversionHelper.toBoolean(fieldsTb.get("replyToQueue")); } msg.body_bytes = ConversionHelper.toBytes(fieldsTb.get("body_bytes")); msg.body_map = (Hashtable) fieldsTb.get("body_map"); msg.body_text = (String) fieldsTb.get("body_text"); msg.bodyRO = ConversionHelper.toBoolean(fieldsTb.get("bodyRO")); msg.propertiesRO = ConversionHelper.toBoolean(fieldsTb.get("propertiesRO")); msg.deliveryCount = ConversionHelper.toInt(fieldsTb.get("deliveryCount")); msg.denied = ConversionHelper.toBoolean(fieldsTb.get("denied")); msg.deletedDest = ConversionHelper.toBoolean(fieldsTb.get("deletedDest")); msg.expired = ConversionHelper.toBoolean(fieldsTb.get("expired")); msg.notWriteable = ConversionHelper.toBoolean(fieldsTb.get("notWriteable")); msg.undeliverable = ConversionHelper.toBoolean(fieldsTb.get("undeliverable")); msg.optionalHeader = (Hashtable) h.get("optionalHeader"); msg.properties = (Hashtable) h.get("properties"); } // Should never happen! catch (MessageValueException exc) { exc.printStackTrace(); } return msg; } /** * Method actually preparing the setting of a new property. * * @param name The property name. * * @exception MessageROException If the message properties are read-only. */ private void preparePropSetting(String name) throws MessageROException { if (propertiesRO) { throw new MessageROException("Can't set property as the message " + "properties are READ-ONLY."); } if (name == null || name.equals("")) throw new IllegalArgumentException("Invalid property name: " + name); if (properties == null) properties = new Hashtable(); } /** * Specializes the serialization method for protecting the message's * properties and body as soon as it is sent. */// private void writeObject(ObjectOutputStream s) throws IOException// {// s.defaultWriteObject();// bodyRO = true;// propertiesRO = true;// } /** * Specializes the deserialization method for initializing the message's * transient fields. */// private void readObject(ObjectInputStream s)// throws IOException, ClassNotFoundException// {// s.defaultReadObject();// acksCounter = 0;// durableAcksCounter = 0;// }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -