| 在Data View Builder中带了很多标准的函数,但这些标准函数不可能实现所有客户的需求,使用Custom Function可以实现标准函数不能实现的功能,提高Liquid Data应用的灵活性。
创建配置Custom Function的步骤如下:
1. 编程实现Custom Function的具体功能。
注:实现Custom Function的Java方法必须定义为静态的(Static)
例程:
package sample.ld.cf;
import java.io.Serializable;
public class CustomFunctionSample implements Serializable
{
public CustomFunctionSample(){}
public static String getDate(String dateString)
{
return dateString.substring(0,10);
}
}
2. 将编译好的class文件用jar命令加到一个Jar文件中,如:ld_sample_cf.jar。
3. 编写客户化函数库定义(CFLD----Custom Function Library Definition)文件。
例:
<?xml version="1.0" encoding="UTF-8"?>
<definitions>
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xs:schema>
</types>
<functions>
<function name="getDate" return_type="xs:string"
class="sample.ld.cf.CustomFunctionSample" method="getDate"
asynchronous="false">
<argument type="xs:string"/>
<presentation group="Sample Custom Function"/>
<description>Function to get the 10 char of date string</description>
</function>
</functions>
</definitions>
4. 将Jar文件和CFLD文件复制到Liquid Data Repository下的相应目录。Jar文件存放在custom_lib目录下,CFLD文件存放在custom_functions目录下。


5. 进入WebLoigc Domain控制台,在Configuration分页下的General分页设置Custom Functions Classpath。将Jar文件(ld_sample_cf.jar)的路径添加到Custom Functions Classpath设置项中。

6. 创建Custom Function。

| 作者简介 |
|
丘晓斌是(dev2dev ID: andy) BEA Channel System Enginner |
|