1. /*
  2. * @(#)FVDCodeBaseImpl.java 1.14 03/01/23
  3. *
  4. * Copyright 2003 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.internal.io;
  16. import org.omg.CORBA.ORB;
  17. import org.omg.CORBA.portable.ObjectImpl;
  18. import java.util.Properties;
  19. import javax.rmi.CORBA.Util;
  20. import javax.rmi.CORBA.ValueHandler;
  21. import java.util.Hashtable;
  22. import java.util.Stack;
  23. import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
  24. import com.sun.org.omg.SendingContext._CodeBaseImplBase;
  25. import com.sun.org.omg.SendingContext.CodeBase;
  26. import com.sun.org.omg.SendingContext.CodeBaseHelper;
  27. import org.omg.CORBA.CompletionStatus;
  28. import org.omg.CORBA.NO_IMPLEMENT;
  29. import org.omg.CORBA.MARSHAL;
  30. import org.omg.CORBA.ORB;
  31. import com.sun.corba.se.internal.util.MinorCodes;
  32. /**
  33. * This class acts as the remote interface to receivers wishing to retrieve
  34. * the information of a remote Class.
  35. */
  36. public class FVDCodeBaseImpl extends _CodeBaseImplBase
  37. {
  38. // Contains rep. ids as keys to FullValueDescriptions
  39. private static Hashtable fvds = new Hashtable();
  40. // Private ORBSingleton used when we need an ORB while not
  41. // having a delegate set.
  42. private ORB orb = null;
  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.internal.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. }
  72. catch(ClassNotFoundException cnfe){
  73. throw new MARSHAL(MinorCodes.MISSING_LOCAL_VALUE_IMPL,
  74. CompletionStatus.COMPLETED_MAYBE);
  75. }
  76. }
  77. public String[] implementations (String[] x){
  78. String result[] = new String[x.length];
  79. for (int i = 0; i < x.length; i++)
  80. result[i] = implementation(x[i]);
  81. return result;
  82. }
  83. // the same information
  84. public FullValueDescription meta (String x){
  85. try{
  86. FullValueDescription result = (FullValueDescription)fvds.get(x);
  87. if (result == null) {
  88. // default to using the current ORB version in case the
  89. // vhandler is not set
  90. if (vhandler == null) {
  91. vhandler = new ValueHandlerImpl(false);
  92. }
  93. try{
  94. result = ValueUtility.translate(_orb(), ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
  95. }
  96. catch(Throwable t){
  97. if (orb == null)
  98. orb = ORB.init(); //d11638
  99. result = ValueUtility.translate(orb, ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
  100. }
  101. if (result != null){
  102. fvds.put(x, result);
  103. }
  104. else {
  105. throw new MARSHAL(MinorCodes.MISSING_LOCAL_VALUE_IMPL,
  106. CompletionStatus.COMPLETED_MAYBE);
  107. }
  108. }
  109. return result;
  110. }
  111. catch(Throwable t){
  112. throw new MARSHAL(MinorCodes.INCOMPATIBLE_VALUE_IMPL,
  113. CompletionStatus.COMPLETED_MAYBE);
  114. }
  115. }
  116. public FullValueDescription[] metas (String[] x){
  117. FullValueDescription descriptions[] = new FullValueDescription[x.length];
  118. for (int i = 0; i < x.length; i++)
  119. descriptions[i] = meta(x[i]);
  120. return descriptions;
  121. }
  122. // information
  123. public String[] bases (String x){
  124. try {
  125. // default to using the current ORB version in case the
  126. // vhandler is not set
  127. if (vhandler == null) {
  128. vhandler = new ValueHandlerImpl(false);
  129. }
  130. Stack repIds = new Stack();
  131. Class parent = ObjectStreamClass.lookup(vhandler.getClassFromType(x)).forClass().getSuperclass();
  132. while (!parent.equals(java.lang.Object.class)) {
  133. repIds.push(vhandler.createForAnyType(parent));
  134. parent = parent.getSuperclass();
  135. }
  136. String result[] = new String[repIds.size()];
  137. for (int i = result.length - 1; i >= 0; i++)
  138. result[i] = (String)repIds.pop();
  139. return result;
  140. }
  141. catch (Throwable t) {
  142. throw new MARSHAL(MinorCodes.MISSING_LOCAL_VALUE_IMPL,
  143. CompletionStatus.COMPLETED_MAYBE);
  144. }
  145. }
  146. //d11638 removed getServantIOR and connect methods
  147. }