| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Component; |
| 11 |
import net.sf.saxon.om.NodeInfo; |
| 12 |
import net.sf.saxon.om.StandardNames; |
| 13 |
import net.sf.saxon.pattern.NameTest; |
| 14 |
import net.sf.saxon.pattern.QNameTest; |
| 15 |
import net.sf.saxon.trans.*; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class XSLAccept extends XSLAcceptExpose { |
| 21 |
@Override |
| 22 |
protected void prepareAttributes() throws XPathException { |
| 23 |
super.prepareAttributes(); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@Override |
| 37 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 38 |
NodeInfo parent = getParent(); |
| 39 |
if (!(parent instanceof XSLUsePackage)) { |
| 40 |
compileError("Parent of xsl:accept must be xsl:use-package"); |
| 41 |
return; |
| 42 |
} |
| 43 |
StylesheetPackage pack = ((XSLUsePackage)parent).getUsedPackage(); |
| 44 |
if (pack != null) { |
| 45 |
for (ComponentTest test : getExplicitComponentTests()) { |
| 46 |
QNameTest nameTest = test.getQNameTest(); |
| 47 |
if (nameTest instanceof NameTest) { |
| 48 |
int kind = test.getComponentKind(); |
| 49 |
SymbolicName sName = kind == StandardNames.XSL_FUNCTION ? |
| 50 |
new SymbolicName.F(((NameTest) nameTest).getMatchingNodeName(), test.getArity()) : |
| 51 |
new SymbolicName(kind, ((NameTest) nameTest).getMatchingNodeName()); |
| 52 |
Component comp = pack.getComponent(sName); |
| 53 |
boolean found = false; |
| 54 |
if (comp == null) { |
| 55 |
if (kind == StandardNames.XSL_FUNCTION && test.getArity() == -1) { |
| 56 |
|
| 57 |
for (int i = 0; i <= pack.getMaxFunctionArity(); i++) { |
| 58 |
sName = new SymbolicName.F(((NameTest) nameTest).getMatchingNodeName(), i); |
| 59 |
comp = pack.getComponent(sName); |
| 60 |
if (comp != null) { |
| 61 |
checkCompatibility(sName, comp.getVisibility(), getVisibility()); |
| 62 |
found = true; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
} else { |
| 68 |
checkCompatibility(sName, comp.getVisibility(), getVisibility()); |
| 69 |
found = true; |
| 70 |
} |
| 71 |
if (!found) { |
| 72 |
compileError("No " + sName.toString() + " exists in the used package", "XTSE3030"); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public void acceptComponent(Component component) throws XPathException { |
| 89 |
for (ComponentTest test : getExplicitComponentTests()) { |
| 90 |
if (test.matches(component.getActor())) { |
| 91 |
|
| 92 |
component.setVisibility(getVisibility(), VisibilityProvenance.ACCEPTED); |
| 93 |
return; |
| 94 |
} |
| 95 |
} |
| 96 |
for (ComponentTest test : getWildcardComponentTests()) { |
| 97 |
if (test.matches(component.getActor())) { |
| 98 |
if (isCompatible(component.getVisibility(), getVisibility())) { |
| 99 |
|
| 100 |
component.setVisibility(getVisibility(), VisibilityProvenance.ACCEPTED); |
| 101 |
return; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
protected void checkCompatibility(SymbolicName name, Visibility declared, Visibility exposed) throws XPathException { |
| 108 |
if (!isCompatible(declared, exposed)) { |
| 109 |
String code = "XTSE3040"; |
| 110 |
compileError("The " + name + " is declared as " + declared.show() + " and cannot be accepted as " + exposed.show(), code); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
public static boolean isCompatible(Visibility declared, Visibility exposed) { |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
switch (declared) { |
| 119 |
case PUBLIC: |
| 120 |
return exposed == Visibility.PUBLIC || exposed == Visibility.PRIVATE || |
| 121 |
exposed == Visibility.FINAL || exposed == Visibility.HIDDEN; |
| 122 |
case ABSTRACT: |
| 123 |
return exposed == Visibility.ABSTRACT || exposed == Visibility.HIDDEN; |
| 124 |
case FINAL: |
| 125 |
return exposed == Visibility.PRIVATE || |
| 126 |
exposed == Visibility.FINAL || exposed == Visibility.HIDDEN; |
| 127 |
default: |
| 128 |
return false; |
| 129 |
} |
| 130 |
} |
| 131 |
} |