Search in sources :

Example 1 with XQResultSequence

use of javax.xml.xquery.XQResultSequence in project iaf by ibissource.

the class XQueryPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    try {
        String stringResult = (String) input;
        // We already specifically use Saxon in this pipe, hence set xslt2
        // to true to make XmlUtils use the Saxon
        // DocumentBuilderFactoryImpl.
        ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true);
        Map parametervalues = null;
        if (getParameterList() != null) {
            parametervalues = prc.getValueMap(getParameterList());
        }
        preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null);
        Iterator iterator = getParameterList().iterator();
        while (iterator.hasNext()) {
            Parameter parameter = (Parameter) iterator.next();
            preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null);
        }
        XQResultSequence resultSequence = preparedExpression.executeQuery();
        stringResult = resultSequence.getSequenceAsString(null);
        return new PipeRunResult(getForward(), stringResult);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on running xquery", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) QName(javax.xml.namespace.QName) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Iterator(java.util.Iterator) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XQException(javax.xml.xquery.XQException) XQResultSequence(javax.xml.xquery.XQResultSequence)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 XQException (javax.xml.xquery.XQException)1 XQResultSequence (javax.xml.xquery.XQResultSequence)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 Parameter (nl.nn.adapterframework.parameters.Parameter)1 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)1