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 org.griphyn.common.util.Currently;
018: import java.util.*;
019: import java.io.Writer;
020: import java.io.IOException;
021:
022: /**
023: * This class is the container for the results of a call to either
024: * stat() or fstat(). Not all stat information is kept.
025: *
026: * @author Jens-S. Vöckler
027: * @author Yong Zhao
028: * @version $Revision: 50 $
029: */
030: public class StatInfo extends Invocation // implements Cloneable
031: {
032: /**
033: * Is the number for the file mode. This is originally an octal string.
034: */
035: private int m_mode;
036:
037: /**
038: * Denotes the size of the file. Files can grow rather large.
039: */
040: private long m_size;
041:
042: /**
043: * We store the inode number, which let's us reference a file uniquely
044: * per filesystem.
045: */
046: private long m_inode;
047:
048: /**
049: * Stores the number of hard links to the file.
050: */
051: private long m_nlink;
052:
053: /**
054: * Stores the blocksize of the file.
055: */
056: private long m_blksize;
057:
058: /**
059: * Stores the number of blocks of the file.
060: */
061: private long m_blocks;
062:
063: /**
064: * Contains the last access time timestamp.
065: */
066: private Date m_atime;
067:
068: /**
069: * Contains the creation time timestamp.
070: */
071: private Date m_ctime;
072:
073: /**
074: * Contains the last modification time timestamp;
075: */
076: private Date m_mtime;
077:
078: /**
079: * user id of the owner of the file.
080: */
081: private int m_uid;
082:
083: /**
084: * symbolical user name of the effective user.
085: */
086: private String m_user;
087:
088: /**
089: * group id of the owner of the file.
090: */
091: private int m_gid;
092:
093: /**
094: * symbolical group name of the effective user.
095: */
096: private String m_group;
097:
098: /**
099: * Default c'tor: Construct a hollow shell and allow further
100: * information to be added later.
101: */
102: public StatInfo() {
103: m_uid = m_gid = -1;
104: m_atime = m_ctime = m_mtime = new Date();
105: }
106:
107: /**
108: * Accessor
109: *
110: * @see #setMode(int)
111: */
112: public int getMode() {
113: return this .m_mode;
114: }
115:
116: /**
117: * Accessor.
118: *
119: * @param mode
120: * @see #getMode()
121: */
122: public void setMode(int mode) {
123: this .m_mode = mode;
124: }
125:
126: /**
127: * Accessor
128: *
129: * @see #setSize(long)
130: */
131: public long getSize() {
132: return this .m_size;
133: }
134:
135: /**
136: * Accessor.
137: *
138: * @param size
139: * @see #getSize()
140: */
141: public void setSize(long size) {
142: this .m_size = size;
143: }
144:
145: /**
146: * Accessor
147: *
148: * @see #setINode(long)
149: */
150: public long getINode() {
151: return this .m_inode;
152: }
153:
154: /**
155: * Accessor.
156: *
157: * @param inode
158: * @see #getINode()
159: */
160: public void setINode(long inode) {
161: this .m_inode = inode;
162: }
163:
164: /**
165: * Accessor
166: *
167: * @see #setLinkCount(long)
168: */
169: public long getLinkCount() {
170: return this .m_nlink;
171: }
172:
173: /**
174: * Accessor.
175: *
176: * @param nlink
177: * @see #getLinkCount()
178: */
179: public void setLinkCount(long nlink) {
180: this .m_nlink = nlink;
181: }
182:
183: /**
184: * Accessor
185: *
186: * @see #setBlockSize(long)
187: */
188: public long getBlockSize() {
189: return this .m_blksize;
190: }
191:
192: /**
193: * Accessor.
194: *
195: * @param blksize
196: * @see #getBlockSize()
197: */
198: public void setBlockSize(long blksize) {
199: this .m_blksize = blksize;
200: }
201:
202: /**
203: * Accessor
204: *
205: * @see #setBlocks(long)
206: */
207: public long getBlocks() {
208: return this .m_blocks;
209: }
210:
211: /**
212: * Accessor.
213: *
214: * @param blocks
215: * @see #getBlocks()
216: */
217: public void setBlocks(long blocks) {
218: this .m_blocks = blocks;
219: }
220:
221: /**
222: * Accessor
223: *
224: * @see #setAccessTime(Date)
225: */
226: public Date getAccessTime() {
227: return this .m_atime;
228: }
229:
230: /**
231: * Accessor.
232: *
233: * @param atime
234: * @see #getAccessTime()
235: */
236: public void setAccessTime(Date atime) {
237: this .m_atime = atime;
238: }
239:
240: /**
241: * Accessor
242: *
243: * @see #setCreationTime(Date)
244: */
245: public Date getCreationTime() {
246: return this .m_ctime;
247: }
248:
249: /**
250: * Accessor.
251: *
252: * @param ctime
253: * @see #getCreationTime()
254: */
255: public void setCreationTime(Date ctime) {
256: this .m_ctime = ctime;
257: }
258:
259: /**
260: * Accessor
261: *
262: * @see #setModificationTime(Date)
263: */
264: public Date getModificationTime() {
265: return this .m_mtime;
266: }
267:
268: /**
269: * Accessor.
270: *
271: * @param mtime
272: * @see #getModificationTime()
273: */
274: public void setModificationTime(Date mtime) {
275: this .m_mtime = mtime;
276: }
277:
278: /**
279: * Accessor
280: *
281: * @see #setUID(int)
282: */
283: public int getUID() {
284: return this .m_uid;
285: }
286:
287: /**
288: * Accessor.
289: *
290: * @param uid
291: * @see #getUID()
292: */
293: public void setUID(int uid) {
294: this .m_uid = uid;
295: }
296:
297: /**
298: * Accessor
299: *
300: * @see #setUser(String)
301: */
302: public String getUser() {
303: return this .m_user;
304: }
305:
306: /**
307: * Accessor.
308: *
309: * @param user
310: * @see #getUser()
311: */
312: public void setUser(String user) {
313: this .m_user = user;
314: }
315:
316: /**
317: * Accessor
318: *
319: * @see #setGID(int)
320: */
321: public int getGID() {
322: return this .m_gid;
323: }
324:
325: /**
326: * Accessor.
327: *
328: * @param gid
329: * @see #getGID()
330: */
331: public void setGID(int gid) {
332: this .m_gid = gid;
333: }
334:
335: /**
336: * Accessor
337: *
338: * @see #setGroup(String)
339: */
340: public String getGroup() {
341: return this .m_group;
342: }
343:
344: /**
345: * Accessor.
346: *
347: * @param group
348: * @see #getGroup()
349: */
350: public void setGroup(String group) {
351: this .m_group = group;
352: }
353:
354: /**
355: * Converts the active state into something meant for human consumption.
356: * The method will be called when recursively traversing the instance
357: * tree.
358: *
359: * @param stream is a stream opened and ready for writing. This can also
360: * be a string stream for efficient output.
361: */
362: public void toString(Writer stream) throws IOException {
363: throw new IOException(
364: "method not implemented, please contact vds-support@griphyn.org");
365: }
366:
367: /**
368: * Dump the state of the current element as XML output. This function
369: * traverses all sibling classes as necessary, and converts the data
370: * into pretty-printed XML output. The stream interface should be able
371: * to handle large output efficiently.
372: *
373: * @param stream is a stream opened and ready for writing. This can also
374: * be a string stream for efficient output.
375: * @param indent is a <code>String</code> of spaces used for pretty
376: * printing. The initial amount of spaces should be an empty string.
377: * The parameter is used internally for the recursive traversal.
378: * If a <code>null</code> value is specified, no indentation nor
379: * linefeeds will be generated.
380: * @param namespace is the XML schema namespace prefix. If neither
381: * empty nor null, each element will be prefixed with this prefix,
382: * and the root element will map the XML namespace.
383: * @exception IOException if something fishy happens to the stream.
384: */
385: public void toXML(Writer stream, String indent, String namespace)
386: throws IOException {
387: if (indent != null && indent.length() > 0)
388: stream.write(indent);
389: stream.write('<');
390: if (namespace != null && namespace.length() > 0) {
391: stream.write(namespace);
392: stream.write(':');
393: }
394: stream.write("statinfo");
395: writeAttribute(stream, " mode=\"0", Integer
396: .toOctalString(m_mode));
397: writeAttribute(stream, " size=\"", Long.toString(m_size));
398: writeAttribute(stream, " inode=\"", Long.toString(m_inode));
399: writeAttribute(stream, " nlink=\"", Long.toString(m_nlink));
400: writeAttribute(stream, " blksize=\"", Long.toString(m_blksize));
401: writeAttribute(stream, " blocks=\"", Long.toString(m_blocks));
402: writeAttribute(stream, " mtime=\"", Currently.iso8601(false,
403: true, false, m_mtime));
404: writeAttribute(stream, " atime=\"", Currently.iso8601(false,
405: true, false, m_atime));
406: writeAttribute(stream, " ctime=\"", Currently.iso8601(false,
407: true, false, m_ctime));
408:
409: writeAttribute(stream, " uid=\"", Integer.toString(m_uid));
410: if (this .m_user != null && this .m_user.length() > 0)
411: writeAttribute(stream, " user=\"", this .m_user);
412: writeAttribute(stream, " gid=\"", Integer.toString(m_gid));
413: if (this .m_group != null && this .m_group.length() > 0)
414: writeAttribute(stream, " group=\"", this .m_group);
415:
416: // done
417: stream.write("/>");
418: if (indent != null)
419: stream.write(System.getProperty("line.separator", "\r\n"));
420: }
421: }
|