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 Job
029: * @see JobStatus
030: */
031: public class JobStatusFailure extends JobStatus implements HasText {
032: /**
033: * This is the errno value with the reason that the invocation
034: * of the application failed.
035: */
036: private int m_errno;
037:
038: /**
039: * This is the data contained between the tags. A <code>null</code>
040: * value is not valid.
041: */
042: private String m_value;
043:
044: /**
045: * Default c'tor: Construct a hollow shell and allow further
046: * information to be added later.
047: */
048: public JobStatusFailure() {
049: m_errno = 0;
050: m_value = null;
051: }
052:
053: /**
054: * Constructs an error number without reason text.
055: * @param errno is the error number
056: */
057: public JobStatusFailure(int errno) {
058: m_errno = errno;
059: m_value = null;
060: }
061:
062: /**
063: * Constructs a piece of data.
064: * @param errno is the error number .
065: * @param value is the textual error reason.
066: */
067: public JobStatusFailure(int errno, String value) {
068: m_errno = errno;
069: m_value = value;
070: }
071:
072: /**
073: * Appends a piece of text to the existing text.
074: * @param fragment is a piece of text to append to existing text.
075: * Appending <code>null</code> is a noop.
076: */
077: public void appendValue(String fragment) {
078: if (fragment != null) {
079: if (this .m_value == null)
080: this .m_value = new String(fragment);
081: else
082: this .m_value += fragment;
083: }
084: }
085:
086: /**
087: * Accessor
088: *
089: * @see #setError(int)
090: */
091: public int getError() {
092: return this .m_errno;
093: }
094:
095: /**
096: * Accessor.
097: *
098: * @param errno
099: * @see #getError()
100: */
101: public void setError(int errno) {
102: this .m_errno = errno;
103: }
104:
105: /**
106: * Accessor
107: *
108: * @see #setValue(String)
109: */
110: public String getValue() {
111: return this .m_value;
112: }
113:
114: /**
115: * Accessor.
116: *
117: * @param value is the new value to set.
118: * @see #getValue()
119: */
120: public void setValue(String value) {
121: this .m_value = value;
122: }
123:
124: /**
125: * Converts the active state into something meant for human consumption.
126: * The method will be called when recursively traversing the instance
127: * tree.
128: *
129: * @param stream is a stream opened and ready for writing. This can also
130: * be a string stream for efficient output.
131: */
132: public void toString(Writer stream) throws IOException {
133: throw new IOException(
134: "method not implemented, please contact vds-support@griphyn.org");
135: }
136:
137: /**
138: * Dumps the state of the current element as XML output. This function
139: * can return the necessary data more efficiently, thus overwriting
140: * the inherited method.
141: *
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: *
146: * @return a String which contains the state of the current class and
147: * its siblings using XML. Note that these strings might become large.
148: */
149: public String toXML(String indent) {
150: StringBuffer result = new StringBuffer(32); // good for no content
151:
152: result.append("<failure error=\"");
153: result.append(Integer.toString(m_errno));
154:
155: if (m_value == null) {
156: // no content
157: result.append("\"/>");
158: } else {
159: // yes, content
160: result.append("\">");
161: result.append(quote(m_value, false));
162: result.append("</failure>");
163: }
164:
165: return result.toString();
166: }
167:
168: /**
169: * Dump the state of the current element as XML output. This function
170: * traverses all sibling classes as necessary, and converts the data
171: * into pretty-printed XML output. The stream interface should be able
172: * to handle large output efficiently.
173: *
174: * @param stream is a stream opened and ready for writing. This can also
175: * be a string stream for efficient output.
176: * @param indent is a <code>String</code> of spaces used for pretty
177: * printing. The initial amount of spaces should be an empty string.
178: * The parameter is used internally for the recursive traversal.
179: * If a <code>null</code> value is specified, no indentation nor
180: * linefeeds will be generated.
181: * @param namespace is the XML schema namespace prefix. If neither
182: * empty nor null, each element will be prefixed with this prefix,
183: * and the root element will map the XML namespace.
184: * @exception IOException if something fishy happens to the stream.
185: */
186: public void toXML(Writer stream, String indent, String namespace)
187: throws IOException {
188: String tag = (namespace != null && namespace.length() > 0) ? namespace
189: + ":failure"
190: : "failure";
191:
192: // open tag
193: stream.write('<');
194: stream.write(tag);
195: writeAttribute(stream, " error=\"", Integer.toString(m_errno));
196:
197: if (m_value == null) {
198: // no content
199: stream.write("/>");
200: } else {
201: // yes, content
202: stream.write('>');
203: stream.write(quote(m_value, false));
204:
205: // close tag
206: stream.write("</");
207: stream.write(tag);
208: stream.write('>');
209: }
210: }
211: }
|