01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.jxpath.ri.model.dynamic;
17:
18: import java.util.Locale;
19:
20: import org.apache.commons.jxpath.DynamicPropertyHandler;
21: import org.apache.commons.jxpath.JXPathBeanInfo;
22: import org.apache.commons.jxpath.JXPathIntrospector;
23: import org.apache.commons.jxpath.ri.QName;
24: import org.apache.commons.jxpath.ri.model.NodePointer;
25: import org.apache.commons.jxpath.ri.model.NodePointerFactory;
26: import org.apache.commons.jxpath.ri.model.beans.NullPointer;
27: import org.apache.commons.jxpath.util.ValueUtils;
28:
29: /**
30: * Implements NodePointerFactory for Dynamic classes like Map.
31: *
32: * @author Dmitri Plotnikov
33: * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:44 $
34: */
35: public class DynamicPointerFactory implements NodePointerFactory {
36:
37: public static final int DYNAMIC_POINTER_FACTORY_ORDER = 800;
38:
39: public int getOrder() {
40: return DYNAMIC_POINTER_FACTORY_ORDER;
41: }
42:
43: public NodePointer createNodePointer(QName name, Object bean,
44: Locale locale) {
45: JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean
46: .getClass());
47: if (bi.isDynamic()) {
48: DynamicPropertyHandler handler = ValueUtils
49: .getDynamicPropertyHandler(bi
50: .getDynamicPropertyHandlerClass());
51: return new DynamicPointer(name, bean, handler, locale);
52: }
53: return null;
54: }
55:
56: public NodePointer createNodePointer(NodePointer parent,
57: QName name, Object bean) {
58: if (bean == null) {
59: return new NullPointer(parent, name);
60: }
61:
62: JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean
63: .getClass());
64: if (bi.isDynamic()) {
65: DynamicPropertyHandler handler = ValueUtils
66: .getDynamicPropertyHandler(bi
67: .getDynamicPropertyHandlerClass());
68: return new DynamicPointer(parent, name, bean, handler);
69: }
70: return null;
71: }
72: }
|