gpt4 book ai didi

java - 使用LS2J访问lotuscript中的java接口(interface)?

转载 作者:行者123 更新时间:2023-12-02 05:42:38 30 4
gpt4 key购买 nike

在这里输入代码我尝试通过他的接口(interface)访问一个java类我在 Ls2J 中创建一个类而不是 java 接口(interface),因为我不知道我该怎么做我有错误:

error : LS2J Error: Java constructor failed to execute

一个想法? ^^

谢谢!

我的莲花类java

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

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

Public Sub notesMain()
Set methodJava = classJava.GetMethod("notesMain","()V")
objectJava.notesMain
End Sub

下课

我的java接口(interface):

包com.pasquier.IDAO.WS;

导入com.pasquier.MesExceptions.ExceptionWS;

公共(public)接口(interface) ILogWebService {

void notesMain() throws ExceptionWS;    

}

我的java类:

public class LogWebService implements ILogWebService {
private Session session;
private LogWSDTO logDTO = null;

public LogWebService(LogWSDTO log) {
this.logDTO = log;
}


public void notesMain() throws ExceptionWS {
try
{
try
{
session = WebServiceBase.getCurrentSession();
ILogWSDAO ilog = FactoryWS.getInstance().createLogWSDAO(session, logDTO);

ilog.ajouterLog();
} finally
{
UtilMemoire.purgeMemoire();
}
} catch (NullPointerException e1)
{
System.out.println("ERREUR NullPointer sur NotesMain sur LogWebService");
throw new ExceptionWS("ERREUR NullPointer sur NotesMain sur LogWebService", e1, logDTO);
} catch (ExceptionWS e)
{
System.out.println( e.getMessage());
} catch (Exception e2)
{
System.out.println("ERREUR sur NotesMain sur LogWebService " + e2.getMessage());
throw new ExceptionWS("ERREUR sur NotesMain sur LogWebService " + e2.getMessage(), e2, logDTO);
}
}

我的莲花脚本:

Class LogGetAllDocumentsDAO

Private ilog As ILogWebService
Private logDTO As LogWSDTO
Private docDTO As LogGetAllDocumentsDTO
Private utilDt As UtilDate

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 ILogWebService(logDTO)
'Call ilog.notesMain()
End Sub

Public Sub ajouterParam()

Dim retourWS As String
Dim paramWS As String

'paramètres d'envoi de web services
paramWS = "dbserver=" + docDTO.getDbServer
paramWS = paramWS + "dbpath=" + docDTO.getDbPath
paramWS = paramWS + "nomVue=" + docDTO.getNomVue
paramWS = paramWS + "key=" + docDTO.getKey
paramWS = paramWS + "sep=" + docDTO.getSep

logDTO.setParamWS(paramWS)

'paramètres de retour de web services
retourWS = "Nombre d'Identifiants : ...."
logDTO.setRetourWS(retourWS)

'logDTO.setDateHeureDebutWS(utilDt.dateTimeDuJour(session, logDTO))

End Sub

下课

感谢您的帮助!!

我回来是因为它不起作用我尝试调用我的类,就好像接口(interface)不存在一样,但它显示错误:“LS2J 错误:Java 构造函数无法执行”

Sub Click(Source As Button)
Dim mySession As JAVASESSION
Dim myClass As JAVACLASS
Dim myObjet As JAVAOBJECT
Dim toto As String
Dim toto2 As String
Dim myCollection As JavaMethodCollection
Dim myMethod As JavaMethod
Dim myMethod2 As JavaMethod
toto2 = "test"

Set mySession = New JAVASESSION
Set myClass = mySession.GetClass("com.pasquier.launcher/LogWebService")
Set myObjet = myClass.CreateObject("(Lcom/pasquier/DTO/WS/LogWSDTO;)V")


Messagebox (toto2)

Set myCollection = myClass.getClassMethods()

Set myMethod = myCollection.getFirst()
Do
If myCollection.count <> 0 Then
toto2 = myMethod.MethodName & " " & myMethod.signature
Messagebox (toto2)

End If
Set myMethod = myCollection.getNext()
Loop While myCollection.current <> 1

结束子

你能帮我吗?

最佳答案

假设我们有一个包 com.pasquier.IDAO.WS 以及其中的以下类/接口(interface):

  • LogWeb服务
  • LogWSDTO
  • ILogWebService

LS2J 是一个奇怪的东西,在某些情况下无法正常工作。开发人员 react like this当 LS2J 报告不应该发生的错误时。

我们假设 LogWSDTO 有默认构造函数,因此我们创建它的实例:

Set logWSDTOClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWSDTO")
Set logWSDTOObject = logWSDTOClass.CreateObject()

然后我们创建对象,在其构造函数中使用此日志。

我们得到了类:

Set logWebServiceClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWebService")

并调用:

Set logWebServiceObject = logWebServiceClass.CreateObject("(Lcom/pasquier/IDAO/WS/LogWSDTO;)V", logWSDTOObject)

TA-DAA!,那是行不通的。我们得到了著名的“Java 构造函数无法执行”。为什么?因为构造函数有一个类型正确的参数,因此不应发生此错误。但这是LS2J,我们需要受苦:)

因此,我们需要一种解决方法来解决此任务。

我们正在修改 LogWebService 类以声明默认构造函数,并添加一个新方法:

public void setLog(LogWSDTO log) {
this.logDTO = log;
}

之后我们做:

Set logWebServiceObject = logWebServiceClass.CreateObject()
Call logWebServiceObject.setLog(logWSDTOObject)
Call logWebServiceObject.notesMain()

它有效。魔法。

下面列出了此示例所需的所有类/代码:

<小时/>
package com.pasquier.IDAO.WS;

public class LogWSDTO {

public LogWSDTO() {
System.out.println("@@@ LogWSDTO constructor called!");
}

public void log() {
System.out.println("@@@ LogWSDTO DO called!");
}

}
<小时/>
package com.pasquier.IDAO.WS;

public interface ILogWebService {
void notesMain();
}
<小时/>
package com.pasquier.IDAO.WS;

import lotus.domino.Session;

public class LogWebService implements ILogWebService {

private Session session;
private LogWSDTO logDTO = null;

public LogWebService() {
System.out.println("LogWebService: Default Constructor called!");
}

public void setLog(LogWSDTO log) {
this.logDTO = log;
}

public LogWebService(LogWSDTO log) {
this.logDTO = log;
System.out.println("~~~ LogWebService.constructor!!!");
}

public void notesMain() {
// TODO Auto-generated method stub
System.out.println("~~~ LogWebService.notesmain called!!!");
this.logDTO.log();

}
}
<小时/>

和 LotusScript 代码:

Sub Click(Source As Button)
Dim javaSession As New JAVASESSION
Dim javaError As JAVAERROR

On Error Goto ErrorHandling

Dim logWSDTOClass As JAVACLASS
Dim logWSDTOObject As JavaObject

Dim logWebServiceClass As JAVACLASS
Dim logWebServiceObject As JavaObject

Set logWSDTOClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWSDTO")
Set logWSDTOObject = logWSDTOClass.CreateObject()

Set logWebServiceClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWebService")

'Does not work, but should
'Set logWebServiceObject = logWebServiceClass.CreateObject("(Lcom/pasquier/IDAO/WS/LogWSDTO;)V", logWSDTOObject)

'workaround
Set logWebServiceObject = logWebServiceClass.CreateObject()
Call logWebServiceObject.setLog(logWSDTOObject)
Call logWebServiceObject.notesMain()

Msgbox "done"

Exit Sub
ErrorHandling:
Msgbox Error '
Set javaError = javaSession.getLastJavaError
Msgbox "Java error: " + javaError.ErrorMsg
End Sub
<小时/>

要查看输出消息(通过 System.out.println),请通过菜单“工具 - 显示 Java 调试控制台”打开 Java 调试控制台。有时此控制台不会显示,您需要重新启动 Lotus 客户端和设计器。

关于java - 使用LS2J访问lotuscript中的java接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24385613/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com