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 is an enumerated data class for the different types of architecture.
021: *
022: * @author Gaurang Mehta gmehta@isi.edu
023: * @version $Revision: 50 $
024: */
025:
026: import java.io.Serializable;
027: import java.util.HashMap;
028:
029: public class Arch implements Serializable {
030: private String _value_;
031: private static HashMap _table_ = new HashMap(5);
032:
033: protected Arch(String value) {
034: _value_ = value;
035: _table_.put(_value_, this );
036: }
037:
038: private static final String _INTEL32 = "INTEL32";
039: private static final String _INTEL64 = "INTEL64";
040: private static final String _SPARCV7 = "SPARCV7";
041: private static final String _SPARCV9 = "SPARCV9";
042: private static final String _AMD64 = "AMD64";
043:
044: public static final Arch INTEL32 = new Arch(_INTEL32);
045: public static final Arch INTEL64 = new Arch(_INTEL64);
046: public static final Arch SPARCV7 = new Arch(_SPARCV7);
047: public static final Arch SPARCV9 = new Arch(_SPARCV9);
048: public static final Arch AMD64 = new Arch(_AMD64);
049:
050: public static final String err = "Error: Illegal Architecture defined. Please specify one of the predefined types \n [INTEL32, INTEL64, AMD64, SPARCV7, SPARCV9]";
051:
052: /**
053: * Returns the value of the architecture as string.
054: * @return String
055: */
056: public String getValue() {
057: return _value_;
058: }
059:
060: /**
061: * Creates a new Arch Object givan a arch string.
062: * @param value String
063: * @throws IllegalStateException Throws Exception if the architecure is not defined in this class.
064: * @return Arch
065: */
066: public static Arch fromValue(String value)
067: throws IllegalStateException {
068: Arch m_enum = (Arch) _table_.get(value.toUpperCase());
069: if (m_enum == null) {
070: throw new IllegalStateException(err);
071: }
072: return m_enum;
073: }
074:
075: /**
076: * Creates a new Arch object given a arch string.
077: * @param value String
078: * @throws IllegalStateException Throws Exception if the architecure is not defined in this class.
079: * @return Arch
080: */
081: public static Arch fromString(String value)
082: throws IllegalStateException {
083: return fromValue(value);
084: }
085:
086: /**
087: * Compares if a given Arch object is equal to this.
088: * @param obj Object
089: * @return boolean
090: */
091: public boolean equals(Object obj) {
092: return (obj == this );
093: }
094:
095: public int hashCode() {
096: return toString().hashCode();
097: }
098:
099: /**
100: * Returns the string value of the architecture.
101: * @return String
102: */
103: public String toString() {
104: return _value_;
105: }
106:
107: }
|