1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model;
18
19 import java.util.Locale;
20
21 import org.apache.commons.jxpath.JXPathContext;
22 import org.apache.commons.jxpath.Variables;
23 import org.apache.commons.jxpath.ri.QName;
24
25
26
27
28
29
30
31 public class VariablePointerFactory implements NodePointerFactory {
32
33 public static final int VARIABLE_POINTER_FACTORY_ORDER = 890;
34
35
36
37
38 public static final class VariableContextWrapper {
39 private final JXPathContext context;
40
41
42
43
44
45 private VariableContextWrapper(JXPathContext context) {
46 this.context = context;
47 }
48
49
50
51
52
53
54 public JXPathContext getContext() {
55 return context;
56 }
57 }
58
59
60
61
62
63
64 public static VariableContextWrapper contextWrapper(JXPathContext context) {
65 return new VariableContextWrapper(context);
66 }
67
68 public NodePointer createNodePointer(QName name, Object object,
69 Locale locale) {
70 if (object instanceof VariableContextWrapper) {
71 JXPathContext varCtx = ((VariableContextWrapper) object).getContext();
72 while (varCtx != null) {
73 Variables vars = varCtx.getVariables();
74 if (vars.isDeclaredVariable(name.toString())) {
75 return new VariablePointer(vars, name);
76 }
77 varCtx = varCtx.getParentContext();
78 }
79
80
81
82 return new VariablePointer(name);
83 }
84 return null;
85 }
86
87 public NodePointer createNodePointer(NodePointer parent, QName name,
88 Object object) {
89 return createNodePointer(name, object, null);
90 }
91
92 public int getOrder() {
93 return VARIABLE_POINTER_FACTORY_ORDER;
94 }
95
96 }