001: /*
002: * $Id: JGraphBusinessObject.java,v 1.2 2005/08/09 08:40:47 david Exp $
003: *
004: * Copyright (c) 2001-2005, Gaudenz Alder
005: *
006: * See LICENSE file in distribution for licensing details of this source file
007: */
008: package com.jgraph.example.adapter;
009:
010: import java.io.Serializable;
011: import java.util.Hashtable;
012: import java.util.Map;
013:
014: /**
015: * @author Gaudenz Alder
016: *
017: * An object that represents an entity with an arbitrary set of properties.
018: */
019: public class JGraphBusinessObject implements Cloneable, Serializable {
020:
021: protected Map properties = new Hashtable();
022:
023: protected String valueKey = "value";
024:
025: public JGraphBusinessObject() {
026: this ("");
027: }
028:
029: public JGraphBusinessObject(Object userObject) {
030: setValue(userObject);
031: }
032:
033: /**
034: * @return Returns the properties.
035: */
036: public Map getProperties() {
037: return properties;
038: }
039:
040: /**
041: * @param properties
042: * The properties to set.
043: */
044: public void setProperties(Map properties) {
045: this .properties = properties;
046: }
047:
048: public void setValue(Object value) {
049: putProperty(valueKey, value);
050: }
051:
052: public Object getValue() {
053: return getProperty(valueKey);
054: }
055:
056: /**
057: * @return Returns the labelKey.
058: */
059: public String getValueKey() {
060: return valueKey;
061: }
062:
063: /**
064: * @param valueKey
065: * The labelKey to set.
066: */
067: public void setValueKey(String valueKey) {
068: this .valueKey = valueKey;
069: }
070:
071: public Object putProperty(Object key, Object value) {
072: if (key != null && value != null)
073: return properties.put(key, value);
074: return null;
075: }
076:
077: public Object getProperty(Object key) {
078: if (key != null)
079: return properties.get(key);
080: return null;
081: }
082:
083: public String toString() {
084: Object value = getValue();
085: if (value != null)
086: return String.valueOf(value);
087: return "";
088: }
089:
090: public Object clone() {
091: JGraphBusinessObject clone;
092: try {
093: clone = (JGraphBusinessObject) super .clone();
094: } catch (CloneNotSupportedException e) {
095: clone = new JGraphBusinessObject();
096: }
097: clone.setProperties(new Hashtable(getProperties()));
098: clone.setValueKey(getValueKey());
099: return clone;
100: }
101:
102: }
|