1. /*
  2. * @(#)ORBSingleton.java 1.38 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.corba;
  16. import java.util.Collection;
  17. import java.util.Properties;
  18. import java.util.Hashtable;
  19. import java.applet.Applet;
  20. import java.net.URL;
  21. import org.omg.CORBA.CompletionStatus;
  22. import org.omg.CORBA.Context;
  23. import org.omg.CORBA.ContextList;
  24. import org.omg.CORBA.Environment;
  25. import org.omg.CORBA.ExceptionList;
  26. import org.omg.CORBA.ORBPackage.InvalidName;
  27. import org.omg.CORBA.NVList;
  28. import org.omg.CORBA.TCKind;
  29. import org.omg.CORBA.NamedValue;
  30. import org.omg.CORBA.ORB;
  31. import org.omg.CORBA.Object;
  32. import org.omg.CORBA.Request;
  33. import org.omg.CORBA.TypeCode;
  34. import org.omg.CORBA.Any;
  35. import org.omg.CORBA.StructMember;
  36. import org.omg.CORBA.UnionMember;
  37. import org.omg.CORBA.ValueMember;
  38. import org.omg.CORBA.NO_IMPLEMENT;
  39. import org.omg.CORBA.portable.OutputStream;
  40. import com.sun.corba.se.connection.ORBSocketFactory;
  41. import com.sun.corba.se.internal.core.ClientGIOP;
  42. import com.sun.corba.se.internal.core.MarshalInputStream;
  43. import com.sun.corba.se.internal.core.MarshalOutputStream;
  44. import com.sun.corba.se.internal.core.ORBVersion;
  45. import com.sun.corba.se.internal.core.ORBVersionFactory;
  46. import com.sun.corba.se.internal.core.ServerGIOP;
  47. import com.sun.corba.se.internal.core.ServiceContextRegistry;
  48. import com.sun.corba.se.internal.core.SubcontractRegistry;
  49. import com.sun.corba.se.internal.core.CodeSetComponentInfo;
  50. import com.sun.corba.se.internal.core.IOR;
  51. import com.sun.corba.se.internal.core.EndPoint;
  52. import com.sun.corba.se.internal.core.GIOPVersion;
  53. import com.sun.corba.se.internal.iiop.BufferManagerFactory;
  54. import com.sun.corba.se.internal.orbutil.ORBConstants;
  55. import com.sun.corba.se.internal.POA.POAORB;
  56. /*
  57. * The restricted singleton ORB implementation.
  58. *
  59. * For now, this class must implement just enough functionality to be
  60. * used as a factory for immutable TypeCode instances.
  61. *
  62. * See ORB.java for the real ORB implementation.
  63. */
  64. public class ORBSingleton
  65. // This was changed from extending core.ORB so that it can
  66. // work for read_Object.
  67. extends com.sun.corba.se.internal.corba.ORB
  68. implements TypeCodeFactory
  69. {
  70. // GIOP Version
  71. // Default is 1.0. We will change it to 1.2 later.
  72. protected GIOPVersion giopVersion = GIOPVersion.DEFAULT_VERSION;
  73. // This map is needed for resolving recursive type code placeholders
  74. // based on the unique repository id.
  75. // _REVISIT_ No garbage collection. For Java2 use WeakHashMap.
  76. private Hashtable typeCodeMap = null;
  77. // This is used to support read_Object.
  78. private static POAORB fullORB;
  79. protected void set_parameters(Applet app, Properties props) {
  80. }
  81. protected void set_parameters (String params[], Properties props) {
  82. }
  83. /*
  84. * We must support these methods to act as a TypeCode factory.
  85. */
  86. public OutputStream create_output_stream() {
  87. return new EncapsOutputStream(this);
  88. }
  89. public TypeCode get_primitive_tc(TCKind tcKind) {
  90. // _REVISIT_ if this returns a null, throw an exception perhaps?
  91. return TypeCodeImpl.get_primitive_tc(tcKind);
  92. }
  93. public TypeCode create_struct_tc(String id,
  94. String name,
  95. StructMember[] members)
  96. {
  97. return new TypeCodeImpl(this, TCKind._tk_struct, id, name, members);
  98. }
  99. public TypeCode create_union_tc(String id,
  100. String name,
  101. TypeCode discriminator_type,
  102. UnionMember[] members)
  103. {
  104. return new TypeCodeImpl(this,
  105. TCKind._tk_union,
  106. id,
  107. name,
  108. discriminator_type,
  109. members);
  110. }
  111. public TypeCode create_enum_tc(String id,
  112. String name,
  113. String[] members)
  114. {
  115. return new TypeCodeImpl(this, TCKind._tk_enum, id, name, members);
  116. }
  117. public TypeCode create_alias_tc(String id,
  118. String name,
  119. TypeCode original_type)
  120. {
  121. return new TypeCodeImpl(this, TCKind._tk_alias, id, name, original_type);
  122. }
  123. public TypeCode create_exception_tc(String id,
  124. String name,
  125. StructMember[] members)
  126. {
  127. return new TypeCodeImpl(this, TCKind._tk_except, id, name, members);
  128. }
  129. public TypeCode create_interface_tc(String id,
  130. String name)
  131. {
  132. return new TypeCodeImpl(this, TCKind._tk_objref, id, name);
  133. }
  134. public TypeCode create_string_tc(int bound) {
  135. return new TypeCodeImpl(this, TCKind._tk_string, bound);
  136. }
  137. public TypeCode create_wstring_tc(int bound) {
  138. return new TypeCodeImpl(this, TCKind._tk_wstring, bound);
  139. }
  140. public TypeCode create_sequence_tc(int bound,
  141. TypeCode element_type)
  142. {
  143. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, element_type);
  144. }
  145. public TypeCode create_recursive_sequence_tc(int bound,
  146. int offset)
  147. {
  148. return new TypeCodeImpl(this, TCKind._tk_sequence, bound, offset);
  149. }
  150. public TypeCode create_array_tc(int length,
  151. TypeCode element_type)
  152. {
  153. return new TypeCodeImpl(this, TCKind._tk_array, length, element_type);
  154. }
  155. public org.omg.CORBA.TypeCode create_native_tc(String id,
  156. String name)
  157. {
  158. return new TypeCodeImpl(this, TCKind._tk_native, id, name);
  159. }
  160. public org.omg.CORBA.TypeCode create_abstract_interface_tc(
  161. String id,
  162. String name)
  163. {
  164. return new TypeCodeImpl(this, TCKind._tk_abstract_interface, id, name);
  165. }
  166. public org.omg.CORBA.TypeCode create_fixed_tc(short digits, short scale)
  167. {
  168. return new TypeCodeImpl(this, TCKind._tk_fixed, digits, scale);
  169. }
  170. // orbos 98-01-18: Objects By Value -- begin
  171. public org.omg.CORBA.TypeCode create_value_tc(String id,
  172. String name,
  173. short type_modifier,
  174. TypeCode concrete_base,
  175. ValueMember[] members)
  176. {
  177. return new TypeCodeImpl(this, TCKind._tk_value, id, name,
  178. type_modifier, concrete_base, members);
  179. }
  180. public org.omg.CORBA.TypeCode create_recursive_tc(String id) {
  181. return new TypeCodeImpl(this, id);
  182. }
  183. public org.omg.CORBA.TypeCode create_value_box_tc(String id,
  184. String name,
  185. TypeCode boxed_type)
  186. {
  187. return new TypeCodeImpl(this, TCKind._tk_value_box, id, name, boxed_type);
  188. }
  189. public Any create_any() {
  190. return new AnyImpl(this);
  191. }
  192. // TypeCodeFactory interface methods.
  193. // Keeping track of type codes by repository id.
  194. public void setTypeCode(String id, TypeCodeImpl code) {
  195. if (typeCodeMap == null)
  196. typeCodeMap = new Hashtable(64);
  197. typeCodeMap.put(id, code);
  198. }
  199. public TypeCodeImpl getTypeCode(String id) {
  200. if (typeCodeMap == null)
  201. return null;
  202. return (TypeCodeImpl)typeCodeMap.get(id);
  203. }
  204. /*
  205. * Not strictly needed for TypeCode factory duty but these seem
  206. * harmless enough.
  207. */
  208. public NVList create_list(int count) {
  209. return new NVListImpl(this, count);
  210. }
  211. public org.omg.CORBA.NVList
  212. create_operation_list(org.omg.CORBA.Object oper) {
  213. throw new NO_IMPLEMENT();
  214. }
  215. public org.omg.CORBA.NamedValue
  216. create_named_value(String s, Any any, int flags) {
  217. return new NamedValueImpl(this, s, any, flags);
  218. }
  219. public org.omg.CORBA.ExceptionList create_exception_list() {
  220. return new ExceptionListImpl();
  221. }
  222. public org.omg.CORBA.ContextList create_context_list() {
  223. return new ContextListImpl(this);
  224. }
  225. public org.omg.CORBA.Context get_default_context() {
  226. throw new NO_IMPLEMENT();
  227. }
  228. public org.omg.CORBA.Environment create_environment() {
  229. return new EnvironmentImpl();
  230. }
  231. public org.omg.CORBA.Current get_current() {
  232. throw new NO_IMPLEMENT();
  233. }
  234. /*
  235. * Things that aren't allowed.
  236. */
  237. public String[] list_initial_services () {
  238. throw new NO_IMPLEMENT();
  239. }
  240. public org.omg.CORBA.Object resolve_initial_references(String identifier)
  241. throws InvalidName
  242. {
  243. throw new NO_IMPLEMENT();
  244. }
  245. public void register_initial_reference(
  246. String id, org.omg.CORBA.Object obj ) throws InvalidName
  247. {
  248. throw new NO_IMPLEMENT();
  249. }
  250. public void send_multiple_requests_oneway(Request[] req) {
  251. throw new SecurityException("ORBSingleton: access denied");
  252. }
  253. public void send_multiple_requests_deferred(Request[] req) {
  254. throw new SecurityException("ORBSingleton: access denied");
  255. }
  256. public boolean poll_next_response() {
  257. throw new SecurityException("ORBSingleton: access denied");
  258. }
  259. public org.omg.CORBA.Request get_next_response() {
  260. throw new SecurityException("ORBSingleton: access denied");
  261. }
  262. public String object_to_string(org.omg.CORBA.Object obj) {
  263. throw new SecurityException("ORBSingleton: access denied");
  264. }
  265. public org.omg.CORBA.Object string_to_object(String s) {
  266. throw new SecurityException("ORBSingleton: access denied");
  267. }
  268. public java.rmi.Remote string_to_remote(String s)
  269. throws java.rmi.RemoteException
  270. {
  271. throw new SecurityException("ORBSingleton: access denied");
  272. }
  273. public void connect(org.omg.CORBA.Object servant) {
  274. throw new SecurityException("ORBSingleton: access denied");
  275. }
  276. public void disconnect(org.omg.CORBA.Object obj) {
  277. throw new SecurityException("ORBSingleton: access denied");
  278. }
  279. public void run()
  280. {
  281. throw new SecurityException("ORBSingleton: access denied");
  282. }
  283. public void shutdown(boolean wait_for_completion)
  284. {
  285. throw new SecurityException("ORBSingleton: access denied");
  286. }
  287. protected void shutdownServants(boolean wait_for_completion) {
  288. throw new SecurityException("ORBSingleton: access denied");
  289. }
  290. protected void destroyConnections() {
  291. throw new SecurityException("ORBSingleton: access denied");
  292. }
  293. public void destroy() {
  294. throw new SecurityException("ORBSingleton: access denied");
  295. }
  296. public boolean work_pending()
  297. {
  298. throw new SecurityException("ORBSingleton: access denied");
  299. }
  300. public void perform_work()
  301. {
  302. throw new SecurityException("ORBSingleton: access denied");
  303. }
  304. public org.omg.CORBA.portable.ValueFactory register_value_factory(String repositoryID,
  305. org.omg.CORBA.portable.ValueFactory factory)
  306. {
  307. throw new SecurityException("ORBSingleton: access denied");
  308. }
  309. public void unregister_value_factory(String repositoryID)
  310. {
  311. throw new SecurityException("ORBSingleton: access denied");
  312. }
  313. public org.omg.CORBA.portable.ValueFactory lookup_value_factory(String repositoryID)
  314. {
  315. throw new SecurityException("ORBSingleton: access denied");
  316. }
  317. /*************************************************************************
  318. These are methods from com.sun.corba.se.internal.se.core.ORB
  319. ************************************************************************/
  320. /**
  321. * Get an instance of the GIOP client implementation.
  322. */
  323. public ClientGIOP getClientGIOP()
  324. {
  325. throw new SecurityException("ORBSingleton: access denied");
  326. }
  327. /**
  328. * Get an instance of the GIOP server implementation.
  329. */
  330. public ServerGIOP getServerGIOP()
  331. {
  332. throw new SecurityException("ORBSingleton: access denied");
  333. }
  334. /**
  335. * Return the subcontract registry
  336. */
  337. public SubcontractRegistry getSubcontractRegistry()
  338. {
  339. // To enable read_Object.
  340. if (fullORB == null) {
  341. Properties props = new Properties();
  342. // This needs to be a POAORB so that all subcontracts
  343. // are available.
  344. props.put("org.omg.CORBA.ORBClass",
  345. "com.sun.corba.se.internal.POA.POAORB");
  346. fullORB = (POAORB) ORB.init((String[])null, props);
  347. }
  348. return fullORB.getSubcontractRegistry();
  349. }
  350. /**
  351. * Return the service context registry
  352. */
  353. public ServiceContextRegistry getServiceContextRegistry()
  354. {
  355. throw new SecurityException("ORBSingleton: access denied");
  356. }
  357. /**
  358. * Get a new instance of a GIOP input stream.
  359. */
  360. public MarshalInputStream newInputStream()
  361. {
  362. return new EncapsInputStream(this);
  363. }
  364. /**
  365. * Get a new instance of a GIOP input stream.
  366. */
  367. public MarshalInputStream newInputStream(byte[] buffer, int size)
  368. {
  369. return new EncapsInputStream(this, buffer, size);
  370. }
  371. public MarshalInputStream newInputStream(byte[] buffer, int size, boolean littleEndian) {
  372. return new EncapsInputStream(this, buffer, size, littleEndian);
  373. }
  374. /**
  375. * Get a new instance of a GIOP output stream.
  376. */
  377. public MarshalOutputStream newOutputStream()
  378. {
  379. return new EncapsOutputStream(this);
  380. }
  381. /**
  382. * Get the transient server ID
  383. */
  384. public int getTransientServerId()
  385. {
  386. throw new SecurityException("ORBSingleton: access denied");
  387. }
  388. /**
  389. * Return the bootstrap naming port specified in the ORBInitialPort param.
  390. */
  391. public int getORBInitialPort()
  392. {
  393. throw new SecurityException("ORBSingleton: access denied");
  394. }
  395. /**
  396. * Return the bootstrap naming host specified in the ORBInitialHost param.
  397. */
  398. public String getORBInitialHost()
  399. {
  400. throw new SecurityException("ORBSingleton: access denied");
  401. }
  402. public String getORBServerHost()
  403. {
  404. throw new SecurityException("ORBSingleton: access denied");
  405. }
  406. public int getORBServerPort()
  407. {
  408. throw new SecurityException("ORBSingleton: access denied");
  409. }
  410. public CodeSetComponentInfo getCodeSetComponentInfo()
  411. {
  412. return new CodeSetComponentInfo();
  413. }
  414. public boolean isLocalHost( String host )
  415. {
  416. // To enable read_Object.
  417. return false;
  418. }
  419. public boolean isLocalServerId( int subcontractId, int serverId )
  420. {
  421. // To enable read_Object.
  422. return false;
  423. }
  424. public boolean isLocalServerPort( int port )
  425. {
  426. return false;
  427. }
  428. public GIOPVersion getGIOPVersion() {
  429. return giopVersion;
  430. }
  431. /*
  432. * Things from corba.ORB.
  433. */
  434. public ORBVersion getORBVersion()
  435. {
  436. // Always use our latest ORB version (latest fixes, etc)
  437. return ORBVersionFactory.getORBVersion();
  438. }
  439. public void setORBVersion(ORBVersion verObj)
  440. {
  441. throw new SecurityException("ORBSingleton: access denied");
  442. }
  443. public String getAppletHost()
  444. {
  445. throw new SecurityException("ORBSingleton: access denied");
  446. }
  447. public URL getAppletCodeBase()
  448. {
  449. throw new SecurityException("ORBSingleton: access denied");
  450. }
  451. public Collection getUserSpecifiedListenPorts ()
  452. {
  453. throw new SecurityException("ORBSingleton: access denied");
  454. }
  455. public ORBSocketFactory getSocketFactory ()
  456. {
  457. throw new SecurityException("ORBSingleton: access denied");
  458. }
  459. public int getHighWaterMark(){
  460. throw new SecurityException("ORBSingleton: access denied");
  461. }
  462. public int getLowWaterMark(){
  463. throw new SecurityException("ORBSingleton: access denied");
  464. }
  465. public int getNumberToReclaim(){
  466. throw new SecurityException("ORBSingleton: access denied");
  467. }
  468. public int getGIOPFragmentSize() {
  469. return ORBConstants.GIOP_DEFAULT_BUFFER_SIZE;
  470. }
  471. // getGIOPBufferSize needed by create_output_stream
  472. public int getGIOPBuffMgrStrategy(GIOPVersion gv) {
  473. return BufferManagerFactory.GROW;
  474. }
  475. // get_current throws NO_IMPLEMENT in parent.
  476. // PI hooks are empty.
  477. public IOR getServantIOR(){
  478. throw new SecurityException("ORBSingleton: access denied");
  479. }
  480. }