简体   繁体   English

在Xquery中导入Java自定义方法

[英]Import Java Custom Method in Xquery

I am using Weblogic Integration framework. 我正在使用Weblogic Integration框架。 While transforming one XML format to another using .xq file, I want to apply some logic written in a custom Java Class. 在使用.xq文件将一种XML格式转换为另一种XML格式时,我想应用一些用自定义Java类编写的逻辑。

For example, XML1 has tag: <UnitCode>XYZ</UnitCode> 例如,XML1具有标签: <UnitCode>XYZ</UnitCode>

Custom Java Class: 自定义Java类:

public class unitcodemapper{
public static String getMappedUnitCode(String unitCode){
    if(unitCode=="XYZ")
       return <<value from DB table>>
    else
       return unitCode;
}
}

XML2 will have a tag: <UnitCode>unitcodemapper.getMappedUnitCode(XML1/UnitCode)</UnitCode> XML2将具有标签: <UnitCode>unitcodemapper.getMappedUnitCode(XML1/UnitCode)</UnitCode>

I cannot find any documentation or example to do this. 我找不到任何文档或示例来执行此操作。 Can someone please help in understanding how this can be done? 有人可以帮助您了解如何完成此操作吗?

This is known as an "extension function". 这称为“扩展功能”。 The documentation for your XQuery implementation should have a section telling you how to write such functions and plug them into the processor. XQuery实现的文档中应有一节告诉您如何编写此类函数并将其插入处理器。 (The details may differ from one XQuery processor to another, which is why I'm referring you to the manual.) (详细信息可能因一个XQuery处理器而异,这就是为什么我要向您介绍该手册的原因。)

Whilst @keshlam mentions Extension Functions, which are indeed supported by many implementations each with their own API. 虽然@keshlam提到了扩展功能,但实际上许多实现都支持扩展功能,每个实现都有自己的API。

I think perhaps what you are looking for instead is Java Binding from XQuery. 我认为也许您正在寻找的是XQuery中的Java绑定。 Many implementations also support this and tend to use the same approach. 许多实现也支持这一点,并且倾向于使用相同的方法。 I do not know whether WebLogic supports this or not! 我不知道WebLogic是否支持! If it does, the trick is to use java: at the start of your namespace URI declaration, you can then use the fully qualified Java class name of a static class, each static method you may then call directly from that namespace. 如果是这样,诀窍是使用java:在名称空间URI声明的开始处,您可以使用静态类的标准Java类名称,然后可以直接从该名称空间调用每个静态方法。

You can from two examples of implementations that offer the same Java Binding from XQuery functionality here: 您可以在此处从XQuery功能提供相同Java绑定的两个实现示例中进行操作:

http://exist-db.org/exist/apps/doc/xquery.xml#calling-java http://exist-db.org/exist/apps/doc/xquery.xml#calling-java

http://docs.basex.org/wiki/Java_Bindings http://docs.basex.org/wiki/Java_Bindings

These could serve as examples for you to try on WebLogic to see if it is supported in the same way. 这些可以作为示例,供您尝试使用WebLogic来查看是否以相同的方式支持它。 However, I strongly suggest you check their documentation as they may take a different approach. 但是,我强烈建议您检查他们的文档,因为他们可能会采用其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM