mev-4.0.01/source/org/tigr/microarray/mev/cluster/algorithm/impl/AlgorithmFactoryImpl.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: AlgorithmFactoryImpl.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.4 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 20:59:45 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.algorithm.impl;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.util.MissingResourceException;
2 26 Feb 07 jari 15 import java.util.ResourceBundle;
2 26 Feb 07 jari 16
2 26 Feb 07 jari 17 import org.tigr.microarray.mev.cluster.algorithm.Algorithm;
2 26 Feb 07 jari 18 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmException;
2 26 Feb 07 jari 19 import org.tigr.microarray.mev.cluster.algorithm.AlgorithmFactory;
2 26 Feb 07 jari 20
2 26 Feb 07 jari 21 public class AlgorithmFactoryImpl implements AlgorithmFactory {
2 26 Feb 07 jari 22     
2 26 Feb 07 jari 23     private static ResourceBundle bundle;
2 26 Feb 07 jari 24     private static String BUNDLE_NAME = "org.tigr.microarray.mev.cluster.algorithm.impl.factory";
2 26 Feb 07 jari 25     
2 26 Feb 07 jari 26     public Algorithm getAlgorithm(String name) throws AlgorithmException {
2 26 Feb 07 jari 27   if (name == null) {
2 26 Feb 07 jari 28       throw new AlgorithmException("Algorithm name expected.");
2 26 Feb 07 jari 29   }
2 26 Feb 07 jari 30   if (bundle == null) {
2 26 Feb 07 jari 31       throw new AlgorithmException("Can't find bundle for base name "+BUNDLE_NAME);
2 26 Feb 07 jari 32   }
2 26 Feb 07 jari 33   try {
2 26 Feb 07 jari 34       Class clazz = Class.forName(bundle.getString(name).trim());
2 26 Feb 07 jari 35       return(Algorithm)clazz.newInstance();
2 26 Feb 07 jari 36   } catch (MissingResourceException e) {
2 26 Feb 07 jari 37       throw new AlgorithmException("There is no such algorithm: "+ name);
2 26 Feb 07 jari 38   } catch (ClassCastException e) {
2 26 Feb 07 jari 39       throw new AlgorithmException("Error: org.tigr.microarray.mev.cluster.algorithm.Algorithm interface expected.");
2 26 Feb 07 jari 40   } catch (Exception e) {
2 26 Feb 07 jari 41       throw new AlgorithmException(e);
2 26 Feb 07 jari 42   }
2 26 Feb 07 jari 43     }
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     static {
2 26 Feb 07 jari 46   try {
2 26 Feb 07 jari 47       bundle = ResourceBundle.getBundle(BUNDLE_NAME);
2 26 Feb 07 jari 48   } catch (Exception e) {
2 26 Feb 07 jari 49       e.printStackTrace();
2 26 Feb 07 jari 50   }
2 26 Feb 07 jari 51     }
2 26 Feb 07 jari 52 }