1. /*
  2. * @(#)StubFactoryFactoryStaticImpl.java 1.10 04/05/25
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.presentation.rmi;
  8. import javax.rmi.CORBA.Util;
  9. import javax.rmi.CORBA.Tie ;
  10. import org.omg.CORBA.CompletionStatus;
  11. import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
  12. import com.sun.corba.se.impl.util.PackagePrefixChecker;
  13. import com.sun.corba.se.impl.util.Utility;
  14. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  15. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  16. public class StubFactoryFactoryStaticImpl extends
  17. StubFactoryFactoryBase
  18. {
  19. private ORBUtilSystemException wrapper = ORBUtilSystemException.get(
  20. CORBALogDomains.RPC_PRESENTATION ) ;
  21. public PresentationManager.StubFactory createStubFactory(
  22. String className, boolean isIDLStub, String remoteCodeBase, Class
  23. expectedClass, ClassLoader classLoader)
  24. {
  25. String stubName = null ;
  26. if (isIDLStub)
  27. stubName = Utility.idlStubName( className ) ;
  28. else
  29. stubName = Utility.stubNameForCompiler( className ) ;
  30. ClassLoader expectedTypeClassLoader =
  31. (expectedClass == null ? classLoader :
  32. expectedClass.getClassLoader());
  33. // The old code was optimized to try to guess which way to load classes
  34. // first. The real stub class name could either be className or
  35. // "org.omg.stub." + className. We will compute this as follows:
  36. // If stubName starts with a "forbidden" package, try the prefixed
  37. // version first, otherwise try the non-prefixed version first.
  38. // In any case, try both forms if necessary.
  39. String firstStubName = stubName ;
  40. String secondStubName = stubName ;
  41. if (PackagePrefixChecker.hasOffendingPrefix(stubName))
  42. firstStubName = PackagePrefixChecker.packagePrefix() + stubName ;
  43. else
  44. secondStubName = PackagePrefixChecker.packagePrefix() + stubName ;
  45. Class clz = null;
  46. try {
  47. clz = Util.loadClass( firstStubName, remoteCodeBase,
  48. expectedTypeClassLoader ) ;
  49. } catch (ClassNotFoundException e1) {
  50. // log only at FINE level
  51. wrapper.classNotFound1( CompletionStatus.COMPLETED_MAYBE,
  52. e1, firstStubName ) ;
  53. try {
  54. clz = Util.loadClass( secondStubName, remoteCodeBase,
  55. expectedTypeClassLoader ) ;
  56. } catch (ClassNotFoundException e2) {
  57. throw wrapper.classNotFound2(
  58. CompletionStatus.COMPLETED_MAYBE, e2, secondStubName ) ;
  59. }
  60. }
  61. // XXX Is this step necessary, or should the Util.loadClass
  62. // algorithm always produce a valid class if the setup is correct?
  63. // Does the OMG standard algorithm need to be changed to include
  64. // this step?
  65. if ((clz == null) ||
  66. ((expectedClass != null) && !expectedClass.isAssignableFrom(clz))) {
  67. try {
  68. ClassLoader cl = Thread.currentThread().getContextClassLoader();
  69. if (cl == null)
  70. cl = ClassLoader.getSystemClassLoader();
  71. clz = cl.loadClass(className);
  72. } catch (Exception exc) {
  73. // XXX make this a system exception
  74. IllegalStateException ise = new IllegalStateException(
  75. "Could not load class " + stubName ) ;
  76. ise.initCause( exc ) ;
  77. throw ise ;
  78. }
  79. }
  80. return new StubFactoryStaticImpl( clz ) ;
  81. }
  82. public Tie getTie( Class cls )
  83. {
  84. Class tieClass = null ;
  85. String className = Utility.tieName(cls.getName());
  86. // XXX log exceptions at FINE level
  87. try {
  88. try {
  89. //_REVISIT_ The spec does not specify a loadingContext parameter for
  90. //the following call. Would it be useful to pass one?
  91. tieClass = Utility.loadClassForClass(className, Util.getCodebase(cls),
  92. null, cls, cls.getClassLoader());
  93. return (Tie) tieClass.newInstance();
  94. } catch (Exception err) {
  95. tieClass = Utility.loadClassForClass(
  96. PackagePrefixChecker.packagePrefix() + className,
  97. Util.getCodebase(cls), null, cls, cls.getClassLoader());
  98. return (Tie) tieClass.newInstance();
  99. }
  100. } catch (Exception err) {
  101. return null;
  102. }
  103. }
  104. public boolean createsDynamicStubs()
  105. {
  106. return false ;
  107. }
  108. }