TIBCO BW6自定义函数,具有dateTime返回类型

时间:2018-12-21 08:11:50

标签: tibco-business-works businessworks

我正在为BW6构建一个自定义函数,该函数应该将ISO 8601格式的字符串解析为dateTime对象。

到目前为止,我已经构建了此功能:

  @XPathFunction(helpText = "Parse a ISO 8601 datetime string",
      parameters = {
          @XPathFunctionParameter(name = "isoDateTimeString", optional = false)
      },
      returnType = "dateTime")
  public Date parseIsoDateTime(String isoDateTimeString) throws ParseException {
    StringBuilder dateFormatBuilder = new StringBuilder();
    dateFormatBuilder.append("yyyy-MM-dd'T'HH:mm:ss");
    if (isoDateTimeString.contains(".")) {
      dateFormatBuilder.append(".SSS");
    }
    DateFormat dateFormat = new SimpleDateFormat(dateFormatBuilder.toString());

    return dateFormat.parse(isoDateTimeString);
  }

当我运行此函数时,BW会引发异常

09:02:42.412 ERROR [bwEngThread:In-Memory Process Worker-1] com.tibco.bw.core - TIBCO-BW-CORE-500050: The BW process [demo.parse-datetime.module.Process] instance faulted, JobId [bw0a100], ProcessInstanceId [bw0a100], ParentProcessInstanceId [-], Module [demo.parse-datetime.module:1.0.0.qualifier], Application [demo.parse-datetime:1.0].  
   <CausedBy> TIBCO-BW-CORE-500058: Activity [SetDateTimeValue] XML related error.  
   <CausedBy> com.tibco.pvm.dataexch.xml.util.exceptions.PmxException: PVM-XML-106017: Expression Evaluation Error: 'bxcom:parseIsoDateTime($dateTimeAsString)'
   <CausedBy> java.lang.ClassCastException: java.util.Date cannot be cast to com.tibco.xml.data.primitive.XmlAtomicValue

那么我该如何从BW6中的自定义xslt函数返回XML dateTime对象。

1 个答案:

答案 0 :(得分:0)

您需要创建一个插件项目以允许自定义XPath功能。 (您将需要ActiveMatrix BusinessWorks™ Plug-in Development Kit

Create Custom XPath Functions

如果要使用它们的设计时间,则需要导出插件项目并将jar作为依赖项。

Using Custom XPath Function at Design Time and Run Time