1 package org.tigris.scarab.da; 2 3 48 49 import java.util.HashMap ; 50 import java.util.Map ; 51 52 import org.apache.commons.lang.exception.NestableError; 53 54 import org.apache.turbine.Turbine; 55 56 61 public class DAFactory 62 { 63 private static Map instances = new HashMap (); 64 65 public static AttributeAccess getAttributeAccess() 66 { 67 return (AttributeAccess) lookup("AttributeAccess"); 68 } 69 70 82 private static Object lookup(String identifier) 83 { 84 Object da = instances.get(identifier); 85 if (da == null) 86 { 87 Map map = new HashMap (instances); 92 String className = Turbine.getConfiguration() 93 .getString("dataaccess." + identifier + ".classname"); 94 try 95 { 96 da = Class.forName(className).newInstance(); 97 map.put(identifier, da); 98 instances = map; 99 } 100 catch (Exception e) 101 { 102 throw new LookupError("Unable to create instantance of class '" 103 + className + '\'', e); } 105 } 106 return da; 107 } 108 109 private static class LookupError extends NestableError 110 { 111 public LookupError(String msg, Throwable t) 112 { 113 super(msg, t); 114 } 115 } 116 } 117 | Popular Tags |