00001
00002
00003
00004 package org.gridlab.gat.engine;
00005
00006 import java.lang.reflect.Constructor;
00007 import java.lang.reflect.InvocationTargetException;
00008
00009 import org.gridlab.gat.Preferences;
00010
00011
00012
00013
00014 class Adaptor {
00015
00016 String cpi;
00017
00018
00019 Class cpiClass;
00020
00021
00022
00023 String adaptorName;
00024
00025
00026 Class adaptorClass;
00027
00028
00029 Preferences preferences;
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 public Adaptor(Class cpiClass, Class adaptorClass, Preferences preferences) {
00047 this.cpi = cpiClass.getName();
00048 this.cpiClass = cpiClass;
00049 this.adaptorName = adaptorClass.getName();
00050 this.adaptorClass = adaptorClass;
00051 this.preferences = preferences;
00052 }
00053
00054 boolean satisfies(Preferences p) {
00055
00056
00057
00058
00059 return true;
00060 }
00061
00062 Object newInstance(Class[] parameterTypes, Object[] parameters) {
00063 try {
00064 Constructor ctor = adaptorClass.getConstructor(parameterTypes);
00065 return ctor.newInstance(parameters);
00066 } catch (InvocationTargetException e) {
00067 if (GATEngine.DEBUG) {
00068 System.err.println("Adaptor constructor threw exception: "
00069 + e.getTargetException());
00070 e.printStackTrace();
00071 }
00072 return null;
00073 } catch (Exception e) {
00074 if (GATEngine.DEBUG) {
00075 System.err
00076 .println("Could not construct adaptor object instance: "
00077 + e + ": " + e.getMessage());
00078 e.printStackTrace();
00079 }
00080 return null;
00081 }
00082 }
00083
00084 String getName() {
00085 return adaptorName;
00086 }
00087 }