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: */package org.cougaar.tools.csmart.experiment;
026:
027: import org.cougaar.tools.csmart.core.cdata.ComponentData;
028: import org.cougaar.tools.csmart.core.cdata.ComponentDataXML;
029: import org.cougaar.tools.csmart.ui.viewer.CSMART;
030: import org.cougaar.util.log.Logger;
031:
032: import java.io.File;
033: import java.io.IOException;
034:
035: /**
036: * ExperimentXML.java
037: *
038: * Allows the conversion of an Experiment to XML and from XML to
039: * an Experiment ComponentData (Host / Node / Agent mapping)
040: *
041: * Created: Wed Jun 5 11:38:56 2002
042: *
043: */
044:
045: public class ExperimentXML extends ComponentDataXML {
046: private Logger log;
047:
048: public ExperimentXML() {
049: log = CSMART
050: .createLogger("org.cougaar.tools.csmart.experiment.ExperimentDump");
051: }
052:
053: /**
054: * Parses the specified file into and Experiment ComponentData.
055: * An Experiment ComponentData contains no detailed Agent information.
056: * Just Host, Node, Agent mappings.
057: *
058: * @param filename - Name of file to parse
059: * @return a <code>ComponentData</code> value
060: */
061: private ComponentData parseExperimentFile(String filename) {
062: // TODO: Parse out and store Agent details from the new ComponentData
063: // this should be just a pure HNA mapping.
064: if (filename == null || filename.equals("")) {
065: if (log.isErrorEnabled()) {
066: log.error("Invaild filename: " + filename);
067: }
068: return null;
069: }
070:
071: return createComponentData(filename);
072:
073: }
074:
075: /**
076: * Parses the specified file into and Experiment ComponentData.
077: * An Experiment ComponentData contains no detailed Agent information.
078: * Just Host, Node, Agent mappings.
079: *
080: * @param file - Handle to file to parse.
081: * @return a <code>ComponentData</code> value
082: */
083: public ComponentData parseExperimentFile(File file) {
084: // TODO: Parse out and store Agent details from the new ComponentData
085: // this should be just a pure HNA mapping.
086: return createComponentData(file);
087:
088: }
089:
090: /**
091: * Creates an Experiment XML file from a ComponentData object.
092: *
093: * @param data ComponentData to convert into XML
094: * @param configDir - Directory to store file.
095: */
096: public void createExperimentFile(ComponentData data, File configDir) {
097: // TODO: Parse out all Agent details from the component data.
098: // make it a pure HNA mapping.
099: if (data == null) {
100: if (log.isErrorEnabled()) {
101: log
102: .error("Cannot create Experiment XML File, ComponentData was null!");
103: }
104: return;
105: }
106: try {
107: writeXMLFile(configDir, createXMLDocument(data), data
108: .getName());
109: } catch (IOException ioe) {
110: if (log.isErrorEnabled()) {
111: log
112: .error(
113: "Caught an Excpetion trying to write Experiment XML File",
114: ioe);
115: }
116: }
117: }
118:
119: public static void main(String[] args) {
120: ExperimentXML exp = new ExperimentXML();
121: ComponentData data = exp.parseExperimentFile(args[0]);
122: String dump = org.cougaar.tools.csmart.core.cdata.CDataDebugUtils
123: .createDataDump(data);
124:
125: System.out.println(dump);
126:
127: File file = new File("/tmp/");
128: exp.createExperimentFile(data, file);
129: }
130:
131: }// ExperimentXML
|