| 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.*; |
| 12 |
import net.sf.saxon.expr.parser.Location; |
| 13 |
import net.sf.saxon.expr.parser.RetainedStaticContext; |
| 14 |
import net.sf.saxon.lib.NamespaceConstant; |
| 15 |
import net.sf.saxon.style.StyleElement; |
| 16 |
import net.sf.saxon.style.StylesheetPackage; |
| 17 |
import net.sf.saxon.style.XSLGlobalParam; |
| 18 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 19 |
import net.sf.saxon.trace.InstructionInfo; |
| 20 |
import net.sf.saxon.trans.SymbolicName; |
| 21 |
import net.sf.saxon.trans.Visibility; |
| 22 |
import net.sf.saxon.trans.VisibilityProvenance; |
| 23 |
import net.sf.saxon.trans.XPathException; |
| 24 |
|
| 25 |
import java.util.Collections; |
| 26 |
import java.util.Iterator; |
| 27 |
import java.util.List; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public abstract class Actor implements InstructionInfo, ExpressionOwner { |
| 40 |
|
| 41 |
protected Expression body; |
| 42 |
private String systemId; |
| 43 |
private int lineNumber; |
| 44 |
private SlotManager stackFrameMap; |
| 45 |
private PackageData packageData; |
| 46 |
private Component declaringComponent; |
| 47 |
private Visibility declaredVisibility; |
| 48 |
private RetainedStaticContext retainedStaticContext; |
| 49 |
|
| 50 |
public Actor() { |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public abstract SymbolicName getSymbolicName(); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public void setPackageData(PackageData packageData) { |
| 69 |
this.packageData = packageData; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public PackageData getPackageData() { |
| 77 |
return packageData; |
| 78 |
} |
| 79 |
|
| 80 |
public Component makeDeclaringComponent(Visibility visibility, StylesheetPackage declaringPackage) { |
| 81 |
if (declaringComponent == null) { |
| 82 |
declaringComponent = Component.makeComponent(this, visibility, VisibilityProvenance.DEFAULTED, declaringPackage, declaringPackage); |
| 83 |
} |
| 84 |
return declaringComponent; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public Component obtainDeclaringComponent(StyleElement declaration) { |
| 94 |
if (declaringComponent == null) { |
| 95 |
StylesheetPackage declaringPackage = declaration.getContainingPackage(); |
| 96 |
Visibility defaultVisibility = declaration instanceof XSLGlobalParam ? Visibility.PUBLIC : Visibility.PRIVATE; |
| 97 |
Visibility declaredVisibility = declaration.getDeclaredVisibility(); |
| 98 |
Visibility actualVisibility = declaredVisibility == null ? defaultVisibility : declaredVisibility; |
| 99 |
VisibilityProvenance provenance = declaredVisibility == null ? VisibilityProvenance.DEFAULTED : VisibilityProvenance.EXPLICIT; |
| 100 |
declaringComponent = Component.makeComponent(this, actualVisibility, provenance, declaringPackage, declaringPackage); |
| 101 |
} |
| 102 |
return declaringComponent; |
| 103 |
} |
| 104 |
|
| 105 |
public Component getDeclaringComponent() { |
| 106 |
return declaringComponent; |
| 107 |
} |
| 108 |
|
| 109 |
public void setDeclaringComponent(Component comp) { |
| 110 |
declaringComponent = comp; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public void allocateAllBindingSlots(StylesheetPackage pack) { |
| 120 |
if (getBody() != null && getDeclaringComponent().getDeclaringPackage() == pack && packageData.getHostLanguage() == Configuration.XSLT) { |
| 121 |
allocateBindingSlotsRecursive(pack, this, getBody(), getDeclaringComponent().getComponentBindings()); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
public static void allocateBindingSlotsRecursive(StylesheetPackage pack, Actor p, Expression exp, List<ComponentBinding> bindings) { |
| 126 |
if (exp instanceof ComponentInvocation) { |
| 127 |
p.processComponentReference(pack, (ComponentInvocation) exp, bindings); |
| 128 |
} |
| 129 |
for (Operand o : exp.operands()) { |
| 130 |
allocateBindingSlotsRecursive(pack, p, o.getChildExpression(), bindings); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
private void processComponentReference(StylesheetPackage pack, ComponentInvocation invocation, List<ComponentBinding> bindings) { |
| 146 |
SymbolicName name = invocation.getSymbolicName(); |
| 147 |
if (name == null) { |
| 148 |
|
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
Component target = pack.getComponent(name); |
| 153 |
if (target == null && name.getComponentName().hasURI(NamespaceConstant.XSLT) && |
| 154 |
name.getComponentName().getLocalPart().equals("original")) { |
| 155 |
target = pack.getOverriddenComponent(getSymbolicName()); |
| 156 |
} |
| 157 |
if (target == null) { |
| 158 |
throw new AssertionError("Target of component reference " + name + " is undefined"); |
| 159 |
} |
| 160 |
if (invocation.getBindingSlot() >= 0) { |
| 161 |
throw new AssertionError("**** Component reference " + name + " is already bound"); |
| 162 |
} |
| 163 |
int slot = bindings.size(); |
| 164 |
ComponentBinding cb = new ComponentBinding(name, target); |
| 165 |
bindings.add(cb); |
| 166 |
invocation.setBindingSlot(slot); |
| 167 |
} |
| 168 |
|
| 169 |
public void setBody(Expression body) { |
| 170 |
this.body = body; |
| 171 |
if (body != null) { |
| 172 |
body.setParentExpression(null); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
public final Expression getBody() { |
| 177 |
return body; |
| 178 |
} |
| 179 |
|
| 180 |
public void setStackFrameMap(SlotManager map) { |
| 181 |
stackFrameMap = map; |
| 182 |
} |
| 183 |
|
| 184 |
public SlotManager getStackFrameMap() { |
| 185 |
return stackFrameMap; |
| 186 |
} |
| 187 |
|
| 188 |
public void setLineNumber(int lineNumber) { |
| 189 |
this.lineNumber = lineNumber; |
| 190 |
} |
| 191 |
|
| 192 |
public void setSystemId(String systemId) { |
| 193 |
this.systemId = systemId; |
| 194 |
} |
| 195 |
|
| 196 |
public Location getLocation() { |
| 197 |
return this; |
| 198 |
} |
| 199 |
|
| 200 |
public int getLineNumber() { |
| 201 |
return lineNumber; |
| 202 |
} |
| 203 |
|
| 204 |
public String getSystemId() { |
| 205 |
return systemId; |
| 206 |
} |
| 207 |
|
| 208 |
public int getColumnNumber() { |
| 209 |
return -1; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
public String getPublicId() { |
| 214 |
return null; |
| 215 |
} |
| 216 |
|
| 217 |
public Location saveLocation() { |
| 218 |
return this; |
| 219 |
} |
| 220 |
|
| 221 |
public void setRetainedStaticContext(RetainedStaticContext rsc) { |
| 222 |
this.retainedStaticContext = rsc; |
| 223 |
} |
| 224 |
|
| 225 |
public RetainedStaticContext getRetainedStaticContext() { |
| 226 |
return retainedStaticContext; |
| 227 |
} |
| 228 |
|
| 229 |
public Object getProperty(String name) { |
| 230 |
return null; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public void setDeclaredVisibility(Visibility visibility) { |
| 240 |
this.declaredVisibility = visibility; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public Visibility getDeclaredVisibility() { |
| 250 |
return declaredVisibility; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public Iterator<String> getProperties() { |
| 262 |
final List<String> list = Collections.emptyList(); |
| 263 |
return list.iterator(); |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public abstract int getComponentKind(); |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public abstract void export(ExpressionPresenter presenter) throws XPathException; |
| 281 |
|
| 282 |
public boolean isExportable() { |
| 283 |
return true; |
| 284 |
} |
| 285 |
|
| 286 |
public void setChildExpression(Expression expr) { |
| 287 |
setBody(expr); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|