KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > locationmap > AbstractWrappingModule


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

17
18 package org.apache.forrest.locationmap;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.avalon.framework.activity.Disposable;
24 import org.apache.avalon.framework.configuration.Configurable;
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.avalon.framework.logger.AbstractLogEnabled;
28 import org.apache.avalon.framework.logger.LogEnabled;
29 import org.apache.avalon.framework.service.ServiceException;
30 import org.apache.avalon.framework.service.ServiceManager;
31 import org.apache.avalon.framework.service.Serviceable;
32
33 import org.apache.cocoon.components.modules.input.InputModule;
34
35 public abstract class AbstractWrappingModule extends AbstractLogEnabled
36     implements InputModule, Configurable, Serviceable, Disposable {
37
38     InputModule child;
39     ServiceManager manager;
40         
41     public void service(ServiceManager manager) throws ServiceException {
42         this.manager = manager;
43     }
44     
45     public void configure(Configuration config) throws ConfigurationException {
46         
47         Configuration childConf = config.getChild("component-instance");
48         String JavaDoc childClassName = childConf.getAttribute("class");
49         getLogger().debug("Loading wrapped class:"+childClassName);
50         
51         try{
52             child = (InputModule) Class.forName(childClassName).newInstance();
53             getLogger().debug("Wrapped class instantiated:"+child);
54             
55             if(child instanceof LogEnabled){
56                 ((LogEnabled)child).enableLogging( getLogger() );
57                 getLogger().debug("Wrapped class LogEnabled");
58             }
59             
60             if(child instanceof Serviceable){
61                 ((Serviceable)child).service( manager );
62                 getLogger().debug("Wrapped class Serviced");
63             }
64     
65             if(child instanceof Configurable){
66                 ((Configurable)child).configure(config.getChild("component-instance"));
67                 getLogger().debug("Wrapped class Configured");
68             }
69                 
70         }catch(Exception JavaDoc e){
71            throw new ConfigurationException
72                   ("Cannot instatiate the wrapped Module of class:"+childClassName, e);
73         }
74      }
75     
76     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
77         throws ConfigurationException {
78         return child.getAttribute(name, modeConf, objectModel);
79     }
80
81     public Iterator JavaDoc getAttributeNames(Configuration modeConf, Map JavaDoc objectModel)
82         throws ConfigurationException {
83         return child.getAttributeNames(modeConf, objectModel);
84     }
85
86     public Object JavaDoc[] getAttributeValues(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
87         throws ConfigurationException {
88         return child.getAttributeValues(name, modeConf, objectModel);
89     }
90   
91     public void dispose() {
92         if(child instanceof Disposable){
93             ((Disposable)child).dispose();
94         }
95     }
96     
97 }
98
Popular Tags