001: /**
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found at $PEGASUS_HOME/GTPL or
004: * http://www.globus.org/toolkit/download/license.html.
005: * This notice must appear in redistributions of this file
006: * with or without modification.
007: *
008: * Redistributions of this Software, with or without modification, must reproduce
009: * the GTPL in:
010: * (1) the Software, or
011: * (2) the Documentation or
012: * some other similar material which is provided with the Software (if any).
013: *
014: * Copyright 1999-2004
015: * University of Chicago and The University of Southern California.
016: * All rights reserved.
017: */package org.griphyn.common.classes;
018:
019: /**
020: * This class keeps the system information associated with a
021: * resource or transformation.
022: *
023: * @author Gaurang Mehta gmehta@isi.edu
024: * @version $Revision: 316 $
025: */
026:
027: public class SysInfo {
028:
029: /**
030: * Architecture of the system.
031: */
032: private Arch arch;
033:
034: /**
035: * Os of the system.
036: */
037: private Os os;
038:
039: /**
040: * Os version of the system.
041: */
042: private String osversion;
043:
044: /**
045: * Glibc version of the system
046: */
047: private String glibc;
048:
049: /**
050: * The secondary convenience constructor.
051: * @param arch Arch The architecture of the system.
052: * @param os Os The os of the system.
053: * @param osversion String The os version of the system.
054: * @param glibc String The glibc version of the system.
055: * @see Arch
056: * @see Os
057: */
058: public SysInfo(Arch arch, Os os, String osversion, String glibc) {
059: this .arch = (arch == null) ? Arch.INTEL32 : arch;
060: this .os = (os == null) ? Os.LINUX : os;
061:
062: this .osversion = (osversion == null || osversion.equals("")) ? null
063: : osversion;
064:
065: this .glibc = (glibc == null || glibc.equals("")) ? null : glibc;
066: }
067:
068: /**
069: * Another convenience constructor that uses all entries as strings.
070: * @param arch String
071: * @param os String
072: * @param glibc String
073: */
074: public SysInfo(String arch, String os, String glibc) {
075: this (arch, os, null, glibc);
076: }
077:
078: /**
079: * Another convenience constructor that uses all entries as strings.
080: * @param arch String
081: * @param os String
082: * @param osversion String
083: * @param glibc String
084: */
085: public SysInfo(String arch, String os, String osversion,
086: String glibc) {
087: this .arch = (arch == null) ? Arch.INTEL32 : Arch
088: .fromString(arch);
089: this .os = (os == null) ? Os.LINUX : Os.fromString(os);
090: this .osversion = (osversion == null || osversion.equals("")) ? null
091: : osversion;
092:
093: this .glibc = (glibc == null || glibc.equals("")) ? null : glibc;
094: }
095:
096: public SysInfo(String system) {
097: if (system != null) {
098: String s1[] = system.split("::", 2);
099: if (s1.length == 2) {
100: arch = Arch.fromString(s1[0]);
101: String s2[] = s1[1].split(":", 3);
102: os = Os.fromString(s2[0]);
103: for (int i = 1; i < s2.length; i++) {
104: if (i == 1) {
105: osversion = s2[i];
106: }
107: if (i == 2) {
108: glibc = s2[i];
109: }
110: }
111: } else {
112: throw new IllegalStateException(
113: "Error : Please check your system info string");
114: }
115: } else {
116: this .arch = Arch.INTEL32;
117: this .os = Os.LINUX;
118: }
119: }
120:
121: /**
122: * The default constructor.
123: * Sets the sysinfo to INTEL32::LINUX
124: */
125: public SysInfo() {
126: this .arch = Arch.INTEL32;
127: this .os = Os.LINUX;
128: }
129:
130: /**
131: * Sets the architecture of the system.
132: * @param arch Arch
133: * @see Arch
134: */
135: public void setArch(Arch arch) {
136: this .arch = (arch == null) ? Arch.INTEL32 : arch;
137: }
138:
139: /**
140: * Sets the Os of the sytem.
141: * @param os Os
142: * @see Os
143: */
144: public void setOs(Os os) {
145: this .os = (os == null) ? Os.LINUX : os;
146: }
147:
148: /**
149: * Sets the Os version of the system.
150: * @param osversion String
151: */
152: public void setOsversion(String osversion) {
153: this .osversion = osversion;
154: }
155:
156: /**
157: * Sets the glibc version of the system
158: * @param glibc String
159: */
160: public void setGlibc(String glibc) {
161: this .glibc = glibc;
162: }
163:
164: /**
165: * Returns the architecture of the sytem.
166: * @return Arch
167: * @see Arch
168: */
169: public Arch getArch() {
170: return arch;
171: }
172:
173: /**
174: * Returns the os type of the system.
175: * @return Os
176: * @see Os
177: */
178: public Os getOs() {
179: return os;
180: }
181:
182: /**
183: * Returns the os version of the system.
184: * @return String
185: */
186: public String getOsversion() {
187: return osversion;
188: }
189:
190: /**
191: * Retuns the glibc version of the system.
192: * @return String
193: */
194: public String getGlibc() {
195: return glibc;
196: }
197:
198: /**
199: * Return a copy of this Sysinfo object
200: * @return Object
201: */
202: public Object clone() {
203: return new SysInfo(arch, os, osversion, glibc);
204: }
205:
206: /**
207: * Check if the system information matches.
208: * @param obj to be compared.
209: * @return boolean
210: */
211: public boolean equals(Object obj) {
212: boolean result = false;
213: if (obj instanceof SysInfo) {
214: SysInfo sysinfo = (SysInfo) obj;
215: result = (arch.equals(sysinfo.getArch()) && os
216: .equals(sysinfo.getOs()));
217: }
218: return result;
219: }
220:
221: /**
222: * Returns the output of the data class as string.
223: * @return String
224: */
225: public String toString() {
226: StringBuffer s = new StringBuffer();
227: s.append(arch + "::" + os);
228: if (osversion != null) {
229: s.append(":" + osversion);
230: }
231: if (glibc != null) {
232: s.append(":" + glibc);
233: }
234: return s.toString();
235: }
236: }
|