001: /*
002: * <copyright>
003: *
004: * Copyright 2001-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.tools.csmart.core.cdata;
027:
028: import java.io.Serializable;
029:
030: /**
031: * Holds the data for one property in a property group
032: * The Value is usually a <code>String</code> but could
033: * be a list of values.
034: * The type might be one of the list types,
035: * in which case there is a sub-type.
036: **/
037: public class PGPropData implements Serializable {
038: private String name = null; // Name of this field
039: private String type = null; // Class of the field
040: private String subtype = null; // if type is a list, class of elements
041: private Object value = null; // Usu. a String
042: private static final String[] listtypes = { "Collection", "List" };
043:
044: /**
045: * Creates a new <code>PGPropData</code> instance.
046: *
047: */
048: public PGPropData() {
049: }
050:
051: /**
052: * Sets the name of the property.
053: *
054: * @param name of the property
055: */
056: public void setName(String name) {
057: this .name = name;
058: }
059:
060: /**
061: * Gets the name of the property.
062: *
063: * @return the property name.
064: */
065: public String getName() {
066: return name;
067: }
068:
069: /**
070: * Sets the type of the property.
071: *
072: * @param type of property.
073: */
074: public void setType(String type) {
075: this .type = type;
076: // check if its a list type here?
077: }
078:
079: /**
080: * Gets the type of the property.
081: *
082: * @return the property type.
083: */
084: public String getType() {
085: return type;
086: }
087:
088: /**
089: * Sets the type of the property when
090: * the type is a list.
091: *
092: * @param list type
093: * @param subtype of elements in the list.
094: */
095: public void setType(String list, String subtype) {
096: this .type = list;
097: this .subtype = subtype;
098: }
099:
100: /**
101: * Gets the property type when the property
102: * contains a list of values.
103: *
104: * @return subtype of property value.
105: */
106: public String getSubType() {
107: return subtype;
108: }
109:
110: /**
111: * Sets the subtype.
112: *
113: * @param subtype of property
114: */
115: public void setSubType(String subtype) {
116: this .subtype = subtype;
117: }
118:
119: /**
120: * Determines if the value is a known listtype
121: * The known list types are:
122: * <code>Collection</code>, <code>List<code>
123: *
124: * @return True if property is a listtype
125: */
126: public boolean isListType() {
127: if (type == null)
128: return false;
129: for (int i = 0; i < listtypes.length; i++) {
130: if (listtypes[i].equalsIgnoreCase(type))
131: return true;
132: }
133: return false;
134: }
135:
136: /**
137: * Sets the value of the property.
138: *
139: * @param val of the property.
140: */
141: public void setValue(Object val) {
142: // check that its a String of PGPropMultiVal?
143: if (isListType() && !(val instanceof PGPropMultiVal)) {
144: throw new RuntimeException(
145: "Value must be PGPropMultiVal for Lists");
146: } else {
147: this .value = val;
148: }
149: }
150:
151: /**
152: * Returns the value of the property.
153: *
154: * @return property value.
155: */
156: public Object getValue() {
157: return value;
158: }
159:
160: /**
161: * String of the Property.
162: *
163: * @return a <code>String</code> of the property.
164: */
165: public String toString() {
166: StringBuffer buf = new StringBuffer();
167: buf.append("Value: " + getName() + " of type " + getType());
168: if (isListType()) {
169: buf.append(", subtype: " + getSubType());
170: }
171: buf.append(" with value " + getValue().toString() + ">");
172: return buf.toString();
173: }
174: } //end of PGPropData.java
|