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 transformation.
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 TCType implements Serializable {
030: private String _value_;
031: private static HashMap _table_ = new HashMap(6);
032:
033: protected TCType(String value) {
034: _value_ = value;
035: _table_.put(_value_, this );
036: }
037:
038: public static final String _STATIC_BINARY = "STATIC_BINARY";
039: public static final String _DYNAMIC_BINARY = "DYNAMIC_BINARY";
040: public static final String _INSTALLED = "INSTALLED";
041: public static final String _SOURCE = "SOURCE";
042: public static final String _PACMAN_PACKAGE = "PACMAN_PACKAGE";
043: public static final String _SCRIPT = "SCRIPT";
044:
045: public static final TCType STATIC_BINARY = new TCType(
046: _STATIC_BINARY);
047: public static final TCType DYNAMIC_BINARY = new TCType(
048: _DYNAMIC_BINARY);
049: public static final TCType INSTALLED = new TCType(_INSTALLED);
050: public static final TCType SOURCE = new TCType(_SOURCE);
051: public static final TCType PACMAN_PACKAGE = new TCType(
052: _PACMAN_PACKAGE);
053: public static final TCType SCRIPT = new TCType(_SCRIPT);
054:
055: public static final String err = "Error : Illegal TCType defined. Please specify one of the predefined types \n [INSTALLED, SOURCE, STATIC_BINARY, DYNAMIC_BINARY, PACMAN_PACKAGE, SCRIPT]";
056:
057: /**
058: * Returns the string value of the type of transformation.
059: * @return String
060: */
061: public String getValue() {
062: return _value_;
063: }
064:
065: /**
066: * Creates an objct of TCType given a string.
067: * @param value String The type value as string
068: * @throws IllegalStateException Throws Exception if the type is not defined in this class
069: * @return TCType
070: */
071: public static TCType fromValue(String value)
072: throws IllegalStateException {
073: TCType m_enum = (TCType) _table_.get(value.toUpperCase());
074: if (m_enum == null) {
075: throw new IllegalStateException(err);
076: }
077: return m_enum;
078: }
079:
080: /**
081: * Creates an object of TCType given a string.
082: * @param value String The type value as string.
083: * @throws IllegalStateException Throws Exception if the type is not defined in this class.
084: * @return TCType
085: */
086: public static TCType fromString(String value)
087: throws IllegalStateException {
088: return fromValue(value);
089: }
090:
091: /**
092: * Compares if a given TCType object equals this TCType object.
093: * @param obj Object
094: * @return boolean
095: */
096: public boolean equals(Object obj) {
097: return (obj == this );
098: }
099:
100: public int hashCode() {
101: return toString().hashCode();
102: }
103:
104: /**
105: * Returns the string value of the type of transformation.
106: * @return String
107: */
108: public String toString() {
109: return _value_;
110: }
111:
112: }
|