javalotus-dominols2j

How pass an object in parameter of another class in LS2J?


I am trying to pass an object of a java class (a bean) to another class with LS2J.

The problem is that an error is returned :

LS2J Error: Threw java.lang.ClassNotFoundException: com.pasquier.DTO.WS.LogWSDTO

I don't know why ?

I have a class bean normally with getter and setter. I want to pass an instance of this class in another.

My class in 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

It is the method setLog which crashes

I call it in the code :

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 

an idea ?

i have a class LogDTO in the same library than LogWebService.

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

if i understand i can't pass logDTO with :

Set Me.logDTO = logWSparam

is it that ? But how i do then ??


well i try but it doesn't work.

I add a getObjet method in LS2J (not in java only on lotus)

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

i try to call this in my prog :

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 

i can't save this change : it returns :

"type mismatch on : GETJAVAOBJECT"


so i try to add the method in LogWebService' s java class. and i try in LS2J :

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

i call with :

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

and it doesn't works, same message, i cry !!!


Solution

  • objectJava.setLog(logDTO) - logDTO has to be a Java object generated by LS2J. It won't work with a LotusScript class object.

    Add a method getJavaObject() to your LotusScript class LogWSDTO which returns the LS2J Java object objectJava. Use it this way then:

    objectJava.setLog(logDTO.getJavaObject())
    

    This is a working example:

    LotusScript agent:

    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 classes in Java ScriptLibrary "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");
        }
    }