GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Adaptor.java

Go to the documentation of this file.
00001 /*
00002  * Created on May 11, 2004
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  * @author rob
00013  */
00014 class Adaptor {
00015 
00016     String cpi;
00017 
00018     /** The fully qualified class name of the api we implement. */
00019     Class cpiClass;
00020 
00021     /** The class of the api this adaptor implements. */
00022 
00023     String adaptorName;
00024 
00025     /** The fully qualified class name of this adaptor. */
00026     Class adaptorClass;
00027 
00028     /** The actual class of this adaptor, must be a subclass of cpiClass. */
00029     Preferences preferences;
00030 
00031     /** Preferences associated with this adaptor. */
00032 
00033     /**
00034      * @param cpi
00035      *            The fully qualified class name of the api we implement.
00036      * @param cpiClazz
00037      *            The class of the api this adaptor implements.
00038      * @param adaptorName
00039      *            The fully qualified class name of this adaptor.
00040      * @param adaptorClazz
00041      *            The actual class of this adaptor, must be a subclass of
00042      *            cpiClass.
00043      * @param preferences
00044      *            Preferences associated with this adaptor.
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         // all requestes keys of p should be in my prefs,
00056         // and also have the same value.
00057         //@@@ todo
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 }