src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java

changeset 512
81d694b1ab2f
parent 402
27d87f0031bf
child 748
6845b95cba6b
child 1052
da53c079df5d
equal deleted inserted replaced
484:d406edd4f6fd 512:81d694b1ab2f
1 /* 1 /*
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
32 32
33 package sun.rmi.rmic.iiop; 33 package sun.rmi.rmic.iiop;
34 34
35 import java.io.File; 35 import java.io.File;
36 import java.io.IOException; 36 import java.io.IOException;
37 import java.io.SerializablePermission;
38 import java.security.AccessController;
39 import java.security.PrivilegedAction;
37 import java.util.Vector; 40 import java.util.Vector;
38 import java.util.Hashtable; 41 import java.util.Hashtable;
39 import java.util.Enumeration; 42 import java.util.Enumeration;
40 import sun.tools.java.Identifier; 43 import sun.tools.java.Identifier;
41 import sun.tools.java.ClassNotFound; 44 import sun.tools.java.ClassNotFound;
46 import java.util.HashSet; 49 import java.util.HashSet;
47 import java.util.Arrays; 50 import java.util.Arrays;
48 import com.sun.corba.se.impl.util.Utility; 51 import com.sun.corba.se.impl.util.Utility;
49 import com.sun.corba.se.impl.util.PackagePrefixChecker; 52 import com.sun.corba.se.impl.util.PackagePrefixChecker;
50 import sun.rmi.rmic.Main; 53 import sun.rmi.rmic.Main;
54
51 55
52 /** 56 /**
53 * An IIOP stub/tie generator for rmic. 57 * An IIOP stub/tie generator for rmic.
54 * 58 *
55 * @author Bryan Atsatt 59 * @author Bryan Atsatt
76 protected String currentPackage = null; 80 protected String currentPackage = null;
77 protected String currentClass = null; 81 protected String currentClass = null;
78 protected boolean castArray = false; 82 protected boolean castArray = false;
79 protected Hashtable transactionalObjects = new Hashtable() ; 83 protected Hashtable transactionalObjects = new Hashtable() ;
80 protected boolean POATie = false ; 84 protected boolean POATie = false ;
85 protected boolean emitPermissionCheck = false;
81 86
82 /** 87 /**
83 * Default constructor for Main to use. 88 * Default constructor for Main to use.
84 */ 89 */
85 public StubGenerator() { 90 public StubGenerator() {
190 } else if (arg.equals("-xnohash")) { 195 } else if (arg.equals("-xnohash")) {
191 useHash = false; 196 useHash = false;
192 argv[i] = null; 197 argv[i] = null;
193 } else if (argv[i].equals("-standardPackage")) { 198 } else if (argv[i].equals("-standardPackage")) {
194 standardPackage = true; 199 standardPackage = true;
200 argv[i] = null;
201 } else if (argv[i].equals("-emitPermissionCheck")) {
202 emitPermissionCheck = true;
195 argv[i] = null; 203 argv[i] = null;
196 } else if (arg.equals("-xstubbase")) { 204 } else if (arg.equals("-xstubbase")) {
197 argv[i] = null; 205 argv[i] = null;
198 if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) { 206 if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) {
199 stubBaseClass = argv[i]; 207 stubBaseClass = argv[i];
388 396
389 // Write package and import statements... 397 // Write package and import statements...
390 398
391 writePackageAndImports(p); 399 writePackageAndImports(p);
392 400
401 // generate
402 // import java.security.AccessController;
403 // import java.security.PrivilegedAction;
404 // import java.io.SerializablePermission;
405 if (emitPermissionCheck) {
406 p.pln("import java.security.AccessController;");
407 p.pln("import java.security.PrivilegedAction;");
408 p.pln("import java.io.SerializablePermission;");
409 p.pln();
410 p.pln();
411 }
412
393 // Declare the stub class; implement all remote interfaces. 413 // Declare the stub class; implement all remote interfaces.
394 414
395 p.p("public class " + currentClass); 415 p.p("public class " + currentClass);
416
396 p.p(" extends " + getName(stubBaseClass)); 417 p.p(" extends " + getName(stubBaseClass));
397 p.p(" implements "); 418 p.p(" implements ");
398 if (remoteInterfaces.length > 0) { 419 if (remoteInterfaces.length > 0) {
399 for(int i = 0; i < remoteInterfaces.length; i++) { 420 for(int i = 0; i < remoteInterfaces.length; i++) {
400 if (i > 0) { 421 if (i > 0) {
419 440
420 // Write the ids... 441 // Write the ids...
421 442
422 writeIds( p, theType, false ); 443 writeIds( p, theType, false );
423 p.pln(); 444 p.pln();
445
446 if (emitPermissionCheck) {
447
448 // produce the following generated code for example
449 // private static Void checkPermission() {
450 // SecurityManager sm = System.getSecurityManager();
451 // if (sm != null) {
452 // sm.checkPermission(new SerializablePermission(
453 // "enableSubclassImplementation")); // testing
454 // }
455 // return null;
456 // }
457 //
458 // private _XXXXX_Stub(Void ignore) {
459 // }
460 //
461 // public _XXXXX_Stub() {
462 // this(checkPermission());
463 // }
464 //
465 // where XXXXX is the name of the remote interface
466
467 p.pln();
468 p.plnI("private static Void checkPermission() {");
469 p.plnI("SecurityManager sm = System.getSecurityManager();");
470 p.pln("if (sm != null) {");
471 p.pI();
472 p.plnI("sm.checkPermission(new SerializablePermission(");
473 p.plnI("\"enableSubclassImplementation\"));");
474 p.pO();
475 p.pO();
476 p.pOln("}");
477 p.pln("return null;");
478 p.pO();
479 p.pOln("}");
480 p.pln();
481 p.pO();
482
483 p.pI();
484 p.pln("private " + currentClass + "(Void ignore) { }");
485 p.pln();
486
487 p.plnI("public " + currentClass + "() { ");
488 p.pln("this(checkPermission());");
489 p.pOln("}");
490 p.pln();
491 }
492
493 if (!emitPermissionCheck) {
494 p.pI();
495 }
424 496
425 // Write the _ids() method... 497 // Write the _ids() method...
426 498
427 p.plnI("public String[] _ids() { "); 499 p.plnI("public String[] _ids() { ");
428 p.pln("return (String[]) _type_ids.clone();"); 500 p.pln("return (String[]) _type_ids.clone();");
813 void writeStubMethod ( IndentingWriter p, 885 void writeStubMethod ( IndentingWriter p,
814 CompoundType.Method method, 886 CompoundType.Method method,
815 CompoundType theType) throws IOException { 887 CompoundType theType) throws IOException {
816 888
817 // Wtite the method declaration and opening brace... 889 // Wtite the method declaration and opening brace...
818
819 String methodName = method.getName(); 890 String methodName = method.getName();
820 String methodIDLName = method.getIDLName(); 891 String methodIDLName = method.getIDLName();
821 892
822 Type paramTypes[] = method.getArguments(); 893 Type paramTypes[] = method.getArguments();
823 String paramNames[] = method.getArgumentNames(); 894 String paramNames[] = method.getArgumentNames();

mercurial