1. /*
  2. * @(#)FVDCodeBaseImpl.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. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.impl.io;
  16. import org.omg.CORBA.ORB;
  17. import java.util.Properties;
  18. import javax.rmi.CORBA.Util;
  19. import javax.rmi.CORBA.ValueHandler;
  20. import java.util.Hashtable;
  21. import java.util.Stack;
  22. import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
  23. import com.sun.org.omg.SendingContext._CodeBaseImplBase;
  24. import com.sun.org.omg.SendingContext.CodeBase;
  25. import com.sun.org.omg.SendingContext.CodeBaseHelper;
  26. import org.omg.CORBA.CompletionStatus;
  27. import org.omg.CORBA.ORB;
  28. import com.sun.corba.se.impl.logging.OMGSystemException;
  29. import com.sun.corba.se.spi.logging.CORBALogDomains;
  30. /**
  31. * This class acts as the remote interface to receivers wishing to retrieve
  32. * the information of a remote Class.
  33. */
  34. public class FVDCodeBaseImpl extends _CodeBaseImplBase
  35. {
  36. // Contains rep. ids as keys to FullValueDescriptions
  37. private static Hashtable fvds = new Hashtable();
  38. // Private ORBSingleton used when we need an ORB while not
  39. // having a delegate set.
  40. private transient ORB orb = null;
  41. private transient OMGSystemException wrapper = OMGSystemException.get(
  42. CORBALogDomains.RPC_ENCODING ) ;
  43. // backward compatability so that appropriate rep-id calculations
  44. // can take place
  45. // this needs to be transient to prevent serialization during
  46. // marshalling/unmarshalling
  47. private transient ValueHandlerImpl vhandler = null;
  48. void setValueHandler(ValueHandler vh)
  49. {
  50. vhandler = (com.sun.corba.se.impl.io.ValueHandlerImpl) vh;
  51. }
  52. // Operation to obtain the IR from the sending context
  53. public com.sun.org.omg.CORBA.Repository get_ir (){
  54. return null;
  55. }
  56. // Operations to obtain a URL to the implementation code
  57. public String implementation (String x){
  58. try{
  59. // default to using the current ORB version in case the
  60. // vhandler is not set
  61. if (vhandler == null) {
  62. vhandler = new ValueHandlerImpl(false);
  63. }
  64. // Util.getCodebase may return null which would
  65. // cause a BAD_PARAM exception.
  66. String result = Util.getCodebase(vhandler.getClassFromType(x));
  67. if (result == null)
  68. return "";
  69. else
  70. return result;
  71. } catch(ClassNotFoundException cnfe){
  72. throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE,
  73. cnfe ) ;
  74. }
  75. }
  76. public String[] implementations (String[] x){
  77. String result[] = new String[x.length];
  78. for (int i = 0; i < x.length; i++)
  79. result[i] = implementation(x[i]);
  80. return result;
  81. }
  82. // the same information
  83. public FullValueDescription meta (String x){
  84. try{
  85. FullValueDescription result = (FullValueDescription)fvds.get(x);
  86. if (result == null) {
  87. // default to using the current ORB version in case the
  88. // vhandler is not set
  89. if (vhandler == null) {
  90. vhandler = new ValueHandlerImpl(false);
  91. }
  92. try{
  93. result = ValueUtility.translate(_orb(),
  94. ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
  95. } catch(Throwable t){
  96. if (orb == null)
  97. orb = ORB.init(); //d11638
  98. result = ValueUtility.translate(orb,
  99. ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
  100. }
  101. if (result != null){
  102. fvds.put(x, result);
  103. } else {
  104. throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE);
  105. }
  106. }
  107. return result;
  108. } catch(Throwable t){
  109. throw wrapper.incompatibleValueImpl(CompletionStatus.COMPLETED_MAYBE,t);
  110. }
  111. }
  112. public FullValueDescription[] metas (String[] x){
  113. FullValueDescription descriptions[] = new FullValueDescription[x.length];
  114. for (int i = 0; i < x.length; i++)
  115. descriptions[i] = meta(x[i]);
  116. return descriptions;
  117. }
  118. // information
  119. public String[] bases (String x){
  120. try {
  121. // default to using the current ORB version in case the
  122. // vhandler is not set
  123. if (vhandler == null) {
  124. vhandler = new ValueHandlerImpl(false);
  125. }
  126. Stack repIds = new Stack();
  127. Class parent = ObjectStreamClass.lookup(vhandler.getClassFromType(x)).forClass().getSuperclass();
  128. while (!parent.equals(java.lang.Object.class)) {
  129. repIds.push(vhandler.createForAnyType(parent));
  130. parent = parent.getSuperclass();
  131. }
  132. String result[] = new String[repIds.size()];
  133. for (int i = result.length - 1; i >= 0; i++)
  134. result[i] = (String)repIds.pop();
  135. return result;
  136. } catch (Throwable t) {
  137. throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE, t );
  138. }
  139. }
  140. }