Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/sun/rmi/server/Util.java
          +++ new/src/share/classes/sun/rmi/server/Util.java
↓ open down ↓ 111 lines elided ↑ open up ↑
 112  112       * class with the clientRef.
 113  113       *
 114  114       * @param implClass the class to obtain remote interfaces from
 115  115       * @param clientRef the remote ref to use in the invocation handler
 116  116       * @param forceStubUse if true, forces creation of a RemoteStub
 117  117       * @throws IllegalArgumentException if implClass implements illegal
 118  118       * remote interfaces
 119  119       * @throws StubNotFoundException if problem locating/creating stub or
 120  120       * creating the dynamic proxy instance
 121  121       **/
 122      -    public static Remote createProxy(Class implClass,
      122 +    public static Remote createProxy(Class<?> implClass,
 123  123                                       RemoteRef clientRef,
 124  124                                       boolean forceStubUse)
 125  125          throws StubNotFoundException
 126  126      {
 127      -        Class remoteClass;
      127 +        Class<?> remoteClass;
 128  128  
 129  129          try {
 130  130              remoteClass = getRemoteClass(implClass);
 131  131          } catch (ClassNotFoundException ex ) {
 132  132              throw new StubNotFoundException(
 133  133                  "object does not implement a remote interface: " +
 134  134                  implClass.getName());
 135  135          }
 136  136  
 137  137          if (forceStubUse ||
↓ open down ↓ 17 lines elided ↑ open up ↑
 155  155              throw new StubNotFoundException("unable to create proxy", e);
 156  156          }
 157  157      }
 158  158  
 159  159      /**
 160  160       * Returns true if a stub class for the given impl class can be loaded,
 161  161       * otherwise returns false.
 162  162       *
 163  163       * @param remoteClass the class to obtain remote interfaces from
 164  164       */
 165      -    private static boolean stubClassExists(Class remoteClass) {
      165 +    private static boolean stubClassExists(Class<?> remoteClass) {
 166  166          if (!withoutStubs.containsKey(remoteClass)) {
 167  167              try {
 168  168                  Class.forName(remoteClass.getName() + "_Stub",
 169  169                                false,
 170  170                                remoteClass.getClassLoader());
 171  171                  return true;
 172  172  
 173  173              } catch (ClassNotFoundException cnfe) {
 174  174                  withoutStubs.put(remoteClass, null);
 175  175              }
 176  176          }
 177  177          return false;
 178  178      }
 179  179  
 180  180      /*
 181  181       * Returns the class/superclass that implements the remote interface.
 182  182       * @throws ClassNotFoundException if no class is found to have a
 183  183       * remote interface
 184  184       */
 185      -    private static Class getRemoteClass(Class cl)
      185 +    private static Class<?> getRemoteClass(Class<?> cl)
 186  186          throws ClassNotFoundException
 187  187      {
 188  188          while (cl != null) {
 189      -            Class[] interfaces = cl.getInterfaces();
      189 +            Class<?>[] interfaces = cl.getInterfaces();
 190  190              for (int i = interfaces.length -1; i >= 0; i--) {
 191  191                  if (Remote.class.isAssignableFrom(interfaces[i]))
 192  192                      return cl;          // this class implements remote object
 193  193              }
 194  194              cl = cl.getSuperclass();
 195  195          }
 196  196          throw new ClassNotFoundException(
 197  197                  "class does not implement java.rmi.Remote");
 198  198      }
 199  199  
 200  200      /**
 201  201       * Returns an array containing the remote interfaces implemented
 202  202       * by the given class.
 203  203       *
 204  204       * @param   remoteClass the class to obtain remote interfaces from
 205  205       * @throws  IllegalArgumentException if remoteClass implements
 206  206       *          any illegal remote interfaces
 207  207       * @throws  NullPointerException if remoteClass is null
 208  208       */
 209      -    private static Class[] getRemoteInterfaces(Class remoteClass) {
 210      -        ArrayList<Class<?>> list = new ArrayList<Class<?>>();
      209 +    private static Class<?>[] getRemoteInterfaces(Class<?> remoteClass) {
      210 +        ArrayList<Class<?>> list = new ArrayList<>();
 211  211          getRemoteInterfaces(list, remoteClass);
 212  212          return list.toArray(new Class<?>[list.size()]);
 213  213      }
 214  214  
 215  215      /**
 216  216       * Fills the given array list with the remote interfaces implemented
 217  217       * by the given class.
 218  218       *
 219  219       * @throws  IllegalArgumentException if the specified class implements
 220  220       *          any illegal remote interfaces
 221  221       * @throws  NullPointerException if the specified class or list is null
 222  222       */
 223      -    private static void getRemoteInterfaces(ArrayList<Class<?>> list, Class cl) {
 224      -        Class superclass = cl.getSuperclass();
      223 +    private static void getRemoteInterfaces(ArrayList<Class<?>> list, Class<?> cl) {
      224 +        Class<?> superclass = cl.getSuperclass();
 225  225          if (superclass != null) {
 226  226              getRemoteInterfaces(list, superclass);
 227  227          }
 228  228  
 229      -        Class[] interfaces = cl.getInterfaces();
      229 +        Class<?>[] interfaces = cl.getInterfaces();
 230  230          for (int i = 0; i < interfaces.length; i++) {
 231      -            Class intf = interfaces[i];
      231 +            Class<?> intf = interfaces[i];
 232  232              /*
 233  233               * If it is a remote interface (if it extends from
 234  234               * java.rmi.Remote) and is not already in the list,
 235  235               * then add the interface to the list.
 236  236               */
 237  237              if (Remote.class.isAssignableFrom(intf)) {
 238  238                  if (!(list.contains(intf))) {
 239  239                      Method[] methods = intf.getMethods();
 240  240                      for (int j = 0; j < methods.length; j++) {
 241  241                          checkMethod(methods[j]);
↓ open down ↓ 23 lines elided ↑ open up ↑
 265  265  
 266  266      /**
 267  267       * Creates a RemoteStub instance for the specified class, constructed
 268  268       * with the specified RemoteRef.  The supplied class must be the most
 269  269       * derived class in the remote object's superclass chain that
 270  270       * implements a remote interface.  The stub class name is the name of
 271  271       * the specified remoteClass with the suffix "_Stub".  The loading of
 272  272       * the stub class is initiated from class loader of the specified class
 273  273       * (which may be the bootstrap class loader).
 274  274       **/
 275      -    private static RemoteStub createStub(Class remoteClass, RemoteRef ref)
      275 +    private static RemoteStub createStub(Class<?> remoteClass, RemoteRef ref)
 276  276          throws StubNotFoundException
 277  277      {
 278  278          String stubname = remoteClass.getName() + "_Stub";
 279  279  
 280  280          /* Make sure to use the local stub loader for the stub classes.
 281  281           * When loaded by the local loader the load path can be
 282  282           * propagated to remote clients, by the MarshalOutputStream/InStream
 283  283           * pickle methods
 284  284           */
 285  285          try {
 286  286              Class<?> stubcl =
 287  287                  Class.forName(stubname, false, remoteClass.getClassLoader());
 288      -            Constructor cons = stubcl.getConstructor(stubConsParamTypes);
      288 +            Constructor<?> cons = stubcl.getConstructor(stubConsParamTypes);
 289  289              return (RemoteStub) cons.newInstance(new Object[] { ref });
 290  290  
 291  291          } catch (ClassNotFoundException e) {
 292  292              throw new StubNotFoundException(
 293  293                  "Stub class not found: " + stubname, e);
 294  294          } catch (NoSuchMethodException e) {
 295  295              throw new StubNotFoundException(
 296  296                  "Stub class missing constructor: " + stubname, e);
 297  297          } catch (InstantiationException e) {
 298  298              throw new StubNotFoundException(
↓ open down ↓ 9 lines elided ↑ open up ↑
 308  308                  "Stub class not instance of RemoteStub: " + stubname, e);
 309  309          }
 310  310      }
 311  311  
 312  312      /**
 313  313       * Locate and return the Skeleton for the specified remote object
 314  314       */
 315  315      static Skeleton createSkeleton(Remote object)
 316  316          throws SkeletonNotFoundException
 317  317      {
 318      -        Class cl;
      318 +        Class<?> cl;
 319  319          try {
 320  320              cl = getRemoteClass(object.getClass());
 321  321          } catch (ClassNotFoundException ex ) {
 322  322              throw new SkeletonNotFoundException(
 323  323                  "object does not implement a remote interface: " +
 324  324                  object.getClass().getName());
 325  325          }
 326  326  
 327  327          // now try to load the skeleton based ont he name of the class
 328  328          String skelname = cl.getName() + "_Skel";
 329  329          try {
 330      -            Class skelcl = Class.forName(skelname, false, cl.getClassLoader());
      330 +            Class<?> skelcl = Class.forName(skelname, false, cl.getClassLoader());
 331  331  
 332  332              return (Skeleton)skelcl.newInstance();
 333  333          } catch (ClassNotFoundException ex) {
 334  334              throw new SkeletonNotFoundException("Skeleton class not found: " +
 335  335                                                  skelname, ex);
 336  336          } catch (InstantiationException ex) {
 337  337              throw new SkeletonNotFoundException("Can't create skeleton: " +
 338  338                                                  skelname, ex);
 339  339          } catch (IllegalAccessException ex) {
 340  340              throw new SkeletonNotFoundException("No public constructor: " +
↓ open down ↓ 43 lines elided ↑ open up ↑
 384  384       * Return a string consisting of the given method's name followed by
 385  385       * its "method descriptor", as appropriate for use in the computation
 386  386       * of the "method hash".
 387  387       *
 388  388       * See section 4.3.3 of The Java Virtual Machine Specification for
 389  389       * the definition of a "method descriptor".
 390  390       */
 391  391      private static String getMethodNameAndDescriptor(Method m) {
 392  392          StringBuffer desc = new StringBuffer(m.getName());
 393  393          desc.append('(');
 394      -        Class[] paramTypes = m.getParameterTypes();
      394 +        Class<?>[] paramTypes = m.getParameterTypes();
 395  395          for (int i = 0; i < paramTypes.length; i++) {
 396  396              desc.append(getTypeDescriptor(paramTypes[i]));
 397  397          }
 398  398          desc.append(')');
 399      -        Class returnType = m.getReturnType();
      399 +        Class<?> returnType = m.getReturnType();
 400  400          if (returnType == void.class) { // optimization: handle void here
 401  401              desc.append('V');
 402  402          } else {
 403  403              desc.append(getTypeDescriptor(returnType));
 404  404          }
 405  405          return desc.toString();
 406  406      }
 407  407  
 408  408      /**
 409  409       * Get the descriptor of a particular type, as appropriate for either
 410  410       * a parameter or return type in a method descriptor.
 411  411       */
 412      -    private static String getTypeDescriptor(Class type) {
      412 +    private static String getTypeDescriptor(Class<?> type) {
 413  413          if (type.isPrimitive()) {
 414  414              if (type == int.class) {
 415  415                  return "I";
 416  416              } else if (type == boolean.class) {
 417  417                  return "Z";
 418  418              } else if (type == byte.class) {
 419  419                  return "B";
 420  420              } else if (type == char.class) {
 421  421                  return "C";
 422  422              } else if (type == short.class) {
↓ open down ↓ 24 lines elided ↑ open up ↑
 447  447      }
 448  448  
 449  449      /**
 450  450       * Returns the binary name of the given type without package
 451  451       * qualification.  Nested types are treated no differently from
 452  452       * top-level types, so for a nested type, the returned name will
 453  453       * still be qualified with the simple name of its enclosing
 454  454       * top-level type (and perhaps other enclosing types), the
 455  455       * separator will be '$', etc.
 456  456       **/
 457      -    public static String getUnqualifiedName(Class c) {
      457 +    public static String getUnqualifiedName(Class<?> c) {
 458  458          String binaryName = c.getName();
 459  459          return binaryName.substring(binaryName.lastIndexOf('.') + 1);
 460  460      }
 461  461  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX