Examples of DynamicQueryContext


Examples of net.sf.saxon.query.DynamicQueryContext

        xmlColumn.setPathExpression(exp);
    }
  }
 
    public Result evaluateXQuery(Object context, Map<String, Object> parameterValues) throws TeiidProcessingException {
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);

        Result result = new Result();
        try {
          try {
            for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
                Object value = entry.getValue();
                if(value instanceof SQLXML) {                   
                  value = XMLSystemFunctions.convertToSource(value);
                  result.sources.add((Source)value);
                } else if (value instanceof java.util.Date) {
                  value = XMLSystemFunctions.convertToAtomicValue(value);
                }
                dynamicContext.setParameter(entry.getKey(), value);               
            }
          } catch (TransformerException e) {
            throw new TeiidProcessingException(e);
          }
          if (context != null) {
            Source source = XMLSystemFunctions.convertToSource(context);
            result.sources.add(source);
              if (contextRoot != null) {
                //create our own filter as this logic is not provided in the free saxon
                  ProxyReceiver filter = new PathMapFilter(contextRoot);
                  AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
                  sourceInput.addFilter(filter);
                  source = sourceInput;
              }
              DocumentInfo doc;
        try {
          doc = config.buildDocument(source);
        } catch (XPathException e) {
          throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
        }
            dynamicContext.setContextItem(doc);
          }
          try {
            result.iter = xQuery.iterator(dynamicContext);
            return result;
          } catch (TransformerException e) {
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

        final Configuration config = new Configuration();
        config.setHostLanguage(Configuration.XQUERY);
        final StaticQueryContext staticContext = new StaticQueryContext(config);
        staticContext.setBaseURI(new File(queryFile).toURI().toString());
        XQueryExpression exp = staticContext.compileQuery(IOUtils.toString(new FileInputStream(queryFile)));
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringWriter res_sw = new StringWriter();
        Properties props = new Properties();
        //props.setProperty(OutputKeys.METHOD, "text");
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    private static String invokeQueryBySaxon(String query) throws XPathException {
        Configuration config = new Configuration();
        config.setHostLanguage(Configuration.XQUERY);
        StaticQueryContext staticContext = new StaticQueryContext(config);
        XQueryExpression exp = staticContext.compileQuery(query);
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringWriter res_sw = new StringWriter();
        Properties props = new Properties();
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    public Node evaluateAsDOM(Exchange exchange) throws Exception {
        initialize(exchange);

        DOMResult result = new DOMResult();
        DynamicQueryContext context = createDynamicContext(exchange);
        XQueryExpression expression = getExpression();
        expression.pull(context, result, properties);
        return result.getNode();
    }
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    /**
     * Creates a dynamic context for the given exchange
     */
    protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exception {
        Configuration config = getConfiguration();
        DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);

        Message in = exchange.getIn();
        Source source = null;
        try {
            Item item = in.getBody(Item.class);
            dynamicQueryContext.setContextItem(item);
        } catch (NoTypeConversionAvailableException e) {
            try {
                source = in.getBody(Source.class);
            } catch (NoTypeConversionAvailableException e2) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("No body available on exchange so using an empty document: " + exchange);
                }
                source = converter.toSource(converter.createDocument());
            }
            DocumentInfo doc = getStaticQueryContext().buildDocument(source);
            dynamicQueryContext.setContextItem(doc);
        }
       
        configureQuery(dynamicQueryContext, exchange);
        // call the reset if the in message body is StreamCache
        MessageHelper.resetStreamCache(exchange.getIn());
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

   */
  public ResultSequence execute(Node contextNode,
      DynamicQueryContext dynamicContext, Map variables) throws XQueryException {
   
    if (dynamicContext == null) {
      dynamicContext = new DynamicQueryContext(getStaticContext().getConfiguration());
    }
   
    try {
      setupDynamicContext(contextNode, dynamicContext, variables);
    } catch (TransformerException e) {
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    public static ListVariable evaluateXPath(String xpath, String xml, RuntimeConfig runtimeConfig) throws XPathException {
        StaticQueryContext sqc = runtimeConfig.getStaticQueryContext();
        Configuration config = sqc.getConfiguration();

        XQueryExpression exp = runtimeConfig.getXQueryExpressionPool().getCompiledExpression(xpath);
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringReader reader = new StringReader(xml);

        dynamicContext.setContextItem(sqc.buildDocument(new StreamSource(reader)));

        return createListOfXmlNodes(exp, dynamicContext);
    }
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

        final StaticQueryContext sqc = runtimeConfig.getStaticQueryContext();
        final Configuration config = sqc.getConfiguration();

      try {
          final XQueryExpression exp = runtimeConfig.getXQueryExpressionPool().getCompiledExpression(xqExpression);
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);

            // define external parameters
            for (int i = 0; i < externalParamDefs.length; i++) {
                XQueryExternalParamDef externalParamDef = externalParamDefs[i];
                String externalParamName = BaseTemplater.execute( externalParamDef.getName(), scraper.getScriptEngine() );
                String externalParamType = BaseTemplater.execute( externalParamDefs[i].getType(), scraper.getScriptEngine() );
                if (externalParamType == null) {
                    externalParamType = DEFAULT_PARAM_TYPE;
                }

                // check if param type is one of allowed
                if ( !ALLOWED_PARAM_TYPES.contains(externalParamType) ) {
                    throw new ScraperXQueryException("Type " + externalParamType + " is not allowed. Use one of " + ALLOWED_PARAM_TYPES.toString());
                }

                if ( externalParamType.endsWith("*") ) {
                    BodyProcessor bodyProcessor = new BodyProcessor(externalParamDef);
                    bodyProcessor.setProperty("Name", externalParamName);
                    bodyProcessor.setProperty("Type", externalParamType);
                    ListVariable listVar = (ListVariable) bodyProcessor.run(scraper, context);
                    debug(externalParamDef, scraper, listVar);
                   
                    Iterator it = listVar.toList().iterator();
                    List paramList = new ArrayList();
                    while (it.hasNext()) {
                        Variable currVar =  (Variable) it.next();
                        paramList.add( castSimpleValue(externalParamType, currVar, sqc) );
                    }

                    dynamicContext.setParameter(externalParamName, paramList);
                } else {
                    KeyValuePair props[] = {new KeyValuePair("Name", externalParamName), new KeyValuePair("Type", externalParamType)};
                    Variable var = getBodyTextContent(externalParamDef, scraper, context, true, props);

                    debug(externalParamDef, scraper, var);
                   
                    Object value = castSimpleValue(externalParamType, var, sqc);
                    dynamicContext.setParameter(externalParamName, value);
                }
            }

          return XmlUtil.createListOfXmlNodes(exp, dynamicContext);
      } catch (XPathException e) {
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    public Node evaluateAsDOM(Exchange exchange) throws Exception {
        LOG.debug("evaluateAsDOM: {} for exchange: {}", expression, exchange);
        initialize(exchange);

        DOMResult result = new DOMResult();
        DynamicQueryContext context = createDynamicContext(exchange);
        XQueryExpression expression = getExpression();
        expression.pull(context, result, properties);
        return result.getNode();
    }
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    /**
     * Creates a dynamic context for the given exchange
     */
    protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exception {
        Configuration config = getConfiguration();
        DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);

        Message in = exchange.getIn();
        Item item = null;
        if (ObjectHelper.isNotEmpty(getHeaderName())) {
            item = in.getHeader(getHeaderName(), Item.class);
        } else {
            item = in.getBody(Item.class);
        }
        if (item != null) {
            dynamicQueryContext.setContextItem(item);
        } else {
            Object body = null;
            if (ObjectHelper.isNotEmpty(getHeaderName())) {
                body = in.getHeader(getHeaderName());
            } else {
                body = in.getBody();
            }

            // the underlying input stream, which we need to close to avoid locking files or other resources
            InputStream is = null;
            try {
                Source source;
                // only convert to input stream if really needed
                if (isInputStreamNeeded(exchange)) {
                    if (ObjectHelper.isNotEmpty(getHeaderName())) {
                        is = exchange.getIn().getHeader(getHeaderName(), InputStream.class);
                    } else {
                        is = exchange.getIn().getBody(InputStream.class);
                    }
                    source = getSource(exchange, is);
                } else {
                    source = getSource(exchange, body);
                }

                // special for bean invocation
                if (source == null) {
                    if (body instanceof BeanInvocation) {
                        // if its a null bean invocation then handle that
                        BeanInvocation bi = exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class, body);
                        if (bi.getArgs() != null && bi.getArgs().length == 1 && bi.getArgs()[0] == null) {
                            // its a null argument from the bean invocation so use null as answer
                            source = null;
                        }
                    }
                }

                if (source == null) {
                    // indicate it was not possible to convert to a Source type
                    throw new NoTypeConversionAvailableException(body, Source.class);
                }

                DocumentInfo doc = config.buildDocument(source);
                dynamicQueryContext.setContextItem(doc);
            } finally {
                // can deal if is is null
                IOHelper.close(is);
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.