001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: SimplePropertyValue.java,v 1.14 2005/03/17 16:15:32 jesper Exp $
023: package net.infonode.properties.propertymap.value;
024:
025: import net.infonode.properties.propertymap.PropertyMapImpl;
026: import net.infonode.util.Printer;
027: import net.infonode.util.Utils;
028:
029: import java.io.IOException;
030: import java.io.ObjectInputStream;
031: import java.io.ObjectOutputStream;
032: import java.io.Serializable;
033:
034: /**
035: * @author $Author: jesper $
036: * @version $Revision: 1.14 $
037: */
038: public class SimplePropertyValue implements PropertyValue {
039: private final Object value;
040:
041: public SimplePropertyValue(Object value) {
042: this .value = value;
043: }
044:
045: public void updateListener(boolean enable) {
046: }
047:
048: public PropertyValue getParent() {
049: return null;
050: }
051:
052: public Object get(PropertyMapImpl object) {
053: return value;
054: }
055:
056: public Object getWithDefault(PropertyMapImpl object) {
057: return value;
058: }
059:
060: public PropertyValue getSubValue(PropertyMapImpl object) {
061: return null;
062: }
063:
064: public void unset() {
065: }
066:
067: public String toString() {
068: return String.valueOf(value);
069: }
070:
071: public void dump(Printer printer) {
072: printer.println(toString());
073: }
074:
075: public boolean equals(Object obj) {
076: return obj != null
077: && obj instanceof SimplePropertyValue
078: && Utils.equals(((SimplePropertyValue) obj).value,
079: value);
080: }
081:
082: public int hashCode() {
083: return value.hashCode();
084: }
085:
086: public void write(ObjectOutputStream out) throws IOException {
087: out.writeInt(ValueDecoder.SIMPLE);
088: out.writeObject(value);
089: }
090:
091: public boolean isSerializable() {
092: return value instanceof Serializable;
093: }
094:
095: public static PropertyValue decode(ObjectInputStream in)
096: throws IOException {
097: try {
098: return new SimplePropertyValue(in.readObject());
099: } catch (ClassNotFoundException e) {
100: throw new IOException(e.getMessage());
101: }
102: }
103:
104: public static void skip(ObjectInputStream in) throws IOException {
105: try {
106: in.readObject();
107: } catch (ClassNotFoundException e) {
108: throw new IOException(e.getMessage());
109: }
110: }
111:
112: public PropertyValue copyTo(PropertyMapImpl propertyMap) {
113: return this;
114: }
115:
116: }
|