src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java

changeset 205
b2fff4b7e8cd
parent 158
91006f157c46
child 443
3c73273667ae
equal deleted inserted replaced
198:cc67fdc4fee9 205:b2fff4b7e8cd
1 /* 1 /*
2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2010, 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
30 */ 30 */
31 31
32 package com.sun.corba.se.impl.io; 32 package com.sun.corba.se.impl.io;
33 33
34 import javax.rmi.CORBA.Util; 34 import javax.rmi.CORBA.Util;
35 import javax.rmi.PortableRemoteObject;
36 35
37 import java.util.Hashtable; 36 import java.util.Hashtable;
38 import java.util.Stack;
39 import java.io.IOException; 37 import java.io.IOException;
40 import java.util.EmptyStackException; 38
41
42 import com.sun.corba.se.impl.util.Utility;
43 import com.sun.corba.se.impl.io.IIOPInputStream;
44 import com.sun.corba.se.impl.io.IIOPOutputStream;
45 import com.sun.corba.se.impl.util.RepositoryId; 39 import com.sun.corba.se.impl.util.RepositoryId;
46 import com.sun.corba.se.impl.util.Utility; 40 import com.sun.corba.se.impl.util.Utility;
47 41
48 import org.omg.CORBA.TCKind; 42 import org.omg.CORBA.TCKind;
49 43
50 import org.omg.CORBA.MARSHAL;
51 import org.omg.CORBA.BAD_PARAM;
52 import org.omg.CORBA.CompletionStatus;
53 import org.omg.CORBA.portable.IndirectionException; 44 import org.omg.CORBA.portable.IndirectionException;
54 import com.sun.org.omg.SendingContext.CodeBase; 45 import com.sun.org.omg.SendingContext.CodeBase;
55 import com.sun.org.omg.SendingContext.CodeBaseHelper; 46 import com.sun.org.omg.SendingContext.CodeBaseHelper;
56 47
57 import java.security.AccessController; 48 import java.security.AccessController;
58 import java.security.PrivilegedAction; 49 import java.security.PrivilegedAction;
59 50 import java.security.PrivilegedExceptionAction;
60 import com.sun.corba.se.impl.io.IIOPInputStream.ActiveRecursionManager;
61 51
62 import com.sun.corba.se.spi.logging.CORBALogDomains; 52 import com.sun.corba.se.spi.logging.CORBALogDomains;
63 import com.sun.corba.se.impl.logging.OMGSystemException; 53 import com.sun.corba.se.impl.logging.OMGSystemException;
64 import com.sun.corba.se.impl.logging.UtilSystemException; 54 import com.sun.corba.se.impl.logging.UtilSystemException;
65 55
807 797
808 protected String getOutputStreamClassName() { 798 protected String getOutputStreamClassName() {
809 return "com.sun.corba.se.impl.io.IIOPOutputStream"; 799 return "com.sun.corba.se.impl.io.IIOPOutputStream";
810 } 800 }
811 801
812 private com.sun.corba.se.impl.io.IIOPOutputStream createOutputStream() { 802 private IIOPOutputStream createOutputStream() {
813 return (com.sun.corba.se.impl.io.IIOPOutputStream)AccessController.doPrivileged( 803 final String name = getOutputStreamClassName();
814 new StreamFactory(getOutputStreamClassName())); 804 try {
805 IIOPOutputStream stream = createOutputStreamBuiltIn(name);
806 if (stream != null) {
807 return stream;
808 }
809 return createCustom(IIOPOutputStream.class, name);
810 } catch (Throwable t) {
811 // Throw exception under the carpet.
812 InternalError ie = new InternalError(
813 "Error loading " + name
814 );
815 ie.initCause(t);
816 throw ie;
817 }
818 }
819
820 /**
821 * Construct a built in implementation with priveleges.
822 * Returning null indicates a non-built is specified.
823 */
824 private IIOPOutputStream createOutputStreamBuiltIn(
825 final String name
826 ) throws Throwable {
827 try {
828 return AccessController.doPrivileged(
829 new PrivilegedExceptionAction<IIOPOutputStream>() {
830 public IIOPOutputStream run() throws IOException {
831 return createOutputStreamBuiltInNoPriv(name);
832 }
833 }
834 );
835 } catch (java.security.PrivilegedActionException exc) {
836 throw exc.getCause();
837 }
838 }
839
840 /**
841 * Returning null indicates a non-built is specified.
842 */
843 private IIOPOutputStream createOutputStreamBuiltInNoPriv(
844 final String name
845 ) throws IOException {
846 return
847 name.equals(
848 IIOPOutputStream
849 .class.getName()
850 ) ?
851 new IIOPOutputStream() :
852
853 name.equals(
854 com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3
855 .class.getName()
856 ) ?
857 new com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3() :
858
859 name.equals(
860 com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3_1
861 .class.getName()
862 ) ?
863 new com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3_1() :
864
865 null;
815 } 866 }
816 867
817 protected String getInputStreamClassName() { 868 protected String getInputStreamClassName() {
818 return "com.sun.corba.se.impl.io.IIOPInputStream"; 869 return "com.sun.corba.se.impl.io.IIOPInputStream";
819 } 870 }
820 871
821 private com.sun.corba.se.impl.io.IIOPInputStream createInputStream() { 872 private IIOPInputStream createInputStream() {
822 return (com.sun.corba.se.impl.io.IIOPInputStream)AccessController.doPrivileged( 873 final String name = getInputStreamClassName();
823 new StreamFactory(getInputStreamClassName())); 874 try {
824 } 875 IIOPInputStream stream = createInputStreamBuiltIn(name);
825 876 if (stream != null) {
826 /** 877 return stream;
827 * Instantiates a class of the given name using the system ClassLoader 878 }
828 * as part of a PrivilegedAction. 879 return createCustom(IIOPInputStream.class, name);
829 * 880 } catch (Throwable t) {
830 * It's private final so hopefully people can't grab it outside of 881 // Throw exception under the carpet.
831 * this class. 882 InternalError ie = new InternalError(
832 * 883 "Error loading " + name
833 * If you're worried that someone could subclass ValueHandlerImpl, 884 );
834 * install his own streams, and snoop what's on the wire: 885 ie.initCause(t);
835 * Someone can do that only if he's allowed to use the feature 886 throw ie;
836 * of installing his own javax.rmi.CORBA.Util delegate (via a 887 }
837 * JVM property or orb.properties file, read the first time the 888 }
838 * Util class is used). If he can do that, he can snoop 889
839 * anything on the wire, anyway, without abusing the 890 /**
840 * StreamFactory class. 891 * Construct a built in implementation with priveleges.
892 * Returning null indicates a non-built is specified.
841 */ 893 */
842 private static final class StreamFactory implements PrivilegedAction { 894 private IIOPInputStream createInputStreamBuiltIn(
843 private String className; 895 final String name
844 896 ) throws Throwable {
845 public StreamFactory (String _className) { 897 try {
846 className = _className; 898 return AccessController.doPrivileged(
847 } 899 new PrivilegedExceptionAction<IIOPInputStream>() {
848 900 public IIOPInputStream run() throws IOException {
849 public Object run() { 901 return createInputStreamBuiltInNoPriv(name);
850 try { 902 }
851 // Note: We must use the system ClassLoader here 903 }
852 // since we want to load classes outside of the 904 );
853 // core JDK when running J2EE Pure ORB and 905 } catch (java.security.PrivilegedActionException exc) {
854 // talking to Kestrel. 906 throw exc.getCause();
907 }
908 }
909
910 /**
911 * Returning null indicates a non-built is specified.
912 */
913 private IIOPInputStream createInputStreamBuiltInNoPriv(
914 final String name
915 ) throws IOException {
916 return
917 name.equals(
918 IIOPInputStream
919 .class.getName()
920 ) ?
921 new IIOPInputStream() :
922
923 name.equals(
924 com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3
925 .class.getName()
926 ) ?
927 new com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3() :
928
929 name.equals(
930 com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3_1
931 .class.getName()
932 ) ?
933 new com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3_1() :
934
935 null;
936 }
937
938 /**
939 * Create a custom implementation without privileges.
940 */
941 private <T> T createCustom(
942 final Class<T> type, final String className
943 ) throws Throwable {
944 // Note: We use the thread context or system ClassLoader here
945 // since we want to load classes outside of the
946 // core JDK when running J2EE Pure ORB and
947 // talking to Kestrel.
855 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 948 ClassLoader cl = Thread.currentThread().getContextClassLoader();
856 if (cl == null) 949 if (cl == null)
857 cl = ClassLoader.getSystemClassLoader(); 950 cl = ClassLoader.getSystemClassLoader();
858 951
859 Class streamClass = cl.loadClass(className); 952 Class<?> clazz = cl.loadClass(className);
953 Class<? extends T> streamClass = clazz.asSubclass(type);
860 954
861 // Since the ClassLoader should cache the class, this isn't 955 // Since the ClassLoader should cache the class, this isn't
862 // as expensive as it looks. 956 // as expensive as it looks.
863 return streamClass.newInstance(); 957 return streamClass.newInstance();
864 958
865 } catch(Throwable t) {
866 InternalError ie = new InternalError( "Error loading " + className ) ;
867 ie.initCause( t ) ;
868 throw ie ;
869 }
870 }
871 } 959 }
872 960
873 /** 961 /**
874 * Our JDK 1.3 and JDK 1.3.1 behavior subclasses override this. 962 * Our JDK 1.3 and JDK 1.3.1 behavior subclasses override this.
875 * The correct behavior is for a Java char to map to a CORBA wchar, 963 * The correct behavior is for a Java char to map to a CORBA wchar,

mercurial