| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.expr.instruct.DocumentInstr; |
| 12 |
import net.sf.saxon.expr.instruct.GlobalVariable; |
| 13 |
import net.sf.saxon.expr.instruct.SlotManager; |
| 14 |
import net.sf.saxon.expr.instruct.ValueOf; |
| 15 |
import net.sf.saxon.expr.parser.RoleDiagnostic; |
| 16 |
import net.sf.saxon.lib.NamespaceConstant; |
| 17 |
import net.sf.saxon.om.*; |
| 18 |
import net.sf.saxon.pattern.NodeKindTest; |
| 19 |
import net.sf.saxon.trans.Visibility; |
| 20 |
import net.sf.saxon.trans.XPathException; |
| 21 |
import net.sf.saxon.tree.AttributeLocation; |
| 22 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 23 |
import net.sf.saxon.type.ItemType; |
| 24 |
import net.sf.saxon.type.TypeHierarchy; |
| 25 |
import net.sf.saxon.type.UType; |
| 26 |
import net.sf.saxon.value.Cardinality; |
| 27 |
import net.sf.saxon.value.SequenceType; |
| 28 |
import net.sf.saxon.value.StringValue; |
| 29 |
import net.sf.saxon.value.Whitespace; |
| 30 |
|
| 31 |
import java.util.ArrayList; |
| 32 |
import java.util.List; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class SourceBinding { |
| 40 |
|
| 41 |
private StyleElement sourceElement; |
| 42 |
private StructuredQName name; |
| 43 |
private Expression select = null; |
| 44 |
private SequenceType declaredType = null; |
| 45 |
private SequenceType inferredType = null; |
| 46 |
protected SlotManager slotManager = null; |
| 47 |
private Visibility visibility; |
| 48 |
private GroundedValue<?> constantValue = null; |
| 49 |
|
| 50 |
private int properties; |
| 51 |
|
| 52 |
public static final int PRIVATE = 1; |
| 53 |
public static final int GLOBAL = 2; |
| 54 |
public static final int PARAM = 4; |
| 55 |
public static final int TUNNEL = 8; |
| 56 |
public static final int REQUIRED = 16; |
| 57 |
public static final int IMPLICITLY_REQUIRED = 32; |
| 58 |
public static final int ASSIGNABLE = 64; |
| 59 |
public static final int SELECT = 128; |
| 60 |
public static final int AS = 256; |
| 61 |
public static final int DISALLOWS_CONTENT = 512; |
| 62 |
public static final int STATIC = 2048; |
| 63 |
public static final int VISIBILITY = 4096; |
| 64 |
public static final int IMPLICITLY_DECLARED = 8192; |
| 65 |
|
| 66 |
|
| 67 |
private List<BindingReference> references = new ArrayList<>(10); |
| 68 |
|
| 69 |
public SourceBinding(StyleElement sourceElement) { |
| 70 |
this.sourceElement = sourceElement; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
public void prepareAttributes(int permittedAttributes) throws XPathException { |
| 75 |
|
| 76 |
AttributeCollection atts = sourceElement.getAttributeList(); |
| 77 |
|
| 78 |
String selectAtt = null; |
| 79 |
String asAtt = null; |
| 80 |
String extraAsAtt = null; |
| 81 |
String requiredAtt = null; |
| 82 |
String tunnelAtt = null; |
| 83 |
String assignableAtt = null; |
| 84 |
String staticAtt = null; |
| 85 |
String visibilityAtt = null; |
| 86 |
|
| 87 |
for (int a = 0; a < atts.getLength(); a++) { |
| 88 |
String f = atts.getQName(a); |
| 89 |
if (f.equals("name")) { |
| 90 |
if (name == null || name.equals(errorName())) { |
| 91 |
processVariableName(atts.getValue(a)); |
| 92 |
} |
| 93 |
} else if (f.equals("select")) { |
| 94 |
if ((permittedAttributes & SELECT) != 0) { |
| 95 |
selectAtt = atts.getValue(a); |
| 96 |
} else { |
| 97 |
sourceElement.compileErrorInAttribute( |
| 98 |
"The select attribute is not permitted on a function parameter", "XTSE0760", "select"); |
| 99 |
} |
| 100 |
} else if (f.equals("as") && ((permittedAttributes & AS) != 0)) { |
| 101 |
asAtt = atts.getValue(a); |
| 102 |
} else if (f.equals("required") && ((permittedAttributes & REQUIRED) != 0)) { |
| 103 |
requiredAtt = Whitespace.trim(atts.getValue(a)); |
| 104 |
} else if (f.equals("tunnel")) { |
| 105 |
tunnelAtt = Whitespace.trim(atts.getValue(a)); |
| 106 |
} else if (f.equals("static") && ((permittedAttributes & STATIC) != 0)) { |
| 107 |
staticAtt = Whitespace.trim(atts.getValue(a)); |
| 108 |
} else if (f.equals("visibility") && ((permittedAttributes & VISIBILITY) != 0)) { |
| 109 |
visibilityAtt = Whitespace.trim(atts.getValue(a)); |
| 110 |
} else if (NamespaceConstant.SAXON.equals(atts.getURI(a))) { |
| 111 |
if (atts.getLocalName(a).equals("assignable") && ((permittedAttributes & ASSIGNABLE) != 0)) { |
| 112 |
assignableAtt = Whitespace.trim(atts.getValue(a)); |
| 113 |
} else if (atts.getLocalName(a).equals("as")) { |
| 114 |
extraAsAtt = atts.getValue(a); |
| 115 |
} else { |
| 116 |
sourceElement.checkUnknownAttribute(atts.getNodeName(a)); |
| 117 |
} |
| 118 |
} else { |
| 119 |
sourceElement.checkUnknownAttribute(atts.getNodeName(a)); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
if (name == null) { |
| 124 |
sourceElement.reportAbsence("name"); |
| 125 |
name = errorName(); |
| 126 |
} |
| 127 |
|
| 128 |
if (selectAtt != null) { |
| 129 |
select = sourceElement.makeExpression(selectAtt, sourceElement.getAttributeList().getIndex("", "select")); |
| 130 |
} |
| 131 |
|
| 132 |
if (requiredAtt != null) { |
| 133 |
boolean required = sourceElement.processBooleanAttribute("required", requiredAtt); |
| 134 |
setProperty(REQUIRED, required); |
| 135 |
if (required && select != null) { |
| 136 |
sourceElement.compileError("xsl:param: cannot supply a default value when required='yes'"); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
if (tunnelAtt != null) { |
| 141 |
boolean tunnel = sourceElement.processBooleanAttribute("tunnel", tunnelAtt); |
| 142 |
if (tunnel && ((permittedAttributes & TUNNEL) == 0)) { |
| 143 |
sourceElement.compileErrorInAttribute("The only permitted value of the 'tunnel' attribute is 'no'", "XTSE0020", "tunnel"); |
| 144 |
} |
| 145 |
setProperty(TUNNEL, tunnel); |
| 146 |
} |
| 147 |
|
| 148 |
if (assignableAtt != null) { |
| 149 |
boolean assignable = sourceElement.processBooleanAttribute("saxon:assignable", assignableAtt); |
| 150 |
setProperty(ASSIGNABLE, assignable); |
| 151 |
} |
| 152 |
|
| 153 |
if (staticAtt != null) { |
| 154 |
boolean statick = sourceElement.processBooleanAttribute("static", staticAtt); |
| 155 |
setProperty(STATIC, statick); |
| 156 |
if (statick) { |
| 157 |
setProperty(SourceBinding.DISALLOWS_CONTENT, true); |
| 158 |
} |
| 159 |
if (statick && !hasProperty(GLOBAL)) { |
| 160 |
sourceElement.compileErrorInAttribute("Only global declarations can be static", "XTSE0020", "static"); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
declaredType = combineTypeDeclarations(asAtt, extraAsAtt); |
| 165 |
|
| 166 |
|
| 167 |
if (visibilityAtt != null) { |
| 168 |
if (hasProperty(PARAM)) { |
| 169 |
sourceElement.compileErrorInAttribute("The visibility attribute is not allowed on xsl:param", "XTSE0020", "visibility"); |
| 170 |
} else { |
| 171 |
visibility = sourceElement.interpretVisibilityValue(visibilityAtt, ""); |
| 172 |
} |
| 173 |
if (!hasProperty(GLOBAL)) { |
| 174 |
sourceElement.compileErrorInAttribute("The visibility attribute is allowed only on global declarations", "XTSE0020", "visibility"); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
if (hasProperty(STATIC) && visibility != Visibility.PRIVATE && visibilityAtt != null) { |
| 179 |
sourceElement.compileErrorInAttribute("A static variable or parameter must be private", "XTSE0020", "static"); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public void prepareTemplateSignatureAttributes() throws XPathException { |
| 192 |
|
| 193 |
AttributeCollection atts = sourceElement.getAttributeList(); |
| 194 |
|
| 195 |
String asAtt = null; |
| 196 |
String extraAsAtt = null; |
| 197 |
|
| 198 |
for (int a = 0; a < atts.getLength(); a++) { |
| 199 |
String f = atts.getQName(a); |
| 200 |
if (f.equals("name")) { |
| 201 |
if (name == null || name.equals(errorName())) { |
| 202 |
processVariableName(atts.getValue(a)); |
| 203 |
} |
| 204 |
} else if (f.equals("as")) { |
| 205 |
asAtt = atts.getValue(a); |
| 206 |
} else if (f.equals("required")) { |
| 207 |
String requiredAtt = Whitespace.trim(atts.getValue(a)); |
| 208 |
boolean required = sourceElement.processBooleanAttribute("required", requiredAtt); |
| 209 |
setProperty(REQUIRED, required); |
| 210 |
} else if (f.equals("tunnel")) { |
| 211 |
String tunnelAtt = Whitespace.trim(atts.getValue(a)); |
| 212 |
boolean tunnel = sourceElement.processBooleanAttribute("tunnel", tunnelAtt); |
| 213 |
setProperty(TUNNEL, tunnel); |
| 214 |
} else if (NamespaceConstant.SAXON.equals(atts.getURI(a))) { |
| 215 |
if (atts.getLocalName(a).equals("as")) { |
| 216 |
extraAsAtt = atts.getValue(a); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
if (name == null) { |
| 222 |
sourceElement.reportAbsence("name"); |
| 223 |
name = errorName(); |
| 224 |
} |
| 225 |
|
| 226 |
declaredType = combineTypeDeclarations(asAtt, extraAsAtt); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
private SequenceType combineTypeDeclarations(String asAtt, String extraAsAtt) { |
| 231 |
SequenceType declaredType = null; |
| 232 |
|
| 233 |
if (asAtt != null) { |
| 234 |
try { |
| 235 |
declaredType = sourceElement.makeSequenceType(asAtt); |
| 236 |
} catch (XPathException e) { |
| 237 |
sourceElement.compileErrorInAttribute(e.getMessage(), e.getErrorCodeLocalPart(), "as"); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
if (extraAsAtt != null) { |
| 242 |
SequenceType extraResultType = null; |
| 243 |
try { |
| 244 |
extraResultType = sourceElement.makeExtendedSequenceType(extraAsAtt); |
| 245 |
} catch (XPathException e) { |
| 246 |
sourceElement.compileErrorInAttribute(e.getMessage(), e.getErrorCodeLocalPart(), "saxon:as"); |
| 247 |
extraResultType = SequenceType.ANY_SEQUENCE; |
| 248 |
} |
| 249 |
if (asAtt != null) { |
| 250 |
int rel = sourceElement.getConfiguration().getTypeHierarchy().sequenceTypeRelationship(extraResultType, declaredType); |
| 251 |
if (rel == TypeHierarchy.SAME_TYPE || rel == TypeHierarchy.SUBSUMED_BY) { |
| 252 |
declaredType = extraResultType; |
| 253 |
} else { |
| 254 |
sourceElement.compileErrorInAttribute("When both are present, @saxon:as must be a subtype of @as", "SXER7TBA", "as"); |
| 255 |
} |
| 256 |
} else { |
| 257 |
declaredType = extraResultType; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
return declaredType; |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public StyleElement getSourceElement() { |
| 272 |
return sourceElement; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
public void setVariableQName(StructuredQName name) { |
| 282 |
this.name = name; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public void setDeclaredType(SequenceType declaredType) { |
| 292 |
this.declaredType = declaredType; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
private void processVariableName(String nameAttribute) throws XPathException { |
| 305 |
try { |
| 306 |
if (nameAttribute != null) { |
| 307 |
name = sourceElement.makeQName(nameAttribute); |
| 308 |
} |
| 309 |
} catch (XPathException err) { |
| 310 |
name = errorName(); |
| 311 |
StructuredQName n = StructuredQName.fromClarkName("name"); |
| 312 |
throw new XPathException("Invalid variable name: " + err.getMessage() + |
| 313 |
(nameAttribute.startsWith("$") ? " (No '$' sign needed)" : ""), "XTSE0020", |
| 314 |
new AttributeLocation(sourceElement, n)); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
private StructuredQName errorName() { |
| 326 |
return new StructuredQName("saxon", NamespaceConstant.SAXON, "error-variable-name"); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
public void validate() throws XPathException { |
| 336 |
if (select != null && sourceElement.hasChildNodes()) { |
| 337 |
sourceElement.compileError("An " + sourceElement.getDisplayName() + " element with a select attribute must be empty", "XTSE0620"); |
| 338 |
} |
| 339 |
if (hasProperty(DISALLOWS_CONTENT) && sourceElement.hasChildNodes()) { |
| 340 |
if (isStatic()) { |
| 341 |
sourceElement.compileError("A static variable or parameter must have no content", "XTSE0010"); |
| 342 |
} else { |
| 343 |
sourceElement.compileError("Within xsl:function, an xsl:param element must have no content", "XTSE0620"); |
| 344 |
} |
| 345 |
} |
| 346 |
if (visibility == Visibility.ABSTRACT && (select != null || sourceElement.hasChildNodes())) { |
| 347 |
sourceElement.compileError("An abstract variable must have no select attribute and no content", "XTSE0620"); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
public void postValidate() throws XPathException { |
| 359 |
checkAgainstRequiredType(declaredType); |
| 360 |
|
| 361 |
if (select == null && !hasProperty(DISALLOWS_CONTENT) && visibility != Visibility.ABSTRACT) { |
| 362 |
AxisIterator kids = sourceElement.iterateAxis(AxisInfo.CHILD); |
| 363 |
NodeInfo first = kids.next(); |
| 364 |
if (first == null) { |
| 365 |
if (declaredType == null) { |
| 366 |
select = new StringLiteral(StringValue.EMPTY_STRING); |
| 367 |
select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext()); |
| 368 |
} else { |
| 369 |
if (sourceElement instanceof XSLLocalParam || sourceElement instanceof XSLGlobalParam) { |
| 370 |
if (!hasProperty(REQUIRED)) { |
| 371 |
if (Cardinality.allowsZero(declaredType.getCardinality())) { |
| 372 |
select = Literal.makeEmptySequence(); |
| 373 |
select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext()); |
| 374 |
} else { |
| 375 |
|
| 376 |
|
| 377 |
setProperty(IMPLICITLY_REQUIRED, true); |
| 378 |
} |
| 379 |
} |
| 380 |
} else { |
| 381 |
if (Cardinality.allowsZero(declaredType.getCardinality())) { |
| 382 |
select = Literal.makeEmptySequence(); |
| 383 |
select.setRetainedStaticContext(sourceElement.makeRetainedStaticContext()); |
| 384 |
} else { |
| 385 |
sourceElement.compileError("The implicit value () is not valid for the declared type", "XTTE0570"); |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
select = sourceElement.typeCheck("select", select); |
| 392 |
} |
| 393 |
|
| 394 |
public boolean isStatic() { |
| 395 |
return hasProperty(STATIC); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public void checkAgainstRequiredType(SequenceType required) { |
| 406 |
if (visibility != Visibility.ABSTRACT) { |
| 407 |
try { |
| 408 |
if (required != null) { |
| 409 |
|
| 410 |
if (select != null) { |
| 411 |
int category = RoleDiagnostic.VARIABLE; |
| 412 |
String errorCode = "XTTE0570"; |
| 413 |
if (sourceElement instanceof XSLLocalParam) { |
| 414 |
category = RoleDiagnostic.PARAM; |
| 415 |
errorCode = "XTTE0600"; |
| 416 |
} else if (sourceElement instanceof XSLWithParam || sourceElement instanceof XSLGlobalParam) { |
| 417 |
category = RoleDiagnostic.PARAM; |
| 418 |
errorCode = "XTTE0590"; |
| 419 |
} |
| 420 |
RoleDiagnostic role = new RoleDiagnostic(category, name.getDisplayName(), 0); |
| 421 |
|
| 422 |
role.setErrorCode(errorCode); |
| 423 |
select = sourceElement.getConfiguration().getTypeChecker(false).staticTypeCheck(select, required, role, sourceElement.makeExpressionVisitor()); |
| 424 |
} else { |
| 425 |
|
| 426 |
} |
| 427 |
} |
| 428 |
} catch (XPathException err) { |
| 429 |
err.setLocator(sourceElement); |
| 430 |
sourceElement.compileError(err); |
| 431 |
select = new ErrorExpression(err); |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public StructuredQName getVariableQName() { |
| 444 |
if (name == null) { |
| 445 |
try { |
| 446 |
processVariableName(sourceElement.getAttributeValue("", "name")); |
| 447 |
} catch (XPathException e) { |
| 448 |
return errorName(); |
| 449 |
} |
| 450 |
} |
| 451 |
return name; |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
public void setProperty(int prop, boolean flag) { |
| 462 |
if (flag) { |
| 463 |
properties |= prop; |
| 464 |
} else { |
| 465 |
properties &= ~prop; |
| 466 |
} |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
public boolean hasProperty(int prop) { |
| 477 |
return (properties & prop) != 0; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
public List<BindingReference> getReferences() { |
| 487 |
return references; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
public SlotManager getSlotManager() { |
| 498 |
return slotManager; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
public void handleSequenceConstructor(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 511 |
|
| 512 |
|
| 513 |
if (sourceElement.hasChildNodes()) { |
| 514 |
if (declaredType == null) { |
| 515 |
Expression b = sourceElement.compileSequenceConstructor(compilation, decl, true); |
| 516 |
if (b == null) { |
| 517 |
b = Literal.makeEmptySequence(); |
| 518 |
} |
| 519 |
boolean textonly = UType.TEXT.subsumes(b.getItemType().getUType()); |
| 520 |
String constant = null; |
| 521 |
if (textonly && b instanceof ValueOf && ((ValueOf) b).getSelect() instanceof StringLiteral) { |
| 522 |
constant = ((StringLiteral) ((ValueOf) b).getSelect()).getStringValue(); |
| 523 |
} |
| 524 |
DocumentInstr doc = new DocumentInstr(textonly, constant); |
| 525 |
doc.setContentExpression(b); |
| 526 |
doc.setRetainedStaticContext(sourceElement.makeRetainedStaticContext()); |
| 527 |
select = doc; |
| 528 |
} else { |
| 529 |
select = sourceElement.compileSequenceConstructor(compilation, decl, true); |
| 530 |
if (select == null) { |
| 531 |
select = Literal.makeEmptySequence(); |
| 532 |
} |
| 533 |
try { |
| 534 |
RoleDiagnostic role = |
| 535 |
new RoleDiagnostic(RoleDiagnostic.VARIABLE, name.getDisplayName(), 0); |
| 536 |
role.setErrorCode("XTTE0570"); |
| 537 |
select = select.simplify(); |
| 538 |
select = sourceElement.getConfiguration().getTypeChecker(false).staticTypeCheck( |
| 539 |
select, declaredType, role, sourceElement.makeExpressionVisitor()); |
| 540 |
} catch (XPathException err) { |
| 541 |
err.setLocator(sourceElement); |
| 542 |
sourceElement.compileError(err); |
| 543 |
select = new ErrorExpression(err); |
| 544 |
} |
| 545 |
} |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public SequenceType getDeclaredType() { |
| 556 |
if (declaredType == null) { |
| 557 |
|
| 558 |
String asAtt = sourceElement.getAttributeValue("", "as"); |
| 559 |
if (asAtt == null) { |
| 560 |
return null; |
| 561 |
} else { |
| 562 |
try { |
| 563 |
declaredType = sourceElement.makeSequenceType(asAtt); |
| 564 |
} catch (XPathException err) { |
| 565 |
|
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
} |
| 570 |
return declaredType; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
public Expression getSelectExpression() { |
| 580 |
return select; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
public SequenceType getInferredType(boolean useContentRules) { |
| 592 |
if (inferredType != null) { |
| 593 |
return inferredType; |
| 594 |
} |
| 595 |
Visibility visibility = sourceElement.getVisibility(); |
| 596 |
if (hasProperty(PARAM) || hasProperty(ASSIGNABLE) || |
| 597 |
!(visibility == Visibility.PRIVATE || visibility == Visibility.FINAL)) { |
| 598 |
SequenceType declared = getDeclaredType(); |
| 599 |
return inferredType = declared == null ? SequenceType.ANY_SEQUENCE : declared; |
| 600 |
} |
| 601 |
if (select != null) { |
| 602 |
TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy(); |
| 603 |
if (Literal.isEmptySequence(select)) { |
| 604 |
|
| 605 |
return inferredType = declaredType == null ? SequenceType.ANY_SEQUENCE : declaredType; |
| 606 |
} |
| 607 |
ItemType actual = select.getItemType(); |
| 608 |
int card = select.getCardinality(); |
| 609 |
if (declaredType != null) { |
| 610 |
if (!th.isSubType(actual, declaredType.getPrimaryType())) { |
| 611 |
actual = declaredType.getPrimaryType(); |
| 612 |
} |
| 613 |
if (!Cardinality.subsumes(declaredType.getCardinality(), card)) { |
| 614 |
card = declaredType.getCardinality(); |
| 615 |
} |
| 616 |
} |
| 617 |
inferredType = SequenceType.makeSequenceType(actual, card); |
| 618 |
return inferredType; |
| 619 |
} |
| 620 |
if (useContentRules) { |
| 621 |
if (sourceElement.hasChildNodes()) { |
| 622 |
if (declaredType == null) { |
| 623 |
return SequenceType.makeSequenceType(NodeKindTest.DOCUMENT, StaticProperty.EXACTLY_ONE); |
| 624 |
} else { |
| 625 |
return declaredType; |
| 626 |
} |
| 627 |
} else { |
| 628 |
if (declaredType == null) { |
| 629 |
|
| 630 |
return SequenceType.SINGLE_STRING; |
| 631 |
} else { |
| 632 |
return declaredType; |
| 633 |
} |
| 634 |
} |
| 635 |
} |
| 636 |
return declaredType; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
public void registerReference(BindingReference ref) { |
| 647 |
references.add(ref); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
public GroundedValue<?> getConstantValue() { |
| 652 |
if (constantValue == null) { |
| 653 |
final SequenceType type = getInferredType(true); |
| 654 |
final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy(); |
| 655 |
if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) { |
| 656 |
if (select instanceof Literal) { |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
int relation = th.relationship(select.getItemType(), type.getPrimaryType()); |
| 661 |
if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { |
| 662 |
constantValue = ((Literal) select).getValue(); |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
} |
| 667 |
return constantValue; |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
public void fixupReferences(GlobalVariable compiledGlobalVariable) { |
| 677 |
final SequenceType type = getInferredType(true); |
| 678 |
final TypeHierarchy th = sourceElement.getConfiguration().getTypeHierarchy(); |
| 679 |
GroundedValue constantValue = null; |
| 680 |
int properties = 0; |
| 681 |
if (!hasProperty(ASSIGNABLE) && !hasProperty(PARAM) && !(visibility == Visibility.PUBLIC || visibility == Visibility.ABSTRACT)) { |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
if (select != null) { |
| 692 |
properties = select.getSpecialProperties(); |
| 693 |
} |
| 694 |
} |
| 695 |
for (BindingReference reference : references) { |
| 696 |
if (compiledGlobalVariable != null) { |
| 697 |
reference.fixup(compiledGlobalVariable); |
| 698 |
} |
| 699 |
reference.setStaticType(type, getConstantValue(), properties); |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
protected void fixupBinding(Binding binding) { |
| 710 |
for (BindingReference reference : references) { |
| 711 |
reference.fixup(binding); |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
} |
| 716 |
|