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 classes.
024: *
025: * @author Jens-S. Vöckler
026: * @author Yong Zhao
027: * @version $Revision: 50 $
028: * @see StatCall
029: */
030: public class Architecture extends Invocation implements HasText {
031: /**
032: * This is the data contained between the tags. A <code>null</code>
033: * value is not valid.
034: */
035: private StringBuffer m_value;
036:
037: /**
038: * Describes the architecture runtime mode. For instance, on a SPARC
039: * can run in ILP32 or LP64 mode, an IA64 may have a
040: * backward-compatible 32bit mode (IA32), etc.
041: */
042: private String m_archmode;
043:
044: /**
045: * Describes the operating system name. For instance: linux, sunos, ...
046: */
047: private String m_sysname;
048:
049: /**
050: * Describes the machine's network node hostname. Note that
051: * incorrect host setup may include the domainname into this.
052: */
053: private String m_nodename;
054:
055: /**
056: * Contains the operating system's version string.
057: */
058: private String m_release;
059:
060: /**
061: * Contains the machine's hardware description. For instance: i686,
062: * sun4u, ...
063: */
064: private String m_machine;
065:
066: /**
067: * Contains the optional domain name on the network. Note that incorrect
068: * setup of the host name may contain the domain portion there.
069: */
070: private String m_domainname;
071:
072: /**
073: * Default c'tor: Construct a hollow shell and allow further
074: * information to be added later.
075: */
076: public Architecture() {
077: m_value = null;
078: m_sysname = m_archmode = m_nodename = m_release = m_machine = m_domainname = null;
079: }
080:
081: /**
082: * Appends a piece of text to the existing text.
083: * @param fragment is a piece of text to append to existing text.
084: * Appending <code>null</code> is a noop.
085: */
086: public void appendValue(String fragment) {
087: if (fragment != null) {
088: if (this .m_value == null)
089: this .m_value = new StringBuffer(fragment);
090: else
091: this .m_value.append(fragment);
092: }
093: }
094:
095: /**
096: * Accessor
097: *
098: * @see #setArchMode(String)
099: */
100: public String getArchMode() {
101: return this .m_archmode;
102: }
103:
104: /**
105: * Accessor.
106: *
107: * @param archmode
108: * @see #getArchMode()
109: */
110: public void setArchMode(String archmode) {
111: this .m_archmode = archmode;
112: }
113:
114: /**
115: * Accessor
116: *
117: * @see #setValue(String)
118: */
119: public String getValue() {
120: return (m_value == null ? null : m_value.toString());
121: }
122:
123: /**
124: * Accessor.
125: *
126: * @param value is the new value to set.
127: * @see #getValue()
128: */
129: public void setValue(String value) {
130: this .m_value = (value == null ? null : new StringBuffer(value));
131: }
132:
133: /**
134: * Accessor
135: *
136: * @see #setSystemName(String)
137: */
138: public String getSystemName() {
139: return this .m_sysname;
140: }
141:
142: /**
143: * Accessor.
144: *
145: * @param sysname
146: * @see #getSystemName()
147: */
148: public void setSystemName(String sysname) {
149: this .m_sysname = sysname;
150: }
151:
152: /**
153: * Accessor
154: *
155: * @see #setNodeName(String)
156: */
157: public String getNodeName() {
158: return this .m_nodename;
159: }
160:
161: /**
162: * Accessor.
163: *
164: * @param nodename
165: * @see #getNodeName()
166: */
167: public void setNodeName(String nodename) {
168: this .m_nodename = nodename;
169: this .normalize();
170: }
171:
172: /**
173: * Accessor
174: *
175: * @see #setRelease(String)
176: */
177: public String getRelease() {
178: return this .m_release;
179: }
180:
181: /**
182: * Accessor.
183: *
184: * @param release
185: * @see #getRelease()
186: */
187: public void setRelease(String release) {
188: this .m_release = release;
189: }
190:
191: /**
192: * Accessor
193: *
194: * @see #setDomainName(String)
195: */
196: public String getDomainName() {
197: return this .m_domainname;
198: }
199:
200: /**
201: * Accessor.
202: *
203: * @param domainname
204: * @see #getDomainName()
205: */
206: public void setDomainName(String domainname) {
207: this .m_domainname = domainname;
208: }
209:
210: /**
211: * Accessor
212: *
213: * @see #setMachine(String)
214: */
215: public String getMachine() {
216: return this .m_machine;
217: }
218:
219: /**
220: * Accessor.
221: *
222: * @param machine
223: * @see #getMachine()
224: */
225: public void setMachine(String machine) {
226: this .m_machine = machine;
227: }
228:
229: /**
230: * Normalizes a misconfigured nodename that contains a domainname.
231: */
232: public void normalize() {
233: int pos = this .m_nodename.indexOf('.');
234: if (pos != -1 && this .m_domainname == null) {
235: // normalize domain portion
236: this .m_domainname = this .m_nodename.substring(pos + 1);
237: this .m_nodename = this .m_nodename.substring(0, pos);
238: }
239: }
240:
241: /**
242: * Converts the active state into something meant for human consumption.
243: * The method will be called when recursively traversing the instance
244: * tree.
245: *
246: * @param stream is a stream opened and ready for writing. This can also
247: * be a string stream for efficient output.
248: */
249: public void toString(Writer stream) throws IOException {
250: throw new IOException(
251: "method not implemented, please contact vds-support@griphyn.org");
252: }
253:
254: /**
255: * Quotes an input string for XML attributes while converting nulls.
256: * @param s is the attribute string, may be null
257: * @return the XML-quoted string, or an empty-but-not-null string.
258: */
259: private String myquote(String s) {
260: if (s == null)
261: return new String();
262: else
263: return quote(s, true);
264: }
265:
266: /**
267: * Dump the state of the current element as XML output. This function
268: * traverses all sibling classes as necessary, and converts the data
269: * into pretty-printed XML output. The stream interface should be able
270: * to handle large output efficiently.
271: *
272: * @param stream is a stream opened and ready for writing. This can also
273: * be a string stream for efficient output.
274: * @param indent is a <code>String</code> of spaces used for pretty
275: * printing. The initial amount of spaces should be an empty string.
276: * The parameter is used internally for the recursive traversal.
277: * If a <code>null</code> value is specified, no indentation nor
278: * linefeeds will be generated.
279: * @param namespace is the XML schema namespace prefix. If neither
280: * empty nor null, each element will be prefixed with this prefix,
281: * and the root element will map the XML namespace.
282: * @exception IOException if something fishy happens to the stream.
283: */
284: public void toXML(Writer stream, String indent, String namespace)
285: throws IOException {
286: String tag = (namespace != null && namespace.length() > 0) ? namespace
287: + ":uname"
288: : "uname";
289:
290: // open tag
291: if (indent != null && indent.length() > 0)
292: stream.write(indent);
293: stream.write('<');
294: stream.write(tag);
295: stream.write(" sysname=\"");
296: stream.write(myquote(m_sysname));
297: stream.write('\"');
298: if (m_archmode != null)
299: writeAttribute(stream, " archmode=\"", m_archmode);
300: stream.write(" nodename=\"");
301: stream.write(myquote(m_nodename));
302: stream.write("\" release=\"");
303: stream.write(myquote(m_release));
304: stream.write("\" machine=\"");
305: stream.write(myquote(m_machine));
306: stream.write('\"');
307: if (this .m_domainname != null)
308: writeAttribute(stream, " domainname=\"", m_domainname);
309:
310: if (this .m_value != null) {
311: stream.write('>');
312: stream.write(quote(getValue(), false));
313: stream.write("</");
314: stream.write(tag);
315: stream.write('>');
316: } else {
317: // no content
318: stream.write("/>");
319: }
320:
321: if (indent != null)
322: stream.write(System.getProperty("line.separator", "\r\n"));
323: }
324: }
|