KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > corba > ORBFactory


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.corba;
23
24 import java.security.AccessController JavaDoc;
25 import java.security.PrivilegedAction JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 import org.jboss.logging.Logger;
30 import org.omg.CORBA.ORB JavaDoc;
31 import org.omg.PortableServer.POA JavaDoc;
32
33 /**
34  * An object factory that creates an ORB on the client
35  *
36  * @author Adrian Brock (adrian@jboss.com)
37  * @version $Revision: 37459 $
38  */

39 public class ORBFactory
40 {
41    // Constants -----------------------------------------------------
42

43    /** The logger */
44    private static final Logger log = Logger.getLogger(ORBFactory.class);
45    
46    /** The orb */
47    private static ORB JavaDoc orb;
48    
49    // Attributes ----------------------------------------------------
50

51    // Static --------------------------------------------------------
52

53    public static ORB JavaDoc getORB()
54    {
55       synchronized (ORBFactory.class)
56       {
57          if (orb == null)
58          {
59             Properties JavaDoc properties;
60             try
61             {
62                properties = (Properties JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc()
63                {
64                   public Object JavaDoc run()
65                   {
66                      return System.getProperties();
67                   }
68                });
69             }
70             catch (SecurityException JavaDoc ignored)
71             {
72                log.trace("Unable to retrieve system properties", ignored);
73                properties = null;
74             }
75
76             // Create the singleton ORB
77
orb = ORB.init(new String JavaDoc[0], properties);
78
79             // Activate the root POA
80
try
81             {
82                 POA JavaDoc rootPOA = (POA JavaDoc) orb.resolve_initial_references("RootPOA");
83                 rootPOA.the_POAManager().activate();
84             }
85             catch (Throwable JavaDoc t)
86             {
87                 log.warn("Unable to activate POA", t);
88             }
89          }
90          return orb;
91       }
92    }
93    
94    public static void setORB(ORB JavaDoc orb)
95    {
96       if (ORBFactory.orb != null)
97          throw new IllegalStateException JavaDoc("ORB has already been set");
98       ORBFactory.orb = orb;
99    }
100    
101    // Constructors --------------------------------------------------
102

103    // Public --------------------------------------------------------
104

105    // Y overrides ---------------------------------------------------
106

107    // Package protected ---------------------------------------------
108

109    // Protected -----------------------------------------------------
110

111    // Private -------------------------------------------------------
112

113    // Inner classes -------------------------------------------------
114
}
115
Popular Tags