001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018
019 package org.activemq.message;
020
021 import java.io.DataInput;
022 import java.io.IOException;
023 import java.io.DataOutput;
024
025 /**
026 * Sent in receipt of a Packet
027 */
028
029 public class CachedValue extends AbstractPacket implements BodyPacket {
030
031 private Object value;
032
033
034 /**
035 * Return the type of Packet
036 *
037 * @return integer representation of the type of Packet
038 */
039
040 public int getPacketType() {
041 return CACHED_VALUE_COMMAND;
042 }
043
044
045 /**
046 * @return pretty print of a CachedValue
047 */
048 public String toString() {
049 return super.toString() + " CachedValue{ " +
050 "value = " + value +
051 " }";
052 }
053 /**
054 * @return Returns the value.
055 */
056 public Object getValue() {
057 return value;
058 }
059
060 /**
061 * @param value The value to set.
062 */
063 public void setValue(Object value) {
064 this.value = value;
065 }
066
067 public void writeBody(DataOutput dataOut) throws IOException {
068 String text = "";
069 if (value != null) {
070 text = value.toString();
071 }
072 dataOut.writeUTF(text);
073 }
074
075 public void readBody(DataInput dataIn) throws IOException {
076 setValue(dataIn.readUTF());
077 }
078 }