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 is transient for XML parsing. The data value will be
023: * incorporated into the job classes.
024: *
025: * @author Jens-S. Vöckler
026: * @author Yong Zhao
027: * @version $Revision: 50 $
028: * @see StatCall
029: */
030: public class WorkingDir extends Invocation implements HasText {
031: /**
032: * This is the data contained between the tags. A <code>null</code>
033: * value is not valid.
034: */
035: private StringBuffer m_value;
036:
037: /**
038: * Default c'tor: Construct a hollow shell and allow further
039: * information to be added later.
040: */
041: public WorkingDir() {
042: m_value = null;
043: }
044:
045: /**
046: * Constructs a piece of data.
047: * @param value is the data to remember. The string may be empty,
048: * but it must not be <code>null</code>.
049: * @exception NullPointerException if the argument was null.
050: */
051: public WorkingDir(String value) {
052: if (value == null)
053: throw new NullPointerException(
054: "the value to the <data> tag constructor must not be null");
055: else
056: m_value = new StringBuffer(value);
057: }
058:
059: /**
060: * Appends a piece of text to the existing text.
061: * @param fragment is a piece of text to append to existing text.
062: * Appending <code>null</code> is a noop.
063: */
064: public void appendValue(String fragment) {
065: if (fragment != null) {
066: if (this .m_value == null)
067: this .m_value = new StringBuffer(fragment);
068: else
069: this .m_value.append(fragment);
070: }
071: }
072:
073: /**
074: * Accessor
075: *
076: * @see #setValue(String)
077: */
078: public String getValue() {
079: return (m_value == null ? null : m_value.toString());
080: }
081:
082: /**
083: * Accessor.
084: *
085: * @param value is the new value to set.
086: * @see #getValue()
087: */
088: public void setValue(String value) {
089: this .m_value = (value == null ? null : new StringBuffer(value));
090: }
091:
092: /**
093: * Converts the active state into something meant for human consumption.
094: * The method will be called when recursively traversing the instance
095: * tree.
096: *
097: * @param stream is a stream opened and ready for writing. This can also
098: * be a string stream for efficient output.
099: */
100: public void toString(Writer stream) throws IOException {
101: throw new IOException(
102: "method not implemented, please contact vds-support@griphyn.org");
103: }
104:
105: /**
106: * Dumps the state of the current element as XML output. This function
107: * can return the necessary data more efficiently, thus overwriting
108: * the inherited method.
109: *
110: * @param indent is a <code>String</code> of spaces used for pretty
111: * printing. The initial amount of spaces should be an empty string.
112: * The parameter is used internally for the recursive traversal.
113: *
114: * @return a String which contains the state of the current class and
115: * its siblings using XML. Note that these strings might become large.
116: */
117: public String toXML(String indent) {
118: if (m_value != null) {
119: String newline = System.getProperty("line.separator",
120: "\r\n");
121: StringBuffer result = new StringBuffer(m_value.length()
122: + 15 + newline.length());
123:
124: if (indent != null && indent.length() > 0)
125: result.append(indent);
126: result.append("<cwd>");
127: result.append(quote(getValue(), false));
128: result.append("</cwd>");
129: if (indent != null)
130: result.append(newline);
131: return result.toString();
132: } else {
133: return new String();
134: }
135: }
136:
137: /**
138: * Dump the state of the current element as XML output. This function
139: * traverses all sibling classes as necessary, and converts the data
140: * into pretty-printed XML output. The stream interface should be able
141: * to handle large output efficiently.
142: *
143: * @param stream is a stream opened and ready for writing. This can also
144: * be a string stream for efficient output.
145: * @param indent is a <code>String</code> of spaces used for pretty
146: * printing. The initial amount of spaces should be an empty string.
147: * The parameter is used internally for the recursive traversal.
148: * If a <code>null</code> value is specified, no indentation nor
149: * linefeeds will be generated.
150: * @param namespace is the XML schema namespace prefix. If neither
151: * empty nor null, each element will be prefixed with this prefix,
152: * and the root element will map the XML namespace.
153: * @exception IOException if something fishy happens to the stream.
154: */
155: public void toXML(Writer stream, String indent, String namespace)
156: throws IOException {
157: String tag = (namespace != null && namespace.length() > 0) ? namespace
158: + ":cwd"
159: : "cwd";
160:
161: if (this .m_value != null) {
162: // open tag
163: if (indent != null && indent.length() > 0)
164: stream.write(indent);
165: stream.write('<');
166: stream.write(tag);
167: stream.write('>');
168:
169: // dump content
170: stream.write(quote(getValue(), false));
171:
172: // close tag
173: stream.write("</");
174: stream.write(tag);
175: stream.write('>');
176: if (indent != null)
177: stream.write(System.getProperty("line.separator",
178: "\r\n"));
179: }
180: }
181: }
|