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 status classes.
024: *
025: * @author Jens-S. Vöckler
026: * @author Yong Zhao
027: * @version $Revision: 50 $
028: * @see StatCall
029: */
030: public class JobStatusSignal extends JobStatus implements HasText {
031: /**
032: * This is the signal number that led to the process termination.
033: */
034: private short m_signo;
035:
036: /**
037: * This flag signals, if a core file was generated. Not all systems
038: * support core files.
039: */
040: private boolean m_core;
041:
042: /**
043: * This is the signal name or message contained between the tags.
044: */
045: private String m_value;
046:
047: /**
048: * Default c'tor: Construct a hollow shell and allow further
049: * information to be added later.
050: */
051: public JobStatusSignal() {
052: m_signo = 0;
053: m_core = false;
054: m_value = null;
055: }
056:
057: /**
058: * Constructs an error number without reason text.
059: * @param signo is the error number
060: */
061: public JobStatusSignal(short signo) {
062: m_signo = signo;
063: m_core = false;
064: m_value = null;
065: }
066:
067: /**
068: * Constructs a piece of data.
069: * @param signo is the error number.
070: * @param core is the core flag.
071: */
072: public JobStatusSignal(short signo, boolean core) {
073: m_signo = signo;
074: m_core = core;
075: m_value = null;
076: }
077:
078: /**
079: * Constructs a piece of data.
080: * @param signo is the error number.
081: * @param core is the core flag.
082: * @param value is the textual error reason.
083: */
084: public JobStatusSignal(short signo, boolean core, String value) {
085: m_signo = signo;
086: m_value = value;
087: }
088:
089: /**
090: * Appends a piece of text to the existing text.
091: * @param fragment is a piece of text to append to existing text.
092: * Appending <code>null</code> is a noop.
093: */
094: public void appendValue(String fragment) {
095: if (fragment != null) {
096: if (this .m_value == null)
097: this .m_value = new String(fragment);
098: else
099: this .m_value += fragment;
100: }
101: }
102:
103: /**
104: * Accessor
105: *
106: * @see #setSignalNumber(short)
107: */
108: public short getSignalNumber() {
109: return this .m_signo;
110: }
111:
112: /**
113: * Accessor.
114: *
115: * @param signo
116: * @see #getSignalNumber()
117: */
118: public void setSignalNumber(short signo) {
119: this .m_signo = signo;
120: }
121:
122: /**
123: * Accessor
124: *
125: * @see #setCoreFlag(boolean)
126: */
127: public boolean getCoreFlag() {
128: return this .m_core;
129: }
130:
131: /**
132: * Accessor.
133: *
134: * @param core
135: * @see #getCoreFlag()
136: */
137: public void setCoreFlag(boolean core) {
138: this .m_core = core;
139: }
140:
141: /**
142: * Accessor
143: *
144: * @see #setValue(String)
145: */
146: public String getValue() {
147: return this .m_value;
148: }
149:
150: /**
151: * Accessor.
152: *
153: * @param value is the new value to set.
154: * @see #getValue()
155: */
156: public void setValue(String value) {
157: this .m_value = value;
158: }
159:
160: /**
161: * Converts the active state into something meant for human consumption.
162: * The method will be called when recursively traversing the instance
163: * tree.
164: *
165: * @param stream is a stream opened and ready for writing. This can also
166: * be a string stream for efficient output.
167: */
168: public void toString(Writer stream) throws IOException {
169: throw new IOException(
170: "method not implemented, please contact vds-support@griphyn.org");
171: }
172:
173: /**
174: * Dumps the state of the current element as XML output. This function
175: * can return the necessary data more efficiently, thus overwriting
176: * the inherited method.
177: *
178: * @param indent is a <code>String</code> of spaces used for pretty
179: * printing. The initial amount of spaces should be an empty string.
180: * The parameter is used internally for the recursive traversal.
181: *
182: * @return a String which contains the state of the current class and
183: * its siblings using XML. Note that these strings might become large.
184: */
185: public String toXML(String indent) {
186: StringBuffer result = new StringBuffer(40); // good for no content
187:
188: result.append("<signalled signal=\"");
189: result.append(Short.toString(m_signo));
190: result.append("\" corefile=\"");
191: result.append(Boolean.toString(m_core));
192:
193: if (m_value == null) {
194: // no content
195: result.append("\"/>");
196: } else {
197: // yes, content
198: result.append("\">");
199: result.append(quote(m_value, false));
200: result.append("</signalled>");
201: }
202:
203: return result.toString();
204: }
205:
206: /**
207: * Dump the state of the current element as XML output. This function
208: * traverses all sibling classes as necessary, and converts the data
209: * into pretty-printed XML output. The stream interface should be able
210: * to handle large output efficiently.
211: *
212: * @param stream is a stream opened and ready for writing. This can also
213: * be a string stream for efficient output.
214: * @param indent is a <code>String</code> of spaces used for pretty
215: * printing. The initial amount of spaces should be an empty string.
216: * The parameter is used internally for the recursive traversal.
217: * If a <code>null</code> value is specified, no indentation nor
218: * linefeeds will be generated.
219: * @param namespace is the XML schema namespace prefix. If neither
220: * empty nor null, each element will be prefixed with this prefix,
221: * and the root element will map the XML namespace.
222: * @exception IOException if something fishy happens to the stream.
223: */
224: public void toXML(Writer stream, String indent, String namespace)
225: throws IOException {
226: String tag = (namespace != null && namespace.length() > 0) ? namespace
227: + ":signalled"
228: : "signalled";
229:
230: stream.write('<');
231: stream.write(tag);
232: writeAttribute(stream, " signal=\"", Short.toString(m_signo));
233: writeAttribute(stream, " corefile=\"", Boolean.toString(m_core));
234:
235: if (m_value == null) {
236: // no content
237: stream.write("/>");
238: } else {
239: // yes, content
240: stream.write('>');
241: stream.write(quote(m_value, false));
242:
243: // close tag
244: stream.write("</");
245: stream.write(tag);
246: stream.write('>');
247: }
248: }
249: }
|