001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.cPlanner.poolinfo;
017:
018: import org.griphyn.common.util.DynamicLoader;
019:
020: import org.griphyn.cPlanner.common.PegasusProperties;
021:
022: /**
023: * A factory class to load the appropriate implementation of Transformation
024: * Catalog as specified by properties.
025: *
026: * @author Karan Vahi
027: * @version $Revision: 50 $
028: */
029:
030: public class SiteFactory {
031:
032: /**
033: * The default package where all the implementations reside.
034: */
035: public static final String DEFAULT_PACKAGE_NAME = "org.griphyn.cPlanner.poolinfo";
036:
037: /**
038: * Constants to specify how to load the class, as singleton or non singleton.
039: */
040: public static final int SINGLETON_LOAD = 0;
041: public static final int NON_SINGLETON_LOAD = 1;
042:
043: /**
044: * The name of the class that connects to an XML based Site Catalog.
045: */
046: public static final String XML_IMPLEMENTING_CLASS = "XML";
047:
048: /**
049: * The name of the class that connects to an multi line Text based Site Catalog.
050: */
051: public static final String TEXT_IMPLEMENTING_CLASS = "Text";
052:
053: /**
054: * Connects the interface with the site catalog implementation. The
055: * choice of backend is configured through properties. This method uses
056: * default properties from the property singleton.
057: *
058: * @param singleton indicates whether to load the singleton implementation
059: * to Site Catalog backend or not.
060: *
061: * @return handle to the Site Catalog.
062: *
063: * @throws SiteFactoryException that nests any error that
064: * might occur during the instantiation
065: *
066: * @see #DEFAULT_PACKAGE_NAME
067: */
068: // public static PoolInfoProvider loadInstance( boolean singleton )
069: // throws SiteFactoryException{
070: // return loadInstance( PegasusProperties.getsingletonInstance(), singleton );
071: // }
072:
073: /**
074: * Connects the interface with the site catalog implementation. The
075: * choice of backend is configured through properties. This class is
076: * useful for non-singleton instances that may require changing
077: * properties.
078: *
079: *
080: * @param properties is an instance of properties to use.
081: * @param singleton indicates whether to load the singleton implementation
082: * to Site Catalog backend or not. It should be set to false
083: * for portals.
084: *
085: * @return handle to the Site Catalog.
086: *
087: * @throws SiteFactoryException that nests any error that
088: * might occur during the instantiation
089: *
090: * @see #DEFAULT_PACKAGE_NAME
091: */
092: public static PoolInfoProvider loadInstance(
093: PegasusProperties properties, boolean singleton)
094: throws SiteFactoryException {
095:
096: /* get the implementor from properties */
097: String catalogImplementor = properties.getPoolMode().trim();
098:
099: /* pick up the right value on basis of case insensitive match */
100: if (catalogImplementor.equalsIgnoreCase(XML_IMPLEMENTING_CLASS)) {
101: catalogImplementor = XML_IMPLEMENTING_CLASS;
102: } else if (catalogImplementor
103: .equalsIgnoreCase(TEXT_IMPLEMENTING_CLASS)) {
104: catalogImplementor = TEXT_IMPLEMENTING_CLASS;
105: }
106:
107: /* prepend the package name if required */
108: catalogImplementor = (catalogImplementor.indexOf('.') == -1) ?
109: //pick up from the default package
110: DEFAULT_PACKAGE_NAME + "." + catalogImplementor
111: :
112: //load directly
113: catalogImplementor;
114:
115: /* determine the method name to invoke */
116: String methodName = (singleton) ? "singletonInstance"
117: : "nonSingletonInstance";
118:
119: /* construct arguments to the method */
120: Object args[] = new Object[2];
121: args[0] = properties.getPoolFile();
122: /* this should not be reqd. the Site Catalog interface should take
123: the properties object while being instantiated */
124: args[1] = org.griphyn.common.util.VDSProperties.PROPERTY_FILENAME;
125:
126: PoolInfoProvider catalog;
127:
128: /* try loading the catalog implementation dynamically */
129: try {
130: DynamicLoader dl = new DynamicLoader(catalogImplementor);
131: catalog = (PoolInfoProvider) dl.static_method(methodName,
132: args);
133: } catch (Exception e) {
134: throw new SiteFactoryException(
135: " Unable to instantiate Site Catalog ",
136: catalogImplementor, e);
137: }
138:
139: return catalog;
140:
141: }
142:
143: }
|