| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.expr.parser.ExplicitLocation; |
| 13 |
import net.sf.saxon.expr.parser.RoleDiagnostic; |
| 14 |
import net.sf.saxon.expr.parser.TypeChecker; |
| 15 |
import net.sf.saxon.om.*; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.value.SequenceType; |
| 18 |
|
| 19 |
import java.util.Collection; |
| 20 |
import java.util.HashMap; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class GlobalParameterSet { |
| 31 |
private HashMap<StructuredQName, GroundedValue<?>> params = |
| 32 |
new HashMap<>(10); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public GlobalParameterSet() { |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public GlobalParameterSet(GlobalParameterSet parameterSet) { |
| 47 |
this.params = new HashMap<>(parameterSet.params); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public void put(StructuredQName qName, GroundedValue<?> value) { |
| 58 |
if (value == null) { |
| 59 |
params.remove(qName); |
| 60 |
} else { |
| 61 |
params.put(qName, value); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public GroundedValue<?> get(StructuredQName qName) { |
| 73 |
return params.get(qName); |
| 74 |
} |
| 75 |
|
| 76 |
public boolean containsKey(StructuredQName qName) { |
| 77 |
return params.containsKey(qName); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public GroundedValue<?> convertParameterValue( |
| 94 |
StructuredQName qName, SequenceType requiredType, boolean convert, XPathContext context) |
| 95 |
throws XPathException { |
| 96 |
Sequence<?> val = get(qName); |
| 97 |
if (val == null) { |
| 98 |
return null; |
| 99 |
} |
| 100 |
|
| 101 |
if (requiredType != null) { |
| 102 |
if (convert) { |
| 103 |
RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.VARIABLE, qName.getDisplayName(), -1); |
| 104 |
Configuration config = context.getConfiguration(); |
| 105 |
val = config.getTypeHierarchy().applyFunctionConversionRules( |
| 106 |
val, requiredType, role, ExplicitLocation.UNKNOWN_LOCATION); |
| 107 |
} else { |
| 108 |
XPathException err = TypeChecker.testConformance(val, requiredType, context); |
| 109 |
if (err != null) { |
| 110 |
throw err; |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
return val.materialize(); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public void clear() { |
| 123 |
params.clear(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public Collection<StructuredQName> getKeys() { |
| 133 |
return params.keySet(); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public int getNumberOfKeys() { |
| 143 |
return params.size(); |
| 144 |
} |
| 145 |
|
| 146 |
} |