简体   繁体   English

从lotus脚本(LS2J)调用Java类的方法

[英]Invoking method on a Java class from lotus script (LS2J)

Most dignified developers, 最有尊严的开发者,

I'm having trouble invoking a method on my own java class from a lotus script agent. 我在从Lotus脚本代理调用我自己的java类中的方法时遇到问题。

My Java class simplified looks like this 我简化的Java类看起来像这样

import lotus.domino.*;

public class MyClass{
   /* .. omitted constructor and other methods .. */

   public void myMethod(Document doc){
      /* ... do things with the document object ...*/
   }

}

Now this class is included with the proper use statement, and I can iterate over the classmethods on the class object in lotus script to get the signature of the arguments needed. 现在这个类包含在正确的use语句中,我可以在lotus脚本中迭代class对象上的classmethods来获取所需参数的签名。

But when I try to invoke the method I get a LS2J: Parameter mismatch calling Method myMethod 但是当我尝试调用该方法时,我得到一个LS2J: Parameter mismatch calling Method myMethod

I've tried both with dot notation on the JavaObject (No I'm not using a Mac ;)) and ADT 我在JavaObject上尝试了点符号(不,我没有使用Mac;))和ADT

Dim doc as NotesDocument
Dim jSession As JavaSession
Dim jClass As JavaClass
Dim jObject As JavaObject

...

Set jSession = New JavaSession()
Set jClass = jSession.Getclass("MyClass")

Set jObject = jClass.Createobject()
Call jObject.myMethod(doc)

and respectively 和分别

Dim jMethod as JavaMethod
...

Set jMethod = jClass.Getmethod("myMethod", "(Llotus/domino/Document;)V")
tmp = jMethod.Invoke(jObject,doc)

Also I've added error handling (OnError ..) to print out the results of any JavaError (+ stacktrace) but they end up empty so no further clues there. 此外,我添加了错误处理(OnError ..)来打印出任何JavaError(+ stacktrace)的结果,但它们最终为空,因此没有进一步的线索。

I'm using Designer version 9.0 我正在使用Designer 9.0版

Any ideas/pointers/gotchas? 任何想法/指针/陷阱? It's driving me bald. 它让我秃顶。

You are using the correct approach to calling your Java method but you can not pass Notes backend objects as parameters. 您正在使用正确的方法来调用Java方法,但是您无法将Notes后端对象作为参数传递。

You can parse a string with the document universal id, for instance, and then in your Java method look up the document using the universal id. 例如,您可以使用文档通用ID解析字符串,然后在Java方法中使用通用ID查找文档。

Alternatively, migrate your Lotusscript logic to Java :-) 或者,将您的Lotusscript逻辑迁移到Java :-)

Maybe you don't need CreateObject.. 也许你不需要CreateObject ..

This is how I do it: 我是这样做的:

Dim jSession As New JavaSession()
Dim jClass As JavaClass()
Set jClass = jSession.GetClass("MyClass")

If jClass.myMethod(doc) Then

Full example added 完整示例添加

Java class:
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class GetFileFromUrl {

    public static boolean getFileFromUrl(String imageUrl, String filePath) {
        try {
            URL url = new URL(imageUrl);
            InputStream is = url.openStream();
            OutputStream os = new FileOutputStream(filePath);
            byte[] b = new byte[2048];
            int length;
            while ((length = is.read(b)) != -1) {
                os.write(b, 0, length);
            }
            is.close();
            os.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

LotusScript: LotusScript中:

UseLSX "*javacon"  
Use "GetFileFromUrl"

Private Function GetFileFromUrl(url As String, outputPath As String) As Boolean
    Dim jSession As New JavaSession
    Dim jClass As JavaClass
    Set jClass = jSession.GetClass("GetFileFromUrl")
    If jClass.getFileFromUrl(url, outputPath) Then
        GetFileFromUrl = True
    End If
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM