View Javadoc
1 /* 2 * Created on 2003-6-11 15:13:20 by joel guo 3 * 4 * vTradEx Information Technology Inc. 5 */ 6 package com.cyclops.dbdigger; 7 import org.apache.avalon.framework.activity.Initializable; 8 import org.apache.avalon.framework.activity.Startable; 9 import org.apache.avalon.framework.configuration.Configurable; 10 import org.apache.avalon.framework.configuration.Configuration; 11 import org.apache.avalon.framework.service.ServiceException; 12 import org.apache.avalon.framework.service.ServiceManager; 13 import org.apache.avalon.framework.service.Serviceable; 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 17 import com.cyclops.dbdigger.schema.Schema; 18 import com.cyclops.dbdigger.sqlcastor.SQLCastor; 19 import com.cyclops.dbdigger.util.ArrayMap; 20 /*** When this class is properly loaded in Avalon contain, DBDigger is ready to use 21 * 22 * @author <a href="mailto:joeblack.guo@vtradex.com">joel guo</a> 23 * @since 2003-6-11 15:13:20 24 */ 25 public class DBDiggerLoader 26 implements Configurable, Serviceable, Startable, Initializable { 27 private static DBDiggerLoader onlyInstance; 28 /*** Role in avalong framework */ 29 public static final String ROLE = "dbdigger.loader"; 30 /*** Method getInstance() 31 * @return The only instance of this class 32 */ 33 public static final DBDiggerLoader getInstance() { 34 return onlyInstance; 35 } 36 private ServiceManager serviceManager; 37 private Configuration configuration; 38 private ArrayMap dbdiggers = new ArrayMap(); 39 private Log logger = LogFactory.getLog(getClass()); 40 private Schema schema; 41 /*** Override method configure() of super class 42 * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) 43 */ 44 public void configure(Configuration conf) { 45 configuration = conf; 46 } 47 /*** Method getDBDigger() 48 * @param name Name of dbdigger 49 * @return DBDigger object 50 */ 51 public DBDigger getDBDigger(String name) { 52 return (DBDigger) dbdiggers.get(name); 53 } 54 /*** Method getDBDiggers() 55 * @return DBDigger object array 56 */ 57 public DBDigger[] getDBDiggers() { 58 return (DBDigger[]) dbdiggers.values().toArray(DBDigger.EMPTY_ARRAY); 59 } 60 /*** Method getSchema() 61 * @return Schema object 62 */ 63 public Schema getSchema() { 64 return schema; 65 } 66 /*** Override method initialize() of super class 67 * @see org.apache.avalon.framework.activity.Initializable#initialize() 68 */ 69 public void initialize() throws Exception { 70 Configuration[] insts = 71 configuration.getChild("instances").getChildren("instance"); 72 for (int i = 0; i < insts.length; i++) { 73 Configuration inst = insts[i]; 74 String name = inst.getAttribute("name"); 75 DBDigger dbdigger = new DBDigger(name); 76 try { 77 String sqlcRole = 78 inst.getChild("sqlcastor").getAttribute("role"); 79 dbdigger.setSQLCastor( 80 (SQLCastor) serviceManager.lookup(sqlcRole)); 81 } catch (Exception e) { 82 logger.error(e); 83 } finally { 84 dbdiggers.put(name, dbdigger); 85 } 86 } 87 } 88 /*** Override method service() of super class 89 * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) 90 */ 91 public void service(ServiceManager sm) throws ServiceException { 92 schema = (Schema) sm.lookup(Schema.ROLE); 93 serviceManager = sm; 94 } 95 /*** Override method start() of super class 96 * @see org.apache.avalon.framework.activity.Startable#start() 97 */ 98 public void start() { 99 onlyInstance = this; 100 } 101 /*** Override method stop() of super class 102 * @see org.apache.avalon.framework.activity.Startable#stop() 103 */ 104 public void stop() { 105 onlyInstance = null; 106 } 107 }

This page was automatically generated by Maven