Frames | No Frames |
1: /* RestrictedORB.java -- 2: Copyright (C) 2005 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 gnu.CORBA; 40: 41: import gnu.CORBA.CDR.BufferedCdrOutput; 42: import gnu.CORBA.typecodes.AliasTypeCode; 43: import gnu.CORBA.typecodes.ArrayTypeCode; 44: import gnu.CORBA.typecodes.PrimitiveTypeCode; 45: import gnu.CORBA.typecodes.RecordTypeCode; 46: import gnu.CORBA.typecodes.StringTypeCode; 47: 48: import org.omg.CORBA.Any; 49: import org.omg.CORBA.BAD_PARAM; 50: import org.omg.CORBA.Context; 51: import org.omg.CORBA.ContextList; 52: import org.omg.CORBA.Environment; 53: import org.omg.CORBA.ExceptionList; 54: import org.omg.CORBA.NO_IMPLEMENT; 55: import org.omg.CORBA.NVList; 56: import org.omg.CORBA.NamedValue; 57: import org.omg.CORBA.ORB; 58: import org.omg.CORBA.ORBPackage.InvalidName; 59: import org.omg.CORBA.Request; 60: import org.omg.CORBA.StructMember; 61: import org.omg.CORBA.TCKind; 62: import org.omg.CORBA.TypeCode; 63: import org.omg.CORBA.TypeCodePackage.BadKind; 64: import org.omg.CORBA.UnionMember; 65: import org.omg.CORBA.portable.OutputStream; 66: import org.omg.CORBA.portable.ValueFactory; 67: import org.omg.PortableInterceptor.ClientRequestInterceptorOperations; 68: import org.omg.PortableInterceptor.IORInterceptorOperations; 69: import org.omg.PortableInterceptor.IORInterceptor_3_0Operations; 70: import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; 71: 72: import java.applet.Applet; 73: 74: import java.util.Hashtable; 75: import java.util.Properties; 76: 77: /** 78: * This class implements so-called Singleton ORB, a highly restricted version 79: * that cannot communicate over network. This ORB is provided for the 80: * potentially malicious applets with heavy security restrictions. It, however, 81: * supports some basic features that might be needed even when the network 82: * access is not granted. 83: * 84: * This ORB can only create typecodes, {@link Any}, {@link ContextList}, 85: * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to 86: * an internal buffer. 87: * 88: * All other methods throw the {@link NO_IMPLEMENT} exception. 89: * 90: * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) 91: */ 92: public class OrbRestricted extends org.omg.CORBA_2_3.ORB 93: { 94: /** 95: * The singleton instance of this ORB. 96: */ 97: public static final ORB Singleton = new OrbRestricted(); 98: 99: /** 100: * The cumulated listener for all IOR interceptors. Interceptors are used by 101: * {@link gnu.CORBA.Poa.ORB_1_4}. 102: */ 103: public IORInterceptor_3_0Operations iIor; 104: 105: /** 106: * The cumulated listener for all server request interceptors. Interceptors 107: * are used by {@link gnu.CORBA.Poa.ORB_1_4}. 108: */ 109: public ServerRequestInterceptorOperations iServer; 110: 111: /** 112: * The cumulated listener for all client request interceptros. Interceptors 113: * are used by {@link gnu.CORBA.Poa.ORB_1_4}. 114: */ 115: public ClientRequestInterceptorOperations iClient; 116: 117: /** 118: * The required size of the interceptor slot array. 119: */ 120: public int icSlotSize = 0; 121: 122: /** 123: * The value factories. 124: */ 125: protected Hashtable factories = new Hashtable(); 126: 127: /** 128: * The policy factories. 129: */ 130: protected Hashtable policyFactories = new Hashtable(); 131: 132: /** 133: * Create a new instance of the RestrictedORB. This is used in derived classes 134: * only. 135: */ 136: protected OrbRestricted() 137: { 138: } 139: 140: /** {@inheritDoc} */ 141: public TypeCode create_alias_tc(String id, String name, TypeCode typecode) 142: { 143: return new AliasTypeCode(typecode, id, name); 144: } 145: 146: /** {@inheritDoc} */ 147: public Any create_any() 148: { 149: gnuAny any = new gnuAny(); 150: any.setOrb(this); 151: return any; 152: } 153: 154: /** {@inheritDoc} */ 155: public TypeCode create_array_tc(int length, TypeCode element_type) 156: { 157: ArrayTypeCode p = 158: new ArrayTypeCode(TCKind.tk_array, element_type); 159: p.setLength(length); 160: return p; 161: } 162: 163: /** {@inheritDoc} */ 164: public ContextList create_context_list() 165: { 166: return new gnuContextList(); 167: } 168: 169: /** {@inheritDoc} */ 170: public TypeCode create_enum_tc(String id, String name, String[] values) 171: { 172: RecordTypeCode r = new RecordTypeCode(TCKind.tk_enum); 173: for (int i = 0; i < values.length; i++) 174: { 175: r.field().name = values [ i ]; 176: } 177: 178: r.setId(id); 179: r.setName(name); 180: 181: return r; 182: } 183: 184: /** {@inheritDoc} */ 185: public Environment create_environment() 186: { 187: return new gnuEnvironment(); 188: } 189: 190: /** {@inheritDoc} */ 191: public ExceptionList create_exception_list() 192: { 193: return new gnuExceptionList(); 194: } 195: 196: /** {@inheritDoc} */ 197: public TypeCode create_exception_tc(String id, String name, 198: StructMember[] members 199: ) 200: { 201: RecordTypeCode r = new RecordTypeCode(TCKind.tk_except); 202: r.setId(id); 203: r.setName(name); 204: 205: for (int i = 0; i < members.length; i++) 206: { 207: r.add(members [ i ]); 208: } 209: 210: return r; 211: } 212: 213: /** 214: * This method is not allowed for a RestrictedORB. 215: * 216: * @throws NO_IMPLEMENT, always. 217: */ 218: public TypeCode create_interface_tc(String id, String name) 219: { 220: no(); 221: return null; 222: } 223: 224: /** {@inheritDoc} */ 225: public NVList create_list(int count) 226: { 227: return new gnuNVList(count); 228: } 229: 230: /** {@inheritDoc} */ 231: public NamedValue create_named_value(String s, Any any, int flags) 232: { 233: return new gnuNamedValue(); 234: } 235: 236: /** {@inheritDoc} */ 237: public OutputStream create_output_stream() 238: { 239: BufferedCdrOutput stream = new BufferedCdrOutput(); 240: stream.setOrb(this); 241: return stream; 242: } 243: 244: /** {@inheritDoc} */ 245: public TypeCode create_sequence_tc(int bound, TypeCode element_type) 246: { 247: ArrayTypeCode p = 248: new ArrayTypeCode(TCKind.tk_sequence, element_type); 249: p.setLength(bound); 250: return p; 251: } 252: 253: /** {@inheritDoc} */ 254: public TypeCode create_string_tc(int bound) 255: { 256: StringTypeCode p = new StringTypeCode(TCKind.tk_string); 257: p.setLength(bound); 258: return p; 259: } 260: 261: /** {@inheritDoc} */ 262: public TypeCode create_struct_tc(String id, String name, 263: StructMember[] members 264: ) 265: { 266: RecordTypeCode r = new RecordTypeCode(TCKind.tk_struct); 267: r.setId(id); 268: r.setName(name); 269: 270: for (int i = 0; i < members.length; i++) 271: { 272: r.add(members [ i ]); 273: } 274: 275: return r; 276: } 277: 278: /** {@inheritDoc} */ 279: public TypeCode create_union_tc(String id, String name, 280: TypeCode discriminator_type, UnionMember[] members 281: ) 282: { 283: RecordTypeCode r = new RecordTypeCode(TCKind.tk_union); 284: r.setId(id); 285: r.setName(name); 286: r.setDiscriminator_type(discriminator_type); 287: r.setDefaultIndex(0); 288: 289: for (int i = 0; i < members.length; i++) 290: { 291: r.add(members [ i ]); 292: } 293: 294: return r; 295: } 296: 297: /** {@inheritDoc} */ 298: public TypeCode create_wstring_tc(int bound) 299: { 300: StringTypeCode p = new StringTypeCode(TCKind.tk_wstring); 301: p.setLength(bound); 302: return p; 303: } 304: 305: /** {@inheritDoc} */ 306: public TypeCode get_primitive_tc(TCKind tcKind) 307: { 308: try 309: { 310: return TypeKindNamer.getPrimitveTC(tcKind); 311: } 312: catch (BadKind ex) 313: { 314: throw new BAD_PARAM("This is not a primitive type code: " + 315: tcKind.value() 316: ); 317: } 318: } 319: 320: /** 321: * This method is not allowed for a RestrictedORB. 322: * 323: * @throws NO_IMPLEMENT, always. 324: */ 325: public String[] list_initial_services() 326: { 327: no(); 328: throw new InternalError(); 329: } 330: 331: /** 332: * This method is not allowed for a RestrictedORB. 333: * 334: * @throws NO_IMPLEMENT, always. 335: */ 336: public String object_to_string(org.omg.CORBA.Object forObject) 337: { 338: no(); 339: throw new InternalError(); 340: } 341: 342: /** 343: * This method is not allowed for a RestrictedORB. 344: * 345: * @throws InvalidName never in this class, but it is thrown in the derived 346: * classes. 347: * 348: * @throws NO_IMPLEMENT, always. 349: */ 350: public org.omg.CORBA.Object resolve_initial_references(String name) 351: throws InvalidName 352: { 353: no(); 354: throw new InternalError(); 355: } 356: 357: /** 358: * Shutdown the ORB server. 359: * 360: * For RestrictedORB, returns witout action. 361: */ 362: public void run() 363: { 364: } 365: 366: /** 367: * Shutdown the ORB server. 368: * 369: * For RestrictedORB, returns witout action. 370: */ 371: public void shutdown(boolean wait_for_completion) 372: { 373: } 374: 375: /** 376: * This method is not allowed for a RestrictedORB. 377: * 378: * @throws NO_IMPLEMENT, always. 379: */ 380: public org.omg.CORBA.Object string_to_object(String IOR) 381: { 382: no(); 383: throw new InternalError(); 384: } 385: 386: /** 387: * This method is not allowed for a RestrictedORB. 388: * 389: * @throws NO_IMPLEMENT, always. 390: */ 391: protected void set_parameters(Applet app, Properties props) 392: { 393: no(); 394: } 395: 396: /** 397: * This method is not allowed for a RestrictedORB. 398: * 399: * @throws NO_IMPLEMENT, always. 400: */ 401: protected void set_parameters(String[] args, Properties props) 402: { 403: no(); 404: } 405: 406: /** 407: * Throws an exception, stating that the given method is not supported by the 408: * Restricted ORB. 409: */ 410: private final void no() 411: { 412: // Apart the programming errors, this can only happen if the 413: // malicious code is trying to do that it is not allowed. 414: throw new NO_IMPLEMENT("Use init(args, props) for the functional version."); 415: } 416: 417: /** 418: * This method is not allowed for a RestrictedORB. 419: * 420: * @throws NO_IMPLEMENT, always. 421: */ 422: public Request get_next_response() throws org.omg.CORBA.WrongTransaction 423: { 424: no(); 425: throw new InternalError(); 426: } 427: 428: /** 429: * This method is not allowed for a RestrictedORB. 430: * 431: * @throws NO_IMPLEMENT, always. 432: */ 433: public boolean poll_next_response() 434: { 435: no(); 436: throw new InternalError(); 437: } 438: 439: /** 440: * This method is not allowed for a RestrictedORB. 441: * 442: * @throws NO_IMPLEMENT, always. 443: */ 444: public void send_multiple_requests_deferred(Request[] requests) 445: { 446: no(); 447: } 448: 449: /** 450: * This method is not allowed for a RestrictedORB. 451: * 452: * @throws NO_IMPLEMENT, always. 453: */ 454: public void send_multiple_requests_oneway(Request[] requests) 455: { 456: no(); 457: } 458: 459: /** 460: * Register the value factory under the given repository id. 461: */ 462: public ValueFactory register_value_factory(String repository_id, 463: ValueFactory factory 464: ) 465: { 466: factories.put(repository_id, factory); 467: return factory; 468: } 469: 470: /** 471: * Unregister the value factroy. 472: */ 473: public void unregister_value_factory(String id) 474: { 475: factories.remove(id); 476: } 477: 478: /** 479: * Look for the value factory for the value, having the given repository id. 480: * The implementation checks for the registered value factories first. If none 481: * found, it tries to load and instantiate the class, mathing the given naming 482: * convention. If this faild, null is returned. 483: * 484: * @param repository_id a repository id. 485: * 486: * @return a found value factory, null if none. 487: */ 488: public ValueFactory lookup_value_factory(String repository_id) 489: { 490: ValueFactory f = (ValueFactory) factories.get(repository_id); 491: if (f != null) 492: { 493: return f; 494: } 495: 496: f = (ValueFactory) ObjectCreator.createObject(repository_id, 497: "DefaultFactory" 498: ); 499: if (f != null) 500: { 501: factories.put(repository_id, f); 502: } 503: return f; 504: } 505: 506: /** 507: * Destroy the interceptors, if they are present. 508: */ 509: public void destroy() 510: { 511: if (iIor != null) 512: { 513: iIor.destroy(); 514: iIor = null; 515: } 516: 517: if (iServer != null) 518: { 519: iServer.destroy(); 520: iServer = null; 521: } 522: 523: if (iClient != null) 524: { 525: iClient.destroy(); 526: iClient = null; 527: } 528: 529: super.destroy(); 530: } 531: 532: /** 533: * Create a typecode, representing a tree-like structure. 534: * This structure contains a member that is a sequence of the same type, 535: * as the structure itself. You can imagine as if the folder definition 536: * contains a variable-length array of the enclosed (nested) folder 537: * definitions. In this way, it is possible to have a tree like 538: * structure that can be transferred via CORBA CDR stream. 539: * 540: * @deprecated It is easier and clearler to use a combination of 541: * create_recursive_tc and create_sequence_tc instead. 542: * 543: * @param bound the maximal expected number of the nested components 544: * on each node; 0 if not limited. 545: * 546: * @param offset the position of the field in the returned structure 547: * that contains the sequence of the structures of the same field. 548: * The members before this field are intialised using parameterless 549: * StructMember constructor. 550: * 551: * @return a typecode, defining a stucture, where a member at the 552: * <code>offset</code> position defines an array of the identical 553: * structures. 554: * 555: * @see #create_recursive_tc(String) 556: * @see #create_sequence_tc(int, TypeCode) 557: */ 558: public TypeCode create_recursive_sequence_tc(int bound, int offset) 559: { 560: RecordTypeCode r = new RecordTypeCode(TCKind.tk_struct); 561: for (int i = 0; i < offset; i++) 562: r.add(new StructMember()); 563: 564: TypeCode recurs = new PrimitiveTypeCode(TCKind.tk_sequence); 565: 566: r.add(new StructMember("", recurs, null)); 567: return r; 568: } 569: 570: /** 571: * Get the default context of this ORB. This is an initial root of all 572: * contexts. 573: * 574: * The default method returns a new context with the empty name and 575: * no parent context. 576: * 577: * @return the default context of this ORB. 578: */ 579: public Context get_default_context() 580: { 581: return new gnuContext("", null); 582: } 583: