| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.trace; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.expr.instruct.*; |
| 12 |
import net.sf.saxon.expr.parser.Location; |
| 13 |
import net.sf.saxon.lib.Logger; |
| 14 |
import net.sf.saxon.lib.NamespaceConstant; |
| 15 |
import net.sf.saxon.ma.arrays.ArrayItem; |
| 16 |
import net.sf.saxon.ma.map.MapItem; |
| 17 |
import net.sf.saxon.om.Function; |
| 18 |
import net.sf.saxon.om.Item; |
| 19 |
import net.sf.saxon.om.NodeInfo; |
| 20 |
import net.sf.saxon.om.StructuredQName; |
| 21 |
import net.sf.saxon.trans.KeyDefinition; |
| 22 |
import net.sf.saxon.tree.util.Navigator; |
| 23 |
import net.sf.saxon.value.AtomicValue; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public abstract class ContextStackFrame { |
| 30 |
|
| 31 |
private XPathContext context; |
| 32 |
private Location location; |
| 33 |
private Item contextItem; |
| 34 |
private Object container; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public void setLocation(Location loc) { |
| 44 |
this.location = loc; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public String getSystemId() { |
| 55 |
return location.getSystemId(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public int getLineNumber() { |
| 66 |
return location.getLineNumber(); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public void setComponent(Object container) { |
| 77 |
this.container = container; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public Object getContainer() { |
| 88 |
return container; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public void setContext(XPathContext context) { |
| 98 |
this.context = context; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public XPathContext getContext() { |
| 108 |
return context; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public void setContextItem(Item contextItem) { |
| 118 |
this.contextItem = contextItem; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public Item getContextItem() { |
| 128 |
return contextItem; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public abstract void print(Logger out); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
protected String showLocation() { |
| 146 |
if (getSystemId() == null) { |
| 147 |
return ""; |
| 148 |
} |
| 149 |
int line = getLineNumber(); |
| 150 |
if (line == -1 || line == 0xfffff) { |
| 151 |
return "(" + getSystemId() + ")"; |
| 152 |
} else { |
| 153 |
return "(" + getSystemId() + "#" + getLineNumber() + ")"; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public static class CallingApplication extends ContextStackFrame { |
| 165 |
public void print(Logger out) { |
| 166 |
|
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
public static class BuiltInTemplateRule extends ContextStackFrame { |
| 175 |
private XPathContext context; |
| 176 |
public BuiltInTemplateRule(XPathContext context) { |
| 177 |
this.context = context; |
| 178 |
} |
| 179 |
public void print(Logger out) { |
| 180 |
Item contextItem = context.getContextItem(); |
| 181 |
String diag; |
| 182 |
if (contextItem instanceof NodeInfo) { |
| 183 |
diag = Navigator.getPath((NodeInfo)contextItem); |
| 184 |
} else if (contextItem instanceof AtomicValue) { |
| 185 |
diag = "value " + contextItem.toString(); |
| 186 |
} else if (contextItem instanceof MapItem) { |
| 187 |
diag = "map"; |
| 188 |
} else if (contextItem instanceof ArrayItem) { |
| 189 |
diag = "array"; |
| 190 |
} else if (contextItem instanceof Function) { |
| 191 |
diag = "function"; |
| 192 |
} else { |
| 193 |
diag = "item"; |
| 194 |
} |
| 195 |
out.error(" in built-in template rule for " + diag + " in " + |
| 196 |
context.getCurrentMode().getActor().getModeTitle().toLowerCase()); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public static class FunctionCall extends ContextStackFrame { |
| 206 |
|
| 207 |
StructuredQName functionName; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
public StructuredQName getFunctionName() { |
| 215 |
return functionName; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public void setFunctionName(StructuredQName functionName) { |
| 224 |
this.functionName = functionName; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public void print(Logger out) { |
| 234 |
out.error(" at " + (functionName == null ? "(anonymous)" : functionName.getDisplayName()) + "() " + showLocation()); |
| 235 |
} |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
public static class ApplyTemplates extends ContextStackFrame { |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
public void print(Logger out) { |
| 252 |
out.error(" at xsl:apply-templates " + showLocation()); |
| 253 |
Item node = getContextItem(); |
| 254 |
if (node instanceof NodeInfo) { |
| 255 |
out.error(" processing " + Navigator.getPath((NodeInfo) node)); |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public static class CallTemplate extends ContextStackFrame { |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public StructuredQName getTemplateName() { |
| 273 |
return templateName; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
public void setTemplateName(StructuredQName templateName) { |
| 282 |
this.templateName = templateName; |
| 283 |
} |
| 284 |
|
| 285 |
StructuredQName templateName; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public void print(Logger out) { |
| 294 |
String name = templateName == null ? "??" : templateName.getDisplayName(); |
| 295 |
out.error(" at xsl:call-template name=\"" + name + "\" " + showLocation()); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
public static class VariableEvaluation extends ContextStackFrame { |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public StructuredQName getVariableName() { |
| 311 |
return variableName; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
public void setVariableName(StructuredQName variableName) { |
| 320 |
this.variableName = variableName; |
| 321 |
} |
| 322 |
|
| 323 |
StructuredQName variableName; |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public void print(Logger out) { |
| 332 |
out.error(" in " + displayContainer(getContainer()) + " " + showLocation()); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
private static String displayContainer( Object container) { |
| 337 |
if (container instanceof Actor) { |
| 338 |
StructuredQName name = ((Actor) container).getObjectName(); |
| 339 |
String objectName = name == null ? "" : name.getDisplayName(); |
| 340 |
if (container instanceof NamedTemplate) { |
| 341 |
return "template name=\"" + objectName + "\""; |
| 342 |
} else if (container instanceof UserFunction) { |
| 343 |
return "function " + objectName + "()"; |
| 344 |
} else if (container instanceof AttributeSet) { |
| 345 |
return "attribute-set " + objectName; |
| 346 |
} else if (container instanceof KeyDefinition) { |
| 347 |
return "key " + objectName; |
| 348 |
} else if (container instanceof GlobalVariable) { |
| 349 |
StructuredQName qName = ((GlobalVariable) container).getVariableQName(); |
| 350 |
if (qName.hasURI(NamespaceConstant.SAXON_GENERATED_VARIABLE)) { |
| 351 |
return "optimizer-created global variable"; |
| 352 |
} else { |
| 353 |
return "global variable $" + qName.getDisplayName(); |
| 354 |
} |
| 355 |
} |
| 356 |
} else if (container instanceof TemplateRule) { |
| 357 |
return "template match=\"" + ((TemplateRule) container).getMatchPattern().toString() + "\""; |
| 358 |
} |
| 359 |
return ""; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
} |
| 364 |
|