OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / org / omg / CORBA / ORB.java
1 /* ORB.java --
2    Copyright (C) 2005, 2006 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package org.omg.CORBA;
40
41 import gnu.CORBA.OrbFocused;
42 import gnu.CORBA.ObjectCreator;
43 import gnu.CORBA.OrbRestricted;
44 import gnu.CORBA.typecodes.FixedTypeCode;
45 import gnu.CORBA.typecodes.GeneralTypeCode;
46 import gnu.CORBA.typecodes.RecordTypeCode;
47 import gnu.CORBA.typecodes.RecursiveTypeCode;
48
49 import org.omg.CORBA.ORBPackage.InconsistentTypeCode;
50 import org.omg.PortableInterceptor.ObjectReferenceTemplate;
51
52 import java.applet.Applet;
53
54 import java.io.BufferedInputStream;
55 import java.io.File;
56 import java.io.FileInputStream;
57 import java.io.IOException;
58
59 import java.util.Properties;
60
61 /**
62  * A central class in CORBA implementation, responsible for sending and handling
63  * remote invocations. ORB also works as a factory for creating instances of
64  * certain CORBA classes.
65  * 
66  * Despite the core library contains the fully working CORBA implementation, it
67  * also provides a simple way to plug-in the alternative CORBA support. This is
68  * done by replacing the ORB. The alternative ORB can be specified via
69  * properties, passed to ORB.Init(...).
70  * 
71  * When creating an ORB instance, the class name is searched in the following
72  * locations:
73  * <p>
74  * 1. Applet parameter or application string array, if any.<br>
75  * 2. The properties parameter, if any.<br>
76  * 3. The System properties.<br>
77  * 4. The orb.properties file located in the user.home directory (if any).<br>
78  * 5. The orb.properties file located in the java.home/lib directory (if any).
79  * </p>
80  * 
81  * The supported properties are: <table border="1">
82  * <tr>
83  * <td> org.omg.CORBA.ORBClass</td>
84  * <td>The class, implementing the functional ORB, returned by
85  * {@link #init(Applet, Properties)} or {@link #init(String[], Properties)}
86  * </td>
87  * </tr>
88  * <tr>
89  * <td>org.omg.CORBA.ORBSingletonClass</td>
90  * <td>The class, implementing the restricted ORB, returned by {@link #init()}.
91  * </td>
92  * </tr>
93  * <tr>
94  * <td>org.omg.CORBA.ORBInitRef</td>
95  * <td>Specifies the initial reference, accessible by name with the method
96  * {@link #resolve_initial_references(String)}.</td>
97  * </tr>
98  * <tr>
99  * <td>org.omg.CORBA.ORBid</td>
100  * <td>Specifies the name (ORB Id) of this ORB. The ORB Id is later accessible
101  * by {@link ObjectReferenceTemplate#orb_id}. The default value includes the
102  * hashcode of the ORB instance that is normally different for each ORB. 
103  * </td>
104  * </tr>
105  * <tr>
106  * <td>org.omg.CORBA.ServerId</td>
107  * <td>Specifies the name (Server Id) of this server. This property assigns
108  * value to the <i>static</i> field, ensuring that all ORB's on the same jre
109  * have the same Server Id. It is normally set as the system property. The
110  * server Id is later accessible as {@link ObjectReferenceTemplate#server_id}.
111  * </td>
112  * </tr>
113  * <tr>
114  * <td>gnu.CORBA.ListenerPort</td>
115  * <td>Specifies that this ORB should serve all its objects on a single port
116  * (for example, "1234") or on a specified port range (for example,
117  * "1100-1108"). The property is used when working with firewals and serves as a
118  * replacement for the proprietary properties like com.ibm.CORBA.ListenerPort
119  * or com.sun.CORBA.POA.ORBPersistentServerPort. The specified port or range
120  * should not overlap with the values, specified for other ORB's.
121  * </td>
122  * </tr>
123  * <tr>
124  * <td>gnu.Corba.SocketFactory</td>
125  * <td>Sets the user-defined server and client socket factory for the ORB being
126  * currently instantiated. Serves as a replacement of the proprietary
127  * property com.sun.CORBA.connection.ORBSocketFactoryClass. To have multiple
128  * types of sockets, instantiate several ORB's with this property each time
129  * set to the different value. 
130  * The factory must implement gnu.CORBA.interfaces.SocketFactory.
131  * </td>
132  * </tr>
133  * </table> 
134  * <p>The command line accepts the same properties as a keys. When
135  * specifying in the command line, the prefix org.omg.CORBA can be omitted, for
136  * instance<code> -ORBInitRef NameService=IOR:aabbccdd....</code>
137  * </p>
138  * 
139  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
140  */
141 public abstract class ORB
142 {
143   /**
144   * By default, {@link #init(String[], Properties)} and
145   * {@link #init(Applet, Properties)} return
146   * the built-in fully functional ORB is returned. If the
147   * <code>props</code> contains the property org.omg.CORBA.ORBClass,
148   * the value of this property is used as a class name to instantiate
149   * a user-defined ORB.
150   */
151   private static final String FUNCTIONAL_ORB = "org.omg.CORBA.ORBClass";
152
153   /**
154    * The name of the restricted ORB property.
155    */
156   private static final String RESTRICTED_ORB =
157     "org.omg.CORBA.ORBSingletonClass";
158   
159   private static final String LISTENER_PORT =
160     OrbFocused.LISTENER_PORT;
161   
162   /**
163    * The class, implementing the default fully functional ORB.
164    */
165   private static final String DEFAULT_FUNCTIONAL_ORB =
166     gnu.CORBA.Poa.ORB_1_4.class.getName();
167   
168   private static final String DEFAULT_FOCUSED_ORB =
169     gnu.CORBA.OrbFocused.class.getName();
170   
171   // There is no need for name of the default restricted ORB as it is 
172   // singleton and it is more effectively referred directly.
173
174   /**
175    * Connect the given CORBA object to this ORB. After the object is
176    * connected, it starts receiving remote invocations via this ORB.
177    *
178    * The OMG group recommends to use Portable Object Adapter (POA) instead
179    * of calling this method.
180    *
181    * This method is implemented in the derived Gnu Classpah classes,
182    * returned by ORB.init(..). In this abstract class, the implementation
183    * just throws {@link NO_IMPLEMENT}.
184    *
185    * @param object the org.omg.CORBA.Object to connect.
186    */
187   public void connect(org.omg.CORBA.Object object)
188   {
189     throw new NO_IMPLEMENT();
190   }
191
192   /**
193    * Disconnect the given CORBA object from this ORB. The object will be
194    * no longer receiving the remote invocations. In response to the
195    * remote invocation on this object, the ORB will send the
196    * exception {@link OBJECT_NOT_EXIST}. The object, however, is not
197    * destroyed and can receive the local invocations.
198    *
199    * This method is implemented in the derived Gnu Classpah classes,
200    * returned by ORB.init(..). In this abstract class, the implementation
201    * just throws {@link NO_IMPLEMENT}.
202    *
203    * @param object the object to disconnect.
204    */
205   public void disconnect(org.omg.CORBA.Object object)
206   {
207     throw new NO_IMPLEMENT();
208   }
209
210   /**
211    * Create a typecode, representing a tree-like structure.
212    * This structure contains a member that is a sequence of the same type,
213    * as the structure itself. You can imagine as if the folder definition
214    * contains a variable-length array of the enclosed (nested) folder
215    * definitions. In this way, it is possible to have a tree like
216    * structure that can be transferred via CORBA CDR stream.
217    *
218    * @deprecated It is easier and clearler to use a combination of
219    * create_recursive_tc and create_sequence_tc instead.
220    *
221    * @param bound the maximal expected number of the nested components
222    * on each node; 0 if not limited.
223    *
224    * @param offset the position of the field in the returned structure
225    * that contains the sequence of the structures of the same field.
226    * The members before this field are intialised using parameterless
227    * StructMember constructor.
228    *
229    * @return a typecode, defining a stucture, where a member at the
230    * <code>offset</code> position defines an array of the identical
231    * structures.
232    *
233    * @see #create_recursive_tc(String)
234    * @see #create_sequence_tc(int, TypeCode)
235    */
236   public abstract TypeCode create_recursive_sequence_tc(int bound, int offset);
237
238   /**
239    * Create alias typecode for the given typecode.
240    */
241   public abstract TypeCode create_alias_tc(String id, String name,
242                                            TypeCode typecode
243                                           );
244
245   /**
246    * Create an instance of the CORBA {@link Any} with the type, intialised
247    * to {@link TCKind#tk_null}
248    */
249   public abstract Any create_any();
250
251   /**
252    * Create a typecode, defining an array of the given elements.
253    *
254    * @param length the size of array
255    * @param element_type the array component type.
256    *
257    * @return the corresponding typecode.
258    */
259   public abstract TypeCode create_array_tc(int length, TypeCode element_type);
260
261   /**
262    * Creates an empty CORBA <code>ContextList</code>.
263    *
264    * @return the newly created context list.
265    */
266   public abstract ContextList create_context_list();
267
268   /**
269    * The support for {@link DynAny} and derived interfaces
270    * has never been implemented in Sun's java releases,
271    * at least till v1.4 inclusive.
272    *
273    * Since v1.4 this stil missing implementation was replaced
274    * by the new DynamicAny package.
275    *
276    * @throws NO_IMPLEMENT, always.
277    */
278   public DynAny create_basic_dyn_any(org.omg.CORBA.TypeCode t)
279                               throws InconsistentTypeCode
280   {
281     throw new NO_IMPLEMENT();
282   }
283   ;
284
285   /**
286    * The support for {@link DynAny} and derived interfaces
287    * has never been implemented in Sun's java releases,
288    * at least till v1.4 inclusive.
289    *
290    * Since v1.4 this stil missing implementation was replaced
291    * by the new DynamicAny package.
292    *
293    * @throws NO_IMPLEMENT, always.
294    */
295   public DynAny create_dyn_any(org.omg.CORBA.Any a)
296   {
297     throw new NO_IMPLEMENT();
298   }
299   ;
300
301   /**
302    * The support for {@link DynArray}
303    * has never been implemented in Sun's java releases,
304    * at least till v1.4 inclusive.
305    *
306    * Since v1.4 this stil missing implementation was replaced
307    * by the new DynamicAny package.
308    *
309    * @throws NO_IMPLEMENT, always.
310    */
311   public DynArray create_dyn_array(org.omg.CORBA.TypeCode t)
312                             throws InconsistentTypeCode
313   {
314     throw new NO_IMPLEMENT();
315   }
316   ;
317
318   /**
319    * The support for {@link DynEnum}
320    * has never been implemented in Sun's java releases,
321    * at least till v1.4 inclusive.
322    *
323    * Since v1.4 this stil missing implementation was replaced
324    * by the new DynamicAny package.
325    *
326    * @throws NO_IMPLEMENT, always.
327    */
328   public DynEnum create_dyn_enum(org.omg.CORBA.TypeCode t)
329                           throws InconsistentTypeCode
330   {
331     throw new NO_IMPLEMENT();
332   }
333   ;
334
335   /**
336    * The support for {@link DynSequence}
337    * has never been implemented in Sun's java releases,
338    * at least till v1.4 inclusive.
339    *
340    * Since v1.4 this stil missing implementation was replaced
341    * by the new DynamicAny package.
342    *
343    * @throws NO_IMPLEMENT, always.
344    */
345   public DynSequence create_dyn_sequence(org.omg.CORBA.TypeCode t)
346                                   throws InconsistentTypeCode
347   {
348     throw new NO_IMPLEMENT();
349   }
350   ;
351
352   /**
353    * The support for {@link DynStruct} and derived interfaces
354    * has never been implemented in Sun's java releases,
355    * at least till v1.4 inclusive.
356    *
357    * Since v1.4 this stil missing implementation was replaced
358    * by the new DynamicAny package.
359    *
360    * @throws NO_IMPLEMENT, always.
361    */
362   public DynStruct create_dyn_struct(org.omg.CORBA.TypeCode t)
363                               throws InconsistentTypeCode
364   {
365     throw new NO_IMPLEMENT();
366   }
367   ;
368
369   /**
370    * The support for {@link DynUnion} and derived interfaces
371    * has never been implemented in Sun's java releases,
372    * at least till v1.4 inclusive.
373    *
374    * Since v1.4 this stil missing implementation was replaced
375    * by the new DynamicAny package.
376    *
377    * @throws NO_IMPLEMENT, always.
378    */
379   public DynUnion create_dyn_union(org.omg.CORBA.TypeCode t)
380                             throws InconsistentTypeCode
381   {
382     throw new NO_IMPLEMENT();
383   }
384   ;
385
386   /**
387    * Create a typecode, defining the given enumeration.
388    *
389    * @param id the id.
390    * @param name the name.
391    * @param members the memebers
392    * @return the created enumeration.
393    */
394   public abstract TypeCode create_enum_tc(String id, String name,
395                                           String[] members
396                                          );
397
398   /**
399    * Create an environment (container for exceptions).
400    *
401    * @return the created container.
402    */
403   public abstract Environment create_environment();
404
405   /**
406    * Creates an empty exception list.
407    *
408    * @return the newly created list.
409    */
410   public abstract ExceptionList create_exception_list();
411
412   /**
413    * Create the exception typecode.
414    *
415    * @param id the id of exception.
416    * @param name the name of exception.
417    * @param members the members of exception.
418    */
419   public abstract TypeCode create_exception_tc(String id, String name,
420                                                StructMember[] members
421                                               );
422
423   /**
424    * Creates a TypeCode object for CORBA <code>fixed</code> that is
425    * mapped to java {@link java.math.BigDecimal}.
426    *
427    * @param digits the number of digits in that <code>fixed</code>.
428    * @param scale the number of digits after the decimal point.
429    *
430    * @return the corresponding TypeCode.
431    */
432   public TypeCode create_fixed_tc(short digits, short scale)
433   {
434     FixedTypeCode r = new FixedTypeCode();
435     r.setDigits(digits);
436     r.setScale(scale);
437     return r;
438   }
439
440   /**
441    * Creates a typecode, representing the IDL interface.
442    *
443    * @param id the interface repository id.
444    * @param name the interface name.
445    *
446    * @return the created typecode.
447    */
448   public abstract TypeCode create_interface_tc(String id, String name);
449
450   /**
451    * Create an instance of a new {@link NVList}.
452    *
453    * @param count the initial size of the list. If more elements are added,
454    * the list automatically expands.
455    *
456    * @return the created list.
457    */
458   public abstract NVList create_list(int count);
459
460   /**
461    * Create a new named value.
462    *
463    * @param name the name of the named value
464    * @param any the content of the named value.
465    * @param flags the flags of the named value
466    *
467    * @return the named value.
468    */
469   public abstract NamedValue create_named_value(String name, Any any, int flags);
470
471   /**
472    * Send multiple prepared requests one way, do not caring about the answer.
473    * The messages, containing requests, will be marked, indicating that
474    * the sender is not expecting to get a reply.
475    *
476    * @param requests the prepared array of requests.
477    *
478    * @see Request#send_oneway()
479    */
480   public abstract void send_multiple_requests_oneway(Request[] requests);
481
482   /**
483    * Send multiple prepared requests expecting to get a reply. All requests
484    * are send in parallel, each in its own separate thread. When the
485    * reply arrives, it is stored in the agreed fields of the corresponing
486    * request data structure. If this method is called repeatedly,
487    * the new requests are added to the set of the currently sent requests,
488    * but the old set is not discarded.
489    *
490    * @param requests the prepared array of requests.
491    *
492    * @see #poll_next_response()
493    * @see #get_next_response()
494    * @see Request#send_deferred()
495    */
496   public abstract void send_multiple_requests_deferred(Request[] requests);
497
498   /**
499    * Find if any of the requests that have been previously sent with
500    * {@link #send_multiple_requests_deferred}, have a response yet.
501    *
502    * @return true if there is at least one response to the previously
503    * sent request, false otherwise.
504    */
505   public abstract boolean poll_next_response();
506
507   /**
508    * Get the next instance with a response being received. If all currently
509    * sent responses not yet processed, this method pauses till at least one of
510    * them is complete. If there are no requests currently sent, the method
511    * pauses till some request is submitted and the response is received.
512    * This strategy is identical to the one accepted by Suns 1.4 ORB
513    * implementation.
514    *
515    * @return the previously sent request that now contains the received
516    * response.
517    *
518    * @throws WrongTransaction If the method was called from the transaction
519    * scope different than the one, used to send the request. The exception
520    * can be raised only if the request is implicitly associated with some
521    * particular transaction.
522    */
523   public abstract Request get_next_response()
524                                      throws WrongTransaction;
525  
526   /**
527    * Create a new CDR output stream, where the parameter values can be written
528    * during the method invocation.
529    *
530    * @return a stream to write values into.
531    */
532   public abstract org.omg.CORBA.portable.OutputStream create_output_stream();
533
534   /**
535    * This should create the list, initialised with the argument descriptions
536    * for the given operation definition (CORBA <code>OperationDef</code>).
537    * The information should be obtained from the interface repository.
538    * However this method is oficially documented as not implemented at least
539    * till v1.4 inclusive.
540    *
541    * @param operation_definition the operation definition, must be
542    * CORBA <code>OperationDef</code>.
543    *
544    * @return never
545    *
546    * @throws NO_IMPLEMENT, always.
547    */
548   public NVList create_operation_list(Object operation_definition)
549   {
550     throw new NO_IMPLEMENT();
551   }
552
553   /**
554    * <p>Creates the new policy of the specified type, having the given value.
555    * This method looks for the policy factory that was previously registered
556    * during ORB initialization by
557    * {@link org.omg.PortableInterceptor#ORBInitialiser}.
558    *
559    * If the suitable factory is found, this factory creates the requested policy,
560    * otherwise the PolicyError is thrown.
561    * </p><p>
562    * The POA policies should be created by POA, not by this method.
563    * </p>
564    * @param type the policy type.
565    * @param value the policy value, wrapped into Any.
566    *
567    * @throws PolicyError if the ORB fails to instantiate the policy object.
568    *
569    * @throws NO_IMPLEMENT always (in this class). Overridden in derived classes
570    * returned by ORB.init(..).
571    *
572    * @see org.omg.PortableInterceptor.ORBInitInfoOperations#register_policy_factory
573    * @see org.omg.PortableInterceptor.PolicyFactoryOperations
574    */
575   public Policy create_policy(int type, Any value)
576                        throws PolicyError
577   {
578     throw new NO_IMPLEMENT();
579   }
580
581   /**
582    * Create typecode, defining the sequence of the elements, having
583    * the given type.
584    *
585    * @param bound the maximal length of the sequence, 0 if not restricted.
586    *
587    * @param element_type the sequence element type.
588    *
589    * @return the typecode.
590    */
591   public abstract TypeCode create_sequence_tc(int bound, TypeCode element_type);
592
593   /**
594    * Create a TypeCode, representing the CORBA <code>string</code>.
595    *
596    * @param bound the maximal length of the string, 0 is unlimited.
597    *
598    * @return the corresponding string typecode.
599    */
600   public abstract TypeCode create_string_tc(int bound);
601
602   /**
603    * Create the typecode, defining the given IDL structure.
604    *
605    * The TypeCode object is initialized with the given id, name, and members.
606    * @param id the Id of this type.
607    * @param name the name of this type.
608    * @param members the member list.
609    *
610    * @return the typecode.
611    */
612   public abstract TypeCode create_struct_tc(String id, String name,
613                                             StructMember[] members
614                                            );
615
616   /**
617    * Create the typecode, defining the given IDL union.
618    *
619    * The TypeCode object is initialized with the given id, name, discriminator
620    * and members.
621    *
622    * @param id the Id of this type.
623    * @param name the name of this type.
624    * @param discriminator the union discriminator.
625    * @param members the member list.
626    *
627    * @return the typecode.
628    */
629   public abstract TypeCode create_union_tc(String id, String name,
630                                            TypeCode discriminator,
631                                            UnionMember[] members
632                                           );
633
634   /**
635    * Create a TypeCode, representing the CORBA <code>wstring</code>.
636    *
637    * @param bound the maximal length of the string, 0 is unlimited.
638    *
639    * @return the corresponding string typecode.
640    */
641   public abstract TypeCode create_wstring_tc(int bound);
642
643   /**
644    * Create a typecode for an abstract interface. The abstract interface
645    * can be either CORBA object or CORBA value type.
646    *
647    * @param id the id of the abstract interface.
648    * @param name the name of the abstract interface.
649    *
650    * @return the created typecode.
651    */
652   public TypeCode create_abstract_interface_tc(String id, String name)
653   {
654     GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_abstract_interface);
655     t.setName(name);
656     t.setId(id);
657     return t;
658   }
659
660   /**
661    * Create a typecode for a native interface.
662    *
663    * @param id the id of the native interface.
664    * @param name the name of the native interface.
665    *
666    * @return the created typecode.
667    */
668   public TypeCode create_native_tc(String id, String name)
669   {
670     GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_native);
671     t.setName(name);
672     t.setId(id);
673     return t;
674   }
675
676
677   /**
678    * Create a typecode which serves as a placeholder for typcode, containing
679    * recursion.
680    *
681    * @param id the id of the recursive typecode, for that this typecode
682    * serves as a placeholder.
683    */
684   public TypeCode create_recursive_tc(String id)
685   {
686     return new RecursiveTypeCode(id);
687   }
688
689   /**
690    * Create value box typecode.
691    */
692   public TypeCode create_value_box_tc(String id, String name,
693                                       TypeCode boxed_type
694                                      )
695   {
696     GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_value_box);
697     t.setName(name);
698     t.setId(id);
699     t.setContentType(boxed_type);
700     return t;
701   }
702
703   /**
704    * Create IDL value type code.
705    */
706   public TypeCode create_value_tc(String id, String name, short type_modifier,
707                                   TypeCode concrete_base, ValueMember[] members
708                                  )
709   {
710     RecordTypeCode r = new RecordTypeCode(TCKind.tk_value);
711     r.setId(id);
712     r.setName(name);
713     r.setTypeModifier(type_modifier);
714     r.setConcreteBase_type(concrete_base);
715
716     for (int i = 0; i < members.length; i++)
717       {
718         r.add(members [ i ]);
719       }
720
721     return r;
722   }
723
724   /**
725    * This should return the information, related to the current thread.
726    * The information is needed, for instance, to get the current object
727    * from the code that serves several objects in parallel threads.
728    * The {@link Current} is very general interface, with no fields and
729    * operations defined. This method is not implemented in Suns
730    * releases at least till v1.5 inclusive. To obtain the
731    * {@link org.omg.PortableServer.Current}, use
732    * {@link #resolve_initial_references}, passing "POACurrent".
733    *
734    * @deprecated since 1.2, use {@link #resolve_initial_references}.
735    *
736    * @return never
737    *
738    * @throws NO_IMPLEMENT always.
739    */
740   public Current get_current()
741   {
742     throw new NO_IMPLEMENT();
743   }
744
745   /**
746    * This should return the information about the CORBA facilities and
747    * services, available from this ORB. However this method is oficially
748    * documented as not implemented at least till v1.5 inclusive.
749    *
750    * @param service_type a type of the service being requested. The OMG
751    * specification currently defines only one value, 1, for security
752    * related services.
753    *
754    * @param service_info a holder, where the returned information should
755    * be stored.
756    *
757    * @return should return true if the service information is available
758    * from the ORB, but this method never returns.
759    *
760    * @throws NO_IMPLEMENT always.
761    */
762   public boolean get_service_information(short service_type,
763                                          ServiceInformationHolder service_info
764                                         )
765   {
766     throw new NO_IMPLEMENT();
767   }
768
769   /**
770    * Get the default context of this ORB. This is an initial root of all
771    * contexts.
772    *
773    * The default method returns a new context with the empty name and
774    * no parent context.
775    *
776    * @return the default context of this ORB.
777    *
778    * @throws NO_IMPLEMENT for the Singleton ORB, returned by
779    * the parameterless {@link #init()}.
780    */
781   public abstract Context get_default_context();
782
783   /**
784    * Return thg typecode, representing the given primitive object type.
785    *
786    * @param tcKind the kind of the primitive typecode.
787    *
788    * @return the typecode of the primitve typecode.
789    */
790   public abstract TypeCode get_primitive_tc(TCKind tcKind);
791
792   /**
793    * Returns so-called Singleton ORB, a highly restricted version
794    * that cannot communicate over network. This ORB is provided
795    * for the potentially malicious applets with heavy security restrictions.
796    *
797    * The returned Singleton ORB can only create typecodes,
798    * {@link Any}, {@link ContextList}, {@link NVList} and
799    * {@link org.omg.CORBA.portable.OutputStream} that writes to an
800    * internal buffer.
801    *
802    * All other methods throw the {@link NO_IMPLEMENT} exception, additionally
803    * printing the error message about the potential attempt to violate
804    * the security rules.
805    *
806    * The implementing ORB class, used in this method, is found as described
807    * in the header.
808    *
809    * @return the working derivative of ORB, implementing the methods
810    * of this abstract class.
811    */
812   public static ORB init()
813   {
814     String orb_cn = getCumulatedProperty(null, RESTRICTED_ORB);
815     if (orb_cn == null)
816       return OrbRestricted.Singleton;
817     else
818       return createORB(null, orb_cn);
819   }
820
821   /**
822    * Creates the working instance of ORB for an applet.
823    *
824    * By default the built-in fully functional ORB is returned. The ORB class
825    * is found as described in the header of this class.
826    *
827    * @param applet the applet. The property org.omg.CORBA.ORBClass,
828    * if present, defines the used ORB implementation class. If this
829    * property is not present, the ORB class is found as described in the
830    * class header.
831    *
832    * @param props the properties, may be <code>null</code>.
833    *
834    * @return a newly created functional derivative of this abstract class.
835    */
836   public static ORB init(Applet applet, Properties props)
837   {
838     String ocn = applet.getParameter(FUNCTIONAL_ORB);
839     String lp = applet.getParameter(LISTENER_PORT);
840     
841     if (ocn==null && lp!=null)
842       ocn = DEFAULT_FOCUSED_ORB;
843     
844     ORB orb = createORB(props, ocn);
845     orb.set_parameters(applet, props);
846
847     return orb;
848   }
849
850   /**
851    * Creates the working instance of ORB for a standalone application.
852    * 
853    * By default the built-in fully functional ORB is returned. The ORB class is
854    * found as described in the header of this class.
855    * 
856    * @param args the parameters, passed to the applications
857    * <code>main(String[] args)</code> method, may be <code>null</code>. The
858    * parameter -org.omg.CORBA.ORBClass <class name> if present, defines the used
859    * ORB implementation class. If this property is not present, the ORB class is
860    * found as described in the class header.
861    * 
862    * @param props application specific properties, may be <code>null</code>.
863    * 
864    * @return a newly created functional derivative of this abstract class.
865    */
866   public static ORB init(String[] args, Properties props)
867   {
868     String ocn = null;
869     String lp = null;
870
871     String orbKey = "-" + FUNCTIONAL_ORB;
872     String lpKey = "-" + LISTENER_PORT;
873
874     if (args != null)
875       if (args.length >= 2)
876         {
877           for (int i = 0; i < args.length - 1; i++)
878             {
879               if (args[i].equals(orbKey))
880                 ocn = args[i + 1];
881               if (args[i].equals(lpKey))
882                 lp = args[i + 1];
883             }
884         }
885
886     if (lp != null && ocn == null)
887       ocn = DEFAULT_FOCUSED_ORB;
888
889     ORB orb = createORB(props, ocn);
890
891     orb.set_parameters(args, props);
892     return orb;
893   }
894
895   /**
896    * List the initially available CORBA objects (services).
897    * 
898    * @return a list of services.
899    * 
900    * @see #resolve_initial_references(String)
901    */
902   public abstract String[] list_initial_services();
903
904   /**
905    * Find and return the easily accessible CORBA object, addressed
906    * by name.  The returned object is typically casted to the more
907    * specific reference using the <code>narrow(Object)</code> method
908    * of its helper. The method resolves the following string values,
909    * returning the working objects:
910    * <table border="1"><tr><th>String</th><th>Object class</th>
911    * <th>Object use</th></tr>
912    *
913    * <tr><td>NameService</td><td>{@link org.omg.CosNaming.NamingContextExt}</td>
914    * <td>Finds (usually remote) object by its name.</td></tr>
915    *
916    * <tr><td>RootPOA</td><td>{@link org.omg.PortableServer.POA}</td>
917    * <td>Holds the POA tree for this ORB, where since 1.4 all servants
918    * should be connected.</td></tr>
919    *
920    * <tr><td>RootPOAManager</td><td>{@link org.omg.PortableServer.POAManager}
921    * </td><td>Regulates (suspends/resumes) the root POA
922    * activity</td></tr>
923    *
924    * <tr><td>POACurrent</td><td>{@link org.omg.PortableServer.Current}
925    * </td><td>Informs the current thread about the Id and POA of the
926    * object being currently served (the methods of
927    * <code>Current</code> return different values for
928    * different threads).
929    * </td></tr>
930    *
931    * <tr><td>CodecFactory</td><td>{@link org.omg.IOP.Codec}</td>
932    * <td>Encodes/decodes IDL data types into/from byte arrays.</td>
933    * </tr>
934    *
935    * <tr><td>DynAnyFactory</td><td>{@link org.omg.DynamicAny.DynAnyFactory}</td>
936    * <td>Creates DynAny's.</td>
937    * </tr>
938    *
939    * <tr><td>PICurrent</td><td>{@link org.omg.PortableInterceptor.Current}</td>
940    * <td>Contains multiple slots where an interceptor can rememeber the
941    * request - specific values between subsequent
942    * calls of the interceptor methods.</td>
943    * </tr>
944    *
945    * </table>
946    *
947    * @param name the object name.
948    * @return the object
949    * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name
950    * is not associated with the known object.
951    */
952   public abstract Object resolve_initial_references(String name)
953     throws org.omg.CORBA.ORBPackage.InvalidName;
954
955   /**
956    * Get the IOR reference string for the given object.
957    * IOR can be compared with the Internet address for a web page,
958    * it provides means to locate the CORBA service on the web.
959    * IOR contains the host address, port number, the object identifier
960    * (key) inside the server, the communication protocol version,
961    * supported charsets and so on.
962    *
963    * @param forObject the CORBA object
964    * @return the object IOR representation.
965    * @see #string_to_object(String)
966    */
967   public abstract String object_to_string(Object forObject);
968
969   /**
970    * This should perform the implementation dependent unit of work in the
971    * main thread.
972    *
973    * This method is part of the support for the distribute use of the
974    * single execution thread.
975    *
976    * Same as in Suns releases at least till 1.4 inclusive,
977    * the distribute use of the single thread is not implemented.
978    * Use multiple threads, provided by jre.
979    *
980    * The method returns without action.
981    */
982   public void perform_work()
983   {
984   }
985
986   /**
987   * Checks if the ORB needs the main thread to perform some work.
988   * The method should return true if the ORB needs the main thread,
989   * and false if it does not.
990   *
991   * This method is part of the support for the distribute use of the
992   * single execution thread.
993   *
994   * Same as in Suns releases at least till 1.4 inclusive,
995   * the distributed use of the single thread is not implemented.
996   * Use multiple threads, provided by jre.
997   *
998   * @return false, always.
999   */
1000   public boolean work_pending()
1001   {
1002     return false;
1003   }
1004
1005   /**
1006    * <p>Find and return the CORBA object, addressed by the given
1007    * string representation. The object can be (an usually is)
1008    * located on a remote computer, possibly running a different
1009    * (not necessary java) CORBA implementation. The returned
1010    * object is typically casted to the more specific reference
1011    * using the <code>narrow(Object)</code> method of its helper.
1012    * </p><p>
1013    * This function supports the following input formats:<br>
1014    * 1. IOR reference (<b>ior:</b>nnnnn ..), usually computer generated.<br> 
1015    * 2. <b>corbaloc:</b>[<b>iiop</b>][version.subversion<b>@</b>]<b>:</b>host[<b>:</b>port]<b>/</b><i>key</i>
1016    * defines similar information as IOR reference, but is more human readable.
1017    * This type of reference may also contain multiple addresses (see
1018    * OMG documentation for complete format).<br>
1019    * 3. <b>corbaloc:rir:/</b><i>name</i> defines internal reference on this
1020    * ORB that is resolved using {@link #resolve_initial_references}, passing 
1021    * the given <i>name</i> as parameter.<br>
1022    * 4. <b>corbaname:rir:#</b><i>name</i> states that the given <i>name</i>
1023    * must be resolved using the naming service, default for this ORB.<br>
1024    * 5. <b>corbaname:</b>[<b>iiop</b>][version.subversion<b>@</b>]<b>:</b>host[<b>:</b>port]<b>#</b><i>name</i>
1025    * states that the <i>name</i> must be resolved using the naming service
1026    * that runs on the given host at the given port. The ORB expects to find 
1027    * there the {@link org.omg.CosNaming.NamingContext} under the key 
1028    * "NameService.<br>
1029    * 7. file://[file name] Read the object definition string from the 
1030    * file system<br>
1031    * 8. http://[url] Read the object definition string from the provided
1032    * url.<br>
1033    * 9. ftp://[url] Read the object definition string from the provided
1034    * url.<br>
1035    * 
1036    * <p>The default port is always 2809. The default iiop version is 1.0
1037    * that now may not always be supported, so we would recommend to specify
1038    * the version explicitly.</p>
1039    * <p>
1040    * The examples of the corbaloc and corbaname addresses:<br>
1041    * corbaname:rir:#xobj - ask local naming service for "xobj".<br>
1042    * corbaname:rir:/NameService#xobj - same (long form).<br>
1043    * corbaname:iiop:1.2@localhost:900#xobj - same, assuming that the naming 
1044    * service runs at port 900 on the local host and supports iiop 1.2.<br>
1045    * corbaname:iiop:localhost#xobj - same, assuming that the naming 
1046    * service runs at port 2809 on the local host and supports iiop 1.0.<br>
1047    * corbaloc::gnu.xxx.yy/Prod/TradingService - the object exists on the
1048    * host gnu.xxx.yy, port 2809 having the key "Prod/TradingService". Its ORB 
1049    * supports iiop 1.0.<br>
1050    * corbaloc::gnu.xxx.yy/Prod/TradingService:801 - the object exists on the
1051    * host gnu.xxx.yy, port 801 having the key "Prod/TradingService". Its ORB 
1052    * supports iiop 1.0 (iiop keyword ommitted).<br>
1053    * corbaloc:iiop:1.1@gnu.xxx.yy/Prod/TradingService - the object exists on the
1054    * host gnu.xxx.yy, port 801 having the key "Prod/TradingService". Its ORB 
1055    * supports iiop 1.1.<br>
1056    * corbaloc:rir:/NameService - the default naming service.
1057    *
1058    * @param IOR the object IOR representation string.
1059    *
1060    * @return the found CORBA object.
1061    * 
1062    * @throws BAD_PARAM if the string being parsed is invalid.
1063    * @throws DATA_CONVERSION if the string being parsed contains unsupported
1064    * prefix or protocol.
1065    * 
1066    * @see #object_to_string(org.omg.CORBA.Object)
1067    */
1068   public abstract Object string_to_object(String IOR);
1069
1070   /**
1071    * Start listening on the input socket. This method
1072    * blocks the current thread until {@link #shutdown(boolean)}
1073    * is called and shutdown process is completed.
1074    */
1075   public void run()
1076   {
1077   }
1078
1079   /**
1080    * Shutdown the ORB server.
1081    *
1082    * @param wait_for_completion if true, the current thread is
1083    * suspended untile the shutdown process is complete.
1084    */
1085   public void shutdown(boolean wait_for_completion)
1086   {
1087   }
1088
1089   /**
1090    * Destroy this server, releasing the occupied resources.
1091    * The default method returns without action.
1092    */
1093   public void destroy()
1094   {
1095   }
1096
1097   /**
1098    * Set the ORB parameters. This method is normally called from
1099    * {@link #init(String[], Properties)}.
1100    *
1101    * @param para the parameters, that were passed as the parameters
1102    * to the  <code>main(String[] args)</code> method of the current standalone
1103    * application.
1104    *
1105    * @param props application specific properties that were passed
1106    * as a second parameter in {@link #init(String[], Properties)}).
1107    * Can be <code>null</code>.
1108    */
1109   protected abstract void set_parameters(String[] para, Properties props);
1110
1111   /**
1112    * Set the ORB parameters. This method is normally called from
1113    * {@link #init(Applet, Properties)}.
1114    *
1115    * @param app the current applet.
1116    *
1117    * @param props application specific properties, passed as the second
1118    * parameter in {@link #init(Applet, Properties)}.
1119    * Can be <code>null</code>.
1120    */
1121   protected abstract void set_parameters(Applet app, Properties props);
1122
1123   /**
1124    * Get the property with the given name, searching in the standard
1125    * places for the ORB properties.
1126    */
1127   private static String getCumulatedProperty(Properties props, String property)
1128   {
1129     String orb_cn = null;
1130
1131     if (props != null)
1132       orb_cn = props.getProperty(property, null);
1133
1134     if (orb_cn == null)
1135       orb_cn = System.getProperty(property, null);
1136
1137     if (orb_cn == null)
1138       orb_cn = checkFile(property, "user.home", null);
1139
1140     if (orb_cn == null)
1141       orb_cn = checkFile(property, "java.home", "lib");
1142     
1143     return orb_cn;
1144   }
1145
1146   /**
1147    * Check if the property is defined in the existsting file orb.properties.
1148    *
1149    * @param property the property
1150    * @param dir the system property, defining the folder where the
1151    * file could be expected.
1152    * @param subdir subfolder where to look for the file.
1153    *
1154    * @return the property value, null if not found or file does not exist.
1155    */
1156   private static String checkFile(String property, String dir, String subdir)
1157   {
1158     try
1159       {
1160         File f = new File(dir);
1161         if (!f.exists())
1162           return null;
1163
1164         if (subdir != null)
1165           f = new File(f, subdir);
1166
1167         f = new File(f, "orb.properties");
1168
1169         if (!f.exists())
1170           return null;
1171
1172         Properties p = new Properties();
1173         p.load(new BufferedInputStream(new FileInputStream(f)));
1174
1175         return p.getProperty(property, null);
1176       }
1177     catch (IOException ex)
1178       {
1179         return null;
1180       }
1181   }
1182
1183   /**
1184    * Create ORB when its name is possibly known.
1185    * 
1186    * @param props properties, possibly containing the ORB name.
1187    * @param orbClassName the direct ORB class name, overriding other possible
1188    * locations, or null if not specified.
1189    */
1190   private static ORB createORB(Properties props, String orbClassName)
1191   {
1192     ORB orb = null;
1193
1194     if (orbClassName == null)
1195       {
1196         orbClassName = getCumulatedProperty(props, FUNCTIONAL_ORB);
1197
1198         if (orbClassName == null)
1199           {
1200             String lp = getCumulatedProperty(props, LISTENER_PORT);
1201             if (lp != null)
1202               orbClassName = DEFAULT_FOCUSED_ORB;
1203             else
1204               orbClassName = DEFAULT_FUNCTIONAL_ORB;
1205           }
1206       }
1207
1208     try
1209       {
1210         orb = (ORB) ObjectCreator.forName(orbClassName).newInstance();
1211       }
1212     catch (ClassNotFoundException ex)
1213       {
1214         noORB(orbClassName, ex);
1215       }
1216     catch (IllegalAccessException ex)
1217       {
1218         noORB(orbClassName, ex);
1219       }
1220     catch (InstantiationException ex)
1221       {
1222         noORB(orbClassName, ex);
1223       }
1224
1225     return orb;
1226   }
1227
1228   /**
1229    * Throw the runtime exception.
1230    *
1231    * @param orb_c the ORB class name.
1232    * @param why the explaining chained exception.
1233    */
1234   private static void noORB(String orb_c, Throwable why)
1235   {
1236     throw new RuntimeException("The ORB " + orb_c + " cannot be instantiated.",
1237                                why
1238                               );
1239   }
1240 }