KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > client > AppClientCORBABean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.geronimo.client;
18
19 import java.util.Properties JavaDoc;
20
21 import org.apache.geronimo.gbean.GBeanInfo;
22 import org.apache.geronimo.gbean.GBeanInfoBuilder;
23 import org.apache.geronimo.gbean.GBeanLifecycle;
24 import org.omg.CORBA.ORB JavaDoc;
25
26 /**
27  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
28  */

29 public class AppClientCORBABean implements GBeanLifecycle {
30     private final ClassLoader JavaDoc classLoader;
31     private ORB JavaDoc orb;
32
33     public AppClientCORBABean(ClassLoader JavaDoc classLoader) {
34         this.classLoader = classLoader;
35     }
36
37     public void doStart() throws Exception JavaDoc {
38         ClassLoader JavaDoc savedLoader = Thread.currentThread().getContextClassLoader();
39         try {
40             Thread.currentThread().setContextClassLoader(classLoader);
41
42             orb = ORB.init(new String JavaDoc[0], new Properties JavaDoc());
43             new Thread JavaDoc(new ORBRunable(orb), "ORBInitialization").start();
44         } finally {
45             Thread.currentThread().setContextClassLoader(savedLoader);
46         }
47     }
48
49     public void doStop() throws Exception JavaDoc {
50         orb.shutdown(true);
51     }
52
53     public void doFail() {
54         orb.shutdown(false);
55     }
56
57     public ORB JavaDoc getORB() {
58         return orb;
59     }
60
61     private static final class ORBRunable implements Runnable JavaDoc {
62         private final ORB JavaDoc orb;
63
64         public ORBRunable(ORB JavaDoc orb) {
65             this.orb = orb;
66         }
67
68         public void run() {
69             orb.run();
70         }
71     }
72
73     public static final GBeanInfo GBEAN_INFO;
74
75     static {
76         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(AppClientCORBABean.class);
77
78         infoFactory.addAttribute("classLoader", ClassLoader JavaDoc.class, false);
79         infoFactory.addAttribute("ORB", ORB JavaDoc.class, false);
80
81         infoFactory.setConstructor(new String JavaDoc[]{"classLoader"});
82
83         GBEAN_INFO = infoFactory.getBeanInfo();
84     }
85
86     public static GBeanInfo getGBeanInfo() {
87         return GBEAN_INFO;
88     }
89
90 }
91
Popular Tags