1 package org.apache.torque.engine.database.model; 2 3 18 19 import java.util.Hashtable ; 20 import java.util.List ; 21 22 import org.apache.torque.engine.EngineException; 23 24 30 public class NameFactory 31 { 32 35 public static final String JAVA_GENERATOR = 36 JavaNameGenerator.class.getName(); 37 38 41 public static final String CONSTRAINT_GENERATOR = 42 ConstraintNameGenerator.class.getName(); 43 44 47 private static NameFactory instance = new NameFactory(); 48 49 53 private Hashtable algorithms; 54 55 58 protected NameFactory() 59 { 60 algorithms = new Hashtable (5); 61 } 62 63 70 protected NameGenerator getAlgorithm(String name) 71 throws EngineException 72 { 73 synchronized (algorithms) 74 { 75 NameGenerator algorithm = (NameGenerator) algorithms.get(name); 76 if (algorithm == null) 77 { 78 try 79 { 80 algorithm = 81 (NameGenerator) Class.forName(name).newInstance(); 82 } 83 catch (InstantiationException e) 84 { 85 throw new EngineException("Unable to instantiate class " 86 + name + ": Make sure it's in your run-time classpath", e); 87 } 88 catch (Exception e) 89 { 90 throw new EngineException(e); 91 } 92 algorithms.put(name, algorithm); 93 } 94 return algorithm; 95 } 96 } 97 98 109 public static String generateName(String algorithmName, List inputs) 110 throws EngineException 111 { 112 NameGenerator algorithm = instance.getAlgorithm(algorithmName); 113 return algorithm.generateName(inputs); 114 } 115 } 116 | Popular Tags |