001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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:
027: package org.cougaar.planning.ldm.policy;
028:
029: /**
030: *
031: **/
032:
033: /**
034: * An StringRuleParameter is a RuleParameter that returns an arbitrary string
035: */
036: public class StringRuleParameter implements RuleParameter,
037: java.io.Serializable {
038: protected String my_name;
039: protected String my_value;
040:
041: /**
042: * Constructor - Initially not set
043: */
044: public StringRuleParameter(String param_name) {
045: my_value = null;
046: my_name = param_name;
047: }
048:
049: public StringRuleParameter() {
050: }
051:
052: /**
053: * Parameter type is String
054: */
055: public int ParameterType() {
056: return RuleParameter.STRING_PARAMETER;
057: }
058:
059: public String getName() {
060: return my_name;
061: }
062:
063: public void setName(String name) {
064: my_name = name;
065: }
066:
067: /**
068: * Get parameter value (String)
069: * @return Object parameter value (String). Note : could be null.
070: */
071: public Object getValue() {
072: return my_value;
073: }
074:
075: /**
076: * Set parameter value
077: * @param new_value : must be String
078: * @throws RuleParameterIllegalValueException (all strings accepted)
079: */
080: public void setValue(Object new_value)
081: throws RuleParameterIllegalValueException {
082: boolean success = false;
083: if (new_value instanceof String) {
084: my_value = (String) new_value;
085: success = true;
086: }
087: if (!success)
088: throw new RuleParameterIllegalValueException(
089: RuleParameter.STRING_PARAMETER,
090: "Argument must be a string.");
091: }
092:
093: /**
094: * @param test_value must be String
095: * @return true if Object is a string, false otherwise
096: */
097: public boolean inRange(Object test_value) {
098: if (test_value instanceof String) {
099: return true;
100: }
101: return false;
102: }
103:
104: public String toString() {
105: return "#<STRING_PARAMETER : " + my_value + ">";
106: }
107:
108: public Object clone() {
109: StringRuleParameter srp = new StringRuleParameter(my_name);
110: try {
111: srp.setValue(my_value);
112: } catch (RuleParameterIllegalValueException rpive) {
113: }
114: return srp;
115: }
116:
117: }
|