001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo;
012:
013: import java.io.Serializable;
014:
015: /**
016: * Serializable information about a property. For properties that are
017: * configurable beans themselves the type will be TYPE_SERVER_BEAN and
018: * the children array will be filled in. The value for these is a bean
019: * defined status object. It should have a useful but short toString().
020: */
021: public class PropertyInfo implements Serializable, Comparable {
022:
023: public static final int TYPE_SERVER_BEAN = 1;
024: public static final int TYPE_INT = 2;
025: public static final int TYPE_STRING = 3;
026: public static final int TYPE_BOOLEAN = 4;
027:
028: private String name;
029: private int type;
030: private String displayName;
031: private String description;
032: private Object value;
033: private PropertyInfo[] children;
034:
035: public PropertyInfo() {
036: }
037:
038: public String getName() {
039: return name;
040: }
041:
042: public void setName(String name) {
043: this .name = name;
044: }
045:
046: public int getType() {
047: return type;
048: }
049:
050: public void setType(int type) {
051: this .type = type;
052: }
053:
054: public String getDisplayName() {
055: return displayName;
056: }
057:
058: public void setDisplayName(String displayName) {
059: this .displayName = displayName;
060: }
061:
062: public String getDescription() {
063: return description;
064: }
065:
066: public void setDescription(String description) {
067: this .description = description;
068: }
069:
070: public Object getValue() {
071: return value;
072: }
073:
074: public void setValue(Object value) {
075: this .value = value;
076: }
077:
078: public PropertyInfo[] getChildren() {
079: return children;
080: }
081:
082: public void setChildren(PropertyInfo[] children) {
083: this .children = children;
084: }
085:
086: /**
087: * Order by name.
088: */
089: public int compareTo(Object o) {
090: return name.compareTo(((PropertyInfo) o).name);
091: }
092:
093: public String toString() {
094: if (type == TYPE_SERVER_BEAN) {
095: return displayName;
096: }
097: return displayName + ": " + value;
098: }
099:
100: /**
101: * Dump to System.out.
102: */
103: public void dump(String indent) {
104: System.out.println(indent + this );
105: if (type == TYPE_SERVER_BEAN) {
106: indent = indent + " ";
107: int n = children.length;
108: for (int i = 0; i < n; i++)
109: children[i].dump(indent);
110: }
111: }
112:
113: /**
114: * Find the child with name or null if none.
115: */
116: public PropertyInfo findChild(String name) {
117: if (children == null)
118: return null;
119: for (int i = children.length - 1; i >= 0; i--) {
120: PropertyInfo child = children[i];
121: if (child.name.equals(name))
122: return child;
123: }
124: return null;
125: }
126: }
|