001: /*
002: * <copyright>
003: *
004: * Copyright 2002-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.core.adaptivity;
028:
029: import org.cougaar.core.blackboard.Publishable;
030: import org.cougaar.core.util.UID;
031:
032: /**
033: * OperatingModePolicy specifies constraints on values of Operating
034: * modes. It consists of an if clause expressing the conditions under
035: * which the policy applies and an array of restrictions on the values
036: * of some {@link OperatingMode}s.
037: **/
038:
039: /* IF clause, then clause
040: * If THREATCON > 3 then
041: * (encription > 128) && (encryption < 512).
042: */
043:
044: public class OperatingModePolicy implements Policy, Publishable {
045:
046: private UID uid = null;
047: private String policyName = "";
048: private String authority;
049: private PolicyKernel policy;
050:
051: public OperatingModePolicy(PolicyKernel pk) {
052: policy = pk;
053: }
054:
055: /**
056: * Constructor
057: * @param ifClause the 'if' ConstrainingClause
058: * @param omConstraints an array of constraints to apply to {@link OperatingMode}s
059: */
060: public OperatingModePolicy(ConstrainingClause ifClause,
061: ConstraintPhrase[] omConstraints) {
062: this (new PolicyKernel(ifClause, omConstraints));
063: }
064:
065: /**
066: * Constructor
067: * @param ifClause the 'if' ConstrainingClause
068: * @param omConstraints an array of constraints to apply to {@link OperatingMode}s
069: */
070: public OperatingModePolicy(String policyName,
071: ConstrainingClause ifClause,
072: ConstraintPhrase[] omConstraints) {
073: this (ifClause, omConstraints);
074: this .policyName = policyName;
075: }
076:
077: /**
078: * Constructor
079: * @param ifClause the 'if' ConstrainingClause
080: * @param omConstraints an array of constraints to apply to {@link OperatingMode}s
081: */
082: public OperatingModePolicy(String policyName,
083: ConstrainingClause ifClause,
084: ConstraintPhrase[] omConstraints, String authority) {
085: this (policyName, ifClause, omConstraints);
086: this .authority = authority;
087: }
088:
089: /**
090: * Returns the originator or creator (authority) of the policy. This
091: * is part of the implementation of the Policy interface.
092: * @return the name of the authority
093: **/
094: public String getAuthority() {
095: return authority;
096: }
097:
098: public void setAuthority(String authority) {
099: if (this .authority != null)
100: throw new RuntimeException(
101: "Attempt to change Policy Authority");
102: this .authority = authority;
103: }
104:
105: public String getName() {
106: return policyName;
107: }
108:
109: public void setName(String name) {
110: if (policyName != null)
111: throw new RuntimeException("Attempt to change Policy Name");
112: policyName = name;
113: }
114:
115: // UniqueObject interface
116: public UID getUID() {
117: return uid;
118: }
119:
120: /**
121: * Set the UID (unique identifier) of this UniqueObject. Used only
122: * during initialization.
123: * @param uid the UID to be given to this
124: **/
125: public void setUID(UID uid) {
126: if (this .uid != null)
127: throw new RuntimeException("Attempt to change UID: " + uid);
128: this .uid = uid;
129: }
130:
131: public PolicyKernel getPolicyKernel() {
132: return policy;
133: }
134:
135: protected void setPolicyKernel(PolicyKernel pk) {
136: policy = pk;
137: }
138:
139: /* convenience methods */
140: public ConstrainingClause getIfClause() {
141: return policy.getIfClause();
142: }
143:
144: public ConstraintPhrase[] getOperatingModeConstraints() {
145: return policy.getOperatingModeConstraints();
146: }
147:
148: public String toString() {
149: StringBuffer sb = new StringBuffer(getName());
150: sb.append(" ");
151: sb.append(policy.getIfClause().toString());
152: ConstraintPhrase[] cp = policy.getOperatingModeConstraints();
153: for (int i = 0; i < cp.length; i++) {
154: sb.append(": ");
155: sb.append(cp[i].toString());
156: }
157: return sb.toString();
158: }
159:
160: public boolean isPersistable() {
161: return true;
162: }
163: }
|