1. /*
  2. * @(#)TOAFactory.java 1.17 03/12/19
  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.oa.toa ;
  8. import java.util.Map ;
  9. import java.util.HashMap ;
  10. import org.omg.CORBA.INTERNAL ;
  11. import org.omg.CORBA.CompletionStatus ;
  12. import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
  13. import com.sun.corba.se.spi.oa.ObjectAdapter ;
  14. import com.sun.corba.se.spi.orb.ORB ;
  15. import com.sun.corba.se.spi.ior.ObjectAdapterId ;
  16. import com.sun.corba.se.impl.oa.toa.TOAImpl ;
  17. import com.sun.corba.se.impl.oa.toa.TransientObjectManager ;
  18. import com.sun.corba.se.impl.javax.rmi.CORBA.Util ;
  19. import com.sun.corba.se.impl.ior.ObjectKeyTemplateBase ;
  20. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  21. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  22. public class TOAFactory implements ObjectAdapterFactory
  23. {
  24. private ORB orb ;
  25. private ORBUtilSystemException wrapper ;
  26. private TOAImpl toa ;
  27. private Map codebaseToTOA ;
  28. private TransientObjectManager tom ;
  29. public ObjectAdapter find ( ObjectAdapterId oaid )
  30. {
  31. if (oaid.equals( ObjectKeyTemplateBase.JIDL_OAID ) )
  32. // Return the dispatch-only TOA, which can dispatch
  33. // request for objects created by any TOA.
  34. return getTOA() ;
  35. else
  36. throw wrapper.badToaOaid() ;
  37. }
  38. public void init( ORB orb )
  39. {
  40. this.orb = orb ;
  41. wrapper = ORBUtilSystemException.get( orb,
  42. CORBALogDomains.OA_LIFECYCLE ) ;
  43. tom = new TransientObjectManager( orb ) ;
  44. codebaseToTOA = new HashMap() ;
  45. }
  46. public void shutdown( boolean waitForCompletion )
  47. {
  48. if (Util.instance != null) {
  49. Util.instance.unregisterTargetsForORB(orb);
  50. }
  51. }
  52. public synchronized TOA getTOA( String codebase )
  53. {
  54. TOA toa = (TOA)(codebaseToTOA.get( codebase )) ;
  55. if (toa == null) {
  56. toa = new TOAImpl( orb, tom, codebase ) ;
  57. codebaseToTOA.put( codebase, toa ) ;
  58. }
  59. return toa ;
  60. }
  61. public synchronized TOA getTOA()
  62. {
  63. if (toa == null)
  64. // The dispatch-only TOA is not used for creating
  65. // objrefs, so its codebase can be null (and must
  66. // be, since we do not have a servant at this point)
  67. toa = new TOAImpl( orb, tom, null ) ;
  68. return toa ;
  69. }
  70. public ORB getORB()
  71. {
  72. return orb ;
  73. }
  74. } ;