1. /*
  2. * @(#)ObjectStreamClassCorbaExt.java 1.3 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. package com.sun.corba.se.internal.io;
  8. import java.security.AccessController;
  9. import java.security.PrivilegedExceptionAction;
  10. import java.security.PrivilegedActionException;
  11. import java.security.PrivilegedAction;
  12. import java.lang.reflect.Modifier;
  13. import java.lang.reflect.Array;
  14. import java.lang.reflect.Field;
  15. import java.lang.reflect.Member;
  16. import java.lang.reflect.Method;
  17. // This file contains some utility methods that
  18. // originally were in the OSC in the RMI-IIOP
  19. // code delivered by IBM. They don't make
  20. // sense there, and hence have been put
  21. // here so that they can be factored out in
  22. // an attempt to eliminate redundant code from
  23. // ObjectStreamClass. Eventually the goal is
  24. // to move to java.io.ObjectStreamClass, and
  25. // java.io.ObjectStreamField.
  26. // class is package private for security reasons
  27. class ObjectStreamClassCorbaExt {
  28. static final boolean isAbstractInterface(Class cl) {
  29. Method[] method = ObjectStreamClassCorbaExt.getDeclaredMethods(cl);
  30. // Test for abstractness (used under rmi/iiop when determining whether
  31. // to call read/write_Abstract
  32. if (!cl.isInterface()) {
  33. return false;
  34. }
  35. if (method.length == 0) {
  36. return false;
  37. }
  38. boolean isAbstractInterface = false;
  39. for (int im = method.length -1 ; (im > -1); im--) {
  40. Class exceptions[] = method[im].getExceptionTypes();
  41. if (exceptions.length == 0) {
  42. return false;
  43. }
  44. // Set abstractness to false and flip to true only if the
  45. // method has at least one good exception
  46. for (int ime = exceptions.length -1; (ime > -1) && (isAbstractInterface == false); ime--) {
  47. if ((java.rmi.RemoteException.class == exceptions[ime]) ||
  48. (java.lang.Throwable.class == exceptions[ime]) ||
  49. (java.lang.Exception.class == exceptions[ime]) ||
  50. (java.io.IOException.class == exceptions[ime])) {
  51. isAbstractInterface = true;
  52. }
  53. }
  54. }
  55. Class superclass = cl.getSuperclass();
  56. isAbstractInterface = (isAbstractInterface && ((superclass == null) || ( ObjectStreamClassCorbaExt.isAbstractInterface(superclass))));
  57. return isAbstractInterface;
  58. }
  59. /*
  60. * Returns TRUE if type is 'any'.
  61. */
  62. static final boolean isAny(String typeString) {
  63. int isAny = 0;
  64. if ( (typeString != null) &&
  65. (typeString.equals("Ljava/lang/Object;") ||
  66. typeString.equals("Ljava/io/Serializable;") ||
  67. typeString.equals("Ljava/io/Externalizable;")) )
  68. isAny = 1;
  69. return (isAny==1);
  70. }
  71. private static final Method[] getDeclaredMethods(final Class clz) {
  72. return (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
  73. public Object run() {
  74. return clz.getDeclaredMethods();
  75. }
  76. });
  77. }
  78. }