Accessing Adapter-Specific Attributes
Use
Sender adapters can write adapter-specific attributes to the message header; these can then be evaluated at configuration time (see: Adapter-Specific Message Attributes in the Message Header ). Java mapping programs can also change the attributes after the message has arrived (see also: Java Mapping of Adapter-Specific Attributes ).
To change the adapter-specific attributes of the message header by using message mappings, you access the required classes of the mapping API by using a mapping runtime constant.
Integration
To access the classes DynamicConfiguration and DynamicConfigurationKey by using the mapping runtime constant DYNAMIC_CONFIGURATION, use the method getTransformationParameters() of the container object .
Example
The following program code for a user-defined function changes the value of the file adapter parameter FileName .
package com.hello;
import com.sap.aii.mapping.api.*;
import com.sap.aii.mappingtool.tf7.rt.*;
import java.util.*;
public class HelloWorld {
public void init(GlobalContainer container) throws StreamTransformationException {
}
public String putASMA(String namespace, String attributename, String attributevalue, Container container)
throws StreamTransformationException {
Map map = container.getTransformationParameters();
DynamicConfiguration conf = (DynamicConfiguration) map.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(namespace, attributename);
conf.put(key, attributevalue);
return "";
}
public String getASMA(String namespace, String attribute, Container container)
throws StreamTransformationException {
Map map = container.getTransformationParameters();
DynamicConfiguration conf = (DynamicConfiguration) map.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(namespace, attribute);
String value = conf.get(key);
return value;
}
public String Example(String namespace, String attribute, Container container)
throws StreamTransformationException {
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String valueOld = conf.get(key);
if (valueOld != null) {
String valueNew = valueOld.replaceAll("input", "output");
conf.put(key, valueNew);
}
return "";
}
public void cleanUp(GlobalContainer container) throws StreamTransformationException {
}
}
访问特定于适配器的属性
采用
发送方适配器可以将特定于适配器的属性写入消息头; 然后可以在配置时评估这些(请参阅:消息头中的适配器特定消息属性)。 Java 映射程序还可以在消息到达后更改属性(另请参阅:适配器特定属性的 Java 映射)。
要使用消息映射更改消息头的特定于适配器的属性,您可以使用映射运行时常量访问映射 API 的所需类。
一体化
要使用映射运行时常量 DYNAMIC_CONFIGURATION 访问类 DynamicConfiguration 和 DynamicConfigurationKey,请使用容器对象的 getTransformationParameters() 方法。
例子
以下用户定义函数的程序代码更改了文件适配器参数 FileName 的值。