1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50:
55: public class XPathImpl
56: implements XPath
57: {
58:
59: XPathParser parser;
60: NamespaceContext namespaceContext;
61: XPathVariableResolver variableResolver;
62: XPathFunctionResolver functionResolver;
63:
64: XPathImpl(NamespaceContext namespaceContext,
65: XPathVariableResolver variableResolver,
66: XPathFunctionResolver functionResolver)
67: {
68: parser = new XPathParser();
69: this.namespaceContext = namespaceContext;
70: this.variableResolver = variableResolver;
71: this.functionResolver = functionResolver;
72: reset();
73: }
74:
75: public void reset()
76: {
77: parser.namespaceContext = namespaceContext;
78: parser.variableResolver = variableResolver;
79: parser.functionResolver = functionResolver;
80: }
81:
82: public void setXPathVariableResolver(XPathVariableResolver resolver)
83: {
84: parser.variableResolver = resolver;
85: }
86:
87: public XPathVariableResolver getXPathVariableResolver()
88: {
89: return parser.variableResolver;
90: }
91:
92: public void setXPathFunctionResolver(XPathFunctionResolver resolver)
93: {
94: parser.functionResolver = resolver;
95: }
96:
97: public XPathFunctionResolver getXPathFunctionResolver()
98: {
99: return parser.functionResolver;
100: }
101:
102: public void setNamespaceContext(NamespaceContext nsContext)
103: {
104: parser.namespaceContext = nsContext;
105: }
106:
107: public NamespaceContext getNamespaceContext()
108: {
109: return parser.namespaceContext;
110: }
111:
112: public XPathExpression compile(String expression)
113: throws XPathExpressionException
114: {
115: XPathTokenizer tokenizer = new XPathTokenizer(expression);
116: try
117: {
118: return (Expr) parser.yyparse(tokenizer);
119: }
120: catch (IOException e)
121: {
122: throw new XPathExpressionException(e);
123: }
124: catch (XPathParser.yyException e)
125: {
126: throw new XPathExpressionException(expression);
127: }
128: }
129:
130: public Object evaluate(String expression,
131: Object item,
132: QName returnType)
133: throws XPathExpressionException
134: {
135: XPathExpression expr = compile(expression);
136: return expr.evaluate(item, returnType);
137: }
138:
139: public String evaluate(String expression,
140: Object item)
141: throws XPathExpressionException
142: {
143: XPathExpression expr = compile(expression);
144: return expr.evaluate(item);
145: }
146:
147: public Object evaluate(String expression,
148: InputSource source,
149: QName returnType)
150: throws XPathExpressionException
151: {
152: XPathExpression expr = compile(expression);
153: return expr.evaluate(source, returnType);
154: }
155:
156: public String evaluate(String expression,
157: InputSource source)
158: throws XPathExpressionException
159: {
160: XPathExpression expr = compile(expression);
161: return expr.evaluate(source);
162: }
163:
164: }