104.7. IDoc 的消息正文
104.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
104.7.2. IDoc 文档模型 复制链接链接已复制到粘贴板!
对于 Camel SAP 组件,IDoc 文档使用 Eclipse Modeling Framework (EMF)建模,它围绕底层 SAP IDoc API 提供打包程序 API。这个模型中最重要的类型是:
org.fusesource.camel.component.sap.model.idoc.Document
org.fusesource.camel.component.sap.model.idoc.Segment
文档 类型代表 IDoc 文档实例。简而言之,Document 接口会公开以下方法:
// 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();
}
以下方法由 Document 接口公开:
- 访问控制记录的方法
- 大多数方法都用于访问或修改 IDoc 控制记录的字段值。这些方法是 AttributeName 的形式,其中 AttributeName 是字段值的名称。
- 访问文档内容的方法
getRootSegment方法提供对文档内容(IDoc 数据记录)的访问,将内容返回为Segment对象。每个分段对象可以包含任意数量的子片段,片段可以嵌套到任意程度。但请注意,片段层次结构的精确布局由文档的特定 IDoc 类型定义。在创建(或读取)片段层次结构时,您必须确保遵循 IDoc 类型定义的确切结构。
分段类型用于访问 IDoc 文档的数据记录,其中片段根据文档的 IDoc 类型定义的结构而定。简而言之,分段 接口会公开以下方法:
// 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();