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.catalog.transformation;
018:
019: import org.griphyn.cPlanner.common.LogManager;
020: import org.griphyn.cPlanner.common.PegasusProperties;
021: import org.griphyn.common.catalog.TransformationCatalog;
022: import org.griphyn.common.util.DynamicLoader;
023:
024: /**
025: * This class defines all the constants
026: * referring to the various interfaces
027: * to the transformation catalog, and
028: * used by the Concrete Planner.
029: *
030: * @author Gaurang Mehta
031: * @version $Revision: 50 $
032: */
033: public class TCMode {
034:
035: /**
036: * Constants for backward compatibility.
037: */
038:
039: public static final String SINGLE_READ = "single";
040:
041: public static final String MULTIPLE_READ = "multiple";
042:
043: public static final String OLDFILE_TC_CLASS = "OldFile";
044:
045: public static final String DEFAULT_TC_CLASS = "File";
046: /**
047: * Default PACKAGE PATH for the TC implementing classes
048: */
049: public static final String PACKAGE_NAME = "org.griphyn.common.catalog.transformation.";
050:
051: private static LogManager mLogger = LogManager.getInstance();
052:
053: //add your constants here.
054:
055: /**
056: * This method just checks and gives the correct classname if a user provides the classname in a different case.
057: * @param tcmode String
058: * @return String
059: */
060: private static String getImplementingClass(String tcmode) {
061:
062: if (tcmode.trim().equalsIgnoreCase(SINGLE_READ)
063: || tcmode.trim().equalsIgnoreCase(MULTIPLE_READ)) {
064: return OLDFILE_TC_CLASS;
065: } else {
066: //no match to any predefined constant
067: //assume that the value of readMode is the
068: //name of the implementing class
069: return tcmode;
070: }
071: }
072:
073: /**
074: * The overloaded method which is to be used internally in Pegasus.
075: *
076: * @return TCMechanism
077: */
078: public static TransformationCatalog loadInstance() {
079: PegasusProperties mProps = PegasusProperties.getInstance();
080: TransformationCatalog tc = null;
081: String tcClass = getImplementingClass(mProps.getTCMode());
082:
083: //if (tcClass.equals(FILE_TC_CLASS)) {
084: // String[] args = {mProps.getTCPath()};
085: // return loadInstance(tcClass, args);
086: // } else {
087: String[] args = new String[0];
088: tc = loadInstance(tcClass, args);
089: if (tc == null) {
090: mLogger.log("Unable to load TC",
091: LogManager.FATAL_MESSAGE_LEVEL);
092: System.exit(1);
093: }
094: return tc;
095: // }
096: }
097:
098: /**
099: * Loads the appropriate TC implementing Class with the given arguments.
100: * @param tcClass String
101: * @param args String[]
102: * @return TCMechanism
103: */
104: public static TransformationCatalog loadInstance(String tcClass,
105: Object[] args) {
106:
107: TransformationCatalog tc = null;
108: String methodName = "getInstance";
109: //get the complete name including
110: //the package if the package name not
111: //specified
112: if (tcClass.indexOf(".") == -1) {
113: tcClass = PACKAGE_NAME + tcClass;
114: }
115:
116: DynamicLoader d = new DynamicLoader(tcClass);
117:
118: try {
119: tc = (TransformationCatalog) d.static_method(methodName,
120: args);
121:
122: //This identifies the signature for
123: //the method
124:
125: } catch (Exception e) {
126: mLogger.log(d.convertException(e),
127: LogManager.FATAL_MESSAGE_LEVEL);
128: System.exit(1);
129: }
130: return tc;
131:
132: }
133:
134: }
|