开发 ActiveX 客户机应用程序代码
开发 ActiveX Windows 程序(例如 Visual Basic、VBScript 和 Active Server Pages)以使用 WebSphere® ActiveX 至 EJB 网桥来访问企业 Bean。
开始之前
要点: 本主题假定您熟悉 Windows 平台上的 ActiveX 编程和开发。有关 ActiveX 应用程序客户机和 ActiveX 到 EJB 网桥的编程概念的信息,请参阅“ActiveX 到 Enterprise JavaBeans™ (EJB)
网桥”主题和相关主题。
您应该考虑将 ActiveX 到 EJB 网桥中给定的信息作为适当的编程准则。
关于此任务
过程
示例
查看 System.out 消息:ActiveX 到 Enterprise JavaBeans (EJB) 网桥没有可用于查看 Java System.out 消息的控制台。要在运行独立的客户机程序(如 Visual Basic)时查看这些消息,请将输出重定向到一个文件。
以下示例说明如何将输出重定向到文件:
launchClientXJB.bat MyProgram.exe > output.txt
- 要在运行“服务”程序(如 Active Server Page)时查看 System.out 消息,将 Java System.out OutputStream 对象重设为 FileOutputStream。 例如,在 VBScript 中:
'Redirect system.out to a file ' Assume that oXJB is an initialized XJB.JClassFactory object Dim clsSystem Dim oOS Dim oPS Dim oArgs ' Get the System class Set clsSystem = oXJB.FindClass("java.lang.System") ' Create a FileOutputStream object ' Create a PrintStream object and assign to it our FileOutputStream Set oArgs = oXJB.GetArgsContainer oArgs.AddObject "java.io.OutputStream", oOS Set oPS = oXJB.NewInstance(oXJB.FindClass("java.io.PrintStream"), oArgs) ' Set our System OutputStream to our file clsSystem.setOut oPS
使用帮助程序方法进行数据类型转换的 ActiveX 客户机应用程序。通常,自动转换 ActiveX(Visual Basic 和 VBScript)和 Java 方法直接的数据类型,这个在 ActiveX to EJB 网桥,转换数据类型中描述的一样。但是,针对不可能进行自动转换的情况,提供了字节帮助程序功能和货币帮助程序功能。
- 字节帮助器功能因为 Java Byte 数据类型有正负之分(-127 到 128)而 Visual Basic Byte 数据类型没有正负之分(0 到 255),因此将没有正负之分的 Byte 转换为 Visual Basic Byte,这与 Java 有正负之分的字节类似。要进行此转换,您可以使用下列帮助器功能:
Private Function GetIntFromJavaByte(Byte jByte) as Integer GetIntFromJavaByte = (CInt(jByte) + 128) Mod 256 - 128 End Function
- 货币帮助器功能Visual Basic 6.0 无法正确地处理 64 位整数,而 Java 方法可以(和长整型数据类型一样)。 因此,Visual Basic 使用货币类型,该数据是内在地 64 位数据类型。使用货币类型的唯一副作用是在类型中插入了小数点。 要在 Visual Basic 中抽取和操纵 64 位长型值,使用与下列示例相似的代码。有关这种转换货币数据类型技术的更多详细信息,请参阅 Microsoft Knowledge Base 中的 Q189862“HOWTO: Do 64-bit Arithmetic in VBA”。
' Currency Helper Types Private Type MungeCurr Value As Currency End Type Private Type Munge2Long LoValue As Long HiValue As Long End Type ' Currency Helper Functions Private Function CurrToText(ByVal Value As Currency) As String Dim Temp As String, L As Long Temp = Format$(Value, "#.0000") L = Len(Temp) Temp = Left$(Temp, L - 5) & Right$(Temp, 4) Do While Len(Temp) > 1 And Left$(Temp, 1) = "0" Temp = Mid$(Temp, 2) Loop Do While Len(Temp) > 2 And Left$(Temp, 2) = "-0" Temp = "-" & Mid$(Temp, 3) Loop CurrToText = Temp End Function Private Function TextToCurr(ByVal Value As String) As Currency Dim L As Long, Negative As Boolean Value = Trim$(Value) If Left$(Value, 1) = "-" Then Negative = True Value = Mid$(Value, 2) End If L = Len(Value) If L < 4 Then TextToCurr = CCur(IIf(Negative, "-0.", "0.") & _ Right$("0000" & Value, 4)) Else TextToCurr = CCur(IIf(Negative, "-", "") & _ Left$(Value, L - 4) & "." & Right$(Value, 4)) End If End Function ' Java Long as Currency Usage Example Dim LC As MungeCurr Dim L2 As Munge2Long ' Assign a Currency Value (really a Java Long) ' to the MungeCurr type variable LC.Value = cyTestIn ' Coerce the value to the Munge2Long type variable LSet L2 = LC ' Perform some operation on the value, now that we ' have it available in two 32-bit chunks L2.LoValue = L2.LoValue + 1 ' Coerce the Munge value back into a currency value LSet LC = L2 cyTestIn = LC.Value