Sviluppando ActiveX codice dell'applicazione client
Sviluppare un ActiveX Programma Windows, come Visual Basic, VBScript e Active Server Pages, per utilizzare il file WebSphere® ActiveX al bridge EJB per accedere ai bean enterprise.
Prima di iniziare
Considera le informazioni fornite in ActiveX al bridge EJB come buone linee guida di programmazione.
Informazioni su questa attività
Procedura
Esempio
Visualizzazione di a System.out messaggio: Il ActiveX all'Impresa JavaBeans Il bridge (EJB) non dispone di una console disponibile per visualizzare Java System.out messaggi. Per visualizzare questi messaggi durante l'esecuzione di un programma client autonomo (come Visual Basic), reindirizzare l'output su un file.
launchClientXJB.bat MyProgram.exe > output.txt- Per visualizzare il System.out messaggi durante l'esecuzione di un programma di servizio come Active Server Pages, sovrascrivono Java System.out OutputStream opporsi a FileOutputStream. Ad esempio, in 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 applicazione client che utilizza metodi di supporto per la conversione del tipo di dati. In generale, la conversione del tipo di dati tra ActiveX (Visual Basic e VBScript) e i metodi Java si verificano automaticamente, come descritto in ActiveX al bridge EJB, convertendo i tipi di dati. Tuttavia, la funzione di supporto byte e la funzione di supporto valuta sono fornite per i casi in cui la conversione automatica non è possibile.
- Funzione di supporto bytePoiché il tipo di dati Byte Java è firmato (da -127 a 128) e il tipo di dati Byte di Visual Basic non è firmato (da 0 a 255), convertire i byte senza segno in numeri interi di Visual Basic, che assomigliano al byte con segno Java. Per effettuare questa conversione, puoi utilizzare la seguente funzione di supporto:
Private Function GetIntFromJavaByte(Byte jByte) as Integer GetIntFromJavaByte = (CInt(jByte) + 128) Mod 256 - 128 End Function - Funzione di aiuto valutaVisual Basic 6.0 non può gestire correttamente numeri interi a 64 bit come possono fare i metodi Java (come il tipo di dati Long). Pertanto, Visual Basic utilizza il tipo Valuta, che è intrinsecamente un tipo di dati a 64 bit. L'unico effetto collaterale dell'utilizzo del tipo Valuta (il tipo Variant VT_CY) è che nel tipo viene inserito un punto decimale. Per estrarre e manipolare il valore Long a 64 bit in Visual Basic, utilizzare codice come nell'esempio seguente. Per ulteriori dettagli su questa tecnica per la conversione dei tipi di dati Valuta, vedere Q189862,
COME FARE: eseguire operazioni aritmetiche a 64 bit in VBA
, nella Microsoft Knowledge Base.' 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