Examples of XQPreparedExpression


Examples of javax.xml.xquery.XQPreparedExpression

      // resolve variables
      final XQParameterLookupParser parser = new XQParameterLookupParser();
      final String translatedQuery = parser.translateAndLookup(xquery, parameters);
      // compile query
      final XQPreparedExpression expression = xqConnection.prepareExpression(translatedQuery);
      // bind variables, we cannot bind all variables of the datarow, only the ones defined in the script
      final List<String> fields = parser.getFields();
      for (final String col: fields)
      {
        final QName var = new QName(col);
        expression.bindObject(var, parameters.get(col), null)// null = do not override the default object mapping
      }
      // execute query
      final XQResultSequence sequence = expression.executeQuery();
      while (sequence.next())
      {
        final XQItem item = sequence.getItem();
        System.out.println(item.getItemType().getTypeName());
        System.out.println(item.getAtomicValue());
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Add implicit declarations as prolog to the user-defined XQuery
            out.xquery = declarations.toString() + xqueryStr;

            // Check the XQuery for compilation errors
            xqconn.setStaticContext(staticContext);           
            XQPreparedExpression exp = xqconn.prepareExpression(out.xquery);
           
            // Pre-evaluate variables and functions by executing query 
            node.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                    xqconn.createItemFromNode(node, xqconn.createNodeType()));
            // Bind external variables to dummy runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
              QName typeQName = variableTypes.get(variable);
                Object value = variableResolver.resolveVariable(variable);
              if (typeQName != null) {
                if (value.getClass().getName().startsWith("java.lang")) {
                      exp.bindAtomicValue(variable, value.toString(),
                          xqconn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE));
                } else if (value instanceof Node) {
                      exp.bindNode(variable, (Node) value, xqconn.createNodeType());
                } else if (value instanceof NodeList) {
                  NodeList nodeList = (NodeList) value;
                  ArrayList nodeArray = new ArrayList();
                  for (int i = 0; i < nodeList.getLength(); i++) {
                    nodeArray.add(nodeList.item(i));
                  }
                  XQSequence sequence = xqconn.createSequence(nodeArray.iterator());
                  exp.bindSequence(variable, sequence);
                }
              }
            }
            // evaluate the expression so as to initialize the variables
            try {
                exp.executeQuery();
            } catch (XQException xpee) {
              // swallow errors caused by uninitialized variables
            }
        } catch (XQException xqe) {
            __log.debug(xqe);
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Prepare expression, for starters
            String xquery = oxquery10.xquery.replaceFirst(
                    Constants.XQUERY_FUNCTION_HANDLER_COMPILER,
                    Constants.XQUERY_FUNCTION_HANDLER_RUNTIME);
            XQPreparedExpression exp = xqconn.prepareExpression(xquery);

            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(ctx,
                    oxquery10);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(ctx,
                    oxquery10, configuration);
            // Bind external variables to runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
              // Evaluate referenced variable
                Object value = variableResolver.resolveVariable(variable);
               
                // Figure out type of variable
                XQSequenceType xqType = getItemType(xqconn, value);
               
                // Saxon doesn't like binding sequences to variables
                if (value instanceof Node) {
                  // a node is a node-list, but the inverse isn't true.
                  // so, if the value is truly a node, leave it alone.
                } else if (value instanceof NodeList) {
                    // So extract the first item from the node list
                  NodeList nodeList = (NodeList) value;
                  ArrayList nodeArray = new ArrayList();
                  for (int i = 0; i < nodeList.getLength(); i++) {
                    nodeArray.add(nodeList.item(i));
                  }
                  value = xqconn.createSequence(nodeArray.iterator());
                }
               
               
                // Bind value with external variable
                if (value != null && xqType != null) {
                  if (value instanceof XQSequence) {
                    exp.bindSequence(variable, (XQSequence) value);
                  } else {
                    if (xqType instanceof XQItemType) {
                      exp.bindObject(variable, value, (XQItemType) xqType);
                    }
                  }
                }
            }

            // Set context node
            Node contextNode = (ctx.getRootNode() == null)
              ? DOMUtils.newDocument() : ctx.getRootNode();
            contextNode.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                xqconn.createItemFromNode(contextNode, xqconn.createNodeType()));

            // Execute query
            XQResultSequence result = exp.executeQuery();

            // Cast Saxon result to Java result
            Object evalResult = getResultValue(type, result);

            if ((evalResult != null) && __log.isDebugEnabled()) {
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

    @Override
    public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException
    {
        try
        {
            XQPreparedExpression transformer = null;
            try
            {
                transformer = (XQPreparedExpression) transformerPool.borrowObject();

                bindParameters(transformer, message);

                bindDocument(message.getPayload(), transformer);
                XQResultSequence result = transformer.executeQuery();
                //No support for return Arrays yet
                List<Object> results = new ArrayList<Object>();
                Class<?> type = returnType.getType();

                while (result.next())
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Prepare expression, for starters
            String xquery = oxquery10.xquery.replaceFirst(
                    Constants.XQUERY_FUNCTION_HANDLER_COMPILER,
                    Constants.XQUERY_FUNCTION_HANDLER_RUNTIME);
            XQPreparedExpression exp = xqconn.prepareExpression(xquery);

            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(ctx,
                    oxquery10);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(ctx,
                    oxquery10, configuration);
            // Bind external variables to runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
                // Evaluate referenced variable
                Object value = variableResolver.resolveVariable(variable);

                 if (value instanceof Value) {
                     SaxonXQConnection saxonConn = (SaxonXQConnection) xqconn;
                     try {
                         Item item = ((Value) value).asItem();
                         if (item == null) {
                             exp.bindSequence(variable, xqconn.createSequence(Collections.EMPTY_LIST.iterator()));
                         } else {
                             XQItem item2 = new SaxonXQItem(item, saxonConn);
                             exp.bindItem(variable, item2);
                         }
                     } catch (XPathException e) {
                         __log.warn("", e);
                     }
                 } else {

                     if (value instanceof Date) {
                         Date d = (Date) value;
                         value = org.apache.ode.utils.ISO8601DateParser.format(d);
                     }

                     // Figure out type of variable
                     XQSequenceType xqType = getItemType(xqconn, value);

                     // Saxon doesn't like binding sequences to variables
                     if (value instanceof Node) {
                         // a node is a node-list, but the inverse isn't true.
                         // so, if the value is truly a node, leave it alone.
                     } else if (value instanceof NodeList) {
                         // So extract the first item from the node list
                         NodeList nodeList = (NodeList) value;
                         ArrayList nodeArray = new ArrayList();
                         for (int i = 0; i < nodeList.getLength(); i++) {
                             nodeArray.add(nodeList.item(i));
                         }
                         value = xqconn.createSequence(nodeArray.iterator());
                     }

                     // Bind value with external variable
                     if (value != null && xqType != null) {
                         if (value instanceof XQSequence) {
                             exp.bindSequence(variable, (XQSequence) value);
                         } else {
                             if (xqType instanceof XQItemType) {
                                 exp.bindObject(variable, value, (XQItemType) xqType);
                             }
                         }
                     }
                  }
            }

            // Set context node
            Node contextNode = (ctx.getRootNode() == null)
                ? DOMUtils.newDocument() : ctx.getRootNode();
            contextNode.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                xqconn.createItemFromNode(contextNode, xqconn.createNodeType()));

            // Execute query
            XQResultSequence result = exp.executeQuery();

            // Cast Saxon result to Java result
            Object evalResult = getResultValue(type, result);

            if ((evalResult != null) && __log.isDebugEnabled()) {
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Add implicit declarations as prolog to the user-defined XQuery
            out.xquery = declarations.toString() + xqueryStr;

            // Check the XQuery for compilation errors
            xqconn.setStaticContext(staticContext);
            XQPreparedExpression exp = xqconn.prepareExpression(out.xquery);

            // Pre-evaluate variables and functions by executing query
            node.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                    funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                    xqconn.createItemFromNode(node, xqconn.createNodeType()));
            // Bind external variables to dummy runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
                QName typeQName = variableTypes.get(variable);
                Object value = variableResolver.resolveVariable(variable);
                if (typeQName != null) {
                    if (value.getClass().getName().startsWith("java.lang")) {
                        exp.bindAtomicValue(variable, value.toString(),
                                xqconn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE));
                    } else if (value instanceof Node) {
                        exp.bindNode(variable, (Node) value, xqconn.createNodeType());
                    } else if (value instanceof NodeList) {
                        NodeList nodeList = (NodeList) value;
                        ArrayList nodeArray = new ArrayList();
                        for (int i = 0; i < nodeList.getLength(); i++) {
                            nodeArray.add(nodeList.item(i));
                        }
                        XQSequence sequence = xqconn.createSequence(nodeArray.iterator());
                        exp.bindSequence(variable, sequence);
                    }
                }
            }
            // evaluate the expression so as to initialize the variables
            try {
                exp.executeQuery();
            } catch (XQException xpee) {
                // swallow errors caused by uninitialized variables
            } finally {
                // reset the expression's user data, in order to avoid
                // serializing the function resolver in the compiled bpel file.
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Prepare expression, for starters
            String xquery = oxquery10.xquery.replaceFirst(
                    Constants.XQUERY_FUNCTION_HANDLER_COMPILER,
                    Constants.XQUERY_FUNCTION_HANDLER_RUNTIME);
            XQPreparedExpression exp = xqconn.prepareExpression(xquery);

            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(ctx,
                    oxquery10);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(ctx,
                    oxquery10, configuration);
            // Bind external variables to runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
              // Evaluate referenced variable
                Object value = variableResolver.resolveVariable(variable);
               
                 if (value instanceof Value) {
                     SaxonXQConnection saxonConn = (SaxonXQConnection) xqconn;
                     try {
                         Item item = ((Value) value).asItem();
                         if (item == null) {
                             exp.bindSequence(variable, xqconn.createSequence(Collections.EMPTY_LIST.iterator()));
                         } else {
                             XQItem item2 = new SaxonXQItem(item, saxonConn);
                             exp.bindItem(variable, item2);
                         }
                     } catch (XPathException e) {
                         __log.warn("", e);
                     }
                 } else {
                    
                     if (value instanceof Date) {
                         Date d = (Date) value;
                         value = org.apache.ode.utils.ISO8601DateParser.format(d);
                     }
                     // Figure out type of variable
                     XQSequenceType xqType = getItemType(xqconn, value);
                     // Saxon doesn't like binding sequences to variables
                     if (value instanceof Node) {
                         // a node is a node-list, but the inverse isn't true.
                         // so, if the value is truly a node, leave it alone.
                     } else if (value instanceof NodeList) {
                         // So extract the first item from the node list
                         NodeList nodeList = (NodeList) value;
                         ArrayList nodeArray = new ArrayList();
                         for (int i = 0; i < nodeList.getLength(); i++) {
                             nodeArray.add(nodeList.item(i));
                         }
                         value = xqconn.createSequence(nodeArray.iterator());
                     }
                     // Bind value with external variable
                     if (value != null && xqType != null) {
                         if (value instanceof XQSequence) {
                             exp.bindSequence(variable, (XQSequence) value);
                         } else {
                             if (xqType instanceof XQItemType) {
                                 exp.bindObject(variable, value, (XQItemType) xqType);
                             }
                         }
                     }
                  }
            }

            // Set context node
            Node contextNode = (ctx.getRootNode() == null)
              ? DOMUtils.newDocument() : ctx.getRootNode();
            contextNode.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                xqconn.createItemFromNode(contextNode, xqconn.createNodeType()));

            // Execute query
            XQResultSequence result = exp.executeQuery();

            // Cast Saxon result to Java result
            Object evalResult = getResultValue(type, result);

            if ((evalResult != null) && __log.isDebugEnabled()) {
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Add implicit declarations as prolog to the user-defined XQuery
            out.xquery = declarations.toString() + xqueryStr;

            // Check the XQuery for compilation errors
            xqconn.setStaticContext(staticContext);           
            XQPreparedExpression exp = xqconn.prepareExpression(out.xquery);
           
            // Pre-evaluate variables and functions by executing query 
            node.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                    xqconn.createItemFromNode(node, xqconn.createNodeType()));
            // Bind external variables to dummy runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
              QName typeQName = variableTypes.get(variable);
                Object value = variableResolver.resolveVariable(variable);
              if (typeQName != null) {
                if (value.getClass().getName().startsWith("java.lang")) {
                      exp.bindAtomicValue(variable, value.toString(),
                          xqconn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE));
                } else if (value instanceof Node) {
                      exp.bindNode(variable, (Node) value, xqconn.createNodeType());
                } else if (value instanceof NodeList) {
                  NodeList nodeList = (NodeList) value;
                  ArrayList nodeArray = new ArrayList();
                  for (int i = 0; i < nodeList.getLength(); i++) {
                    nodeArray.add(nodeList.item(i));
                  }
                  XQSequence sequence = xqconn.createSequence(nodeArray.iterator());
                  exp.bindSequence(variable, sequence);
                }
              }
            }
            // evaluate the expression so as to initialize the variables
            try {
                exp.executeQuery();
            } catch (XQException xpee) {
              // swallow errors caused by uninitialized variables
            } finally {
              // reset the expression's user data, in order to avoid
              // serializing the function resolver in the compiled bpel file.
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

            // Add implicit declarations as prolog to the user-defined XQuery
            out.xquery = declarations.toString() + xqueryStr;

            // Check the XQuery for compilation errors
            xqconn.setStaticContext(staticContext);           
            XQPreparedExpression exp = xqconn.prepareExpression(out.xquery);
           
            // Pre-evaluate variables and functions by executing query 
            node.setUserData(XQuery10BpelFunctions.USER_DATA_KEY_FUNCTION_RESOLVER,
                funcResolver, null);
            exp.bindItem(XQConstants.CONTEXT_ITEM,
                    xqconn.createItemFromNode(node, xqconn.createNodeType()));
            // Bind external variables to dummy runtime values
            for (QName variable : exp.getAllUnboundExternalVariables()) {
              QName typeQName = variableTypes.get(variable);
                Object value = variableResolver.resolveVariable(variable);
              if (typeQName != null) {
                if (value.getClass().getName().startsWith("java.lang")) {
                      exp.bindAtomicValue(variable, value.toString(),
                          xqconn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE));
                } else if (value instanceof Node) {
                      exp.bindNode(variable, (Node) value, xqconn.createNodeType());
                } else if (value instanceof NodeList) {
                  NodeList nodeList = (NodeList) value;
                  ArrayList nodeArray = new ArrayList();
                  for (int i = 0; i < nodeList.getLength(); i++) {
                    nodeArray.add(nodeList.item(i));
                  }
                  XQSequence sequence = xqconn.createSequence(nodeArray.iterator());
                  exp.bindSequence(variable, sequence);
                }
              }
            }
            // evaluate the expression so as to initialize the variables
            try {
                exp.executeQuery();
            } catch (XQException xpee) {
              // swallow errors caused by uninitialized variables
            } finally {
              // reset the expression's user data, in order to avoid
              // serializing the function resolver in the compiled bpel file.
View Full Code Here

Examples of javax.xml.xquery.XQPreparedExpression

                XQConnection xqconn = xqds.getConnection();
   
                net.sf.saxon.Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
                configuration.setHostLanguage(net.sf.saxon.Configuration.XQUERY);
//                XQStaticContext staticEnv = xqconn.getStaticContext();
                XQPreparedExpression exp = xqconn.prepareExpression(xquery);
                Node requestNode = DOMUtils.parse(request.newXMLStreamReader());
                if (__log.isDebugEnabled()) {
                    __log.debug("request " + request.toString());
                }
                exp.bindItem(XQConstants.CONTEXT_ITEM, xqconn.createItemFromNode(requestNode, xqconn.createNodeType()));
                XQResultSequence result = exp.executeQuery();
                MockQueryResponseDocument response = MockQueryResponseDocument.Factory.parse(result.getSequenceAsStream());
                {
                    XmlOptions opts = new XmlOptions();
                    List<Object> errors = new ArrayList<Object>();
                    opts.setErrorListener(errors);
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.