001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015: package org.griphyn.vdl.invocation;
016:
017: import java.util.*;
018: import java.io.Writer;
019: import java.io.IOException;
020:
021: /**
022: * This class maintains the application that was run, and the
023: * arguments to the commandline that were actually passed on to
024: * the application.
025: *
026: * @author Jens-S. Vöckler
027: * @author Yong Zhao
028: * @version $Revision: 50 $
029: * @see Job
030: */
031: public class ArgString extends Arguments implements HasText {
032: /**
033: * This is the data contained between the tags. There may be
034: * no data.
035: */
036: private StringBuffer m_value;
037:
038: /**
039: * Default c'tor: Construct a hollow shell and allow further
040: * information to be added later.
041: */
042: public ArgString() {
043: super ();
044: m_value = null;
045: }
046:
047: /**
048: * Constructs an applications without arguments.
049: * @param executable is the name of the application.
050: */
051: public ArgString(String executable) {
052: super (executable);
053: m_value = null;
054: }
055:
056: /**
057: * Constructs an applications with arguments.
058: * @param executable is the name of the application.
059: * @param value represents the argument line passed.
060: */
061: public ArgString(String executable, String value) {
062: super (executable);
063: m_value = new StringBuffer(value);
064: }
065:
066: /**
067: * Appends a piece of text to the existing text.
068: * @param fragment is a piece of text to append to existing text.
069: * Appending <code>null</code> is a noop.
070: */
071: public void appendValue(String fragment) {
072: if (fragment != null) {
073: if (this .m_value == null)
074: this .m_value = new StringBuffer(fragment);
075: else
076: this .m_value.append(fragment);
077: }
078: }
079:
080: /**
081: * Accessor
082: *
083: * @see #setValue(String)
084: */
085: public String getValue() {
086: return (m_value == null ? null : m_value.toString());
087: }
088:
089: /**
090: * Accessor.
091: *
092: * @param value is the new value to set.
093: * @see #getValue()
094: */
095: public void setValue(String value) {
096: this .m_value = (value == null ? null : new StringBuffer(value));
097: }
098:
099: /**
100: * Dumps the state of the current element as XML output. This function
101: * can return the necessary data more efficiently, thus overwriting
102: * the inherited method.
103: *
104: * @param indent is a <code>String</code> of spaces used for pretty
105: * printing. The initial amount of spaces should be an empty string.
106: * The parameter is used internally for the recursive traversal.
107: *
108: * @return a String which contains the state of the current class and
109: * its siblings using XML. Note that these strings might become large.
110: */
111: public String toXML(String indent) {
112: StringBuffer result = new StringBuffer(64);
113:
114: result.append("<arguments");
115: if (m_executable != null) {
116: result.append(" executable=\"");
117: result.append(quote(m_executable, true));
118: result.append('"');
119: }
120:
121: if (m_value == null) {
122: // no content
123: result.append("/>");
124: } else {
125: // yes, content
126: result.append('>');
127: result.append(quote(getValue(), false));
128: result.append("</arguments>");
129: }
130:
131: return result.toString();
132: }
133:
134: /**
135: * Dump the state of the current element as XML output. This function
136: * traverses all sibling classes as necessary, and converts the data
137: * into pretty-printed XML output. The stream interface should be able
138: * to handle large output efficiently.
139: *
140: * @param stream is a stream opened and ready for writing. This can also
141: * be a string stream for efficient output.
142: * @param indent is a <code>String</code> of spaces used for pretty
143: * printing. The initial amount of spaces should be an empty string.
144: * The parameter is used internally for the recursive traversal.
145: * If a <code>null</code> value is specified, no indentation nor
146: * linefeeds will be generated.
147: * @param namespace is the XML schema namespace prefix. If neither
148: * empty nor null, each element will be prefixed with this prefix,
149: * and the root element will map the XML namespace.
150: * @exception IOException if something fishy happens to the stream.
151: */
152: public void toXML(Writer stream, String indent, String namespace)
153: throws IOException {
154: String tag = (namespace != null && namespace.length() > 0) ? namespace
155: + ":arguments"
156: : "arguments";
157:
158: // open tag
159: if (indent != null && indent.length() > 0)
160: stream.write(indent);
161: stream.write('<');
162: stream.write(tag);
163: if (m_executable != null)
164: writeAttribute(stream, " executable=\"", m_executable);
165:
166: if (m_value != null) {
167: // yes, content
168: stream.write('>');
169: stream.write(quote(getValue(), false));
170: stream.write("</");
171: stream.write(tag);
172: stream.write('>');
173: } else {
174: // no content
175: stream.write("/>");
176: }
177: if (indent != null)
178: stream.write(System.getProperty("line.separator", "\r\n"));
179: }
180: }
|