KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > classloaderserver > ConfigurationClassLoaderExporter


1 /**
2  *
3  * Copyright 2005 The Apache Software Foundation
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.geronimo.classloaderserver;
19
20 import java.net.URL JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
28 import org.apache.geronimo.kernel.config.Configuration;
29 import org.apache.geronimo.kernel.config.ConfigurationClassLoader;
30
31
32 /**
33  *
34  * @version $Rev: 109957 $ $Date: 2004-12-06 18:52:06 +1100 (Mon, 06 Dec 2004) $
35  */

36 public class ConfigurationClassLoaderExporter implements GBeanLifecycle {
37     private static final Log log = LogFactory.getLog(ConfigurationClassLoaderExporter.class);
38     
39     private final ClassLoaderServer networkServer;
40     private final Configuration configuration;
41     private ClassLoaderInfoAdapter adapter;
42     
43     public ConfigurationClassLoaderExporter(ClassLoaderServer networkServer, Configuration configuration) {
44         this.networkServer = networkServer;
45         this.configuration = configuration;
46     }
47
48     public void doStart() throws Exception JavaDoc {
49         ConfigurationClassLoader cl = configuration.getConfigurationClassLoader();
50         
51         adapter = new ClassLoaderInfoAdapter(cl);
52         networkServer.export(adapter);
53     }
54
55     public void doStop() throws Exception JavaDoc {
56         networkServer.unexport(adapter);
57     }
58
59     public void doFail() {
60         try {
61             networkServer.unexport(adapter);
62         } catch (ClassLoaderServerException e) {
63             log.error(e);
64         }
65     }
66     
67     private static class ClassLoaderInfoAdapter implements ClassLoaderInfo {
68         private final ConfigurationClassLoader cl;
69         
70         private ClassLoaderInfoAdapter(ConfigurationClassLoader cl) {
71             this.cl = cl;
72         }
73         
74         public ClassLoader JavaDoc getClassLoader() {
75             return cl;
76         }
77
78         public Object JavaDoc getID() {
79             return cl.getID();
80         }
81
82         public void setClassLoaderServerURLs(URL JavaDoc[] urls) {
83             cl.setClassLoaderServerURLs(urls);
84         }
85     }
86     
87     public static final GBeanInfo GBEAN_INFO;
88
89     static {
90         GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("ConfigurationClassLoader Exporter", ConfigurationClassLoaderExporter.class);
91
92         infoBuilder.addReference("ClassLoaderServer", ClassLoaderServer.class, NameFactory.GERONIMO_SERVICE);
93         infoBuilder.addReference("Configuration", Configuration.class, NameFactory.CONFIGURATION_ENTRY);
94         
95         infoBuilder.setConstructor(new String JavaDoc[] {"ClassLoaderServer", "Configuration"});
96         
97         GBEAN_INFO = infoBuilder.getBeanInfo();
98     }
99
100     public static GBeanInfo getGBeanInfo() {
101         return GBEAN_INFO;
102     }
103 }
104
105
Popular Tags