38 |
|
|
39 |
package org.omg.CORBA; |
package org.omg.CORBA; |
40 |
|
|
41 |
import gnu.CORBA.Restricted_ORB; |
import gnu.CORBA.OrbFocused; |
42 |
import gnu.CORBA.fixedTypeCode; |
import gnu.CORBA.ObjectCreator; |
43 |
import gnu.CORBA.generalTypeCode; |
import gnu.CORBA.OrbRestricted; |
44 |
import gnu.CORBA.gnuContext; |
import gnu.CORBA.gnuContext; |
45 |
import gnu.CORBA.primitiveTypeCode; |
import gnu.CORBA.typecodes.FixedTypeCode; |
46 |
import gnu.CORBA.recordTypeCode; |
import gnu.CORBA.typecodes.GeneralTypeCode; |
47 |
import gnu.CORBA.recursiveTypeCode; |
import gnu.CORBA.typecodes.PrimitiveTypeCode; |
48 |
|
import gnu.CORBA.typecodes.RecordTypeCode; |
49 |
|
import gnu.CORBA.typecodes.RecursiveTypeCode; |
50 |
|
|
51 |
import org.omg.CORBA.ORBPackage.InconsistentTypeCode; |
import org.omg.CORBA.ORBPackage.InconsistentTypeCode; |
52 |
|
|
60 |
import java.util.Properties; |
import java.util.Properties; |
61 |
|
|
62 |
/** |
/** |
63 |
* A central class in CORBA implementation, responsible for sending and |
* A central class in CORBA implementation, responsible for sending and handling |
64 |
* handling remote invocations. ORB also works as a factory for |
* remote invocations. ORB also works as a factory for creating instances of |
65 |
* creating instances of certain CORBA classes. |
* certain CORBA classes. |
66 |
* |
* |
67 |
* Despite the core library contains the fully working CORBA implementation, |
* Despite the core library contains the fully working CORBA implementation, it |
68 |
* it also provides a simple way to plug-in the alternative CORBA support. |
* also provides a simple way to plug-in the alternative CORBA support. This is |
69 |
* This is done by replacing the ORB. The alternative ORB can be specified |
* done by replacing the ORB. The alternative ORB can be specified via |
70 |
* via properties, passed to ORB.Init(...). |
* properties, passed to ORB.Init(...). |
71 |
* |
* |
72 |
* When creating an ORB instance, the class name |
* When creating an ORB instance, the class name is searched in the following |
73 |
* is searched in the following locations: |
* locations: |
74 |
* <p> |
* <p> |
75 |
* 1. Applet parameter or application string array, if any.<br> |
* 1. Applet parameter or application string array, if any.<br> |
76 |
* 2. The properties parameter, if any.<br> |
* 2. The properties parameter, if any.<br> |
78 |
* 4. The orb.properties file located in the user.home directory (if any).<br> |
* 4. The orb.properties file located in the user.home directory (if any).<br> |
79 |
* 5. The orb.properties file located in the java.home/lib directory (if any). |
* 5. The orb.properties file located in the java.home/lib directory (if any). |
80 |
* </p> |
* </p> |
81 |
* |
* |
82 |
* The supported properties are: |
* The supported properties are: <table border="1"> |
83 |
* <table border="1"> |
* <tr> |
84 |
* <tr><td> org.omg.CORBA.ORBClass</td><td>The class, |
* <td> org.omg.CORBA.ORBClass</td> |
85 |
* implementing the functional ORB, returned by |
* <td>The class, implementing the functional ORB, returned by |
86 |
* {@link #init(Applet, Properties)} or |
* {@link #init(Applet, Properties)} or {@link #init(String[], Properties)} |
87 |
* {@link #init(String[], Properties)} </td></tr> |
* </td> |
88 |
* <tr><td>org.omg.CORBA.ORBSingletonClass</td><td>The class, |
* </tr> |
89 |
* implementing the restricted ORB, returned by |
* <tr> |
90 |
* {@link #init()}. |
* <td>org.omg.CORBA.ORBSingletonClass</td> |
91 |
* </td></tr> |
* <td>The class, implementing the restricted ORB, returned by {@link #init()}. |
92 |
* <tr><td>org.omg.CORBA.ORBInitRef</td><td>Specifies the |
* </td> |
93 |
* initial reference, accessible by name with the method |
* </tr> |
94 |
* {@link #resolve_initial_references(String)}. |
* <tr> |
95 |
* </table> |
* <td>org.omg.CORBA.ORBInitRef</td> |
96 |
* The command line accepts the same properties as a keys. When specifying |
* <td>Specifies the initial reference, accessible by name with the method |
97 |
* in the command line, the prefix org.omg.CORBA can be omitted, |
* {@link #resolve_initial_references(String)}.</td> |
98 |
* for instance<code> -ORBInitRef NameService=IOR:aabbccdd....</code> |
* </tr> |
99 |
* |
* <tr> |
100 |
|
* <td>gnu.CORBA.ListenerPort</td> |
101 |
|
* <td>Specifies that this ORB should serve all its objects on a single port |
102 |
|
* (for example, "1234") or on a specified port range (for example, |
103 |
|
* "1100-1108"). The property is used when working with firewals and serves as a |
104 |
|
* replacement for the proprietary properties like com.ibm.CORBA.ListenerPort |
105 |
|
* or com.sun.CORBA.POA.ORBPersistentServerPort. The specified port or range |
106 |
|
* should not overlap with the values, specified for other ORB's. |
107 |
|
* </td> |
108 |
|
* </tr> |
109 |
|
* <tr> |
110 |
|
* <td>gnu.Corba.SocketFactory</td> |
111 |
|
* <td>Sets the user-defined server and client socket factory for the ORB being |
112 |
|
* currently instantiated. Serves as a replacement of the proprietary |
113 |
|
* property com.sun.CORBA.connection.ORBSocketFactoryClass. To have multiple |
114 |
|
* types of sockets, instantiate several ORB's with this property each time |
115 |
|
* set to the different value. |
116 |
|
* The factory must implement gnu.CORBA.interfaces.SocketFactory. |
117 |
|
* </td> |
118 |
|
* </tr> |
119 |
|
* </table> |
120 |
|
* <p>The command line accepts the same properties as a keys. When |
121 |
|
* specifying in the command line, the prefix org.omg.CORBA can be omitted, for |
122 |
|
* instance<code> -ORBInitRef NameService=IOR:aabbccdd....</code> |
123 |
|
* </p> |
124 |
|
* |
125 |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
126 |
*/ |
*/ |
127 |
public abstract class ORB |
public abstract class ORB |
141 |
*/ |
*/ |
142 |
private static final String RESTRICTED_ORB = |
private static final String RESTRICTED_ORB = |
143 |
"org.omg.CORBA.ORBSingletonClass"; |
"org.omg.CORBA.ORBSingletonClass"; |
144 |
|
|
145 |
|
private static final String LISTENER_PORT = |
146 |
|
OrbFocused.LISTENER_PORT; |
147 |
|
|
148 |
/** |
/** |
149 |
* The class, implementing the default fully functional ORB. |
* The class, implementing the default fully functional ORB. |
150 |
*/ |
*/ |
151 |
private static final String DEFAULT_FUNCTIONAL_ORB = |
private static final String DEFAULT_FUNCTIONAL_ORB = |
152 |
gnu.CORBA.Poa.ORB_1_4.class.getName(); |
gnu.CORBA.Poa.ORB_1_4.class.getName(); |
153 |
|
|
154 |
/** |
private static final String DEFAULT_FOCUSED_ORB = |
155 |
* The class, implementing the default restricted ORB. |
gnu.CORBA.OrbFocused.class.getName(); |
156 |
*/ |
|
157 |
private static final String DEFAULT_RESTRICTED_ORB = |
// There is no need for name of the default restricted ORB as it is |
158 |
gnu.CORBA.Restricted_ORB.class.getName(); |
// singleton and it is more effectively referred directly. |
159 |
|
|
160 |
/** |
/** |
161 |
* Connect the given CORBA object to this ORB. After the object is |
* Connect the given CORBA object to this ORB. After the object is |
221 |
*/ |
*/ |
222 |
public TypeCode create_recursive_sequence_tc(int bound, int offset) |
public TypeCode create_recursive_sequence_tc(int bound, int offset) |
223 |
{ |
{ |
224 |
recordTypeCode r = new recordTypeCode(TCKind.tk_struct); |
RecordTypeCode r = new RecordTypeCode(TCKind.tk_struct); |
225 |
for (int i = 0; i < offset; i++) |
for (int i = 0; i < offset; i++) |
226 |
r.add(new StructMember()); |
r.add(new StructMember()); |
227 |
|
|
228 |
TypeCode recurs = new primitiveTypeCode(TCKind.tk_sequence); |
TypeCode recurs = new PrimitiveTypeCode(TCKind.tk_sequence); |
229 |
|
|
230 |
r.add(new StructMember("", recurs, null)); |
r.add(new StructMember("", recurs, null)); |
231 |
return r; |
return r; |
427 |
*/ |
*/ |
428 |
public TypeCode create_fixed_tc(short digits, short scale) |
public TypeCode create_fixed_tc(short digits, short scale) |
429 |
{ |
{ |
430 |
fixedTypeCode r = new fixedTypeCode(); |
FixedTypeCode r = new FixedTypeCode(); |
431 |
r.setDigits(digits); |
r.setDigits(digits); |
432 |
r.setScale(scale); |
r.setScale(scale); |
433 |
return r; |
return r; |
647 |
*/ |
*/ |
648 |
public TypeCode create_abstract_interface_tc(String id, String name) |
public TypeCode create_abstract_interface_tc(String id, String name) |
649 |
{ |
{ |
650 |
generalTypeCode t = new generalTypeCode(TCKind.tk_abstract_interface); |
GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_abstract_interface); |
651 |
t.setName(name); |
t.setName(name); |
652 |
t.setId(id); |
t.setId(id); |
653 |
return t; |
return t; |
663 |
*/ |
*/ |
664 |
public TypeCode create_native_tc(String id, String name) |
public TypeCode create_native_tc(String id, String name) |
665 |
{ |
{ |
666 |
generalTypeCode t = new generalTypeCode(TCKind.tk_native); |
GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_native); |
667 |
t.setName(name); |
t.setName(name); |
668 |
t.setId(id); |
t.setId(id); |
669 |
return t; |
return t; |
679 |
*/ |
*/ |
680 |
public TypeCode create_recursive_tc(String id) |
public TypeCode create_recursive_tc(String id) |
681 |
{ |
{ |
682 |
return new recursiveTypeCode(id); |
return new RecursiveTypeCode(id); |
683 |
} |
} |
684 |
|
|
685 |
/** |
/** |
689 |
TypeCode boxed_type |
TypeCode boxed_type |
690 |
) |
) |
691 |
{ |
{ |
692 |
generalTypeCode t = new generalTypeCode(TCKind.tk_value_box); |
GeneralTypeCode t = new GeneralTypeCode(TCKind.tk_value_box); |
693 |
t.setName(name); |
t.setName(name); |
694 |
t.setId(id); |
t.setId(id); |
695 |
t.setContentType(boxed_type); |
t.setContentType(boxed_type); |
703 |
TypeCode concrete_base, ValueMember[] members |
TypeCode concrete_base, ValueMember[] members |
704 |
) |
) |
705 |
{ |
{ |
706 |
recordTypeCode r = new recordTypeCode(TCKind.tk_value); |
RecordTypeCode r = new RecordTypeCode(TCKind.tk_value); |
707 |
r.setId(id); |
r.setId(id); |
708 |
r.setName(name); |
r.setName(name); |
709 |
r.setTypeModifier(type_modifier); |
r.setTypeModifier(type_modifier); |
810 |
*/ |
*/ |
811 |
public static ORB init() |
public static ORB init() |
812 |
{ |
{ |
813 |
String orb_cn = getORBName(null, RESTRICTED_ORB); |
String orb_cn = getCumulatedProperty(null, RESTRICTED_ORB); |
814 |
if (orb_cn == null) |
if (orb_cn == null) |
815 |
return Restricted_ORB.Singleton; |
return OrbRestricted.Singleton; |
816 |
else |
else |
817 |
return createORB(null, orb_cn); |
return createORB(null, orb_cn); |
818 |
} |
} |
835 |
public static ORB init(Applet applet, Properties props) |
public static ORB init(Applet applet, Properties props) |
836 |
{ |
{ |
837 |
String ocn = applet.getParameter(FUNCTIONAL_ORB); |
String ocn = applet.getParameter(FUNCTIONAL_ORB); |
838 |
|
String lp = applet.getParameter(LISTENER_PORT); |
839 |
|
|
840 |
|
if (ocn==null && lp!=null) |
841 |
|
ocn = DEFAULT_FOCUSED_ORB; |
842 |
|
|
843 |
ORB orb = createORB(props, ocn); |
ORB orb = createORB(props, ocn); |
844 |
orb.set_parameters(applet, props); |
orb.set_parameters(applet, props); |
845 |
|
|
847 |
} |
} |
848 |
|
|
849 |
/** |
/** |
850 |
* Creates the working instance of ORB for a |
* Creates the working instance of ORB for a standalone application. |
851 |
* standalone application. |
* |
852 |
* |
* By default the built-in fully functional ORB is returned. The ORB class is |
853 |
* By default the built-in fully functional ORB is returned. The ORB class |
* found as described in the header of this class. |
854 |
* is found as described in the header of this class. |
* |
|
* |
|
855 |
* @param args the parameters, passed to the applications |
* @param args the parameters, passed to the applications |
856 |
* <code>main(String[] args)</code> method, may be <code>null</code>. |
* <code>main(String[] args)</code> method, may be <code>null</code>. The |
857 |
* The parameter -org.omg.CORBA.ORBClass <class name> |
* parameter -org.omg.CORBA.ORBClass <class name> if present, defines the used |
858 |
* if present, defines the used ORB implementation class. If this |
* ORB implementation class. If this property is not present, the ORB class is |
859 |
* property is not present, the ORB class is found as described in the |
* found as described in the class header. |
860 |
* class header. |
* |
|
|
|
|
* |
|
861 |
* @param props application specific properties, may be <code>null</code>. |
* @param props application specific properties, may be <code>null</code>. |
862 |
* |
* |
863 |
* @return a newly created functional derivative of this abstract class. |
* @return a newly created functional derivative of this abstract class. |
864 |
*/ |
*/ |
865 |
public static ORB init(String[] args, Properties props) |
public static ORB init(String[] args, Properties props) |
866 |
{ |
{ |
867 |
String ocn = null; |
String ocn = null; |
868 |
|
String lp = null; |
869 |
|
|
870 |
String orbKey = "-" + FUNCTIONAL_ORB; |
String orbKey = "-" + FUNCTIONAL_ORB; |
871 |
|
String lpKey = "-" + LISTENER_PORT; |
872 |
|
|
873 |
if (args != null) |
if (args != null) |
874 |
if (args.length >= 2) |
if (args.length >= 2) |
875 |
{ |
{ |
876 |
for (int i = 0; i < args.length - 1; i++) |
for (int i = 0; i < args.length - 1; i++) |
877 |
{ |
{ |
878 |
if (args [ i ].equals(orbKey)) |
if (args[i].equals(orbKey)) |
879 |
ocn = args [ i + 1 ]; |
ocn = args[i + 1]; |
880 |
|
if (args[i].equals(lpKey)) |
881 |
|
lp = args[i + 1]; |
882 |
} |
} |
883 |
} |
} |
884 |
|
|
885 |
|
if (lp != null && ocn == null) |
886 |
|
ocn = DEFAULT_FOCUSED_ORB; |
887 |
|
|
888 |
ORB orb = createORB(props, ocn); |
ORB orb = createORB(props, ocn); |
889 |
|
|
890 |
orb.set_parameters(args, props); |
orb.set_parameters(args, props); |
893 |
|
|
894 |
/** |
/** |
895 |
* List the initially available CORBA objects (services). |
* List the initially available CORBA objects (services). |
896 |
* |
* |
897 |
* @return a list of services. |
* @return a list of services. |
898 |
* |
* |
899 |
* @see #resolve_initial_references(String) |
* @see #resolve_initial_references(String) |
900 |
*/ |
*/ |
901 |
public abstract String[] list_initial_services(); |
public abstract String[] list_initial_services(); |
1114 |
protected abstract void set_parameters(Applet app, Properties props); |
protected abstract void set_parameters(Applet app, Properties props); |
1115 |
|
|
1116 |
/** |
/** |
1117 |
* Checks if the communication over network is allowed. |
* Get the property with the given name, searching in the standard |
1118 |
* @throws java.lang.SecurityException |
* places for the ORB properties. |
1119 |
*/ |
*/ |
1120 |
private static final void checkNetworkingPermission(String host, int port) |
private static String getCumulatedProperty(Properties props, String property) |
|
throws SecurityException |
|
|
{ |
|
|
SecurityManager security = System.getSecurityManager(); |
|
|
if (security != null) |
|
|
{ |
|
|
security.checkConnect(host, port); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get the ORB class name. |
|
|
*/ |
|
|
private static String getORBName(Properties props, String property) |
|
1121 |
{ |
{ |
1122 |
String orb_cn = null; |
String orb_cn = null; |
1123 |
|
|
1132 |
|
|
1133 |
if (orb_cn == null) |
if (orb_cn == null) |
1134 |
orb_cn = checkFile(property, "java.home", "lib"); |
orb_cn = checkFile(property, "java.home", "lib"); |
1135 |
|
|
1136 |
return orb_cn; |
return orb_cn; |
1137 |
} |
} |
1138 |
|
|
1175 |
|
|
1176 |
/** |
/** |
1177 |
* Create ORB when its name is possibly known. |
* Create ORB when its name is possibly known. |
1178 |
* |
* |
1179 |
* @param props properties, possibly containing the ORB name. |
* @param props properties, possibly containing the ORB name. |
1180 |
* @param orbClassName the direct ORB class name, overriding |
* @param orbClassName the direct ORB class name, overriding other possible |
1181 |
* other possible locations, or null if not specified. |
* locations, or null if not specified. |
1182 |
*/ |
*/ |
1183 |
private static ORB createORB(Properties props, String orbClassName) |
private static ORB createORB(Properties props, String orbClassName) |
1184 |
{ |
{ |
1186 |
|
|
1187 |
if (orbClassName == null) |
if (orbClassName == null) |
1188 |
{ |
{ |
1189 |
orbClassName = getORBName(props, FUNCTIONAL_ORB); |
orbClassName = getCumulatedProperty(props, FUNCTIONAL_ORB); |
1190 |
|
|
1191 |
if (orbClassName == null) |
if (orbClassName == null) |
1192 |
orbClassName = DEFAULT_FUNCTIONAL_ORB; |
{ |
1193 |
|
String lp = getCumulatedProperty(props, LISTENER_PORT); |
1194 |
|
if (lp != null) |
1195 |
|
orbClassName = DEFAULT_FOCUSED_ORB; |
1196 |
|
else |
1197 |
|
orbClassName = DEFAULT_FUNCTIONAL_ORB; |
1198 |
|
} |
1199 |
} |
} |
1200 |
|
|
1201 |
try |
try |
1202 |
{ |
{ |
1203 |
orb = (ORB) Class.forName(orbClassName).newInstance(); |
orb = (ORB) ObjectCreator.forName(orbClassName).newInstance(); |
1204 |
} |
} |
1205 |
catch (ClassNotFoundException ex) |
catch (ClassNotFoundException ex) |
1206 |
{ |
{ |