Examples of XQConnection


Examples of javax.xml.xquery.XQConnection

    if (xquery == null)
    {
      throw new ReportDataFactoryException("No such query: " + queryName);
    }

    final XQConnection xqConnection = getConnection();

    try
    {

      // 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);
View Full Code Here

Examples of javax.xml.xquery.XQConnection

        throw new IllegalArgumentException("Unable to load XQJ datasource driver: " + xqdatasource);
      }
      else
      {
        datasource.setProperties(properties);
        final XQConnection xqConnection = datasource.getConnection();
        return xqConnection;
        /*try
        {
          final Connection sqlConnection = DriverManager.getConnection(url, properties);
          datasource.setProperties(properties);
View Full Code Here

Examples of javax.xml.xquery.XQConnection

            throw new CompilationException(__msgs.warnXPath20Syntax(DOMUtils.domToString(node), "empty string"));
        }

        try {
          XQDataSource xqds = new SaxonXQDataSource();
            XQConnection xqconn = xqds.getConnection();
           
            __log.debug("Compiling expression " + xqueryStr);
            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticContext = xqconn.getStaticContext();
            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
                    _compilerContext, out, source.getNamespaceContext(), _bpelNS);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(
                _compilerContext, out);

            XQueryDeclarations declarations = new XQueryDeclarations();           
            NSContext nsContext = source.getNamespaceContext();
          Set<String> prefixes = nsContext.getPrefixes();
          if (!nsContext.getUriSet().contains(Namespaces.ODE_EXTENSION_NS)) {
            nsContext.register("ode", Namespaces.ODE_EXTENSION_NS);
          }
          for (String prefix : prefixes) {
            String uri = nsContext.getNamespaceURI(prefix);
            staticContext.declareNamespace(prefix, uri);
            if ("".equals(prefix)) {
              declarations.declareDefaultElementNamespace(uri);
            } else if ("bpws".equals(prefix)) {
                    declarations.declareNamespace("bpws", "java:" + Constants.XQUERY_FUNCTION_HANDLER_COMPILER);
            } else {
              declarations.declareNamespace(prefix, uri);
            }
          }
            declarations.declareVariable(
                getQName(nsContext, Namespaces.ODE_EXTENSION_NS, "pid"),
                getQName(nsContext, Namespaces.XML_SCHEMA, "integer"));
            Map<URI, Source> schemaDocuments = _compilerContext.getSchemaSources();
            for (URI schemaUri : schemaDocuments.keySet()) {
              Source schemaSource = schemaDocuments.get(schemaUri);
              // Don't add schema sources, since our Saxon library is not schema-aware.
              // configuration.addSchemaSource(schemaSource);
            }
            configuration.setSchemaValidationMode(Validation.SKIP);
            List<OScope.Variable> variables = _compilerContext.getAccessibleVariables();
            Map<QName, QName> variableTypes = new HashMap<QName, QName>();
            for (String variableName : getVariableNames(xqueryStr)) {
              OScope.Variable variable = getVariable(variables, variableName);
              if (variable == null) {
                continue;
              }
                OVarType type = variable.type;
                QName nameQName = getNameQName(variableName);
                QName typeQName = getTypeQName(variableName, type);
                variableTypes.put(nameQName, typeQName);
                String prefix = typeQName.getPrefix();
                if (prefix == null || "".equals(prefix.trim())) {
                  prefix = getPrefixForUri(nsContext, typeQName.getNamespaceURI());
                }
                // don't declare typed variables, as our engine is not schema-aware
                // declarations.declareVariable(variable.name, typeQName);
                declarations.declareVariable(variableName);
            }
           
            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

        throws FaultException {
        try {
            OXQuery10ExpressionBPEL20 oxquery10 = ((OXQuery10ExpressionBPEL20) cexp);

            XQDataSource xqds = new SaxonXQDataSource();
            XQConnection xqconn = xqds.getConnection();

            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticEnv = xqconn.getStaticContext();

            NSContext nsContext = oxquery10.namespaceCtx;
            Set<String> prefixes = nsContext.getPrefixes();
            for (String prefix : prefixes) {
                String uri = nsContext.getNamespaceURI(prefix);
                staticEnv.declareNamespace(prefix, uri);
            }

            configuration.setSchemaValidationMode(Validation.SKIP);
            xqconn.setStaticContext(staticEnv);

            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

        throws FaultException, EvaluationException {
        try {
            OXQuery10ExpressionBPEL20 oxquery10 = ((OXQuery10ExpressionBPEL20) cexp);

            XQDataSource xqds = new SaxonXQDataSource();
            XQConnection xqconn = xqds.getConnection();

            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticEnv = xqconn.getStaticContext();

            NSContext nsContext = oxquery10.namespaceCtx;
            Set<String> prefixes = nsContext.getPrefixes();
            for (String prefix : prefixes) {
                String uri = nsContext.getNamespaceURI(prefix);
                staticEnv.declareNamespace(prefix, uri);
            }

            configuration.setSchemaValidationMode(Validation.SKIP);
            xqconn.setStaticContext(staticEnv);

            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

            throw new CompilationException(__msgs.warnXPath20Syntax(DOMUtils.domToString(node), "empty string"));
        }

        try {
            XQDataSource xqds = new SaxonXQDataSource(new Configuration());
            XQConnection xqconn = xqds.getConnection();

            __log.debug("Compiling expression " + xqueryStr);
            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticContext = xqconn.getStaticContext();
            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
                    _compilerContext, out, source.getNamespaceContext(), _bpelNS);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(
                    _compilerContext, out);

            XQueryDeclarations declarations = new XQueryDeclarations();
            NSContext nsContext = source.getNamespaceContext();
            Set<String> prefixes = nsContext.getPrefixes();
            if (!nsContext.getUriSet().contains(Namespaces.ODE_EXTENSION_NS)) {
                nsContext.register("ode", Namespaces.ODE_EXTENSION_NS);
            }
            for (String prefix : prefixes) {
                String uri = nsContext.getNamespaceURI(prefix);
                staticContext.declareNamespace(prefix, uri);
                if ("".equals(prefix)) {
                    declarations.declareDefaultElementNamespace(uri);
                } else if ("bpws".equals(prefix)) {
                    declarations.declareNamespace("bpws", "java:" + Constants.XQUERY_FUNCTION_HANDLER_COMPILER);
                } else {
                    declarations.declareNamespace(prefix, uri);
                }
            }
            declarations.declareVariable(
                    getQName(nsContext, Namespaces.ODE_EXTENSION_NS, "pid"),
                    getQName(nsContext, Namespaces.XML_SCHEMA, "integer"));
//            Map<URI, Source> schemaDocuments = _compilerContext.getSchemaSources();
//            for (URI schemaUri : schemaDocuments.keySet()) {
//              Source schemaSource = schemaDocuments.get(schemaUri);
//              // Don't add schema sources, since our Saxon library is not schema-aware.
//              // configuration.addSchemaSource(schemaSource);
//            }
            configuration.setSchemaValidationMode(Validation.SKIP);
            List<OScope.Variable> variables = _compilerContext.getAccessibleVariables();
            Map<QName, QName> variableTypes = new HashMap<QName, QName>();
            for (String variableName : getVariableNames(xqueryStr)) {
                OScope.Variable variable = getVariable(variables, variableName);
                if (variable == null) {
                    continue;
                }
                OVarType type = variable.type;
                QName nameQName = getNameQName(variableName);
                QName typeQName = getTypeQName(variableName, type);
                variableTypes.put(nameQName, typeQName);
                String prefix = typeQName.getPrefix();
                if (prefix == null || "".equals(prefix.trim())) {
                    prefix = getPrefixForUri(nsContext, typeQName.getNamespaceURI());
                }
                // don't declare typed variables, as our engine is not schema-aware
                // declarations.declareVariable(variable.name, typeQName);
                declarations.declareVariable(variableName);
            }

            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

        throws FaultException, EvaluationException {
        try {
            OXQuery10ExpressionBPEL20 oxquery10 = ((OXQuery10ExpressionBPEL20) cexp);

            XQDataSource xqds = new SaxonXQDataSource();
            XQConnection xqconn = xqds.getConnection();

            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticEnv = xqconn.getStaticContext();

            NSContext nsContext = oxquery10.namespaceCtx;
            Set<String> prefixes = nsContext.getPrefixes();
            for (String prefix : prefixes) {
                String uri = nsContext.getNamespaceURI(prefix);
                staticEnv.declareNamespace(prefix, uri);
            }

            configuration.setSchemaValidationMode(Validation.SKIP);
            xqconn.setStaticContext(staticEnv);

            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

            throw new CompilationException(__msgs.warnXPath20Syntax(DOMUtils.domToString(node), "empty string"));
        }

        try {
          XQDataSource xqds = new SaxonXQDataSource();
            XQConnection xqconn = xqds.getConnection();
           
            __log.debug("Compiling expression " + xqueryStr);
            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticContext = xqconn.getStaticContext();
            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
                    _compilerContext, out, source.getNamespaceContext(), _bpelNS);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(
                _compilerContext, out);

            XQueryDeclarations declarations = new XQueryDeclarations();           
            NSContext nsContext = source.getNamespaceContext();
          Set<String> prefixes = nsContext.getPrefixes();
          if (!nsContext.getUriSet().contains(Namespaces.ODE_EXTENSION_NS)) {
            nsContext.register("ode", Namespaces.ODE_EXTENSION_NS);
          }
          for (String prefix : prefixes) {
            String uri = nsContext.getNamespaceURI(prefix);
            staticContext.declareNamespace(prefix, uri);
            if ("".equals(prefix)) {
              declarations.declareDefaultElementNamespace(uri);
            } else if ("bpws".equals(prefix)) {
                    declarations.declareNamespace("bpws", "java:" + Constants.XQUERY_FUNCTION_HANDLER_COMPILER);
            } else {
              declarations.declareNamespace(prefix, uri);
            }
          }
            declarations.declareVariable(
                getQName(nsContext, Namespaces.ODE_EXTENSION_NS, "pid"),
                getQName(nsContext, Namespaces.XML_SCHEMA, "integer"));
            Map<URI, Source> schemaDocuments = _compilerContext.getSchemaSources();
            for (URI schemaUri : schemaDocuments.keySet()) {
              Source schemaSource = schemaDocuments.get(schemaUri);
              // Don't add schema sources, since our Saxon library is not schema-aware.
              // configuration.addSchemaSource(schemaSource);
            }
            configuration.setSchemaValidationMode(Validation.SKIP);
            List<OScope.Variable> variables = _compilerContext.getAccessibleVariables();
            Map<QName, QName> variableTypes = new HashMap<QName, QName>();
            for (String variableName : getVariableNames(xqueryStr)) {
              OScope.Variable variable = getVariable(variables, variableName);
              if (variable == null) {
                continue;
              }
                OVarType type = variable.type;
                QName nameQName = getNameQName(variableName);
                QName typeQName = getTypeQName(variableName, type);
                variableTypes.put(nameQName, typeQName);
                String prefix = typeQName.getPrefix();
                if (prefix == null || "".equals(prefix.trim())) {
                  prefix = getPrefixForUri(nsContext, typeQName.getNamespaceURI());
                }
                // don't declare typed variables, as our engine is not schema-aware
                // declarations.declareVariable(variable.name, typeQName);
                declarations.declareVariable(variableName);
            }
           
            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

            throw new CompilationException(__msgs.warnXPath20Syntax(DOMUtils.domToString(node), "empty string"));
        }

        try {
          XQDataSource xqds = new SaxonXQDataSource(new Configuration());
            XQConnection xqconn = xqds.getConnection();
           
            __log.debug("Compiling expression " + xqueryStr);
            Configuration configuration = ((SaxonXQConnection) xqconn).getConfiguration();
            configuration.setAllNodesUntyped(true);
            configuration.setHostLanguage(Configuration.XQUERY);

            XQStaticContext staticContext = xqconn.getStaticContext();
            JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(
                    _compilerContext, out, source.getNamespaceContext(), _bpelNS);
            JaxpVariableResolver variableResolver = new JaxpVariableResolver(
                _compilerContext, out);

            XQueryDeclarations declarations = new XQueryDeclarations();           
            NSContext nsContext = source.getNamespaceContext();
          Set<String> prefixes = nsContext.getPrefixes();
          if (!nsContext.getUriSet().contains(Namespaces.ODE_EXTENSION_NS)) {
            nsContext.register("ode", Namespaces.ODE_EXTENSION_NS);
          }
          for (String prefix : prefixes) {
            String uri = nsContext.getNamespaceURI(prefix);
            staticContext.declareNamespace(prefix, uri);
            if ("".equals(prefix)) {
              declarations.declareDefaultElementNamespace(uri);
            } else if ("bpws".equals(prefix)) {
                    declarations.declareNamespace("bpws", "java:" + Constants.XQUERY_FUNCTION_HANDLER_COMPILER);
            } else {
              declarations.declareNamespace(prefix, uri);
            }
          }
            declarations.declareVariable(
                getQName(nsContext, Namespaces.ODE_EXTENSION_NS, "pid"),
                getQName(nsContext, Namespaces.XML_SCHEMA, "integer"));
//            Map<URI, Source> schemaDocuments = _compilerContext.getSchemaSources();
//            for (URI schemaUri : schemaDocuments.keySet()) {
//              Source schemaSource = schemaDocuments.get(schemaUri);
//              // Don't add schema sources, since our Saxon library is not schema-aware.
//              // configuration.addSchemaSource(schemaSource);
//            }
            configuration.setSchemaValidationMode(Validation.SKIP);
            List<OScope.Variable> variables = _compilerContext.getAccessibleVariables();
            Map<QName, QName> variableTypes = new HashMap<QName, QName>();
            for (String variableName : getVariableNames(xqueryStr)) {
              OScope.Variable variable = getVariable(variables, variableName);
              if (variable == null) {
                continue;
              }
                OVarType type = variable.type;
                QName nameQName = getNameQName(variableName);
                QName typeQName = getTypeQName(variableName, type);
                variableTypes.put(nameQName, typeQName);
                String prefix = typeQName.getPrefix();
                if (prefix == null || "".equals(prefix.trim())) {
                  prefix = getPrefixForUri(nsContext, typeQName.getNamespaceURI());
                }
                // don't declare typed variables, as our engine is not schema-aware
                // declarations.declareVariable(variable.name, typeQName);
                declarations.declareVariable(variableName);
            }
           
            // 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
View Full Code Here

Examples of javax.xml.xquery.XQConnection

                MockQueryRequestDocument request = MockQueryRequestDocument.Factory.newInstance();
                request.addNewMockQueryRequest().addNewIn().set(XmlObject.Factory.parse(outgoingMessage));
                String xquery = serviceConfig.getReplayType().getMockQuery();
               
                XQDataSource xqds = new SaxonXQDataSource();
                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>();
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.