00001 package org.gridlab.gat.resources;
00002
00003 import java.util.List;
00004 import java.util.Map;
00005 import java.util.NoSuchElementException;
00006
00007 /**
00008 * An instance of this class is a description of a software resource,
00009 * which may be required by a hardware or software component.
00010 * It does not describe the application itself,
00011 * the SoftwareDescription is used for that.
00012 * <p>
00013 * To clarify this concept, let us give various examples.
00014 * A software library is described by a
00015 * SoftwareResourceDescription; a helper application is described by a
00016 * SoftwareResourceDescription; a plugin is described a
00017 * SoftwareResourceDescription... However, a piece of hardware is not described
00018 * by a SoftwareResourceDescription.
00019 * <p>
00020 * Software is generally useless without hardware. For example, a software
00021 * driver without the appropriate Disk drive is all but useless. Similarly,
00022 * software often depends upon other software. For example, having a Photoshop
00023 * without any plugins is not of much use. Hence, in describing a software
00024 * component one needs to also describe the software and hardware that this
00025 * software component requires. This is reflected in the fact that a
00026 * SoftwareResourceDescription contains in addition to a "parent" description of
00027 * a software component a list of HardwareResourceDescriptions, each
00028 * element of which describes a hardware component upon which the parent
00029 * software component depends, and a list of
00030 * SoftwareResourceDescriptions, each element of which describes a software
00031 * component upon which the parent software component depends. Hence, the entire
00032 * structure is recursive.
00033 * <p>
00034 * To construct an instance of a SoftwareResourceDescription one requires three
00035 * quantities:
00036 * <ul>
00037 * <li>A map which contains a set of name/value pairs, detailed
00038 * later, which describe a software resource.</li>
00039 * <li>A list of SoftwareResourceDescription instances each of which
00040 * describes a software resource upon which the parent software resource
00041 * depends.</li>
00042 * <li>A list of HardwareResourceDescription instances each of which
00043 * describes a hardware resource upon which the parent software resource
00044 * depends.</li>
00045 * </ul>
00046 * <p>
00047 * The GAT-API defines a minimum set of supported name/value pairs which can be
00048 * included in the map used to construct a SoftwareResourceDescription
00049 * instance. This minimum set of name/value pairs MUST be supported by any
00050 * implementation of the GAT-API. This minimum set of supported name/values is
00051 * given in the table
00052 *
00053 * <TABLE border="2" frame="box" rules="groups" summary="Minimum set of
00054 * supported name/value pairs"> <CAPTION>Minimum set of supported name/value
00055 * pairs </CAPTION> <COLGROUP align="left"> <COLGROUP align="center"> <COLGROUP
00056 * align="left" > <THEAD valign="top">
00057 * <TR>
00058 * <TH>Name
00059 * <TH>Type
00060 * <TH>Description <TBODY>
00061 * <TR>
00062 * <TD>os.name
00063 * <TD>java.lang.String
00064 * <TD>The os name as returned from uname -s
00065 * <TR>
00066 * <TD>os.type
00067 * <TD>java.lang.String
00068 * <TD>The os type as returned from uname -p
00069 * <TR>
00070 * <TD>os.version
00071 * <TD>java.lang.String
00072 * <TD>The os version as returned from uname -v
00073 * <TR>
00074 * <TD>os.release
00075 * <TD>java.lang.String
00076 * <TD>The os release as returned from uname -r
00077 * <TR>
00078 * </TBODY></TABLE>
00079 */00080publicclass SoftwareResourceDescriptionimplementsResourceDescription {
00081
00082 /**
00083 * This member variable holds the Map which describes the "parent" software
00084 * component
00085 */00086private Map softwareResourceDescription = null;
00087
00088 /**
00089 * This member variable holds a List of SoftwareResourceDescription's
00090 * describing each of which describes a software component upon which the
00091 * "parent" software component depends.
00092 */00093private List softwareResourceDescriptions = null;
00094
00095 /**
00096 * This member variable holds a List of HardwareResourceDescription's
00097 * describing each of which describes a hardware component upon which the
00098 * "parent" software component depends.
00099 */00100private List hardwareResourceDescriptions = null;
00101
00102 /**
00103 * Constructs a SoftwareResourceDescription associated with the passed
00104 * objects:
00105 * <ul>
00106 * <li><em>SoftwareResourceDescription</em> --- A java.util.Map, which
00107 * describes the "parent" software component.</li>
00108 * <li><em>SoftwareResourceDescriptions</em> --- A java.util.List, which
00109 * is a list of SoftwareResourceDescriptions each of which describes a
00110 * software component upon which the "parent" software component depends.
00111 * </li>
00112 * <li>
00113 * <em>HardwareResourceDescriptions</li> --- A java.util.List, which is a list
00114 * of HardwareResourceDescriptions each of which describes a hardware component
00115 * upon which the "parent" software component depends.</li>
00116 * </ul>
00117 *
00118 * @param softwareResourceDescription A java.util.Map, which describes the "parent"
00119 * software component.
00120 * @param softwareResourceDescriptions A java.util.List, which is a list of
00121 * SoftwareResourceDescriptions each of which describes a software component upon
00122 * which the "parent" software component depends.
00123 * @param hardwareResourceDescriptions A java.util.List, which is a list of
00124 * HardwareResourceDescriptions each of which describes a hardware component upon
00125 * which the "parent" software component depends.
00126 */00127publicSoftwareResourceDescription(Map softwareResourceDescription,
00128 List softwareResourceDescriptions, List hardwareResourceDescriptions) {
00129 this.softwareResourceDescription = softwareResourceDescription;
00130 this.softwareResourceDescriptions = softwareResourceDescriptions;
00131 this.hardwareResourceDescriptions = hardwareResourceDescriptions;
00132 }
00133
00134 /**
00135 * Tests this SoftwareResourceDescription for equality with the passed
00136 * Object.
00137 * <p>
00138 * If the given object is not a SoftwareResourceDescription, then this
00139 * method immediately returns false.
00140 * <p>
00141 * If the passed object is a SoftwareResourceDescription, then it is deemed
00142 * equal if it has an equivalent SoftwareResourceDescription, as determined
00143 * by the Equals method on java.util.Map, and an equivalent
00144 * SoftwareResourceDescriptions, as determined by the Equals method on
00145 * java.util.List, and an equivalent HardwareResourceDescriptions, as
00146 * determined by the Equals method on java.util.List.
00147 *
00148 * @param object
00149 * The Object to test for equality
00150 * @return A boolean indicating equality
00151 */00152publicbooleanequals(Object object) {
00153 SoftwareResourceDescription sResourceDescription = null;
00154
00155 if (false == (object instanceof SoftwareResourceDescription))
00156 returnfalse;
00157
00158 sResourceDescription = (SoftwareResourceDescription) object;
00159
00160 if (false == softwareResourceDescription
00161 .equals(sResourceDescription.softwareResourceDescription))
00162 returnfalse;
00163 if (false == softwareResourceDescriptions
00164 .equals(sResourceDescription.softwareResourceDescriptions))
00165 returnfalse;
00166 if (false == hardwareResourceDescriptions
00167 .equals(sResourceDescription.hardwareResourceDescriptions))
00168 returnfalse;
00169
00170 returntrue;
00171 }
00172
00173 /**
00174 * Gets the SoftwareResourceDescription associated with this instance
00175 *
00176 * @return A java.util.Map, the SoftwareResourceDescription associated with
00177 * this instance
00178 */00179public Map getDescription() {
00180 returnsoftwareResourceDescription;
00181 }
00182
00183 /**
00184 * Sets the SoftwareResourceDescription associated with this instance
00185 *
00186 * @param The
00187 * new java.util.Map, the SoftwareResourceDescription associated
00188 * with this instance
00189 */00190publicvoidsetDescription(Map softwareResourceDescription) {
00191 this.softwareResourceDescription = softwareResourceDescription;
00192 }
00193
00194 /**
00195 * Adds the name/value pair to the java.util.Map of name/value pairs which
00196 * describe the "parent" software component.
00197 *
00198 * @param name
00199 * The Name, a java.lang.String, to add to the name/value pairs
00200 * which describe the "parent" software component.
00201 * @param value
00202 * The Value, an Object, to add to the name/value pairs which
00203 * describe the "parent" software component.
00204 */00205publicvoidaddResourceAttribute(String name, Object value) {
00206 softwareResourceDescription.put(name, value);
00207 }
00208
00209 /**
00210 * Removes the name/value pair with the passed name from the java.util.Map
00211 * of name/value pairs which describe the "parent" software component.
00212 *
00213 * @param name
00214 * The Name, a java.lang.String, to of the name/value pair to
00215 * remove from the name/value pairs which describe the "parent"
00216 * software component.
00217 */00218publicvoidremoveResourceAttribute(String name) {
00219 softwareResourceDescription.remove(name);
00220 }
00221
00222 /**
00223 * Adds the passed HardwareResourceDescription to the java.util.List of
00224 * HardwareResourceDescriptions which describe this
00225 * SoftwareResourceDescription.
00226 *
00227 * @param hardwareResourceDescription
00228 * The HardwareResourceDescription to add to the java.util.List
00229 * of HardwareResourceDescriptions which describe this
00230 * SoftwareResourceDescription.
00231 */00232publicvoidaddResourceDescription(
00233 ResourceDescription hardwareResourceDescription) {
00234 hardwareResourceDescriptions.add(hardwareResourceDescription);
00235 }
00236
00237 /**
00238 * Removes the passed HardwareResourceDescription from the java.util.List of
00239 * HardwareResourceDescriptions which describe this
00240 * SoftwareResourceDescription.
00241 *
00242 * @param hardwareResourceDescription
00243 * The HardwareResourceDescription to remove from the
00244 * java.util.List of HardwareResourceDescriptions which describe
00245 * this SoftwareResourceDescription.
00246 */00247publicvoidremoveResourceDescription(
00248 ResourceDescription hardwareResourceDescription)
00249 throws NoSuchElementException {
00250 hardwareResourceDescriptions.remove(hardwareResourceDescription);
00251 }
00252
00253 /**
00254 * Sets the java.util.List of HardwareResourceDescriptions which describe
00255 * this SoftwareResourceDescription to the passed java.util.List.
00256 *
00257 * @param hardwareResourceDescriptions
00258 * The new java.util.List of HardwareResourceDescriptions which
00259 * describe this SoftwareResourceDescription.
00260 */00261publicvoidsetHardwareResourceDescriptions(
00262 List hardwareResourceDescriptions) {
00263 this.hardwareResourceDescriptions = hardwareResourceDescriptions;
00264 }
00265
00266 /**
00267 * Gets the java.util.List of HardwareResourceDescriptions which describe
00268 * this SoftwareResourceDescription.
00269 *
00270 * @return The java.util.List of HardwareResourceDescriptions which describe
00271 * this SoftwareResourceDescription.
00272 */00273public List getHardwareResourceDescriptions() {
00274 returnhardwareResourceDescriptions;
00275 }
00276
00277 /**
00278 * Adds the passed SoftwareResourceDescription to the java.util.List of
00279 * SoftwareResourceDescriptions which describe this
00280 * SoftwareResourceDescription.
00281 *
00282 * @param softwareResourceDescription
00283 * The SoftwareResourceDescription to add to the java.util.List
00284 * of SoftwareResourceDescriptions which describe this
00285 * SoftwareResourceDescription.
00286 */00287publicvoidaddSoftwareResourceDescription(
00288 SoftwareResourceDescriptionsoftwareResourceDescription) {
00289 softwareResourceDescriptions.add(softwareResourceDescription);
00290 }
00291
00292 /**
00293 * Removes the passed SoftwareResourceDescription from the java.util.List of
00294 * SoftwareResourceDescriptions which describe this
00295 * SoftwareResourceDescription.
00296 *
00297 * @param softwareResourceDescription
00298 * The SoftwareResourceDescription to remove from the
00299 * java.util.List of SoftwareResourceDescriptions which describe
00300 * this SoftwareResourceDescription.
00301 */00302publicvoidremoveSoftwareResourceDescription(
00303 SoftwareResourceDescriptionsoftwareResourceDescription) {
00304 softwareResourceDescriptions.remove(softwareResourceDescription);
00305 }
00306
00307 /**
00308 * Sets the java.util.List of SoftwareResourceDescriptions which describe
00309 * this SoftwareResourceDescription to the passed java.util.List.
00310 *
00311 * @param softwareResourceDescriptions
00312 * The new java.util.List of SoftwareResourceDescriptions which
00313 * describe this SoftwareResourceDescription.
00314 */00315publicvoidsetSoftwareResourceDescriptions(
00316 List softwareResourceDescriptions) {
00317 this.softwareResourceDescriptions = softwareResourceDescriptions;
00318 }
00319
00320 /**
00321 * Gets the java.util.List of SoftwareResourceDescriptions which describe
00322 * this SoftwareResourceDescription.
00323 *
00324 * @return The java.util.List of SoftwareResourceDescriptions which describe
00325 * this SoftwareResourceDescription.
00326 */00327public List getSoftwareResourceDescriptions() {
00328 returnsoftwareResourceDescriptions;
00329 }
00330 }