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 the container for a complete call to stat() or fstat().
023: * It contains information about the file or descriptor. Optionally, it
024: * may also contain some data from the file or descriptor.
025: *
026: * @author Jens-S. Vöckler
027: * @author Yong Zhao
028: * @version $Revision: 50 $
029: */
030: public class StatCall extends Invocation // implements Cloneable
031: {
032: /**
033: * optional handle for stat calls of the invocation record
034: */
035: private String m_handle;
036:
037: /**
038: * optional logical filename associated with this stat call
039: */
040: private String m_lfn;
041:
042: /**
043: * value of errno after calling any stat function, or -1 for failure.
044: */
045: private int m_errno;
046:
047: /**
048: * the object (fn,fd) that the stat call was taken on.
049: */
050: private File m_file;
051:
052: /**
053: * the stat information itself, only present for unfailed calls.
054: */
055: private StatInfo m_statinfo;
056:
057: /**
058: * Optional data gleaned from stdout or stderr.
059: */
060: private Data m_data;
061:
062: /**
063: * Default c'tor: Construct a hollow shell and allow further
064: * information to be added later.
065: */
066: public StatCall() {
067: m_handle = m_lfn = null;
068: m_file = null;
069: m_statinfo = null;
070: m_data = null;
071: }
072:
073: /**
074: * Construct a specific but empty stat call object.
075: * @param handle is the identifier to give this specific stat call.
076: */
077: public StatCall(String handle) {
078: m_handle = handle;
079: m_lfn = null;
080: m_file = null;
081: m_statinfo = null;
082: m_data = null;
083: }
084:
085: /**
086: * Accessor
087: *
088: * @see #setHandle(String)
089: */
090: public String getHandle() {
091: return this .m_handle;
092: }
093:
094: /**
095: * Accessor.
096: *
097: * @param handle
098: * @see #getHandle()
099: */
100: public void setHandle(String handle) {
101: this .m_handle = handle;
102: }
103:
104: /**
105: * Accessor
106: *
107: * @see #setLFN(String)
108: */
109: public String getLFN() {
110: return this .m_lfn;
111: }
112:
113: /**
114: * Accessor.
115: *
116: * @param lfn
117: * @see #getLFN()
118: */
119: public void setLFN(String lfn) {
120: this .m_lfn = lfn;
121: }
122:
123: /**
124: * Accessor
125: *
126: * @see #setError(int)
127: */
128: public int getError() {
129: return this .m_errno;
130: }
131:
132: /**
133: * Accessor.
134: *
135: * @param errno
136: * @see #getError()
137: */
138: public void setError(int errno) {
139: this .m_errno = errno;
140: }
141:
142: /**
143: * Accessor
144: *
145: * @see #setFile(File)
146: */
147: public File getFile() {
148: return this .m_file;
149: }
150:
151: /**
152: * Accessor.
153: *
154: * @param file
155: * @see #getFile()
156: */
157: public void setFile(File file) {
158: this .m_file = file;
159: }
160:
161: /**
162: * Accessor
163: *
164: * @see #setStatInfo(StatInfo)
165: */
166: public StatInfo getStatInfo() {
167: return this .m_statinfo;
168: }
169:
170: /**
171: * Accessor.
172: *
173: * @param statinfo
174: * @see #getStatInfo()
175: */
176: public void setStatInfo(StatInfo statinfo) {
177: this .m_statinfo = statinfo;
178: }
179:
180: /**
181: * Accessor
182: *
183: * @see #setData(String)
184: */
185: public Data getData() {
186: return this .m_data;
187: }
188:
189: /**
190: * Accessor.
191: *
192: * @param data
193: * @see #getData()
194: */
195: public void setData(String data) {
196: this .m_data = new Data(data);
197: }
198:
199: /**
200: * Conversion accessor.
201: *
202: * @param data
203: * @see #getData()
204: * @see #setData( String )
205: */
206: public void setData(Data data) {
207: this .m_data = data;
208: }
209:
210: /**
211: * Converts the active state into something meant for human consumption.
212: * The method will be called when recursively traversing the instance
213: * tree.
214: *
215: * @param stream is a stream opened and ready for writing. This can also
216: * be a string stream for efficient output.
217: */
218: public void toString(Writer stream) throws IOException {
219: throw new IOException(
220: "method not implemented, please contact vds-support@griphyn.org");
221: }
222:
223: /**
224: * Dump the state of the current element as XML output. This function
225: * traverses all sibling classes as necessary, and converts the data
226: * into pretty-printed XML output. The stream interface should be able
227: * to handle large output efficiently.
228: *
229: * @param stream is a stream opened and ready for writing. This can also
230: * be a string stream for efficient output.
231: * @param indent is a <code>String</code> of spaces used for pretty
232: * printing. The initial amount of spaces should be an empty string.
233: * The parameter is used internally for the recursive traversal.
234: * If a <code>null</code> value is specified, no indentation nor
235: * linefeeds will be generated.
236: * @param namespace is the XML schema namespace prefix. If neither
237: * empty nor null, each element will be prefixed with this prefix,
238: * and the root element will map the XML namespace.
239: * @exception IOException if something fishy happens to the stream.
240: */
241: public void toXML(Writer stream, String indent, String namespace)
242: throws IOException {
243: String newline = System.getProperty("line.separator", "\r\n");
244: String tag = (namespace != null && namespace.length() > 0) ? namespace
245: + ":statcall"
246: : "statcall";
247:
248: // open tag
249: if (indent != null && indent.length() > 0)
250: stream.write(indent);
251: stream.write('<');
252: stream.write(tag);
253: writeAttribute(stream, " error=\"", Integer.toString(m_errno));
254: if (m_handle != null)
255: writeAttribute(stream, " id=\"", m_handle);
256: if (m_lfn != null)
257: writeAttribute(stream, " lfn=\"", m_lfn);
258: stream.write('>');
259: if (indent != null)
260: stream.write(newline);
261:
262: // dump content
263: String newindent = indent == null ? null : indent + " ";
264: m_file.toXML(stream, newindent, namespace);
265: if (m_statinfo != null)
266: m_statinfo.toXML(stream, newindent, namespace);
267: if (m_data != null)
268: m_data.toXML(stream, newindent, namespace);
269:
270: // close tag
271: if (indent != null && indent.length() > 0)
272: stream.write(indent);
273: stream.write("</");
274: stream.write(tag);
275: stream.write('>');
276: if (indent != null)
277: stream.write(newline);
278: }
279: }
|