Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / org / omg / CORBA / ORB.java
blobaf05488280ff19c047457ed5fdc05c4fc078bf3e
1 /* ORB.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package org.omg.CORBA;
41 import gnu.CORBA.OrbFocused;
42 import gnu.CORBA.ObjectCreator;
43 import gnu.CORBA.OrbRestricted;
44 import gnu.CORBA.gnuContext;
45 import gnu.CORBA.typecodes.FixedTypeCode;
46 import gnu.CORBA.typecodes.GeneralTypeCode;
47 import gnu.CORBA.typecodes.PrimitiveTypeCode;
48 import gnu.CORBA.typecodes.RecordTypeCode;
49 import gnu.CORBA.typecodes.RecursiveTypeCode;
51 import org.omg.CORBA.ORBPackage.InconsistentTypeCode;
52 import org.omg.PortableInterceptor.ObjectReferenceTemplate;
54 import java.applet.Applet;
56 import java.io.BufferedInputStream;
57 import java.io.File;
58 import java.io.FileInputStream;
59 import java.io.IOException;
61 import java.util.Properties;
63 /**
64 * A central class in CORBA implementation, responsible for sending and handling
65 * remote invocations. ORB also works as a factory for creating instances of
66 * certain CORBA classes.
68 * Despite the core library contains the fully working CORBA implementation, it
69 * also provides a simple way to plug-in the alternative CORBA support. This is
70 * done by replacing the ORB. The alternative ORB can be specified via
71 * properties, passed to ORB.Init(...).
73 * When creating an ORB instance, the class name is searched in the following
74 * locations:
75 * <p>
76 * 1. Applet parameter or application string array, if any.<br>
77 * 2. The properties parameter, if any.<br>
78 * 3. The System properties.<br>
79 * 4. The orb.properties file located in the user.home directory (if any).<br>
80 * 5. The orb.properties file located in the java.home/lib directory (if any).
81 * </p>
83 * The supported properties are: <table border="1">
84 * <tr>
85 * <td> org.omg.CORBA.ORBClass</td>
86 * <td>The class, implementing the functional ORB, returned by
87 * {@link #init(Applet, Properties)} or {@link #init(String[], Properties)}
88 * </td>
89 * </tr>
90 * <tr>
91 * <td>org.omg.CORBA.ORBSingletonClass</td>
92 * <td>The class, implementing the restricted ORB, returned by {@link #init()}.
93 * </td>
94 * </tr>
95 * <tr>
96 * <td>org.omg.CORBA.ORBInitRef</td>
97 * <td>Specifies the initial reference, accessible by name with the method
98 * {@link #resolve_initial_references(String)}.</td>
99 * </tr>
100 * <tr>
101 * <td>org.omg.CORBA.ORBid</td>
102 * <td>Specifies the name (ORB Id) of this ORB. The ORB Id is later accessible
103 * by {@link ObjectReferenceTemplate#orb_id}. The default value includes the
104 * hashcode of the ORB instance that is normally different for each ORB.
105 * </td>
106 * </tr>
107 * <tr>
108 * <td>org.omg.CORBA.ServerId</td>
109 * <td>Specifies the name (Server Id) of this server. This property assigns
110 * value to the <i>static</i> field, ensuring that all ORB's on the same jre
111 * have the same Server Id. It is normally set as the system property. The
112 * server Id is later accessible as {@link ObjectReferenceTemplate#server_id}.
113 * </td>
114 * </tr>
115 * <tr>
116 * <td>gnu.CORBA.ListenerPort</td>
117 * <td>Specifies that this ORB should serve all its objects on a single port
118 * (for example, "1234") or on a specified port range (for example,
119 * "1100-1108"). The property is used when working with firewals and serves as a
120 * replacement for the proprietary properties like com.ibm.CORBA.ListenerPort
121 * or com.sun.CORBA.POA.ORBPersistentServerPort. The specified port or range
122 * should not overlap with the values, specified for other ORB's.
123 * </td>
124 * </tr>
125 * <tr>
126 * <td>gnu.Corba.SocketFactory</td>
127 * <td>Sets the user-defined server and client socket factory for the ORB being
128 * currently instantiated. Serves as a replacement of the proprietary
129 * property com.sun.CORBA.connection.ORBSocketFactoryClass. To have multiple
130 * types of sockets, instantiate several ORB's with this property each time
131 * set to the different value.
132 * The factory must implement gnu.CORBA.interfaces.SocketFactory.
133 * </td>
134 * </tr>
135 * </table>
136 * <p>The command line accepts the same properties as a keys. When
137 * specifying in the command line, the prefix org.omg.CORBA can be omitted, for
138 * instance<code> -ORBInitRef NameService=IOR:aabbccdd....</code>
139 * </p>
141 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
143 public abstract class ORB
146 * By default, {@link #init(String[], Properties)} and
147 * {@link #iinit(Applet, Properties)} return
148 * the built-in fully functional ORB is returned. If the
149 * <code>props</code> contains the property org.omg.CORBA.ORBClass,
150 * the value of this property is used as a class name to instantiate
151 * a user-defined ORB.
153 private static final String FUNCTIONAL_ORB = "org.omg.CORBA.ORBClass";
156 * The name of the restricted ORB property.
158 private static final String RESTRICTED_ORB =
159 "org.omg.CORBA.ORBSingletonClass";
161 private static final String LISTENER_PORT =
162 OrbFocused.LISTENER_PORT;
165 * The class, implementing the default fully functional ORB.
167 private static final String DEFAULT_FUNCTIONAL_ORB =
168 gnu.CORBA.Poa.ORB_1_4.class.getName();
170 private static final String DEFAULT_FOCUSED_ORB =
171 gnu.CORBA.OrbFocused.class.getName();
173 // There is no need for name of the default restricted ORB as it is
174 // singleton and it is more effectively referred directly.
177 * Connect the given CORBA object to this ORB. After the object is
178 * connected, it starts receiving remote invocations via this ORB.
180 * The OMG group recommends to use Portable Object Adapter (POA) instead
181 * of calling this method.
183 * This method is implemented in the derived Gnu Classpah classes,
184 * returned by ORB.init(..). In this abstract class, the implementation
185 * just throws {@link NO_IMPLEMENT}.
187 * @param object the org.omg.CORBA.Object to connect.
189 public void connect(org.omg.CORBA.Object object)
191 throw new NO_IMPLEMENT();
195 * Disconnect the given CORBA object from this ORB. The object will be
196 * no longer receiving the remote invocations. In response to the
197 * remote invocation on this object, the ORB will send the
198 * exception {@link OBJECT_NOT_EXIST}. The object, however, is not
199 * destroyed and can receive the local invocations.
201 * This method is implemented in the derived Gnu Classpah classes,
202 * returned by ORB.init(..). In this abstract class, the implementation
203 * just throws {@link NO_IMPLEMENT}.
205 * @param object the object to disconnect.
207 public void disconnect(org.omg.CORBA.Object object)
209 throw new NO_IMPLEMENT();
213 * Create alias typecode for the given typecode.
215 public abstract TypeCode create_alias_tc(String id, String name,
216 TypeCode typecode
220 * Create an instance of the CORBA {@link Any} with the type, intialised
221 * to {@link TCKind#tk_null}
223 public abstract Any create_any();
226 * Create a typecode, defining an array of the given elements.
228 * @param length the size of array
229 * @param element_type the array component type.
231 * @return the corresponding typecode.
233 public abstract TypeCode create_array_tc(int length, TypeCode element_type);
236 * Creates an empty CORBA <code>ContextList</code>.
238 * @return the newly created context list.
240 public abstract ContextList create_context_list();
243 * The support for {@link DynAny} and derived interfaces
244 * has never been implemented in Sun's java releases,
245 * at least till v1.4 inclusive.
247 * Since v1.4 this stil missing implementation was replaced
248 * by the new DynamicAny package.
250 * @throws NO_IMPLEMENT, always.
252 public DynAny create_basic_dyn_any(org.omg.CORBA.TypeCode t)
253 throws InconsistentTypeCode
255 throw new NO_IMPLEMENT();
260 * The support for {@link DynAny} and derived interfaces
261 * has never been implemented in Sun's java releases,
262 * at least till v1.4 inclusive.
264 * Since v1.4 this stil missing implementation was replaced
265 * by the new DynamicAny package.
267 * @throws NO_IMPLEMENT, always.
269 public DynAny create_dyn_any(org.omg.CORBA.Any a)
271 throw new NO_IMPLEMENT();
276 * The support for {@link DynArray}
277 * has never been implemented in Sun's java releases,
278 * at least till v1.4 inclusive.
280 * Since v1.4 this stil missing implementation was replaced
281 * by the new DynamicAny package.
283 * @throws NO_IMPLEMENT, always.
285 public DynArray create_dyn_array(org.omg.CORBA.TypeCode t)
286 throws InconsistentTypeCode
288 throw new NO_IMPLEMENT();
293 * The support for {@link DynEnum}
294 * has never been implemented in Sun's java releases,
295 * at least till v1.4 inclusive.
297 * Since v1.4 this stil missing implementation was replaced
298 * by the new DynamicAny package.
300 * @throws NO_IMPLEMENT, always.
302 public DynEnum create_dyn_enum(org.omg.CORBA.TypeCode t)
303 throws InconsistentTypeCode
305 throw new NO_IMPLEMENT();
310 * The support for {@link DynSequence}
311 * has never been implemented in Sun's java releases,
312 * at least till v1.4 inclusive.
314 * Since v1.4 this stil missing implementation was replaced
315 * by the new DynamicAny package.
317 * @throws NO_IMPLEMENT, always.
319 public DynSequence create_dyn_sequence(org.omg.CORBA.TypeCode t)
320 throws InconsistentTypeCode
322 throw new NO_IMPLEMENT();
327 * The support for {@link DynStruct} and derived interfaces
328 * has never been implemented in Sun's java releases,
329 * at least till v1.4 inclusive.
331 * Since v1.4 this stil missing implementation was replaced
332 * by the new DynamicAny package.
334 * @throws NO_IMPLEMENT, always.
336 public DynStruct create_dyn_struct(org.omg.CORBA.TypeCode t)
337 throws InconsistentTypeCode
339 throw new NO_IMPLEMENT();
344 * The support for {@link DynUnion} and derived interfaces
345 * has never been implemented in Sun's java releases,
346 * at least till v1.4 inclusive.
348 * Since v1.4 this stil missing implementation was replaced
349 * by the new DynamicAny package.
351 * @throws NO_IMPLEMENT, always.
353 public DynUnion create_dyn_union(org.omg.CORBA.TypeCode t)
354 throws InconsistentTypeCode
356 throw new NO_IMPLEMENT();
361 * Create a typecode, defining the given enumeration.
363 * @param id the id.
364 * @param name the name.
365 * @param members the memebers
366 * @return the created enumeration.
368 public abstract TypeCode create_enum_tc(String id, String name,
369 String[] members
373 * Create an environment (container for exceptions).
375 * @return the created container.
377 public abstract Environment create_environment();
380 * Creates an empty exception list.
382 * @return the newly created list.
384 public abstract ExceptionList create_exception_list();
387 * Create the exception typecode.
389 * @param id the id of exception.
390 * @param name the name of exception.
391 * @param members the members of exception.
393 public abstract TypeCode create_exception_tc(String id, String name,
394 StructMember[] members
398 * Creates a TypeCode object for CORBA <code>fixed</code> that is
399 * mapped to java {@link java.math.BigDecimal}.
401 * @param digits the number of digits in that <code>fixed</code>.
402 * @param scale the number of digits after the decimal point.
404 * @return the corresponding TypeCode.
406 public TypeCode create_fixed_tc(short digits, short scale)
408 FixedTypeCode r = new FixedTypeCode();
409 r.setDigits(digits);
410 r.setScale(scale);
411 return r;
415 * Creates a typecode, representing the IDL interface.
417 * @param id the interface repository id.
418 * @param name the interface name.
420 * @return the created typecode.
422 public abstract TypeCode create_interface_tc(String id, String name);
425 * Create an instance of a new {@link NVList}.
427 * @param count the initial size of the list. If more elements are added,
428 * the list automatically expands.
430 * @return the created list.
432 public abstract NVList create_list(int count);
435 * Create a new named value.
437 * @param name the name of the named value
438 * @param any the content of the named value.
439 * @param flags the flags of the named value
441 * @return the named value.
443 public abstract NamedValue create_named_value(String name, Any any, int flags);
446 * Send multiple prepared requests one way, do not caring about the answer.
447 * The messages, containing requests, will be marked, indicating that
448 * the sender is not expecting to get a reply.
450 * @param requests the prepared array of requests.
452 * @see Request#send_oneway()
454 public abstract void send_multiple_requests_oneway(Request[] requests);
457 * Send multiple prepared requests expecting to get a reply. All requests
458 * are send in parallel, each in its own separate thread. When the
459 * reply arrives, it is stored in the agreed fields of the corresponing
460 * request data structure. If this method is called repeatedly,
461 * the new requests are added to the set of the currently sent requests,
462 * but the old set is not discarded.
464 * @param requests the prepared array of requests.
466 * @see #poll_next_response()
467 * @see #get_next_response()
468 * @see Request#send_deferred()
470 public abstract void send_multiple_requests_deferred(Request[] requests);
473 * Find if any of the requests that have been previously sent with
474 * {@link #send_multiple_requests_deferred}, have a response yet.
476 * @return true if there is at least one response to the previously
477 * sent request, false otherwise.
479 public abstract boolean poll_next_response();
482 * Get the next instance with a response being received. If all currently
483 * sent responses not yet processed, this method pauses till at least one of
484 * them is complete. If there are no requests currently sent, the method
485 * pauses till some request is submitted and the response is received.
486 * This strategy is identical to the one accepted by Suns 1.4 ORB
487 * implementation.
489 * @return the previously sent request that now contains the received
490 * response.
492 * @throws WrongTransaction If the method was called from the transaction
493 * scope different than the one, used to send the request. The exception
494 * can be raised only if the request is implicitly associated with some
495 * particular transaction.
497 public abstract Request get_next_response()
498 throws WrongTransaction;
501 * Create a new CDR output stream, where the parameter values can be written
502 * during the method invocation.
504 * @return a stream to write values into.
506 public abstract org.omg.CORBA.portable.OutputStream create_output_stream();
509 * This should create the list, initialised with the argument descriptions
510 * for the given operation definition (CORBA <code>OperationDef</code>).
511 * The information should be obtained from the interface repository.
512 * However this method is oficially documented as not implemented at least
513 * till v1.4 inclusive.
515 * @param operation_definition the operation definition, must be
516 * CORBA <code>OperationDef</code>.
518 * @return never
520 * @throws NO_IMPLEMENT, always.
522 public NVList create_operation_list(Object operation_definition)
524 throw new NO_IMPLEMENT();
528 * <p>Creates the new policy of the specified type, having the given value.
529 * This method looks for the policy factory that was previously registered
530 * during ORB initialization by
531 * {@link org.omg.PortableInterceptor#ORBInitialiser}.
533 * If the suitable factory is found, this factory creates the requested policy,
534 * otherwise the PolicyError is thrown.
535 * </p><p>
536 * The POA policies should be created by POA, not by this method.
537 * </p>
538 * @param type the policy type.
539 * @param value the policy value, wrapped into Any.
541 * @throws PolicyError if the ORB fails to instantiate the policy object.
543 * @throws NO_IMPLEMENT always (in this class). Overridden in derived classes
544 * returned by ORB.init(..).
546 * @see org.omg.PortableInterceptor.ORBInitInfoOperations#register_policy_factory
547 * @see org.omg.PortableInterceptor.PolicyFactoryOperations
549 public Policy create_policy(int type, Any value)
550 throws PolicyError
552 throw new NO_IMPLEMENT();
556 * Create typecode, defining the sequence of the elements, having
557 * the given type.
559 * @param bound the maximal length of the sequence, 0 if not restricted.
561 * @param element_type the sequence element type.
563 * @return the typecode.
565 public abstract TypeCode create_sequence_tc(int bound, TypeCode element_type);
568 * Create a TypeCode, representing the CORBA <code>string</code>.
570 * @param bound the maximal length of the string, 0 is unlimited.
572 * @return the corresponding string typecode.
574 public abstract TypeCode create_string_tc(int bound);
577 * Create the typecode, defining the given IDL structure.
579 * The TypeCode object is initialized with the given id, name, and members.
580 * @param id the Id of this type.
581 * @param name the name of this type.
582 * @param members the member list.
584 * @return the typecode.
586 public abstract TypeCode create_struct_tc(String id, String name,
587 StructMember[] members
591 * Create the typecode, defining the given IDL union.
593 * The TypeCode object is initialized with the given id, name, discriminator
594 * and members.
596 * @param id the Id of this type.
597 * @param name the name of this type.
598 * @param discriminator the union discriminator.
599 * @param members the member list.
601 * @return the typecode.
603 public abstract TypeCode create_union_tc(String id, String name,
604 TypeCode discriminator,
605 UnionMember[] members
609 * Create a TypeCode, representing the CORBA <code>wstring</code>.
611 * @param bound the maximal length of the string, 0 is unlimited.
613 * @return the corresponding string typecode.
615 public abstract TypeCode create_wstring_tc(int bound);
618 * Create a typecode for an abstract interface. The abstract interface
619 * can be either CORBA object or CORBA value type.
621 * @param id the id of the abstract interface.
622 * @param name the name of the abstract interface.
624 * @return the created typecode.
626 public TypeCode create_abstract_interface_tc(String id, String name)
628 GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_abstract_interface);
629 t.setName(name);
630 t.setId(id);
631 return t;
635 * Create a typecode for a native interface.
637 * @param id the id of the native interface.
638 * @param name the name of the native interface.
640 * @return the created typecode.
642 public TypeCode create_native_tc(String id, String name)
644 GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_native);
645 t.setName(name);
646 t.setId(id);
647 return t;
651 * Create a typecode, representing a tree-like structure.
652 * This structure contains a member that is a sequence of the same type,
653 * as the structure itself. You can imagine as if the folder definition
654 * contains a variable-length array of the enclosed (nested) folder
655 * definitions. In this way, it is possible to have a tree like
656 * structure that can be transferred via CORBA CDR stream.
658 * @deprecated It is easier and clearler to use a combination of
659 * create_recursive_tc and create_sequence_tc instead.
661 * @param bound the maximal expected number of the nested components
662 * on each node; 0 if not limited.
664 * @param offset the position of the field in the returned structure
665 * that contains the sequence of the structures of the same field.
666 * The members before this field are intialised using parameterless
667 * StructMember constructor.
669 * @return a typecode, defining a stucture, where a member at the
670 * <code>offset</code> position defines an array of the identical
671 * structures.
673 * @see #create_recursive_tc(String)
674 * @see #create_sequence_tc(int, TypeCode)
676 public abstract TypeCode create_recursive_sequence_tc(int bound, int offset);
679 * Create a typecode which serves as a placeholder for typcode, containing
680 * recursion.
682 * @param id the id of the recursive typecode, for that this typecode
683 * serves as a placeholder.
685 public TypeCode create_recursive_tc(String id)
687 return new RecursiveTypeCode(id);
691 * Create value box typecode.
693 public TypeCode create_value_box_tc(String id, String name,
694 TypeCode boxed_type
697 GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_value_box);
698 t.setName(name);
699 t.setId(id);
700 t.setContentType(boxed_type);
701 return t;
705 * Create IDL value type code.
707 public TypeCode create_value_tc(String id, String name, short type_modifier,
708 TypeCode concrete_base, ValueMember[] members
711 RecordTypeCode r = new RecordTypeCode(TCKind.tk_value);
712 r.setId(id);
713 r.setName(name);
714 r.setTypeModifier(type_modifier);
715 r.setConcreteBase_type(concrete_base);
717 for (int i = 0; i < members.length; i++)
719 r.add(members [ i ]);
722 return r;
726 * This should return the information, related to the current thread.
727 * The information is needed, for instance, to get the current object
728 * from the code that serves several objects in parallel threads.
729 * The {@link Current} is very general interface, with no fields and
730 * operations defined. This method is not implemented in Suns
731 * releases at least till v1.5 inclusive. To obtain the
732 * {@link org.omg.PortableServer.Current}, use
733 * {@link #resolve_initial_references}, passing "POACurrent".
735 * @deprecated since 1.2, use {@link #resolve_initial_references}.
737 * @return never
739 * @throws NO_IMPLEMENT always.
741 public Current get_current()
743 throw new NO_IMPLEMENT();
747 * This should return the information about the CORBA facilities and
748 * services, available from this ORB. However this method is oficially
749 * documented as not implemented at least till v1.5 inclusive.
751 * @param service_type a type of the service being requested. The OMG
752 * specification currently defines only one value, 1, for security
753 * related services.
755 * @param service_info a holder, where the returned information should
756 * be stored.
758 * @return should return true if the service information is available
759 * from the ORB, but this method never returns.
761 * @throws NO_IMPLEMENT always.
763 public boolean get_service_information(short service_type,
764 ServiceInformationHolder service_info
767 throw new NO_IMPLEMENT();
771 * Get the default context of this ORB. This is an initial root of all
772 * contexts.
774 * The default method returns a new context with the empty name and
775 * no parent context.
777 * @return the default context of this ORB.
779 * @throws NO_IMPLEMENT for the Singleton ORB, returned by
780 * the parameterless {@link #init()}.
782 public abstract Context get_default_context();
785 * Return thg typecode, representing the given primitive object type.
787 * @param tcKind the kind of the primitive typecode.
789 * @return the typecode of the primitve typecode.
791 public abstract TypeCode get_primitive_tc(TCKind tcKind);
794 * Returns so-called Singleton ORB, a highly restricted version
795 * that cannot communicate over network. This ORB is provided
796 * for the potentially malicious applets with heavy security restrictions.
798 * The returned Singleton ORB can only create typecodes,
799 * {@link Any}, {@link ContextList}, {@link NVList} and
800 * {@link org.omg.CORBA.portable.OutputStream} that writes to an
801 * internal buffer.
803 * All other methods throw the {@link NO_IMPLEMENT} exception, additionally
804 * printing the error message about the potential attempt to violate
805 * the security rules.
807 * The implementing ORB class, used in this method, is found as described
808 * in the header.
810 * @return the working derivative of ORB, implementing the methods
811 * of this abstract class.
813 public static ORB init()
815 String orb_cn = getCumulatedProperty(null, RESTRICTED_ORB);
816 if (orb_cn == null)
817 return OrbRestricted.Singleton;
818 else
819 return createORB(null, orb_cn);
823 * Creates the working instance of ORB for an applet.
825 * By default the built-in fully functional ORB is returned. The ORB class
826 * is found as described in the header of this class.
828 * @param applet the applet. The property org.omg.CORBA.ORBClass,
829 * if present, defines the used ORB implementation class. If this
830 * property is not present, the ORB class is found as described in the
831 * class header.
833 * @param props the properties, may be <code>null</code>.
835 * @return a newly created functional derivative of this abstract class.
837 public static ORB init(Applet applet, Properties props)
839 String ocn = applet.getParameter(FUNCTIONAL_ORB);
840 String lp = applet.getParameter(LISTENER_PORT);
842 if (ocn==null && lp!=null)
843 ocn = DEFAULT_FOCUSED_ORB;
845 ORB orb = createORB(props, ocn);
846 orb.set_parameters(applet, props);
848 return orb;
852 * Creates the working instance of ORB for a standalone application.
854 * By default the built-in fully functional ORB is returned. The ORB class is
855 * found as described in the header of this class.
857 * @param args the parameters, passed to the applications
858 * <code>main(String[] args)</code> method, may be <code>null</code>. The
859 * parameter -org.omg.CORBA.ORBClass <class name> if present, defines the used
860 * ORB implementation class. If this property is not present, the ORB class is
861 * found as described in the class header.
863 * @param props application specific properties, may be <code>null</code>.
865 * @return a newly created functional derivative of this abstract class.
867 public static ORB init(String[] args, Properties props)
869 String ocn = null;
870 String lp = null;
872 String orbKey = "-" + FUNCTIONAL_ORB;
873 String lpKey = "-" + LISTENER_PORT;
875 if (args != null)
876 if (args.length >= 2)
878 for (int i = 0; i < args.length - 1; i++)
880 if (args[i].equals(orbKey))
881 ocn = args[i + 1];
882 if (args[i].equals(lpKey))
883 lp = args[i + 1];
887 if (lp != null && ocn == null)
888 ocn = DEFAULT_FOCUSED_ORB;
890 ORB orb = createORB(props, ocn);
892 orb.set_parameters(args, props);
893 return orb;
897 * List the initially available CORBA objects (services).
899 * @return a list of services.
901 * @see #resolve_initial_references(String)
903 public abstract String[] list_initial_services();
906 * Find and return the easily accessible CORBA object, addressed
907 * by name. The returned object is typically casted to the more
908 * specific reference using the <code>narrow(Object)</code> method
909 * of its helper. The method resolves the following string values,
910 * returning the working objects:
911 * <table border="1"><tr><th>String</th><th>Object class</th>
912 * <th>Object use</th></tr>
914 * <tr><td>NameService</td><td>{@link org.omg.CosNaming.NamingContextExt}</td>
915 * <td>Finds (usually remote) object by its name.</td></tr>
917 * <tr><td>RootPOA</td><td>{@link org.omg.PortableServer.POA}</td>
918 * <td>Holds the POA tree for this ORB, where since 1.4 all servants
919 * should be connected.</td></tr>
921 * <tr><td>RootPOAManager</td><td>{@link org.omg.PortableServer.POAManager}
922 * </td><td>Regulates (suspends/resumes) the root POA
923 * activity</td></tr>
925 * <tr><td>POACurrent</td><td>{@link org.omg.PortableServer.Current}
926 * </td><td>Informs the current thread about the Id and POA of the
927 * object being currently served (the methods of
928 * <code>Current</code> return different values for
929 * different threads).
930 * </td></tr>
932 * <tr><td>CodecFactory</td><td>{@link org.omg.IOP.Codec}</td>
933 * <td>Encodes/decodes IDL data types into/from byte arrays.</td>
934 * </tr>
936 * <tr><td>DynAnyFactory</td><td>{@link org.omg.DynamicAny.DynAnyFactory}</td>
937 * <td>Creates DynAny's.</td>
938 * </tr>
940 * <tr><td>PICurrent</td><td>{@link org.omg.PortableInterceptor.Current}</td>
941 * <td>Contains multiple slots where an interceptor can rememeber the
942 * request - specific values between subsequent
943 * calls of the interceptor methods.</td>
944 * </tr>
946 * </table>
948 * @param name the object name.
949 * @return the object
950 * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name
951 * is not associated with the known object.
953 public abstract Object resolve_initial_references(String name)
954 throws org.omg.CORBA.ORBPackage.InvalidName;
957 * Get the IOR reference string for the given object.
958 * IOR can be compared with the Internet address for a web page,
959 * it provides means to locate the CORBA service on the web.
960 * IOR contains the host address, port number, the object identifier
961 * (key) inside the server, the communication protocol version,
962 * supported charsets and so on.
964 * @param forObject the CORBA object
965 * @return the object IOR representation.
966 * @see #string_to_object(String)
968 public abstract String object_to_string(Object forObject);
971 * This should perform the implementation dependent unit of work in the
972 * main thread.
974 * This method is part of the support for the distribute use of the
975 * single execution thread.
977 * Same as in Suns releases at least till 1.4 inclusive,
978 * the distribute use of the single thread is not implemented.
979 * Use multiple threads, provided by jre.
981 * The method returns without action.
983 public void perform_work()
988 * Checks if the ORB needs the main thread to perform some work.
989 * The method should return true if the ORB needs the main thread,
990 * and false if it does not.
992 * This method is part of the support for the distribute use of the
993 * single execution thread.
995 * Same as in Suns releases at least till 1.4 inclusive,
996 * the distributed use of the single thread is not implemented.
997 * Use multiple threads, provided by jre.
999 * @return false, always.
1001 public boolean work_pending()
1003 return false;
1007 * <p>Find and return the CORBA object, addressed by the given
1008 * string representation. The object can be (an usually is)
1009 * located on a remote computer, possibly running a different
1010 * (not necessary java) CORBA implementation. The returned
1011 * object is typically casted to the more specific reference
1012 * using the <code>narrow(Object)</code> method of its helper.
1013 * </p><p>
1014 * This function supports the following input formats:<br>
1015 * 1. IOR reference (<b>ior:</b>nnnnn ..), usually computer generated.<br>
1016 * 2. <b>corbaloc:</b>[<b>iiop</b>][version.subversion<b>@</b>]<b>:</b>host[<b>:</b>port]<b>/</b><i>key</i>
1017 * defines similar information as IOR reference, but is more human readable.
1018 * This type of reference may also contain multiple addresses (see
1019 * OMG documentation for complete format).<br>
1020 * 3. <b>corbaloc:rir:/</b><i>name</i> defines internal reference on this
1021 * ORB that is resolved using {@link #resolve_initial_references}, passing
1022 * the given <i>name</i> as parameter.<br>
1023 * 4. <b>corbaname:rir:#</b><i>name</i> states that the given <i>name</i>
1024 * must be resolved using the naming service, default for this ORB.<br>
1025 * 5. <b>corbaname:</b>[<b>iiop</b>][version.subversion<b>@</b>]<b>:</b>host[<b>:</b>port]<b>#</b><i>name</i>
1026 * states that the <i>name</i> must be resolved using the naming service
1027 * that runs on the given host at the given port. The ORB expects to find
1028 * there the {@link org.omg.CosNaming.NamingContext} under the key
1029 * "NameService.<br>
1030 * 7. file://[file name] Read the object definition string from the
1031 * file system<br>
1032 * 8. http://[url] Read the object definition string from the provided
1033 * url.<br>
1034 * 9. ftp://[url] Read the object definition string from the provided
1035 * url.<br>
1037 * <p>The default port is always 2809. The default iiop version is 1.0
1038 * that now may not always be supported, so we would recommend to specify
1039 * the version explicitly.</p>
1040 * <p>
1041 * The examples of the corbaloc and corbaname addresses:<br>
1042 * corbaname:rir:#xobj - ask local naming service for "xobj".<br>
1043 * corbaname:rir:/NameService#xobj - same (long form).<br>
1044 * corbaname:iiop:1.2@localhost:900#xobj - same, assuming that the naming
1045 * service runs at port 900 on the local host and supports iiop 1.2.<br>
1046 * corbaname:iiop:localhost#xobj - same, assuming that the naming
1047 * service runs at port 2809 on the local host and supports iiop 1.0.<br>
1048 * corbaloc::gnu.xxx.yy/Prod/TradingService - the object exists on the
1049 * host gnu.xxx.yy, port 2809 having the key "Prod/TradingService". Its ORB
1050 * supports iiop 1.0.<br>
1051 * corbaloc::gnu.xxx.yy/Prod/TradingService:801 - the object exists on the
1052 * host gnu.xxx.yy, port 801 having the key "Prod/TradingService". Its ORB
1053 * supports iiop 1.0 (iiop keyword ommitted).<br>
1054 * corbaloc:iiop:1.1@gnu.xxx.yy/Prod/TradingService - the object exists on the
1055 * host gnu.xxx.yy, port 801 having the key "Prod/TradingService". Its ORB
1056 * supports iiop 1.1.<br>
1057 * corbaloc:rir:/NameService - the default naming service.
1059 * @param IOR the object IOR representation string.
1061 * @return the found CORBA object.
1063 * @throws BAD_PARAM if the string being parsed is invalid.
1064 * @throws DATA_CONVERSION if the string being parsed contains unsupported
1065 * prefix or protocol.
1067 * @see #object_to_string(org.omg.CORBA.Object)
1069 public abstract Object string_to_object(String IOR);
1072 * Start listening on the input socket. This method
1073 * blocks the current thread until {@link #shutdown(boolean)}
1074 * is called and shutdown process is completed.
1076 public void run()
1081 * Shutdown the ORB server.
1083 * @param wait_for_completion if true, the current thread is
1084 * suspended untile the shutdown process is complete.
1086 public void shutdown(boolean wait_for_completion)
1091 * Destroy this server, releasing the occupied resources.
1092 * The default method returns without action.
1094 public void destroy()
1099 * Set the ORB parameters. This method is normally called from
1100 * {@link #init(String[], Properties)}.
1102 * @param para the parameters, that were passed as the parameters
1103 * to the <code>main(String[] args)</code> method of the current standalone
1104 * application.
1106 * @param props application specific properties that were passed
1107 * as a second parameter in {@link #init(String[], Properties)}).
1108 * Can be <code>null</code>.
1110 protected abstract void set_parameters(String[] para, Properties props);
1113 * Set the ORB parameters. This method is normally called from
1114 * {@link #init(Applet, Properties)}.
1116 * @param app the current applet.
1118 * @param props application specific properties, passed as the second
1119 * parameter in {@link #init(Applet, Properties)}.
1120 * Can be <code>null</code>.
1122 protected abstract void set_parameters(Applet app, Properties props);
1125 * Get the property with the given name, searching in the standard
1126 * places for the ORB properties.
1128 private static String getCumulatedProperty(Properties props, String property)
1130 String orb_cn = null;
1132 if (props != null)
1133 orb_cn = props.getProperty(property, null);
1135 if (orb_cn == null)
1136 orb_cn = System.getProperty(property, null);
1138 if (orb_cn == null)
1139 orb_cn = checkFile(property, "user.home", null);
1141 if (orb_cn == null)
1142 orb_cn = checkFile(property, "java.home", "lib");
1144 return orb_cn;
1148 * Check if the property is defined in the existsting file orb.properties.
1150 * @param property the property
1151 * @param dir the system property, defining the folder where the
1152 * file could be expected.
1153 * @param subdir subfolder where to look for the file.
1155 * @return the property value, null if not found or file does not exist.
1157 private static String checkFile(String property, String dir, String subdir)
1161 File f = new File(dir);
1162 if (!f.exists())
1163 return null;
1165 if (subdir != null)
1166 f = new File(f, subdir);
1168 f = new File(f, "orb.properties");
1170 if (!f.exists())
1171 return null;
1173 Properties p = new Properties();
1174 p.load(new BufferedInputStream(new FileInputStream(f)));
1176 return p.getProperty(property, null);
1178 catch (IOException ex)
1180 return null;
1185 * Create ORB when its name is possibly known.
1187 * @param props properties, possibly containing the ORB name.
1188 * @param orbClassName the direct ORB class name, overriding other possible
1189 * locations, or null if not specified.
1191 private static ORB createORB(Properties props, String orbClassName)
1193 ORB orb = null;
1195 if (orbClassName == null)
1197 orbClassName = getCumulatedProperty(props, FUNCTIONAL_ORB);
1199 if (orbClassName == null)
1201 String lp = getCumulatedProperty(props, LISTENER_PORT);
1202 if (lp != null)
1203 orbClassName = DEFAULT_FOCUSED_ORB;
1204 else
1205 orbClassName = DEFAULT_FUNCTIONAL_ORB;
1211 orb = (ORB) ObjectCreator.forName(orbClassName).newInstance();
1213 catch (ClassNotFoundException ex)
1215 noORB(orbClassName, ex);
1217 catch (IllegalAccessException ex)
1219 noORB(orbClassName, ex);
1221 catch (InstantiationException ex)
1223 noORB(orbClassName, ex);
1226 return orb;
1230 * Throw the runtime exception.
1232 * @param orb_c the ORB class name.
1233 * @param why the explaining chained exception.
1235 private static void noORB(String orb_c, Throwable why)
1237 throw new RuntimeException("The ORB " + orb_c + " cannot be instantiated.",