Package net.sf.saxon.pattern

Examples of net.sf.saxon.pattern.NameTest


      if (test == AnyNodeTest.getInstance()) { // performance hack
        test = null; // mark as AnyNodeTest
      }
      else if (test instanceof NameTest) {
        NameTest nt = (NameTest) test;
        if (nt.getPrimitiveType() == Type.ELEMENT) { // performance hack
          // mark as element name test
          NamePool pool = getNamePool();
          this.testLocalName = pool.getLocalName(nt.getFingerprint());
          this.testURI = pool.getURI(nt.getFingerprint());
        }
      }
      else if (test instanceof NodeKindTest) {
        if (test.getPrimitiveType() == Type.ELEMENT) { // performance hack
          // mark as element type test
View Full Code Here


      if (test == AnyNodeTest.getInstance()) { // performance hack
        test = null; // mark as AnyNodeTest
      }
      else if (test instanceof NameTest) {
        NameTest nt = (NameTest) test;
        if (nt.getPrimitiveType() == Type.ELEMENT) { // performance hack
          // mark as element name test
          NamePool pool = getNamePool();
          this.testLocalName = pool.getLocalName(nt.getFingerprint());
          this.testURI = pool.getURI(nt.getFingerprint());
        }
      }
      else if (test instanceof NodeKindTest) {
        if (test.getPrimitiveType() == Type.ELEMENT) { // performance hack
          // mark as element type test
View Full Code Here

            ValueRepresentation value, SequenceType requiredType, final XPathContext context)
            throws XPathException {
        final TypeHierarchy th = context.getConfiguration().getTypeHierarchy();
        final ItemType requiredItemType = requiredType.getPrimaryType();
        ItemType suppliedItemType = (value instanceof NodeInfo
                ? new NameTest(((NodeInfo)value))
                : ((Value)value).getItemType(th));

        SequenceIterator iterator = Value.asIterator(value);

        if (requiredItemType.isAtomicType()) {
View Full Code Here

                schemaType = decl.getType();
                instr.setSchemaType(schemaType);
                    // TODO: this causes validation against the type, rather than the declaration:
                    // are identity constraints being tested on the top-level element?
                itemType = new CombinedNodeTest(
                        new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
                        Token.INTERSECT,
                        new ContentTypeTest(Type.ELEMENT, schemaType, config));
                try {
                    schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
                } catch (XPathException e) {
                    e.setErrorCode(instr.isXSLT() ? "XTTE1510" : "XQDY0027");
                    e.setLocator(instr);
                    throw e;
                }
                SchemaType xsiType = instr.getXSIType(env);
                if (xsiType != null) {
                    xsiType.analyzeContentExpression(content, Type.ELEMENT, env);
                    try {
                        config.checkTypeDerivationIsOK(xsiType, schemaType, 0);
                    } catch (SchemaException e) {
                        ValidationException ve = new ValidationException("The specified xsi:type " + xsiType.getDescription() +
                                " is not validly derived from the required type " + schemaType.getDescription());
                        ve.setConstraintReference(1, "cvc-elt", "4.3");
                        ve.setErrorCode(instr.isXSLT() ? "XTTE1515" : "XQDY0027");
                        ve.setLocator((Locator)instr);
                        throw ve;
                    }
                }
            } else if (validation == Validation.LAX) {
                SchemaDeclaration decl = config.getElementDeclaration(nameCode & 0xfffff);
                if (decl == null) {
                    env.issueWarning("There is no global element declaration for " +
                            env.getNamePool().getDisplayName(nameCode), instr);
                    itemType = new NameTest(Type.ELEMENT, nameCode, env.getNamePool());
                } else {
                    schemaType = decl.getType();
                    instr.setSchemaType(schemaType);
                    itemType = new CombinedNodeTest(
                            new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
                            Token.INTERSECT,
                            new ContentTypeTest(Type.ELEMENT, instr.getSchemaType(), config));
                    try {
                        schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
                    } catch (XPathException e) {
                        e.setErrorCode(instr.isXSLT() ? "XTTE1515" : "XQDY0027");
                        e.setLocator(instr);
                        throw e;
                    }
                }
            } else if (validation == Validation.PRESERVE) {
                // we know the result will be an element of type xs:anyType
                itemType = new CombinedNodeTest(
                        new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
                        Token.INTERSECT,
                        new ContentTypeTest(Type.ELEMENT, AnyType.getInstance(), config));
            } else {
                // we know the result will be an untyped element
                itemType = new CombinedNodeTest(
                        new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
                        Token.INTERSECT,
                        new ContentTypeTest(Type.ELEMENT, Untyped.getInstance(), config));
            }
        } else {
            itemType = new CombinedNodeTest(
                    new NameTest(Type.ELEMENT, nameCode, env.getNamePool()),
                    Token.INTERSECT,
                    new ContentTypeTest(Type.ELEMENT, schemaType, config)
            );
            try {
                schemaType.analyzeContentExpression(content, Type.ELEMENT, env);
View Full Code Here

                if (!(nodeTest instanceof NameTest)) {
                    break;
                }

                NameTest nameTest = (NameTest) nodeTest;

                QName childName = getQualifiedName(nameTest.getFingerprint(),
                        namePool, contextUris);

                if (Axis.CHILD == axisExpr.getAxis()) {
                    if (NodeKindTest.ELEMENT.getNodeKindMask() != nameTest.getNodeKindMask()) {
                        break;
                    }

                    NodeList children = ((Element) contextNode).getElementsByTagNameNS(childName.getNamespaceURI(),
                            childName.getLocalPart());
                    if ((children == null) || (children.getLength() == 0)) {
                        Node child = document.createElementNS(childName.getNamespaceURI(),
                                DOMUtils.getQualifiedName(childName));
                        contextNode.appendChild(child);
                        contextNode = child;
                    } else if (children.getLength() == 1) {
                        contextNode = children.item(0);
                    } else {
                        break;
                    }
                } else if (Axis.ATTRIBUTE == axisExpr.getAxis()) {
                    if (NodeKindTest.ATTRIBUTE.getNodeKindMask() != nameTest.getNodeKindMask()) {
                        break;
                    }

                    Attr attribute = ((Element) contextNode).getAttributeNodeNS(childName.getNamespaceURI(), childName.getLocalPart());
                    if (attribute == null) {
View Full Code Here

    public StreamSource[] resolve(String moduleURI, String baseURI, String[] locations) throws XPathException {
        NamePool pool = testCase.getNamePool();
        int moduleNC = pool.allocate("", "http://www.w3.org/2005/02/query-test-XQTSCatalog", "module");
        int namespaceNC = pool.allocate("", "", "namespace");
        AxisIterator iter = testCase.iterateAxis(Axis.CHILD, new NameTest(Type.ELEMENT, moduleNC, pool));
        List catalogLocations = new ArrayList(5);
        while (true) {
            NodeInfo m = (NodeInfo)iter.next();
            if (m == null) break;
            if (moduleURI.equals(m.getAttributeValue(namespaceNC))) {
View Full Code Here

        if (!(href.equals(collectionElement.getAttributeValue(IDNC)) || (href.equals("") && isDefault))) {
            throw new XPathException("Unknown collection name " + href);
        }

        AxisIterator iter = collectionElement.iterateAxis(
                Axis.CHILD, new NameTest(Type.ELEMENT, inputDocumentNC, pool));
        List documents = new ArrayList(5);

        while (true) {
            NodeInfo m = (NodeInfo)iter.next();
            if (m==null) {
View Full Code Here

    }

    private NameTest elementNameTest(NamePool pool, String local) {
        int nameFP = pool.allocate("", "http://www.w3.org/2005/02/query-test-XQTSCatalog", local) & NamePool.FP_MASK;
        return new NameTest(Type.ELEMENT, nameFP, pool);
    }
View Full Code Here

                    new File(saxonDir + "/results" + Version.getProductVersion() + ".log")));

            MyErrorListener errorListener = new MyErrorListener(log);
            saConfig.setErrorListener(errorListener);

            NameTest testCaseNT = elementNameTest(pool, "test-case");
            NameTest inputUriNT = elementNameTest(pool, "input-URI");
            NameTest inputFileNT = elementNameTest(pool, "input-file");
            NameTest queryNT = elementNameTest(pool, "query");
            NameTest inputQueryNT = elementNameTest(pool, "input-query");
            NameTest contextItemNT = elementNameTest(pool, "contextItem");
            NameTest outputFileNT = elementNameTest(pool, "output-file");
            NameTest sourceNT = elementNameTest(pool, "source");
            NameTest schemaNT = elementNameTest(pool, "schema");
            NameTest expectedErrorNT = elementNameTest(pool, "expected-error");
            NameTest collectionNT = elementNameTest(pool, "collection");
            NameTest defaultCollectionNT = elementNameTest(pool, "defaultCollection");
            NameTest optimizationNT = elementNameTest(pool, "optimization");


            int schemaAtt = pool.allocate("", "", "schema") & NamePool.FP_MASK;
            int nameAtt = pool.allocate("", "", "name") & NamePool.FP_MASK;
            int filePathAtt = pool.allocate("", "", "FilePath") & NamePool.FP_MASK;
            int fileNameAtt = pool.allocate("", "", "FileName") & NamePool.FP_MASK;
            int idAtt = pool.allocate("", "", "ID") & NamePool.FP_MASK;
            int compareAtt = pool.allocate("", "", "compare") & NamePool.FP_MASK;
            int variableAtt = pool.allocate("", "", "variable") & NamePool.FP_MASK;
            int scenarioAtt = pool.allocate("", "", "scenario") & NamePool.FP_MASK;
            int explainAtt = pool.allocate("", "", "explain") & NamePool.FP_MASK;
            int assertAtt = pool.allocate("", "", "assert") & NamePool.FP_MASK;
            int versionAtt = pool.allocate("", "", "version") & NamePool.FP_MASK;
            int specVersionAtt = pool.allocate("", "", "spec-version") & NamePool.FP_MASK;

            /**
             * Look for an exceptions.xml document with the general format:
             *
             * <exceptions>
             *   <exception>
             *     <tests>testname1 testname2 ...</tests>
             *     <decription>text explanation</description>
             *   </exception>
             * </exceptions>
             *
             * Tests listed in this file will not be run.
             */

            DocumentInfo exceptionsDoc = saConfig.buildDocument(
                    new StreamSource(new File(saxonDir + "/exceptions.xml"))
            );

            NameTest exceptionTestsNT = new NameTest(Type.ELEMENT, pool.allocate("", "", "tests"), pool);
            AxisIterator exceptionTestCases = exceptionsDoc.iterateAxis(Axis.DESCENDANT, exceptionTestsNT);
            while (true) {
                NodeInfo testCase = (NodeInfo)exceptionTestCases.next();
                if (testCase == null) {
                    break;
View Full Code Here

    Writer results;
    int xlinkHref;

    private NameTest elementNameTest(NamePool pool, String local) {
        int nameFP = pool.allocate("", testNS, local) & NamePool.FP_MASK;
        return new NameTest(Type.ELEMENT, nameFP, pool);
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.pattern.NameTest

Copyright © 2018 www.massapicom. 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.