55.7. IDoc 的消息正文
55.7.1. IDoc 消息类型 复制链接链接已复制到粘贴板!
当使用 IDoc Camel SAP 端点之一时,消息正文的类型取决于您使用的特定端点。
对于 sap-idoc-destination 端点或 sap-qidoc-destination 端点,消息正文为 Document 类型:
org.fusesource.camel.component.sap.model.idoc.Document
对于 sap-idoclist-destination 端点、sap-qidoclist-destination 端点或 sap-idoclist-server 端点,消息正文为 DocumentList 类型:
org.fusesource.camel.component.sap.model.idoc.DocumentList
55.7.2. IDoc 文档模型 复制链接链接已复制到粘贴板!
对于 Camel SAP 组件,IDoc 文档使用 Eclipse Modeling Framework (EMF)进行建模,它提供了一个围绕底层 SAP IDoc API 的 wrapper API。这个模型中最重要的类型是:
org.fusesource.camel.component.sap.model.idoc.Document
org.fusesource.camel.component.sap.model.idoc.Segment
文档类型 代表 IDoc 文档实例。另外,文档 界面会公开以下方法:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface Document extends EObject {
// Access the field values from the IDoc control record
String getArchiveKey();
void setArchiveKey(String value);
String getClient();
void setClient(String value);
...
// Access the IDoc document contents
Segment getRootSegment();
}
以下方法通过 文档 界面公开:
- 访问控制记录的方法
- 大多数方法是访问或修改 IDoc 控制记录的字段值。这些方法的格式是 AttributeName,其中 AttributeName 是字段值的名称。
- 访问文档内容的方法
getRootSegment方法提供对文档内容(IDoc data 记录)的访问,将内容返回为Segment对象。每个Segment对象可以包含任意数量的子片段,网段可以嵌套为任意程度。但请注意,网段层次结构的确切布局由文档的特定 IDoc 类型定义。在创建(或读取)网段层次结构时,您必须遵循 IDoc 类型定义的精确结构。
Segment 类型用于访问 IDoc 文档的数据记录,其中片段会根据文档 IDoc 类型定义的结构更宽松。另外,S eg ment 接口会公开以下方法:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface Segment extends EObject, java.util.Map<String, Object> {
// Returns the value of the '<em><b>Parent</b></em>' reference.
Segment getParent();
// Return an immutable list of all child segments
<S extends Segment> EList<S> getChildren();
// Returns a list of child segments of the specified segment type.
<S extends Segment> SegmentList<S> getChildren(String segmentType);
EList<String> getTypes();
Document getDocument();
String getDescription();
String getType();
String getDefinition();
int getHierarchyLevel();
String getIdocType();
String getIdocTypeExtension();
String getSystemRelease();
String getApplicationRelease();
int getNumFields();
long getMaxOccurrence();
long getMinOccurrence();
boolean isMandatory();
boolean isQualified();
int getRecordLength();
<T> T get(Object key, Class<T> type);
}
getChildren (String segmentType) 方法对向片段添加新的(嵌套)子项特别有用。它返回一个类型为 SegmentList 的对象,它定义如下:
// Java
package org.fusesource.camel.component.sap.model.idoc;
...
public interface SegmentList<S extends Segment> extends EObject, EList<S> {
S add();
S add(int index);
}
因此,要创建 E1SCU_CRE 类型的数据记录,您可以使用类似如下的 Java 代码:
Segment rootSegment = document.getRootSegment();
Segment E1SCU_CRE_Segment = rootSegment.getChildren("E1SCU_CRE").add();