01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15:
16: package org.griphyn.cPlanner.provenance.pasoa.producer;
17:
18: import org.griphyn.cPlanner.common.PegasusProperties;
19: import org.griphyn.common.util.DynamicLoader;
20:
21: import org.griphyn.cPlanner.provenance.pasoa.XMLProducer;
22:
23: /**
24: *
25: * The factory for instantiating an XMLProducer.
26: *
27: * @author Karan Vahi
28: * @version $Revision: 241 $
29: */
30: public class XMLProducerFactory {
31: /**
32: * The default package where all the implementations reside.
33: */
34: public static final String DEFAULT_PACKAGE_NAME = "org.griphyn.cPlanner.provenance.pasoa.producer";
35:
36: /**
37: * The default XML producer implementation to be used.
38: */
39: public static final String DEFAULT_XML_PRODUCER = "InMemory";
40:
41: /**
42: * Loads the appropriate XMLProducer on the basis of the property set in the
43: * properties.
44: *
45: *
46: * @param properties the <code>PegasusProperties</code> object containing all
47: * the properties required by Pegasus.
48: *
49: * @return the instance of the appropriate XML Producer.
50: *
51: * @throws XMLProducerFactoryException that nests any error that
52: * might occur during the instantiation
53: *
54: * @see #DEFAULT_PACKAGE_NAME
55: */
56: public static XMLProducer loadXMLProducer(
57: PegasusProperties properties)
58: throws XMLProducerFactoryException {
59:
60: //sanity check
61:
62: String className = DEFAULT_XML_PRODUCER;
63: XMLProducer producer = null;
64: try {
65:
66: //prepend the package name if required
67: className = (className.indexOf('.') == -1) ?
68: //pick up from the default package
69: DEFAULT_PACKAGE_NAME + "." + className
70: :
71: //load directly
72: className;
73:
74: //try loading the class dynamically
75: DynamicLoader dl = new DynamicLoader(className);
76: producer = (XMLProducer) dl.instantiate(new Object[0]);
77: } catch (Exception e) {
78: throw new XMLProducerFactoryException(
79: " Unable to instantiate XMLProducer ", className, e);
80: }
81: return producer;
82: }
83:
84: }
|