Debian Codegraph @

net/sf/saxon/type/AnyFunctionTypeWithAssertions.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8
9 package net.sf.saxon.type;
10
11 import net.sf.saxon.Configuration;
12 import net.sf.saxon.lib.FunctionAnnotationHandler;
13 import net.sf.saxon.om.Function;
14 import net.sf.saxon.om.Item;
15 import net.sf.saxon.query.Annotation;
16 import net.sf.saxon.query.AnnotationList;
17 import net.sf.saxon.trans.XPathException;
18
19 /**
20 * The item type function(*) when it is preceded by one or more annotation assertions
21 */
22 public class AnyFunctionTypeWithAssertions extends AnyFunctionType {
23
24 private AnnotationList assertions;
25
26 /**
27 * Construct an item type representing the item type function(*) with a list of annotation assertions
28 * @param assertions the annotation assertions
29 */
30
31 public AnyFunctionTypeWithAssertions(AnnotationList assertions) {
32 this.assertions = assertions;
33 }
34
35 /**
36 * Get the list of annotation assertions defined on this function item type.
37 *
38 * @return the list of annotation assertions, or an empty list if there are none
39 */
40
41 public AnnotationList getAnnotationAssertions() {
42 return assertions;
43 }
44
45 /**
46 * Test whether a given item conforms to this type
47 *
48 * @param item The item to be tested
49 * @param th the type hierarchy cache
50 * @return true if the item is an instance of this type; false otherwise
51 */
52 @Override
53 public boolean matches(Item item, TypeHierarchy th) throws XPathException {
54 return item instanceof Function && checkAnnotationAssertions(assertions, (Function) item, th.getConfiguration());
55 }
56
57 private static boolean checkAnnotationAssertions(AnnotationList assertions, Function item, Configuration config) {
58 AnnotationList annotations = item.getAnnotations();
59 for (Annotation ann : assertions) {
60 FunctionAnnotationHandler handler = config.getFunctionAnnotationHandler(ann.getAnnotationQName().getURI());
61 if (handler != null) {
62 boolean ok = handler.satisfiesAssertion(ann, annotations);
63 if (!ok) {
64 return false;
65 }
66 }
67 }
68 return true;
69 }
70 }
71