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

📄 message.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  /**   * Sets a property as a double value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setDoubleProperty(String name, double value) throws MessageROException {    setProperty(name, new Double(value));  }  /**   * Sets a property as a float value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setFloatProperty(String name, float value) throws MessageROException {    setProperty(name, new Float(value));  }  /**   * Sets a property as an int value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setIntProperty(String name, int value) throws MessageROException {    setProperty(name, new Integer(value));  }  /**   * Sets a property as a long value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setLongProperty(String name, long value) throws MessageROException {    setProperty(name, new Long(value));  }  /**   * Sets a property as a short value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setShortProperty(String name, short value) throws MessageROException {    setProperty(name, new Short(value));  }  /**   * Sets a property as a String.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException  If the message properties are read-only.   */  public void setStringProperty(String name, String value) throws MessageROException {    setProperty(name, value);  }  /**   * Sets a property value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException   * 	If the message properties are read-only.   * @exception MessageValueException   *	If the value is not a Java primitive object.   * @exception IllegalArgumentException   *	If the key name is illegal (null or empty string).   */  public void setObjectProperty(String name, Object value) throws MessageException {    if (value instanceof Boolean || value instanceof Number        || value instanceof String) {      setProperty(name, value);    } else {      throw new MessageValueException("Can't set non primitive Java object"                                      + " as a property value.");    }  }   /**   * Sets a property value.   *   * @param name  The property name.   * @param value  The property value.   *   * @exception MessageROException   * 	If the message properties are read-only.   * @exception IllegalArgumentException   *	If the key name is illegal (null or empty string).   */  private void setProperty(String name, Object value) 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();    properties.put(name, value);  }   /**   * Returns a property as a boolean value.   *   * @exception MessageValueException  If the property type is invalid.   */  public boolean getBooleanProperty(String name) throws MessageValueException  {    return ConversionHelper.toBoolean(getObjectProperty(name));  }    /**   *   * @exception MessageValueException  If the property type is invalid.   */  public byte getByteProperty(String name) throws MessageValueException {    return ConversionHelper.toByte(getObjectProperty(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 {    return ConversionHelper.toDouble(getObjectProperty(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 {    return ConversionHelper.toFloat(getObjectProperty(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 {    return ConversionHelper.toInt(getObjectProperty(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 {    return ConversionHelper.toLong(getObjectProperty(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 {    return ConversionHelper.toShort(getObjectProperty(name));  }  /**   * Returns a property as a String.   *   * @param name  The property name.   */  public String getStringProperty(String name) {    return ConversionHelper.toString(getObjectProperty(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 <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;  }  /**   * Resets the read-only flag, in order to allow the modification   * of message properties.   */  public void resetPropertiesRO() {    propertiesRO = false;  }     /**   *  Copies all of the mappings from the properties of this message to   * the specified hashtable. These mappings will replace any mappings that   * this Hashtable had for any of the keys currently in the properties.   */  public void getProperties(Hashtable h) {    if (properties != null)      h.putAll(properties);  }  /**   * Sets an object as the body of the message.    *   * @exception IOException  In case of an error while setting the object.   * @exception  MessageROException  If the message body is read-only.   */  public void setObject(Object object) throws IOException, MessageROException {    if (bodyRO)      throw new MessageROException("Can't set the body as it is READ-ONLY.");    type = MessageType.OBJECT;    if (object == null)      setBodyBytes(null);    else {      ByteArrayOutputStream baos = new ByteArrayOutputStream();      ObjectOutputStream oos = new ObjectOutputStream(baos);      oos.writeObject(object);      oos.flush();      setBodyBytes(baos.toByteArray());      oos.close();      baos.close();    }  }  /**   * 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(HashMap map) throws Exception {    if (bodyRO)      throw new MessageROException("Can't set the body as it is READ-ONLY.");    type = MessageType.MAP;    setBodyMap(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.");    type = MessageType.TEXT;    setBodyText(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.");    type = MessageType.STREAM;    setBodyBytes(bytes);  }  /**   * 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.");    type = MessageType.BYTES;    setBodyBytes(bytes);  }   /**   * Returns the object body of the message.   *   * @exception IOException  In case of an error while getting the object.   * @exception ClassNotFoundException  If the object class is unknown.   */  public Object getObject() throws Exception {    if (getBodyBytes() == null)      return null;    ByteArrayInputStream bais = new ByteArrayInputStream(getBodyBytes());    ObjectInputStream ois = new ObjectInputStream(bais);    return ois.readObject();  }  /**   * Returns the map body of the message.   */   public Map getMap() {    return getBodyMap();  }  /** Gets the String body of the message. */  public String getText() {    return getBodyText();  }  /** Returns the stream of bytes body of the message. */  public byte[] getStream() {    return getBodyBytes();  }  /** Returns the array of bytes body of the message. */  public byte[] getBytes() {    return getBodyBytes();  }  /**    * Method clearing the message body.   */  public void clearBody() {    setBodyBytes(null);    setBodyMap(null);    setBodyText(null);    bodyRO = false;  }  /** set message read-only */  public void setReadOnly() {    propertiesRO = true;    bodyRO = true;  }  /**   * Returns <code>true</code> if the message is valid.   *   * @param currentTime	The current time to verify the expiration time.   */

⌨️ 快捷键说明

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