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.lib.util;
028:
029: import java.util.Iterator;
030: import java.util.Vector;
031:
032: import org.cougaar.core.mts.MessageAddress;
033: import org.cougaar.lib.param.Param;
034: import org.cougaar.lib.param.ParamTable;
035: import org.cougaar.util.log.Logger;
036:
037: /**
038: * <pre>
039: * This is a convenience class for the UTIL plugins. This class
040: * uses the ConfigFinder to find the param files.
041: *
042: * To look for the parameter files in a non-default location,
043: * add a system parameter like this to setarguments.csh:
044: *
045: * -Dorg.cougaar.config.path=$COUGAAR_INSTALL_PATH/plugins/TOPS/data;
046: *
047: * WARNING : the trailing semi-colon is ABSOLUTELY necessary.
048: *
049: * Expects an extension of ".env.xml," which will be prefixed
050: * with the name of the cluster, e.g. TRANSCOM.env.xml. This can be
051: * overridden by setting the envFile parameter (see below).
052: *
053: * Supports plugin specific (as opposed to Cluster-specific)
054: * env files by allowing the specification
055: * of both an "envDir" and/or an "envFile" following the plugin in the .ini
056: * file.
057: *
058: * The envDir can be relative or absolute.
059: *
060: * For example :
061: * plugin = com.bbn.tops.plugins.ground.TOPSGAFortAggregatorPlugin
062: * (envDir={String}../../tops/data, envFile={String}FortStewartAggregator.env.xml)
063: *
064: * The envDir can be used if there are two files of the same name in the
065: * config file finder path (which shouldn't happen...)
066: *
067: * </pre>
068: */
069: public class UTILParamTable extends ParamTable {
070:
071: /**
072: * Convenience constructor. The default name of the parameter file
073: * is derived from the name of the cluster.
074: * For example TRANSCOM.env.xml.
075: *
076: * @see org.cougaar.lib.param.ParamTable#ParamTable
077: * @param envParams vector of environment parameters
078: * @param cluster pointer to the cluster
079: */
080: public UTILParamTable(Vector envParams, MessageAddress cluster,
081: Logger logger) {
082: super (logger);
083: addIniParameters(addEnvFileParam(envParams, cluster));
084: }
085:
086: /**
087: * Help for the constructor. Sets the name of the parameter
088: * file. If this file name is not set in the ini file
089: * (and passed in the envParams variable) then it is set
090: * to be the name of the cluster plus env.xml.
091: */
092: private Vector addEnvFileParam(final Vector envParams,
093: MessageAddress cluster) {
094: boolean hasfile = false;
095: // boolean hasdir = false;
096:
097: Vector paramCopy = new Vector(envParams);
098:
099: Iterator runtimeParams = paramCopy.iterator();
100: while (runtimeParams.hasNext()) {
101: String runtimeParam = (String) runtimeParams.next();
102: Param p = paramParser.getParam(runtimeParam);
103: if (p != null) {
104: String name = p.getName();
105:
106: if (name.equals("envFile")) {
107: hasfile = true;
108: } else if (name.equals("envDir")) {
109: // hasdir = true;
110: }
111: }
112: }
113:
114: if (!hasfile) {
115: String newParam = "envFile={String}" + cluster.getAddress()
116: + ".env.xml";
117: paramCopy.add(newParam);
118: }
119:
120: return paramCopy;
121: }
122: }
|