使用 JAX-RPC 访问 IBM WebSphere Service Registry and Repository
2009-10-23 00:00:00 来源:WEB开发网处理查询结果
所有与查询相关的操作都返回 QueryResult 类型的实例。QueryResult 实例包含一列 DataGraphType 实例,一个 DataGraphType 实例对应一个与查询条件匹配的对象。如果是属性查询,则每个 DataGraphType 实例都包含一组 UserDefinedProperty 实例,一个 UserDefinedProperty 实例对应查询中请求的一个属性。如果是 datagraph 查询,则每个 DataGraphType 实例都包含与查询匹配的对象的数据图。
以下代码说明如何访问 datagraph 查询的结果。
static void printQueryResult(QueryResult queryResult) {
DataGraphType[] resultArray = queryResult.getDatagraph();
if (resultArray != null) {
System.out.println("Number of results: " + resultArray.length);
for (int i = 0; i < resultArray.length; i++) {
DataGraphType dg = (DataGraphType) resultArray[i];
if (dg != null) {
printRootObject(dg);
} else {
System.err.println("Null dg");
}
}
} else {
System.err.println("Null resultArray");
}
}
static void printRootObject(DataGraphType dg) {
BaseObject baseObject = getRootObject(dg);
if (baseObject != null) {
System.out.print("{");
System.out.print(baseObject.getName());
System.out.print(", ");
System.out.print(baseObject.getNamespace());
System.out.print(", ");
System.out.print(baseObject.getVersion());
System.out.println("}");
if (baseObject instanceof Document) {
System.out.println("content:");
Document doc = (Document) baseObject;
String documentContent = new String(doc.getContent());
System.out.println(documentContent);
}
} else {
System.err.println("Root object not found");
}
}
static BaseObject getRootObject(DataGraphType dg) {
BaseObject baseObject = null;
WSRR wsrr = dg.getWSRR();
if (wsrr != null) {
String rootObjectID = wsrr.getRoot();
if (rootObjectID != null) {
if (!rootObjectID.equals("")) {
HashMap hm = buildHashMap(dg);
if (hm != null) {
baseObject = (BaseObject)(hm.get(rootObjectID));
} else {
System.err.println("Root object not in HashMap");
}
} else {
System.err.println("empty rootObjectID");
}
} else {
System.err.println("null rootObjectID");
}
} else {
System.err.println("null wsrr");
}
return baseObject;
}
更多精彩
赞助商链接