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: * A BooleanRuleParameter is a RuleParameter that contains a single true
035: * or false value
036: */
037: public class BooleanRuleParameter implements RuleParameter,
038: java.io.Serializable {
039: protected String my_name;
040: protected Boolean my_value;
041:
042: /**
043: * Constructor - Initially not set
044: */
045: public BooleanRuleParameter(String param_name) {
046: my_value = null;
047: my_name = param_name;
048: }
049:
050: /**
051: * Constructor with value set
052: */
053: public BooleanRuleParameter(String param_name, boolean value) {
054: my_value = new Boolean(value);
055: my_name = param_name;
056: }
057:
058: public BooleanRuleParameter() {
059: }
060:
061: /**
062: * Parameter type is Boolean
063: */
064: public int ParameterType() {
065: return RuleParameter.BOOLEAN_PARAMETER;
066: }
067:
068: public String getName() {
069: return my_name;
070: }
071:
072: public void setName(String name) {
073: my_name = name;
074: }
075:
076: /**
077: * Get parameter value (Boolean)
078: * @return Object parameter value (Boolean). Note : could be null.
079: */
080: public Object getValue() {
081: return my_value;
082: }
083:
084: /**
085: * Set parameter value
086: * @param new_value : must be Boolean
087: * @throws RuleParameterIllegalValueException (only Boolean accepted)
088: */
089: public void setValue(Object new_value)
090: throws RuleParameterIllegalValueException {
091: boolean success = false;
092: if (new_value instanceof Boolean) {
093: my_value = (Boolean) new_value;
094: success = true;
095: }
096: if (!success)
097: throw new RuleParameterIllegalValueException(
098: RuleParameter.BOOLEAN_PARAMETER,
099: "Argument must be a Boolean.");
100: }
101:
102: /**
103: * @param test_value : must be Boolean
104: * @return true if Object is a Boolean, false otherwise
105: */
106: public boolean inRange(Object test_value) {
107: if (test_value instanceof Boolean) {
108: return true;
109: }
110: return false;
111: }
112:
113: public String toString() {
114: return "#<BOOLEAN_PARAMETER : " + my_value + ">";
115: }
116:
117: public Object clone() {
118: BooleanRuleParameter brp = new BooleanRuleParameter(my_name);
119: try {
120: brp.setValue(my_value);
121: } catch (RuleParameterIllegalValueException rpive) {
122: }
123: return brp;
124: }
125:
126: }
|