KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > jacorb > 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.iiop.jacorb;
23
24 import java.util.Properties JavaDoc;
25
26 import org.omg.CORBA_2_3.ORB JavaDoc;
27 import org.omg.CORBA.INITIALIZE JavaDoc;
28 import org.omg.CORBA.Any JavaDoc;
29 import org.omg.CORBA.TypeCode JavaDoc;
30 import org.omg.CORBA.StructMember JavaDoc;
31 import org.omg.CORBA.NO_IMPLEMENT JavaDoc;
32 import org.omg.CORBA.UnionMember JavaDoc;
33 import org.omg.CORBA.TCKind JavaDoc;
34 import org.omg.CORBA.ValueMember JavaDoc;
35 import org.omg.CORBA.ExceptionList JavaDoc;
36 import org.omg.CORBA.NVList JavaDoc;
37 import org.omg.CORBA.NamedValue JavaDoc;
38 import org.omg.CORBA.Environment JavaDoc;
39 import org.omg.CORBA.ContextList JavaDoc;
40 import org.omg.CORBA.Current JavaDoc;
41 import org.omg.CORBA.Context JavaDoc;
42 import org.omg.CORBA.Request JavaDoc;
43 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
44 import org.jboss.iiop.naming.ORBInitialContextFactory;
45
46
47 /**
48  * Thin wrapper class that fulfills the contract of an ORB singleton and
49  * forwards every invocation to an instance of org.jacorb.orb.ORBSingleton
50  * and initializes the ORBInitialContextFactory ORB attribute.
51  *
52  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
53  * @version $Revision: 37459 $
54  */

55 public class ORBSingleton extends ORB JavaDoc
56 {
57    /** The ORB singleton instance to which all invocations are forwarded. */
58    private static ORB JavaDoc delegate = null;
59
60    public ORBSingleton()
61    {
62       if( delegate == null )
63       {
64          String JavaDoc className = "org.jacorb.orb.ORBSingleton";
65          try
66          {
67             delegate = (ORB JavaDoc) Class.forName(className).newInstance();
68             ORBInitialContextFactory.setORB(delegate);
69          }
70          catch(ClassNotFoundException JavaDoc ex)
71          {
72          }
73          catch(Exception JavaDoc ex)
74          {
75             throw new INITIALIZE JavaDoc(
76                "can't instantiate ORBSingleton implementation " + className);
77          }
78
79          ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
80          if( cl == null )
81             cl = ClassLoader.getSystemClassLoader();
82          try
83          {
84             delegate = (ORB JavaDoc) Class.forName(className, true, cl).newInstance();
85          }
86          catch(Exception JavaDoc ex)
87          {
88             throw new INITIALIZE JavaDoc(
89                "can't instantiate ORBSingleton implementation " + className);
90          }
91       }
92    }
93
94    // All the rest is pretty dumb code: it implements all the methods of the
95
// class org.omg.CORBA.ORB, either forwarding the invocation to the
96
// delegate (methods that may be called on the restricted singleton ORB
97
// instance) or throwing an exception (methods that may not be called on
98
// the restricted singleton ORB instance).
99

100    public Any JavaDoc create_any()
101    {
102       return delegate.create_any();
103    }
104
105    public TypeCode JavaDoc create_alias_tc(String JavaDoc id,
106       String JavaDoc name,
107       TypeCode JavaDoc original_type)
108    {
109       return delegate.create_alias_tc(id, name, original_type);
110    }
111
112    public TypeCode JavaDoc create_array_tc(int length, TypeCode JavaDoc element_type)
113    {
114       return delegate.create_array_tc(length, element_type);
115    }
116
117    public TypeCode JavaDoc create_enum_tc(String JavaDoc id, String JavaDoc name, String JavaDoc[] members)
118    {
119       return delegate.create_enum_tc(id, name, members);
120    }
121
122    public TypeCode JavaDoc create_exception_tc(String JavaDoc id,
123       String JavaDoc name,
124       StructMember JavaDoc[] members)
125    {
126       return delegate.create_exception_tc(id, name, members);
127    }
128
129    public TypeCode JavaDoc create_interface_tc(String JavaDoc id, String JavaDoc name)
130    {
131       return delegate.create_interface_tc(id, name);
132    }
133
134    public TypeCode JavaDoc create_fixed_tc(short digits, short scale)
135    {
136       return delegate.create_fixed_tc(digits, scale);
137    }
138
139    public TypeCode JavaDoc create_recursive_tc(String JavaDoc id)
140    {
141       return delegate.create_recursive_tc(id);
142    }
143
144    /**
145     * @deprecated Deprecated by CORBA 2.3.
146     */

147    public TypeCode JavaDoc create_recursive_sequence_tc(int bound, int offset)
148    {
149       throw new NO_IMPLEMENT JavaDoc("deprecated by CORBA 2.3");
150    }
151
152    public TypeCode JavaDoc create_sequence_tc(int bound, TypeCode JavaDoc element_type)
153    {
154       return delegate.create_sequence_tc(bound, element_type);
155    }
156
157    public TypeCode JavaDoc create_string_tc(int bound)
158    {
159       return delegate.create_string_tc(bound);
160    }
161
162    public TypeCode JavaDoc create_wstring_tc(int bound)
163    {
164       return delegate.create_wstring_tc(bound);
165    }
166
167    public TypeCode JavaDoc create_struct_tc(String JavaDoc id,
168       String JavaDoc name,
169       StructMember JavaDoc[] members)
170    {
171       return delegate.create_struct_tc(id, name, members);
172    }
173
174    public TypeCode JavaDoc create_union_tc(String JavaDoc id,
175       String JavaDoc name,
176       TypeCode JavaDoc discriminator_type,
177       UnionMember JavaDoc[] members)
178    {
179       return delegate.create_union_tc(id, name,
180          discriminator_type, members);
181    }
182
183    public TypeCode JavaDoc get_primitive_tc(TCKind JavaDoc tcKind)
184    {
185       return delegate.get_primitive_tc(tcKind);
186    }
187
188    public TypeCode JavaDoc create_value_tc(String JavaDoc id,
189       String JavaDoc name,
190       short type_modifier,
191       TypeCode JavaDoc concrete_base,
192       ValueMember JavaDoc[] members)
193    {
194       return delegate.create_value_tc(id, name, type_modifier,
195          concrete_base, members);
196    }
197
198    public TypeCode JavaDoc create_value_box_tc(String JavaDoc id,
199       String JavaDoc name,
200       TypeCode JavaDoc boxed_type)
201    {
202       return delegate.create_value_box_tc(id, name, boxed_type);
203    }
204
205    public TypeCode JavaDoc create_abstract_interface_tc(String JavaDoc id, String JavaDoc name)
206    {
207       return delegate.create_abstract_interface_tc(id, name);
208    }
209
210    public TypeCode JavaDoc create_native_tc(String JavaDoc id, String JavaDoc name)
211    {
212       return delegate.create_native_tc(id, name);
213    }
214    
215    /* Methods not allowed on the singleton ORB: */
216
217    public ExceptionList JavaDoc create_exception_list()
218    {
219       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
220    }
221
222    public NVList JavaDoc create_list(int count)
223    {
224       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
225    }
226
227    public NamedValue JavaDoc create_named_value(String JavaDoc name, Any JavaDoc value, int flags)
228    {
229       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
230    }
231
232    public NVList JavaDoc create_operation_list(org.omg.CORBA.Object JavaDoc obj)
233    {
234       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
235    }
236
237    public NVList JavaDoc create_operation_list(org.omg.CORBA.OperationDef JavaDoc oper)
238    {
239       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
240    }
241
242    public org.omg.CORBA.Object JavaDoc string_to_object(String JavaDoc str)
243    {
244       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
245    }
246
247    public Environment JavaDoc create_environment()
248    {
249       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
250    }
251
252    public ContextList JavaDoc create_context_list()
253    {
254       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
255    }
256
257    public org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
258    {
259       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
260    }
261
262    /**
263     * @deprecated Deprecated by CORBA 2.3.
264     */

265    public Current JavaDoc get_current()
266    {
267       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
268    }
269
270    public Context JavaDoc get_default_context()
271    {
272       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
273    }
274
275    public Request JavaDoc get_next_response()
276    {
277       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
278    }
279
280    public String JavaDoc[] list_initial_services()
281    {
282       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
283    }
284
285    public String JavaDoc object_to_string(org.omg.CORBA.Object JavaDoc obj)
286    {
287       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
288    }
289
290    public boolean poll_next_response()
291    {
292       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
293    }
294
295    public org.omg.CORBA.Object JavaDoc resolve_initial_references(String JavaDoc identifier)
296       throws InvalidName JavaDoc
297    {
298       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
299    }
300
301    public void send_multiple_requests_deferred(Request JavaDoc[] req)
302    {
303       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
304    }
305
306    public void send_multiple_requests_oneway(Request JavaDoc[] req)
307    {
308       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
309    }
310
311    protected void set_parameters(String JavaDoc[] args, Properties JavaDoc props)
312    {
313       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
314    }
315
316    protected void set_parameters(java.applet.Applet JavaDoc app, Properties JavaDoc props)
317    {
318       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
319    }
320
321    public void run()
322    {
323       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
324    }
325
326    public void shutdown(boolean wait_for_completion)
327    {
328       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
329    }
330
331    public boolean work_pending()
332    {
333       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
334    }
335
336    public void perform_work()
337    {
338       throw new NO_IMPLEMENT JavaDoc("The Singleton ORB only permits factory methods");
339    }
340 }
341
Popular Tags