01: /*
02: * Created on 13-Jan-2006
03: */
04: package uk.org.ponder.beanutil.support;
05:
06: import uk.org.ponder.beanutil.BeanLocator;
07: import uk.org.ponder.beanutil.BeanResolver;
08: import uk.org.ponder.saxalizer.SAXalizerMappingContext;
09:
10: /** Will return a named field of any bean, rendered as a String */
11:
12: public class BeanFieldResolver implements BeanLocator {
13:
14: private SAXalizerMappingContext mappingcontext;
15:
16: public void setMappingContext(SAXalizerMappingContext mappingcontext) {
17: this .mappingcontext = mappingcontext;
18: }
19:
20: public Object locateBean(final String path) {
21: return new BeanResolver() {
22: public String resolveBean(Object bean) {
23: // A line of code only Andy could love.
24: return mappingcontext.saxleafparser
25: .render(mappingcontext.getAnalyser(
26: bean.getClass()).getAccessMethod(path)
27: .getChildObject(bean));
28: }
29: };
30: }
31:
32: }
|