我最终会在笔记文档中写一些自定义数据。但在此之前我想看看它是如何工作的,所以我从IBM Knowledge Center复制/粘贴了关于在两个单独的代理中替换/ getItemValueCustomData的示例。
问题是,当我尝试读取自定义数据时,Read Agent会抛出该异常:
java.lang.ClassNotFoundException: customData.IntIntString
at java.lang.Class.forName(Class.java:291)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:619)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1609)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1768)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:364)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
以下是代码:
写代理人:
import customData.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
IntIntString iis = new IntIntString();
iis.setData(1, 2, "String1");
Document doc = agentContext.getDocumentContext();
doc.replaceItemValueCustomData("IntIntStringItem", "IntIntStringType", iis);
doc.save();
} catch (Exception e) {
e.printStackTrace();
}
}
阅读代理商:
import intIntString.IntIntString;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
if (doc.hasItem("IntIntStringItem")) {
IntIntString iis = (IntIntString) doc.getItemValueCustomData("IntIntStringItem", "IntIntStringType");
iis.show();
} else {
System.out.println("No item IntIntStringItem in document");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
IntIntString类:
package customData;
import java.io.Serializable;
public class IntIntString implements Serializable {
private static final long serialVersionUID = 6875473472063311349L;
private int int1;
private int int2;
private String string1;
public void setData(int i1, int i2, String s1) {
int1 = i1;
int2 = i2;
string1 = s1;
}
public void show() {
System.out.println("Int1 = " + int1);
System.out.println("Int2 = " + int2);
System.out.println("String1 = " + string1);
}
}
代理人的字谜:
. I n t I n t S t r i n g T y p e . . .
10 49 6E 74 49 6E 74 53 74 72 69 6E 67 54 79 70 65 AC ED 00
. s r . . c u s t o m D a t a . I n t I
05 73 72 00 17 63 75 73 74 6F 6D 44 61 74 61 2E 49 6E 74 49
n t S t r i n g _ j . . . . . . . . . I
6E 74 53 74 72 69 6E 67 5F 6A 96 B1 EC F4 8D F5 02 00 03 49
. . i n t 1 I . . i n t 2 L . . s t r i
00 04 69 6E 74 31 49 00 04 69 6E 74 32 4C 00 07 73 74 72 69
n g 1 t . . L j a v a / l a n g / S t r
6E 67 31 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F 53 74 72
i n g ; x p . . . . . . . . t . . S t r
69 6E 67 3B 78 70 00 00 00 01 00 00 00 02 74 00 07 53 74 72
i n g 1
69 6E 67 31
我想念一些东西还是IBM醉了?
示例链接:replaceItemValueCustomData method,getItemValueCustomData method。
编辑:试图在“Agent”类中定义“IntIntString”类,但这不起作用,也不将该类放在.jar中并导入它。
编辑2:正如评论中所建议的那样,我试图在代理中声明类public。出于某种原因,当我尝试时,我必须在代理中实现Serializable,我做了。仍然有同样的例外。
然后我尝试在“customData”包中的单独文件中公开它(因为公共类需要自己的文件),但这也不起作用。
还尝试在文档以读取模式打开时读取字段。我得到了那个例外并且字段被删除了(从文档属性中看到):
NotesException: Supplied Data type name does not match stored CustomData type
at lotus.domino.local.Document.NgetItemValueCustomData(Native Method)
at lotus.domino.local.Document.getItemValueCustomData(Unknown Source)
at JavaAgent.NotesMain(JavaAgent.java:14)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
接收该字段未正确读/写,数据类型应匹配。
代码已更新。
答案 0 :(得分:4)
从自定义类IntIntString
创建一个jar文件import java.io.Serializable;
// Define custom data
public class IntIntString implements Serializable {
private static final long serialVersionUID = 1L;
int int1;
int int2;
String string1;
public void setData(int i1, int i2, String s1) {
int1 = i1;
int2 = i2;
string1 = s1;
}
public void show() {
System.out.println("Int1 = " + int1);
System.out.println("Int2 = " + int2);
System.out.println("String1 = " + string1);
}
}
并将jar文件放入文件夹
这样,ObjectInputStream可以找到自定义类IntIntString,因为它在代理的JVM中是全局可用的。这是IBM的replaceItemValueCustomData / getItemValueCustomData文档中缺少的部分。
答案 1 :(得分:2)
这就是我所做的......
编译并运行时没有错误并更新了文档。