如何在LS2J中传递另一个类的参数中的对象?

时间:2014-06-26 13:53:08

标签: java lotus-domino ls2j

我试图将一个java类(bean)的对象传递给另一个使用LS2J的类。

问题是返回错误:

  

LS2J错误:抛出java.lang.ClassNotFoundException:   com.pasquier.DTO.WS.LogWSDTO

我不知道为什么?

我有一个通常带有getter和setter的类bean。 我想在另一个实例中传递这个类的实例。

我在Lotus LS2J中的课程:

Class LogWebService
    sessionJava As JAVASESSION      
    classJava As JAVACLASS
    objectJava As JAVAOBJECT        
    methodJava As JAVAMETHOD

    Public Sub New()
        Set sessionJava = New JAVASESSION
        Set classJava = sessionJava.GetClass("com.pasquier.launcher/LogWebService")
        Set objectJava = classJava.CreateObject     
    End Sub 

    Public Sub setLog(logDTO As LogWSDTO)
        Set methodJava = classJava.GetMethod("setLog","(Lcom/pasquier/DTO/WS/LogWSDTO;)V")      
             objectJava.setLog(logDTO)      
    End Sub 

End Class

崩溃的方法setLog

我在代码中调用它:

Class LogGetAllDocumentsDAO

    Private ilog As LogWebService 
    Private logDTO As LogWSDTO
    Private docDTO As LogGetAllDocumentsDTO

    Public Sub New(logWSparam As LogWSDTO, docDTOparam As LogGetAllDocumentsDTO)
        Set Me.logDTO = logWSparam
        Set Me.docDTO = docDTOparam     
    End Sub 


    Public Sub appelLog()           
        Set ilog = New LogWebService()

        ' error: LS2J Error: Threw java.lang.ClassNotFoundException: com.pasquier.DTO.WS.LogWSDTO
        Call ilog.setLog(logDTO)


    End Sub 

一个想法?

我在与LogWebService相同的库中有一个LogDTO类。

Class LogWSDTO
sessionJava As JAVASESSION      
classJava As JAVACLASS
objectJava As JAVAOBJECT        
methodJava As JAVAMETHOD


Public Sub New()
    Set sessionJava = New JAVASESSION
    Set classJava = sessionJava.GetClass("com.pasquier.DTO.WS/LogWSDTO")
    Set objectJava = classJava.CreateObject     
End Sub

如果我理解我无法通过logDTO:

Set Me.logDTO = logWSparam
是吗?但我怎么做呢?


我尝试但是它没有用。

我在LS2J中添加了一个getObjet方法(不仅仅在Lotus上的java中)

Class LogWSDTO
sessionJava As JAVASESSION      
classJava As JAVACLASS
objectJava As JAVAOBJECT        
methodJava As JAVAMETHOD


Public Sub New()
    Set sessionJava = New JAVASESSION
    Set classJava = sessionJava.GetClass("com.pasquier.DTO.WS/LogWSDTO")
    Set objectJava = classJava.CreateObject     
End Sub


Public Function getJavaObject()
    Set getJavaObject = objectJava      
End Function

我试着在我的编程中调用它:

Class LogGetAllDocumentsDAO

Private ilog As LogWebService 
Private logDTO As LogWSDTO
Private docDTO As LogGetAllDocumentsDTO

Public Sub New(logWSparam As LogWSDTO, docDTOparam As LogGetAllDocumentsDTO)        
    Set Me.logDTO = logWSparam
    Set Me.docDTO = docDTOparam     
End Sub 


Public Sub appelLog()           
    Call ajouterParam()         
    Set ilog = New LogWebService()      

    Call ilog.setLog(logDTO.getJavaObject())
End Sub 

我无法保存此更改:它返回:

"type mismatch on : GETJAVAOBJECT"


所以我尝试在LogWebService中添加方法' s java类。 我在LS2J尝试:

Public Function getJavaObject()         
    Set methodJava = classJava.GetMethod("getJavaObject","()Lcom/pasquier/DTO/WS/LogWSDTO;")        
    getJavaObject = objectJava.getJavaObject()  
End Function

我致电:

Public Sub appelLog()           
    Set ilog = New LogWebService()          
    Set logDTO = logDTO.getJavaObject
    Call ilog.setLog(logDTO)

它不起作用,同样的消息,我哭!

1 个答案:

答案 0 :(得分:3)

objectJava.setLog(logDTO) - logDTO必须是LS2J生成的Java对象。它不能使用LotusScript类对象。

将方法getJavaObject()添加到您的LotusScript类LogWSDTO,它返回LS2J Java对象objectJava。然后以这种方式使用它:

objectJava.setLog(logDTO.getJavaObject())

这是一个有效的例子:

LotusScript代理:

Option Declare
UseLSX "*javacon"
Use "AandB"

Class LogWSDTO
    sessionJava As JAVASESSION      
    classJava As JAVACLASS
    objectJava As JAVAOBJECT        

    Public Sub New()
        Set sessionJava = New JAVASESSION
        Set classJava = sessionJava.GetClass("de.leonso.test/B")
        Set objectJava = classJava.CreateObject     
    End Sub

    Public Function getJavaObject()
        Set getJavaObject = objectJava      
    End Function
End Class

Sub Initialize
    Dim sessionJava As JAVASESSION      
    Dim classJavaA As JAVACLASS
    Dim objectJavaA As JAVAOBJECT        
    Dim lsB As LogWSDTO

    Set sessionJava = New JAVASESSION
    Set classJavaA = sessionJava.GetClass("de.leonso.test/A")
    Set objectJavaA = classJavaA.CreateObject     
    Set lsB = New LogWSDTO()

    print objectJavaA.a(lsB.getJavaObject())

End Sub

Java ScriptLibrary中的Java类" AandB":

package de.leonso.test;

public class A {
    public String a(B b) {
        return b.b();
    }
}

package de.leonso.test;

public class B {
    public String b() {
         return ("hallo");
    }
}