001: /*
002: * %W% %E%
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jump.module.contentstore;
028:
029: /**
030: * <code>JUMPData</code> encapsulates the value stored in the persistant store.
031: * This class consists of the type of the value and the actual value.
032: */
033: public class JUMPData {
034: public static final int FORMAT_UNKNOWN = -1;
035: public static final int FORMAT_STRING = 0;
036: public static final int FORMAT_INT = 1;
037: public static final int FORMAT_FLOAT = 2;
038: public static final int FORMAT_BOOLEAN = 3;
039: public static final int FORMAT_BYTES = 4;
040: public static final int FORMAT_SERIALIZABLE = 5;
041:
042: protected int format;
043: private Object value;
044:
045: public JUMPData(Object value, int format) {
046: this .value = value;
047: this .format = format;
048: }
049:
050: /**
051: * Creates a new instance of JUMPData
052: */
053: public JUMPData() {
054: this (null, FORMAT_UNKNOWN);
055: }
056:
057: public JUMPData(String value) {
058: this (value, FORMAT_STRING);
059: }
060:
061: public JUMPData(int value) {
062: this (new Integer(value), FORMAT_INT);
063: }
064:
065: public JUMPData(float value) {
066: this (new Float(value), FORMAT_FLOAT);
067: }
068:
069: public JUMPData(boolean value) {
070: this (new Boolean(value), FORMAT_BOOLEAN);
071: }
072:
073: public JUMPData(byte[] value) {
074: this (value, FORMAT_BYTES);
075: }
076:
077: public JUMPData(java.io.Serializable value) {
078: this (value, FORMAT_SERIALIZABLE);
079: }
080:
081: public int getFormat() {
082: return this .format;
083: }
084:
085: public String getStringValue() {
086: return (String) value;
087: }
088:
089: public int getIntValue() {
090: return ((Integer) value).intValue();
091: }
092:
093: public float getFloatValue() {
094: return ((Float) value).floatValue();
095: }
096:
097: public boolean getBooleanValue() {
098: return ((Boolean) value).booleanValue();
099: }
100:
101: public byte[] getBytesValue() {
102: return (byte[]) this .value;
103: }
104:
105: /**
106: * Returns the value of this JUMPData as an Object.
107: */
108: public Object getValue() {
109: return this .value;
110: }
111:
112: /**
113: * Returns the String summerizing the content of this JUMPData.
114: */
115: public String toString() {
116: return "JUMPData(" + this .value + ",format=" + this .format
117: + ")";
118: }
119:
120: /**
121: * Tells whether or not this JUMPData is equal to another object.
122: * Two JUMPDatas are equal if the data format is the same and the value
123: * is <code> equals </code> to one another.
124: */
125: public boolean equals(Object obj) {
126: if (!(obj instanceof JUMPData))
127: return false;
128: JUMPData other = (JUMPData) obj;
129: return (format == other.format && value.equals(other.value));
130: }
131: }
|