Thursday, August 21, 2008

Reference on the current bpel instance from a XPath function

How to get a reference on the current bpel process into a xpath function ?
That's a big question ...

This is very simple, but you have to know which properties you have to get from the xpathContext.

package com.bpelsoa.xpath;

import java.util.List;
import java.util.Map;

import com.collaxa.cube.engine.CubeContextHelper;
import com.collaxa.cube.engine.ICubeContext;
import com.collaxa.cube.engine.core.ICubeInstanceImpl;
import com.oracle.bpel.xml.xpath.IXPathContext;
import com.oracle.bpel.xml.xpath.IXPathFunction;
import com.oracle.bpel.xml.xpath.XPathFunctionException;

public class CubeInstanceXPath implements IXPathFunction {

  public Object call(IXPathContext context, List list)
      throws XPathFunctionException {

    Map xpathProperties = (Map) context.getVariableValue(null, null,"xpath-function-data");
    ICubeContext cubeContext = (ICubeContext) xpathProperties.get("ICubeContext");

    // get the cube instance from the cube context
    ICubeInstanceImpl cubeInstance = CubeContextHelper.getCubeInstance(cubeContext);

    // do something with cubeInstance ...
    
    return null;
  }
}

You can do any operations on the cubeInstance object (such as modify a partner link, set a correlation id, change any properties, ...) to modify your bpel instance.