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