KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > datasource > DriverRegistrarImpl


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.datasource;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.avalon.framework.activity.Initializable;
23 import org.apache.avalon.framework.configuration.Configurable;
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.outerj.daisy.configutil.PropertyResolver;
27 import org.outerj.daisy.jdbcutil.DriverLoader;
28
29 /**
30  * @avalon.component version="1.0" name="driverregistrar" lifestyle="singleton"
31  * @avalon.service type="org.outerj.daisy.datasource.DriverRegistrar"
32  */

33 public class DriverRegistrarImpl implements Initializable, Configurable, DriverRegistrar {
34     private Map JavaDoc drivers;
35
36     public void configure(Configuration configuration) throws ConfigurationException {
37         drivers = new HashMap JavaDoc();
38         Configuration[] driverConfs = configuration.getChild("drivers").getChildren("driver");
39         for (int i = 0; i < driverConfs.length; i++) {
40             String JavaDoc classpath = PropertyResolver.resolveProperties(driverConfs[i].getChild("classpath").getValue(""));
41             String JavaDoc classname = driverConfs[i].getChild("classname").getValue("com.mysql.jdbc.Driver");
42             drivers.put(classname, classpath);
43         }
44     }
45
46     public void initialize() throws Exception JavaDoc {
47         Iterator JavaDoc it = drivers.keySet().iterator();
48         while (it.hasNext()) {
49             String JavaDoc classname = (String JavaDoc)it.next();
50             String JavaDoc classpath = (String JavaDoc)drivers.get(classname);
51             DriverLoader.loadDatabaseDriver(classpath, classname);
52         }
53     }
54 }
55
Popular Tags