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.cPlanner.classes;
018:
019: import org.griphyn.common.util.Escape;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: /**
025: * This Class hold informations about profiles associated with a tc.</p>
026: *
027: * @author Gaurang Mehta gmehta@isi.edu
028: * @author Karan Vahi vahi@isi.edu
029: *
030: * @version $Revision: 109 $
031: */
032: public class Profile extends Data {
033:
034: /**
035: * A private static handle to the escape class.
036: */
037: private static Escape mEscape = new Escape();
038:
039: public static final String CONDOR = "condor";
040:
041: public static final String GLOBUS = "globus";
042:
043: public static final String VDS = "pegasus";
044:
045: public static final String DAGMAN = "dagman";
046:
047: public static final String HINTS = "hints";
048:
049: public static final String ENV = "env";
050:
051: private String mNamespace;
052:
053: private String mKey;
054:
055: private String mValue;
056:
057: /**
058: * Returns a comma separated string containing the valid namespace types.
059: *
060: * @return comma separated list.
061: */
062: public static String validTypesToString() {
063: StringBuffer sb = new StringBuffer();
064: sb.append(CONDOR).append(',').append(GLOBUS).append(',')
065: .append(VDS).append(',').append(DAGMAN).append(',')
066: .append(HINTS).append(',').append(ENV);
067: return sb.toString();
068: }
069:
070: /**
071: *
072: * C'tpr for the class;
073: * @throws java.lang.Exception
074: */
075: public Profile() {
076: mNamespace = null;
077: mKey = null;
078: mValue = null;
079:
080: }
081:
082: /**
083: * This constructor allows to set the namespace , key and value of the PoolProfile.
084: *
085: * @param namespace Takes a String as the namespace. Has to be one of the predefined types.
086: * @param key Takes a String as the key.
087: * @param value The value for the key as String
088: * @throws Exception
089: */
090: public Profile(String namespace, String key, String value) {
091: if (namespace.equalsIgnoreCase(CONDOR)
092: || namespace.equalsIgnoreCase(GLOBUS)
093: || namespace.equalsIgnoreCase(VDS)
094: || namespace.equalsIgnoreCase(DAGMAN)
095: || namespace.equalsIgnoreCase(HINTS)
096: || namespace.equalsIgnoreCase(ENV)) {
097: mNamespace = new String(namespace);
098: mKey = new String(key);
099: mValue = new String(value);
100: } else {
101: throw new RuntimeException("Unknown namespace type "
102: + namespace + " . Valid types are "
103: + validTypesToString());
104: }
105: }
106:
107: /**
108: * This method allows to set the namespace , key and value of the Profile.
109: *
110: * @param namespace Takes a String as the namespace. Has to be one of the predefined types.
111: * @param key Takes a String as the key.
112: * @param value The value for the key as String
113: * @throws Exception
114: */
115:
116: public void setProfile(String namespace, String key, String value) {
117: if (namespace.equalsIgnoreCase(CONDOR)
118: || namespace.equalsIgnoreCase(GLOBUS)
119: || namespace.equalsIgnoreCase(VDS)
120: || namespace.equalsIgnoreCase(DAGMAN)
121: || namespace.equalsIgnoreCase(HINTS)
122: || namespace.equalsIgnoreCase(ENV)) {
123: mNamespace = new String(namespace);
124: mKey = new String(key);
125: mValue = new String(value);
126: } else {
127: throw new RuntimeException(
128: "Unknown namespace type. Please check that "
129: + "you have specified one of the valid namespace types.");
130: }
131: }
132:
133: /**
134: * Returns the Profile (namespace, value and key);
135: * @return ArrayList
136: */
137: public List getProfile() {
138: ArrayList m_profile = new ArrayList(3);
139: m_profile.add(mNamespace);
140: m_profile.add(mKey);
141: m_profile.add(mValue);
142: return m_profile;
143: }
144:
145: /**
146: * Returns the NameSpace of the Profile
147: * @return String
148: */
149: public String getProfileNamespace() {
150: return mNamespace;
151: }
152:
153: /**
154: * Returns the Key of the Profile
155: * @return String
156: */
157: public String getProfileKey() {
158: return mKey;
159: }
160:
161: /**
162: * Returns the Value for the profile
163: * @return String
164: */
165: public String getProfileValue() {
166: return mValue;
167: }
168:
169: /**
170: * Returns the textual description of the contents of <code>Profile</code>
171: * object in the multiline format.
172: *
173: * @return the textual description in multiline format.
174: */
175: public String toMultiLine() {
176: return this .toString();
177: }
178:
179: /**
180: * This method returns a string of the contents of this object.
181: * The values are always escaped.
182: *
183: * @return String
184: * @see org.griphyn.common.util.Escape
185: */
186: public String toString() {
187: String output = "profile " + mNamespace + " \"" + mKey
188: + "\" \"" + mEscape.escape(mValue) + "\"";
189: // System.out.println(output);
190: return output;
191: }
192:
193: /**
194: * This method returns an xml of the contents of this object.
195: * @return String.
196: */
197: public String toXML() {
198: String output = "<profile namespace=\"" + mNamespace
199: + "\" key=\"" + mKey + "\" >" + mValue + "</profile>";
200: // System.out.println(output);
201: return output;
202:
203: }
204:
205: /**
206: * Returns a copy of the object.
207: *
208: * @return copy of the object.
209: */
210: public Object clone() {
211: Profile newprofile = null;
212: try {
213: newprofile = new Profile(mNamespace, mKey, mValue);
214:
215: } catch (Exception e) {
216: }
217: return newprofile;
218: }
219:
220: }
|