| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.trans; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Component; |
| 11 |
import net.sf.saxon.expr.ContextOriginator; |
| 12 |
import net.sf.saxon.expr.Expression; |
| 13 |
import net.sf.saxon.expr.instruct.Actor; |
| 14 |
import net.sf.saxon.expr.instruct.SlotManager; |
| 15 |
import net.sf.saxon.lib.NamespaceConstant; |
| 16 |
import net.sf.saxon.lib.StringCollator; |
| 17 |
import net.sf.saxon.om.StandardNames; |
| 18 |
import net.sf.saxon.om.StructuredQName; |
| 19 |
import net.sf.saxon.pattern.Pattern; |
| 20 |
import net.sf.saxon.style.StylesheetPackage; |
| 21 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 22 |
import net.sf.saxon.trace.LocationKind; |
| 23 |
import net.sf.saxon.type.BuiltInAtomicType; |
| 24 |
import net.sf.saxon.type.UType; |
| 25 |
|
| 26 |
import java.util.Map; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class KeyDefinition extends Actor implements ContextOriginator { |
| 35 |
|
| 36 |
private SymbolicName symbolicName; |
| 37 |
private Pattern match; |
| 38 |
private BuiltInAtomicType useType; |
| 39 |
private StringCollator collation; |
| 40 |
private String collationName; |
| 41 |
private boolean backwardsCompatible = false; |
| 42 |
private boolean strictComparison = false; |
| 43 |
private boolean convertUntypedToOther = false; |
| 44 |
private boolean rangeKey = false; |
| 45 |
private boolean composite = false; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public KeyDefinition(SymbolicName symbolicName, Pattern match, Expression use, String collationName, StringCollator collation) { |
| 58 |
this.symbolicName = symbolicName; |
| 59 |
this.match = match; |
| 60 |
setBody(use); |
| 61 |
this.collation = collation; |
| 62 |
this.collationName = collationName; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@Override |
| 71 |
public SymbolicName getSymbolicName() { |
| 72 |
return symbolicName; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public void setRangeKey(boolean rangeKey) { |
| 83 |
this.rangeKey = rangeKey; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public boolean isRangeKey() { |
| 94 |
return rangeKey; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void setComposite(boolean composite) { |
| 104 |
this.composite = composite; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public boolean isComposite() { |
| 113 |
return composite; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public void setIndexedItemType(BuiltInAtomicType itemType) { |
| 123 |
useType = itemType; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public BuiltInAtomicType getIndexedItemType() { |
| 133 |
if (useType == null) { |
| 134 |
return BuiltInAtomicType.ANY_ATOMIC; |
| 135 |
} else { |
| 136 |
return useType; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public void setBackwardsCompatible(boolean bc) { |
| 148 |
backwardsCompatible = bc; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public boolean isBackwardsCompatible() { |
| 158 |
return backwardsCompatible; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public void setStrictComparison(boolean strict) { |
| 170 |
strictComparison = strict; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public boolean isStrictComparison() { |
| 182 |
return strictComparison; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public void setConvertUntypedToOther(boolean convertToOther) { |
| 195 |
convertUntypedToOther = convertToOther; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public boolean isConvertUntypedToOther() { |
| 206 |
return convertUntypedToOther; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public void setStackFrameMap(SlotManager map) { |
| 214 |
if (map != null && map.getNumberOfVariables() > 0) { |
| 215 |
super.setStackFrameMap(map); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
@Override |
| 220 |
public void allocateAllBindingSlots(StylesheetPackage pack) { |
| 221 |
super.allocateAllBindingSlots(pack); |
| 222 |
allocateBindingSlotsRecursive(pack, this, match, getDeclaringComponent().getComponentBindings()); |
| 223 |
} |
| 224 |
|
| 225 |
@Override |
| 226 |
public int getComponentKind() { |
| 227 |
return StandardNames.XSL_KEY; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public void setLocation(String systemId, int lineNumber) { |
| 238 |
setSystemId(systemId); |
| 239 |
setLineNumber(lineNumber); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public Pattern getMatch() { |
| 249 |
return match; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public Expression getUse() { |
| 259 |
return getBody(); |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public String getCollationName() { |
| 269 |
return collationName; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public StringCollator getCollation() { |
| 279 |
return collation; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
public int getConstructType() { |
| 289 |
return StandardNames.XSL_KEY; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public StructuredQName getObjectName() { |
| 299 |
return symbolicName.getComponentName(); |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public void export(ExpressionPresenter out, boolean reusable, Map<Component, Integer> componentIdMap) throws XPathException { |
| 310 |
out.startElement("key"); |
| 311 |
out.emitAttribute("name", getObjectName()); |
| 312 |
if (!NamespaceConstant.CODEPOINT_COLLATION_URI.equals(collationName)) { |
| 313 |
out.emitAttribute("collation", collationName); |
| 314 |
} |
| 315 |
out.emitAttribute("line", getLineNumber() + ""); |
| 316 |
out.emitAttribute("module", getSystemId()); |
| 317 |
if (getStackFrameMap() != null && getStackFrameMap().getNumberOfVariables() != 0) { |
| 318 |
out.emitAttribute("slots", getStackFrameMap().getNumberOfVariables() + ""); |
| 319 |
} |
| 320 |
if (componentIdMap != null) { |
| 321 |
out.emitAttribute("binds", "" + getDeclaringComponent().listComponentReferences(componentIdMap)); |
| 322 |
} |
| 323 |
String flags = ""; |
| 324 |
if (backwardsCompatible) { |
| 325 |
flags += "b"; |
| 326 |
} |
| 327 |
if (isRangeKey()) { |
| 328 |
flags += "r"; |
| 329 |
out.emitAttribute("range", "1"); |
| 330 |
} |
| 331 |
if (match.getUType().overlaps(UType.ATTRIBUTE)) { |
| 332 |
flags += "a"; |
| 333 |
} |
| 334 |
if (match.getUType().overlaps(UType.NAMESPACE)) { |
| 335 |
flags += "n"; |
| 336 |
} |
| 337 |
if (composite) { |
| 338 |
flags += "c"; |
| 339 |
} |
| 340 |
if (reusable) { |
| 341 |
flags += "u"; |
| 342 |
} |
| 343 |
if (!"".equals(flags)) { |
| 344 |
out.emitAttribute("flags", flags); |
| 345 |
} |
| 346 |
getMatch().export(out); |
| 347 |
getBody().export(out); |
| 348 |
out.endElement(); |
| 349 |
} |
| 350 |
|
| 351 |
@Override |
| 352 |
public void export(ExpressionPresenter presenter) throws XPathException { |
| 353 |
throw new UnsupportedOperationException(); |
| 354 |
} |
| 355 |
} |
| 356 |
|