KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > ORBSingleton


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.system;
23
24 import java.util.Properties JavaDoc;
25 import org.omg.CORBA.Any JavaDoc;
26 import org.omg.CORBA.Context JavaDoc;
27 import org.omg.CORBA.ContextList JavaDoc;
28 import org.omg.CORBA.Current JavaDoc;
29 import org.omg.CORBA.Environment JavaDoc;
30 import org.omg.CORBA.ExceptionList JavaDoc;
31 import org.omg.CORBA.INITIALIZE JavaDoc;
32 import org.omg.CORBA.NamedValue JavaDoc;
33 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
34 import org.omg.CORBA.NVList JavaDoc;
35 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
36 import org.omg.CORBA.Request JavaDoc;
37 import org.omg.CORBA.StructMember JavaDoc;
38 import org.omg.CORBA.TCKind JavaDoc;
39 import org.omg.CORBA.TypeCode JavaDoc;
40 import org.omg.CORBA.UnionMember JavaDoc;
41 import org.omg.CORBA.ValueMember JavaDoc;
42 import org.omg.CORBA_2_3.ORB JavaDoc;
43
44 /**
45  * Thin wrapper class that fulfills the contract of an ORB singleton and
46  * forwards every invocation to an instance of the actual ORB singleton class,
47  * which it loads with the context classloader. The name of the actual ORB
48  * singleton class is specified by the system property
49  * <code>org.jboss.ORBSingletonDelegate</code>.
50  * <p>
51  * This class is a workaround to the the following problem: unlike the Sun VMs,
52  * IBM VMs do not use the context classloader to load the ORB singleton class
53  * specified by the system property
54  * <code>org.omg.CORBA.ORBSingletonClass</code>. IBM VMs use the
55  * system classloader, thus requiring the ORB singleton class to be in
56  * the system classpath. Rather than adding a third-party jar file (e.g.
57  * jacorb.jar) to the system classpath, we include this class in run.jar.
58  * Instead of setting the system property
59  * <pre>
60  * org.omg.CORBA.ORBSingletonClass=some.orb.impl.ORBSingletonImpl
61  * </pre>
62  * we set two properties:
63  * <pre>
64  * org.omg.CORBA.ORBSingletonClass=org.jboss.system.ORBSingleton
65  * org.jboss.ORBSingletonDelegate=some.orb.impl.ORBSingletonImpl
66  * </pre>
67  * <p>
68  * This class should be removed when IBM fixes its VMs.
69  *
70  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
71  * @version $Revision: 37459 $
72  */

73 public class ORBSingleton extends ORB JavaDoc
74 {
75    /** System property key that specifies the actual ORB singleton class. */
76    public static String JavaDoc DELEGATE_CLASS_KEY = "org.jboss.ORBSingletonDelegate";
77
78    /** The ORB singleton instance to which all invocations are forwarded. */
79    private static ORB JavaDoc delegate = null;
80    
81    /**
82     * The ORBSingleton constructor does what the IBM VM does not do: it uses
83     * the context classloader to load the actual ORB singleton class.
84     */

85    public ORBSingleton()
86    {
87       if (delegate == null)
88       {
89          String JavaDoc className = System.getProperty(DELEGATE_CLASS_KEY);
90          if (className == null)
91             className = "org.jacorb.orb.ORBSingleton";
92          try
93          {
94             delegate = (ORB JavaDoc)Class.forName(className).newInstance();
95          }
96          catch (ClassNotFoundException JavaDoc ex)
97          {
98          }
99          catch (Exception JavaDoc ex) {
100             throw new INITIALIZE JavaDoc(
101                "can't instantiate ORBSingleton implementation " + className);
102          }
103
104          ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
105          if (cl == null)
106             cl = ClassLoader.getSystemClassLoader();
107          try
108          {
109             delegate = (ORB JavaDoc)Class.forName(className, true, cl).newInstance();
110          }
111          catch (Exception JavaDoc ex)
112          {
113             throw new INITIALIZE JavaDoc(
114                "can't instantiate ORBSingleton implementation " + className);
115          }
116       }
117    }
118
119    // All the rest is pretty dumb code: it implements all the methods of the
120
// class org.omg.CORBA.ORB, either forwarding the invocation to the
121
// delegate (methods that may be called on the restricted singleton ORB
122
// instance) or throwing an exception (methods that may not be called on
123
// the restricted singleton ORB instance).
124

125    public Any JavaDoc create_any()
126    {
127       return delegate.create_any();
128    }
129    
130    public TypeCode JavaDoc create_alias_tc(String JavaDoc id,
131                                    String JavaDoc name,
132                                    TypeCode JavaDoc original_type)
133    {
134       return delegate.create_alias_tc(id, name, original_type);
135    }
136    
137    public TypeCode JavaDoc create_array_tc(int length, TypeCode JavaDoc element_type)
138    {
139       return delegate.create_array_tc(length, element_type);
140    }
141    
142    public TypeCode JavaDoc create_enum_tc(String JavaDoc id, String JavaDoc name, String JavaDoc[] members)
143    {
144       return delegate.create_enum_tc(id, name, members);
145    }
146
147    public TypeCode JavaDoc create_exception_tc(String JavaDoc id,
148                                        String JavaDoc name,
149                                        StructMember JavaDoc[] members)
150    {
151       return delegate.create_exception_tc(id, name, members);
152    }
153    
154    public TypeCode JavaDoc create_interface_tc(String JavaDoc id, String JavaDoc name)
155    {
156       return delegate.create_interface_tc(id, name);
157    }
158
159    public TypeCode JavaDoc create_fixed_tc(short digits, short scale)
160    {
161       return delegate.create_fixed_tc(digits, scale);
162    }
163
164    public TypeCode JavaDoc create_recursive_tc(String JavaDoc id)
165    {
166       return delegate.create_recursive_tc(id);
167    }
168  
169    /**
170     * @deprecated Deprecated by CORBA 2.3.
171     */

172    public TypeCode JavaDoc create_recursive_sequence_tc(int bound, int offset)
173    {
174       throw new NO_IMPLEMENT JavaDoc("deprecated by CORBA 2.3");
175    }
176
177    public TypeCode JavaDoc create_sequence_tc(int bound, TypeCode JavaDoc element_type)
178    {
179       return delegate.create_sequence_tc(bound, element_type);
180    }
181    
182    public TypeCode JavaDoc create_string_tc(int bound)
183    {
184       return delegate.create_string_tc(bound);
185    }
186
187    public TypeCode JavaDoc create_wstring_tc(int bound)
188    {
189       return delegate.create_wstring_tc(bound);
190    }
191
192    public TypeCode JavaDoc create_struct_tc(String JavaDoc id,
193                                     String JavaDoc name,
194                                     StructMember JavaDoc[] members)
195    {
196       return delegate.create_struct_tc(id, name, members);
197    }
198    
199    public TypeCode JavaDoc create_union_tc(String JavaDoc id,
200                                    String JavaDoc name,
201                                    TypeCode JavaDoc discriminator_type,
202                                    UnionMember JavaDoc[] members)
203    {
204       return delegate.create_union_tc(id, name,
205                                       discriminator_type, members);
206    }
207    
208    public TypeCode JavaDoc get_primitive_tc(TCKind JavaDoc tcKind)
209    {
210       return delegate.get_primitive_tc(tcKind);
211    }
212
213    public TypeCode JavaDoc create_value_tc(String JavaDoc id,
214                                    String JavaDoc name,
215                                    short type_modifier,
216                                    TypeCode JavaDoc concrete_base,
217                                    ValueMember JavaDoc[] members)
218     {
219        return delegate.create_value_tc(id, name, type_modifier,
220                                        concrete_base, members);
221     }
222
223    public TypeCode JavaDoc create_value_box_tc(String JavaDoc id,
224                                        String JavaDoc name,
225                                        TypeCode JavaDoc boxed_type)
226    {
227       return delegate.create_value_box_tc(id, name, boxed_type);
228    }
229    
230    public TypeCode JavaDoc create_abstract_interface_tc(String JavaDoc id, String JavaDoc name)
231    {
232       return delegate.create_abstract_interface_tc(id, name);
233    }
234    
235    public TypeCode JavaDoc create_native_tc(String JavaDoc id, String JavaDoc name)
236    {
237       return delegate.create_native_tc(id, name);
238    }
239    
240    /* Methods not allowed on the singleton ORB: */
241
242    public ExceptionList JavaDoc create_exception_list()
243    {
244       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
245    }
246    
247    public NVList JavaDoc create_list(int count)
248    {
249       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
250    }
251    
252    public NamedValue JavaDoc create_named_value(String JavaDoc name, Any JavaDoc value, int flags)
253    {
254       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
255    }
256    
257    public NVList JavaDoc create_operation_list(org.omg.CORBA.Object JavaDoc obj)
258    {
259       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
260    }
261    
262    public org.omg.CORBA.Object JavaDoc string_to_object(String JavaDoc str)
263    {
264       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
265    }
266
267    public Environment JavaDoc create_environment()
268    {
269       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
270    }
271  
272    public ContextList JavaDoc create_context_list()
273    {
274       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
275    }
276    
277    public org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
278    {
279       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
280    }
281    
282    /**
283     * @deprecated Deprecated by CORBA 2.3.
284     */

285    public Current JavaDoc get_current()
286    {
287       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
288    }
289    
290    public Context JavaDoc get_default_context()
291    {
292       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
293    }
294    
295    public Request JavaDoc get_next_response()
296    {
297       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
298    }
299    
300    public String JavaDoc[] list_initial_services()
301    {
302       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
303    }
304    
305    public String JavaDoc object_to_string(org.omg.CORBA.Object JavaDoc obj)
306    {
307       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
308    }
309    
310    public boolean poll_next_response()
311    {
312       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
313    }
314    
315    public org.omg.CORBA.Object JavaDoc resolve_initial_references(String JavaDoc identifier)
316       throws InvalidName JavaDoc
317    {
318       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
319    }
320    
321    public void send_multiple_requests_deferred(Request JavaDoc[] req)
322    {
323       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
324    }
325    
326    public void send_multiple_requests_oneway(Request JavaDoc[] req)
327    {
328       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
329    }
330    
331    protected void set_parameters(String JavaDoc[] args, Properties JavaDoc props)
332    {
333       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
334    }
335    
336    protected void set_parameters(java.applet.Applet JavaDoc app, Properties JavaDoc props)
337    {
338       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
339    }
340    
341    public void run()
342    {
343       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
344    }
345    
346    public void shutdown(boolean wait_for_completion)
347    {
348       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
349    }
350    
351    public boolean work_pending()
352    {
353       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
354    }
355    
356    public void perform_work()
357    {
358       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
359    }
360 }
361
Popular Tags