KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > linkextraction > LinkExtractorImpl


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.linkextraction;
17
18 import org.apache.avalon.framework.configuration.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.avalon.framework.configuration.Configurable;
21 import org.apache.avalon.framework.service.Serviceable;
22 import org.apache.avalon.framework.service.ServiceManager;
23 import org.apache.avalon.framework.service.ServiceException;
24 import org.apache.avalon.framework.activity.Initializable;
25
26 /**
27  * @avalon.component version="1.0" name="linkextractor" lifestyle="singleton"
28  */

29 public class LinkExtractorImpl implements Serviceable, Initializable, Configurable {
30     private ServiceManager serviceManager;
31     private Configuration config;
32
33
34     public void configure(Configuration configuration) throws ConfigurationException {
35         this.config = configuration;
36     }
37
38     /**
39      * @avalon.dependency key="linkExtractorRegistrar" type="org.outerj.daisy.linkextraction.LinkExtractorRegistrar"
40      */

41     public void service(ServiceManager serviceManager) throws ServiceException {
42         this.serviceManager = serviceManager;
43     }
44
45     public void initialize() throws Exception JavaDoc {
46         LinkExtractorRegistrar linkExtractorRegistrar = (LinkExtractorRegistrar)serviceManager.lookup("linkExtractorRegistrar");
47         try {
48             Configuration[] extractorConf = config.getChild("extractors").getChildren("extractor");
49             for (int i = 0; i < extractorConf.length; i++) {
50                 String JavaDoc name = extractorConf[i].getAttribute("name");
51                 String JavaDoc description = extractorConf[i].getAttribute("description");
52                 String JavaDoc className = extractorConf[i].getAttribute("class");
53                 try {
54                     Class JavaDoc clazz = Class.forName(className);
55                     linkExtractorRegistrar.registerLinkExtractor(name, description, (LinkExtractor)clazz.newInstance());
56                 } catch (ClassNotFoundException JavaDoc e) {
57                     throw new ConfigurationException("Class not found: " + className + " specified at: " + extractorConf[i].getLocation());
58                 }
59             }
60         } finally {
61             serviceManager.release(linkExtractorRegistrar);
62         }
63     }
64
65 }
66
Popular Tags