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.cPlanner.partitioner.graph.Bag;
020:
021: import org.griphyn.cPlanner.common.PegasusProperties;
022: import org.griphyn.cPlanner.common.LogManager;
023:
024: import org.griphyn.cPlanner.poolinfo.PoolInfoProvider;
025:
026: import org.griphyn.common.catalog.TransformationCatalog;
027: import org.griphyn.common.catalog.ReplicaCatalog;
028:
029: import org.griphyn.common.catalog.transformation.Mapper;
030:
031: /**
032: * A bag of objects that needs to be passed to various refiners.
033: * It contains handles to the various catalogs, the properties and the
034: * planner options.
035: *
036: * @author Karan Vahi
037: * @version $Revision: 410 $
038: */
039: public class PegasusBag implements Bag {
040:
041: /**
042: * Array storing the names of the attributes that are stored with the
043: * site.
044: */
045: public static final String PEGASUS_INFO[] = { "pegasus-properties",
046: "planner-options", "replica-catalog", "site-catalog",
047: "transformation-catalog", "pegasus-logger" };
048:
049: /**
050: * The constant to be passed to the accessor functions to get or set the
051: * PegasusProperties.
052: */
053: public static final Integer PEGASUS_PROPERTIES = new Integer(0);
054:
055: /**
056: * The constant to be passed to the accessor functions to get or set the
057: * options passed to the planner.
058: */
059: public static final Integer PLANNER_OPTIONS = new Integer(1);
060:
061: /**
062: * The constant to be passed to the accessor functions to get or set the
063: * handle to the replica catalog
064: */
065: public static final Integer REPLICA_CATALOG = new Integer(2);
066:
067: /**
068: * The constant to be passed to the accessor functions to get or set the
069: * handle to the site catalog.
070: */
071: public static final Integer SITE_CATALOG = new Integer(3);
072:
073: /**
074: * The constant to be passed to the accessor functions to get or set the
075: * handle to the transformation catalog.
076: */
077: public static final Integer TRANSFORMATION_CATALOG = new Integer(4);
078:
079: /**
080: * The constant to be passed to the accessor functions to get or set the
081: * handle to the Transformation Mapper.
082: */
083: public static final Integer TRANSFORMATION_MAPPER = new Integer(5);
084:
085: /**
086: * The constant to be passed to the accessor functions to get or set the
087: * handle to the Logging manager
088: */
089: public static final Integer PEGASUS_LOGMANAGER = new Integer(6);
090:
091: /**
092: * The handle to the <code>PegasusProperties</code>.
093: */
094: private PegasusProperties mProps;
095:
096: /**
097: * The options passed to the planner.
098: */
099: private PlannerOptions mPOptions;
100:
101: /**
102: * The handle to the replica catalog.
103: */
104: private ReplicaCatalog mRCHandle;
105:
106: /**
107: * The handle to the site catalog.
108: */
109: private PoolInfoProvider mSCHandle;
110:
111: /**
112: * The handle to the transformation catalog.
113: */
114: private TransformationCatalog mTCHandle;
115:
116: /**
117: * The handle to the Transformation Mapper.
118: */
119: private Mapper mTCMapper;
120:
121: /**
122: * The handle to the LogManager.
123: */
124: private LogManager mLogger;
125:
126: /**
127: * The default constructor.
128: */
129: public PegasusBag() {
130: }
131:
132: /**
133: * Adds an object to the underlying bag corresponding to a particular key.
134: *
135: * @param key the key with which the value has to be associated.
136: * @param value the value to be associated with the key.
137: *
138: * @return boolean indicating if insertion was successful.
139: *
140: */
141: public boolean add(Object key, Object value) {
142: //to denote if object is of valid type or not.
143: boolean valid = true;
144: int k = getIntValue(key);
145:
146: switch (k) {
147:
148: case 0: //PEGASUS_PROPERTIES
149: if (value != null && value instanceof PegasusProperties)
150: mProps = (PegasusProperties) value;
151: else
152: valid = false;
153: break;
154:
155: case 1: //PLANNER_OPTIONS
156: if (value != null && value instanceof PlannerOptions)
157: mPOptions = (PlannerOptions) value;
158: else
159: valid = false;
160: break;
161:
162: case 2: //REPLICA_CATALOG:
163: if (value != null && value instanceof ReplicaCatalog)
164: mRCHandle = (ReplicaCatalog) value;
165: else
166: valid = false;
167: break;
168:
169: case 3: //SITE_CATALOG:
170: if (value != null && value instanceof PoolInfoProvider)
171: mSCHandle = (PoolInfoProvider) value;
172: else
173: valid = false;
174: break;
175:
176: case 4: //TRANSFORMATION_CATALOG:
177: if (value != null && value instanceof TransformationCatalog)
178: mTCHandle = (TransformationCatalog) value;
179: else
180: valid = false;
181: break;
182:
183: case 5: //TRANSFORMATION_MAPPER
184: if (value != null && value instanceof Mapper)
185: mTCMapper = (Mapper) value;
186: else
187: valid = false;
188: break;
189:
190: case 6: //PEGASUS_LOGGER
191: if (value != null && value instanceof LogManager)
192: mLogger = (LogManager) value;
193: else
194: valid = false;
195: break;
196:
197: default:
198: throw new RuntimeException(
199: " Wrong Pegasus Bag key. Please use one of the predefined Integer key types");
200: }
201:
202: //if object is not null , and valid == false
203: //throw exception
204: if (!valid && value != null) {
205: throw new RuntimeException("Invalid object passed for key "
206: + PEGASUS_INFO[k]);
207: }
208:
209: return valid;
210: }
211:
212: /**
213: * Returns true if the namespace contains a mapping for the specified key.
214: *
215: * @param key The key that you want to search for in the bag.
216: *
217: * @return boolean
218: */
219: public boolean containsKey(Object key) {
220:
221: int k = -1;
222: try {
223: k = ((Integer) key).intValue();
224: } catch (Exception e) {
225: }
226:
227: return (k >= this .PEGASUS_PROPERTIES.intValue() && k <= this .TRANSFORMATION_CATALOG
228: .intValue());
229: }
230:
231: /**
232: * Returns an objects corresponding to the key passed.
233: *
234: * @param key the key corresponding to which the objects need to be
235: * returned.
236: *
237: * @return the object that is found corresponding to the key or null.
238: */
239: public Object get(Object key) {
240: int k = getIntValue(key);
241:
242: switch (k) {
243: case 0:
244: return this .mProps;
245:
246: case 1:
247: return this .mPOptions;
248:
249: case 2:
250: return this .mRCHandle;
251:
252: case 3:
253: return this .mSCHandle;
254:
255: case 4:
256: return this .mTCHandle;
257:
258: case 5: //TRANSFORMATION_MAPPER
259: return this .mTCMapper;
260:
261: case 6: //PEGASUS_LOGMANAGER
262: return this .mLogger;
263:
264: default:
265: throw new RuntimeException(
266: " Wrong Pegasus Bag key. Please use one of the predefined Integer key types");
267: }
268: }
269:
270: /**
271: * A convenice method to get PlannerOptions
272: *
273: * @return the handle to options passed to the planner.
274: */
275: public PlannerOptions getPlannerOptions() {
276: return (PlannerOptions) get(PegasusBag.PLANNER_OPTIONS);
277: }
278:
279: /**
280: * A convenice method to get PegasusProperties
281: *
282: * @return the handle to the properties.
283: */
284: public PegasusProperties getPegasusProperties() {
285: return (PegasusProperties) get(PegasusBag.PEGASUS_PROPERTIES);
286: }
287:
288: /**
289: * A convenice method to get Logger/
290: *
291: * @return the handle to the logger.
292: */
293: public LogManager getLogger() {
294: return (LogManager) get(PegasusBag.PEGASUS_LOGMANAGER);
295: }
296:
297: /**
298: * A convenice method to get the handle to the site catalog.
299: *
300: * @return the handle to site catalog
301: */
302: public PoolInfoProvider getHandleToSiteCatalog() {
303: return (PoolInfoProvider) get(PegasusBag.SITE_CATALOG);
304: }
305:
306: /**
307: * A convenice method to get the handle to the transformation catalog.
308: *
309: * @return the handle to transformation catalog
310: */
311: public TransformationCatalog getHandleToTransformationCatalog() {
312: return (TransformationCatalog) get(PegasusBag.TRANSFORMATION_CATALOG);
313: }
314:
315: /**
316: * A convenience method to get the intValue for the object passed.
317: *
318: * @param key the key to be converted
319: *
320: * @return the int value if object an integer, else -1
321: */
322: private int getIntValue(Object key) {
323:
324: int k = -1;
325: try {
326: k = ((Integer) key).intValue();
327: } catch (Exception e) {
328: }
329:
330: return k;
331:
332: }
333: }
|