| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
package net.sf.saxon.lib; |
| 10 |
|
| 11 |
import net.sf.saxon.om.StructuredQName; |
| 12 |
import net.sf.saxon.query.Annotation; |
| 13 |
import net.sf.saxon.query.AnnotationList; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.type.TypeHierarchy; |
| 16 |
|
| 17 |
import java.util.Collections; |
| 18 |
import java.util.HashSet; |
| 19 |
import java.util.Set; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class XQueryFunctionAnnotationHandler implements FunctionAnnotationHandler { |
| 28 |
|
| 29 |
private static class DisallowedCombination { |
| 30 |
public DisallowedCombination(StructuredQName one, StructuredQName two, String errorCode, String... where) { |
| 31 |
this.one = one; |
| 32 |
this.two = two; |
| 33 |
this.errorCode = errorCode; |
| 34 |
this.where = new HashSet<String>(where.length); |
| 35 |
Collections.addAll(this.where, where); |
| 36 |
} |
| 37 |
|
| 38 |
public StructuredQName one; |
| 39 |
public StructuredQName two; |
| 40 |
public String errorCode; |
| 41 |
public Set<String> where; |
| 42 |
} |
| 43 |
|
| 44 |
private static DisallowedCombination[] blackList = { |
| 45 |
new DisallowedCombination(Annotation.SIMPLE, null, "XUST0032", "DV"), |
| 46 |
new DisallowedCombination(Annotation.UPDATING, null, "XUST0032", "DV"), |
| 47 |
new DisallowedCombination(Annotation.PUBLIC, null, "XQST0125", "IF"), |
| 48 |
new DisallowedCombination(Annotation.PRIVATE, null, "XQST0125", "IF"), |
| 49 |
new DisallowedCombination(Annotation.PRIVATE, Annotation.PRIVATE, "XQST0106", "DF"), |
| 50 |
new DisallowedCombination(Annotation.PRIVATE, Annotation.PUBLIC, "XQST0106", "DF"), |
| 51 |
new DisallowedCombination(Annotation.PUBLIC, Annotation.PUBLIC, "XQST0106", "DF"), |
| 52 |
new DisallowedCombination(Annotation.PUBLIC, Annotation.PRIVATE, "XQST0106", "DF"), |
| 53 |
new DisallowedCombination(Annotation.PRIVATE, Annotation.PRIVATE, "XQST0116", "DV"), |
| 54 |
new DisallowedCombination(Annotation.PRIVATE, Annotation.PUBLIC, "XQST0116", "DV"), |
| 55 |
new DisallowedCombination(Annotation.PUBLIC, Annotation.PUBLIC, "XQST0116", "DV"), |
| 56 |
new DisallowedCombination(Annotation.PUBLIC, Annotation.PRIVATE, "XQST0116", "DV"), |
| 57 |
new DisallowedCombination(Annotation.UPDATING, Annotation.UPDATING, "XUST0033", "DF", "IF"), |
| 58 |
new DisallowedCombination(Annotation.UPDATING, Annotation.SIMPLE, "XUST0033", "DF", "IF"), |
| 59 |
new DisallowedCombination(Annotation.SIMPLE, Annotation.SIMPLE, "XUST0033", "DF", "IF"), |
| 60 |
new DisallowedCombination(Annotation.SIMPLE, Annotation.UPDATING, "XUST0033", "DF", "IF"), |
| 61 |
}; |
| 62 |
|
| 63 |
public XQueryFunctionAnnotationHandler() { |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void check(AnnotationList annotations, String construct) throws XPathException { |
| 69 |
for (int i = 0; i < annotations.size(); i++) { |
| 70 |
Annotation ann = annotations.get(i); |
| 71 |
for (DisallowedCombination dc : blackList) { |
| 72 |
if (dc.one.equals(ann.getAnnotationQName()) && dc.where.contains(construct)) { |
| 73 |
if (dc.two == null) { |
| 74 |
throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + " is not allowed here", |
| 75 |
dc.errorCode); |
| 76 |
} else { |
| 77 |
for (int j = 0; j < i; j++) { |
| 78 |
Annotation other = annotations.get(j); |
| 79 |
if (dc.two.equals(other.getAnnotationQName())) { |
| 80 |
if (dc.two.equals(ann.getAnnotationQName())) { |
| 81 |
throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + |
| 82 |
" cannot appear more than once", dc.errorCode); |
| 83 |
} else { |
| 84 |
throw new XPathException("Annotations %" + ann.getAnnotationQName().getLocalPart() + |
| 85 |
" and " + other.getAnnotationQName().getLocalPart() + " cannot appear together", |
| 86 |
dc.errorCode); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public String getAssertionNamespace() { |
| 104 |
return "http://www.w3.org/2012/xquery"; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public boolean satisfiesAssertion(Annotation assertion, AnnotationList annotationList) { |
| 117 |
|
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public int relationship(AnnotationList firstList, AnnotationList secondList) { |
| 147 |
return TypeHierarchy.OVERLAPS; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
} |
| 152 |
|