1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model.dynamic;
18
19 import java.util.Locale;
20
21 import org.apache.commons.jxpath.DynamicPropertyHandler;
22 import org.apache.commons.jxpath.JXPathBeanInfo;
23 import org.apache.commons.jxpath.JXPathIntrospector;
24 import org.apache.commons.jxpath.ri.QName;
25 import org.apache.commons.jxpath.ri.model.NodePointer;
26 import org.apache.commons.jxpath.ri.model.NodePointerFactory;
27 import org.apache.commons.jxpath.ri.model.beans.NullPointer;
28 import org.apache.commons.jxpath.util.ValueUtils;
29
30
31
32
33
34
35
36 public class DynamicPointerFactory implements NodePointerFactory {
37
38
39
40
41 public static final int DYNAMIC_POINTER_FACTORY_ORDER = 800;
42
43 public int getOrder() {
44 return DYNAMIC_POINTER_FACTORY_ORDER;
45 }
46
47 public NodePointer createNodePointer(
48 QName name,
49 Object bean,
50 Locale locale) {
51 JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
52 if (bi.isDynamic()) {
53 DynamicPropertyHandler handler =
54 ValueUtils.getDynamicPropertyHandler(
55 bi.getDynamicPropertyHandlerClass());
56 return new DynamicPointer(name, bean, handler, locale);
57 }
58 return null;
59 }
60
61 public NodePointer createNodePointer(
62 NodePointer parent,
63 QName name,
64 Object bean) {
65 if (bean == null) {
66 return new NullPointer(parent, name);
67 }
68
69 JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
70 if (bi.isDynamic()) {
71 DynamicPropertyHandler handler =
72 ValueUtils.getDynamicPropertyHandler(
73 bi.getDynamicPropertyHandlerClass());
74 return new DynamicPointer(parent, name, bean, handler);
75 }
76 return null;
77 }
78 }