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:
016: package org.griphyn.cPlanner.classes;
017:
018: /**
019: * This is a data class that is used to store information about the scratch
020: * work directory or the execution mount point on the remote pool.
021: * <p>
022: * The various attributes that can be associated with the work directory
023: * displayed in the following table.
024: *
025: * <p>
026: * <table border="1">
027: * <tr align="left"><th>Attribute Name</th><th>Attribute Description</th></tr>
028: * <tr align="left"><th>path</th>
029: * <td>the absolute path on the remote site to the work directory.</td>
030: * </tr>
031: * <tr align="left"><th>total size</th>
032: * <td>the total scratch space available under the work directory.</td>
033: * </tr>
034: * <tr align="left"><th>free size</th>
035: * <td>the free space available under the work directory.</td>
036: * </tr>
037: * </table>
038:
039: *
040: * @author Gaurang Mehta gmehta@isi.edu
041: * @author Karan Vahi vahi@isi.edu
042: *
043: * @version $Revision: 109 $
044: */
045: public class WorkDir {
046:
047: /**
048: * Array storing the names of the attributes that are stored with the
049: * work directory.
050: */
051: public static final String[] WORKDIRINFO = { "path", "total-size",
052: "free-size" };
053:
054: /**
055: * The constant to be passed to the accessor functions to get or set the
056: * path to the work directory.
057: */
058: public static final int WORKDIR = 0;
059:
060: /**
061: * The constant to be passed to the accessor functions to get or set the
062: * total space available.
063: */
064: public static final int TOTAL_SIZE = 1;
065:
066: /**
067: * The constant to be passed to the accessor functions to get or set the
068: * free space available.
069: */
070: public static final int FREE_SIZE = 2;
071:
072: /**
073: * The path to the work directory.
074: */
075: private String mWorkDir;
076:
077: /**
078: * The total space available at the file system under this directory.
079: */
080: private String mTotalSize;
081:
082: /**
083: * The free space available at the file system under this directory.
084: */
085: private String mFreeSize;
086:
087: /**
088: * The default constructor. Sets all the variables to null.
089: */
090: public WorkDir() {
091: mWorkDir = null;
092: mTotalSize = null;
093: mFreeSize = null;
094: }
095:
096: /**
097: * Returns the attribute value of a particular attribute of the work
098: * directory.
099: *
100: * @param key the key/attribute name.
101: *
102: * @return the attribute value
103: * @throws RuntimeException if illegal key defined.
104: */
105: public String getInfo(int key) {
106: switch (key) {
107: case 0:
108: return mWorkDir;
109:
110: case 1:
111: return mTotalSize;
112:
113: case 2:
114: return mFreeSize;
115:
116: default:
117: throw new RuntimeException("Illegal workdir key type="
118: + key + ". Use on of the predefined types");
119: }
120: }
121:
122: /**
123: * Sets an attribute associated with the work directory.
124: *
125: * @param key the attribute key, which is one of the predefined keys.
126: * @param value value of the attribute.
127: *
128: * @throws Exception if illegal key defined.
129: */
130: public void setInfo(int key, String value) throws RuntimeException {
131: switch (key) {
132: case 0:
133: mWorkDir = value == null ? null : new String(value);
134: break;
135:
136: case 1:
137: mTotalSize = value == null ? null : new String(value);
138: break;
139:
140: case 2:
141: mFreeSize = value == null ? null : new String(value);
142: break;
143:
144: default:
145: throw new RuntimeException("Illegal workdir key type="
146: + key + ". Use on of the predefined types");
147: }
148: }
149:
150: /**
151: * Returns the textual description of the contents of <code>WorkDir</code>
152: * object in the multiline format.
153: *
154: * @return the textual description in multiline format.
155: */
156: public String toMultiLine() {
157: String output = "workdir \"" + mWorkDir + "\"";
158: return output;
159: }
160:
161: /**
162: * Returns the textual description of the contents of <code>WorkDir</code>
163: * object.
164: *
165: * @return the textual description.
166: */
167: public String toString() {
168: String output = "workdir \"" + mWorkDir + "\"";
169: if (mWorkDir != null) {
170: output += " " + WORKDIRINFO[0] + "=" + mWorkDir;
171: }
172: if (mTotalSize != null) {
173: output += " " + WORKDIRINFO[1] + "=" + mTotalSize;
174: }
175: if (mFreeSize != null) {
176: output += " " + WORKDIRINFO[2] + "=" + mFreeSize;
177: }
178: output += " )";
179: // System.out.println(output);
180: return output;
181: }
182:
183: /**
184: * Returns the XML description of the contents of <code>WorkDir</code>
185: * object.
186: *
187: * @return the xml description.
188: */
189: public String toXML() {
190: String output = "";
191: if (mWorkDir != null) {
192: output += "<workdirectory";
193:
194: if (mTotalSize != null) {
195: output += " " + WORKDIRINFO[1] + "=\"" + mTotalSize
196: + "\"";
197: }
198: if (mFreeSize != null) {
199: output += " " + WORKDIRINFO[2] + "=\"" + mFreeSize
200: + "\"";
201: }
202: output += " >";
203: output += mWorkDir;
204: }
205: output += "</workdirectory>";
206:
207: return output;
208: }
209:
210: }
|