KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > CorbaORB


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop;
23
24 import javax.naming.InitialContext JavaDoc;
25
26 import org.jboss.corba.ORBFactory;
27 import org.omg.CORBA.ORB JavaDoc;
28
29 /**
30  * Singleton class to ensure that all code running in the JBoss VM uses the
31  * same ORB instance. The CorbaORBService MBean calls CorbaORB.setInstance()
32  * at service creation time, after it creates an ORB instance. Code that runs
33  * both in the server VM and in client VM calls CorbaORB.getInstance() to get
34  * an ORB.
35  *
36  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
37  * @version $Revision: 37459 $
38  */

39 public class CorbaORB
40 {
41    /** The ORB instance in this VM. */
42    private static ORB JavaDoc instance;
43
44    /** Enforce non-instantiability. */
45    private CorbaORB()
46    {
47    }
48    
49    /**
50     * This method is called only by the CorbaORBService MBean, so it has
51     * package visibility.
52     */

53    static void setInstance(ORB JavaDoc orb)
54    {
55       if (instance == null)
56          instance = orb;
57       else
58          throw new RuntimeException JavaDoc(CorbaORB.class.getName()
59                                     + ".setInstance() called more than once");
60    }
61    
62    /**
63     * This method is called by classes that are used both at the server and at
64     * the client side: the handle impl (org.jboss.proxy.ejb.HandleImplIIOP),
65     * the home handle impl (org.jboss.proxy.ejb.HomeHandleImplIIOP),
66     * and the home factory (org.jboss.proxy.ejb.IIOPHomeFactory).
67     * When called by code running in the same VM as the the JBoss server,
68     * getInstance() returns the ORB instance used by the CorbaORBService MBean
69     * (which previously issued a setInstance() call). Otherwise getInstance()
70     * returns an ORB instance obtained with an ORB.init() call.
71     */

72    public static ORB JavaDoc getInstance()
73    {
74       // No instance established, we must be on the client
75
// Use the orb consistent with java:comp/ORB (if any).
76
if (instance == null)
77       {
78          try
79          {
80             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
81             ORB JavaDoc orb = (ORB JavaDoc) ctx.lookup("java:comp/ORB");
82          }
83          catch (Exception JavaDoc ignored)
84          {
85          }
86          if (instance == null)
87             instance = ORBFactory.getORB();
88       }
89       return instance;
90    }
91 }
92
Popular Tags