1. /*
  2. * @(#)CopyobjectDefaults.java 1.9 04/06/21
  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.spi.copyobject ;
  8. import com.sun.corba.se.spi.orb.ORB ;
  9. import com.sun.corba.se.impl.copyobject.ReferenceObjectCopierImpl ;
  10. import com.sun.corba.se.impl.copyobject.FallbackObjectCopierImpl ;
  11. import com.sun.corba.se.impl.copyobject.ORBStreamObjectCopierImpl ;
  12. import com.sun.corba.se.impl.copyobject.JavaStreamObjectCopierImpl ;
  13. public abstract class CopyobjectDefaults
  14. {
  15. private CopyobjectDefaults() { }
  16. /** Obtain the ORB stream copier factory. Note that this version behaves differently
  17. * than the others: each ObjectCopier produced by the factory only preserves aliasing
  18. * within a single call to copy. The others copiers all preserve aliasing across
  19. * all calls to copy (on the same ObjectCopier instance).
  20. */
  21. public static ObjectCopierFactory makeORBStreamObjectCopierFactory( final ORB orb )
  22. {
  23. return new ObjectCopierFactory() {
  24. public ObjectCopier make( )
  25. {
  26. return new ORBStreamObjectCopierImpl( orb ) ;
  27. }
  28. } ;
  29. }
  30. public static ObjectCopierFactory makeJavaStreamObjectCopierFactory( final ORB orb )
  31. {
  32. return new ObjectCopierFactory() {
  33. public ObjectCopier make( )
  34. {
  35. return new JavaStreamObjectCopierImpl( orb ) ;
  36. }
  37. } ;
  38. }
  39. private static final ObjectCopier referenceObjectCopier = new ReferenceObjectCopierImpl() ;
  40. private static ObjectCopierFactory referenceObjectCopierFactory =
  41. new ObjectCopierFactory() {
  42. public ObjectCopier make()
  43. {
  44. return referenceObjectCopier ;
  45. }
  46. } ;
  47. /** Obtain the reference object "copier". This does no copies: it just
  48. * returns whatever is passed to it.
  49. */
  50. public static ObjectCopierFactory getReferenceObjectCopierFactory()
  51. {
  52. return referenceObjectCopierFactory ;
  53. }
  54. /** Create a fallback copier factory from the two ObjectCopierFactory
  55. * arguments. This copier makes an ObjectCopierFactory that creates
  56. * instances of a fallback copier that first tries an ObjectCopier
  57. * created from f1, then tries one created from f2, if the first
  58. * throws a ReflectiveCopyException.
  59. */
  60. public static ObjectCopierFactory makeFallbackObjectCopierFactory(
  61. final ObjectCopierFactory f1, final ObjectCopierFactory f2 )
  62. {
  63. return new ObjectCopierFactory() {
  64. public ObjectCopier make()
  65. {
  66. ObjectCopier c1 = f1.make() ;
  67. ObjectCopier c2 = f2.make() ;
  68. return new FallbackObjectCopierImpl( c1, c2 ) ;
  69. }
  70. } ;
  71. }
  72. }