简体   繁体   中英

Import Java Custom Method in Xquery

I am using Weblogic Integration framework. While transforming one XML format to another using .xq file, I want to apply some logic written in a custom Java Class.

For example, XML1 has tag: <UnitCode>XYZ</UnitCode>

Custom Java Class:

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>

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. (The details may differ from one XQuery processor to another, which is why I'm referring you to the manual.)

Whilst @keshlam mentions Extension Functions, which are indeed supported by many implementations each with their own API.

I think perhaps what you are looking for instead is Java Binding from XQuery. Many implementations also support this and tend to use the same approach. I do not know whether WebLogic supports this or not! 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.

You can from two examples of implementations that offer the same Java Binding from XQuery functionality here:

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

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. However, I strongly suggest you check their documentation as they may take a different approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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