Dashboard > PXE > Home2 > Custom XPath Functions > View

Page Operations


Navigation


PXE Log In   View a printable version of the current page.
Custom XPath Functions
Added by Alex Boisvert, last edited by Alex Boisvert on Aug 30, 2006

Introduction

Ode uses the Saxon XPath processor to support custom XPath functions.

This text is a quick summary of Saxon's own extensibility documentation. I recommend you read it if you need more information. It goes into much more detail on Java invocation, supported data types, conversions, etc.

To use XPath extensions, you must use the XPath 2.0 expression language.

Writing extension functions

An extension function is invoked using a name such as prefix:localname(). The prefix must be the prefix associated with a namespace declaration that is in scope.

Extension functions must be implemented in Java. You bind external Java classes by encoding the class name part in the namespace URI. The URI for the namespace identifies the class where the external function will be found. The namespace URI must either be "java:" followed by the fully-qualified class name (for example xmlns:date="java:java.util.Date"), or a string containing a "/", in which the fully-qualified class name appears after the final "/". (for example xmlns:date="http://www.jclark.com/xt/java/java.util.Date"). The part of the URI before the final "/" is immaterial. The class must be on the classpath, or more specifically accessible from the current classloader.

BPEL code

<assign>
    <copy xmlns:ext="java:com.example.xpath.Random">
        <from expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">ext:random()</from>
        <to>$myVariable</to>
    </copy>
</assign>

Java Code

package com.example.xpath;

/**
 * Returns a random number
 */
public class Random {
    public static int random() {
        java.util.Random randomizer = new java.util.Random();
        int number = randomizer.nextInt();
        return Math.abs(number);
    }
}

You can download source code or the ready-to-use jar for testing.

Deploying extension functions

There are a few options:

  • As a generic solution, you can add your XPath function jar in the application CLASSPATH
  • If Ode is deployed as a webapp, you can copy your XPath function jar in the webapp /lib directory
  • If Ode is deployed inside a JBI container, you can deploy your XPath function jar as a shared library


Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 1.4.1 Build:#212 Jun 02, 2005) - Bug/feature request - Contact Administrators