1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. import java.util.Locale;
  18. import org.apache.commons.jxpath.DynamicPropertyHandler;
  19. import org.apache.commons.jxpath.JXPathBeanInfo;
  20. import org.apache.commons.jxpath.JXPathIntrospector;
  21. import org.apache.commons.jxpath.ri.QName;
  22. import org.apache.commons.jxpath.ri.model.NodePointer;
  23. import org.apache.commons.jxpath.ri.model.NodePointerFactory;
  24. import org.apache.commons.jxpath.ri.model.beans.NullPointer;
  25. import org.apache.commons.jxpath.util.ValueUtils;
  26. /**
  27. * Implements NodePointerFactory for Dynamic classes like Map.
  28. *
  29. * @author Dmitri Plotnikov
  30. * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:44 $
  31. */
  32. public class DynamicPointerFactory implements NodePointerFactory {
  33. public static final int DYNAMIC_POINTER_FACTORY_ORDER = 800;
  34. public int getOrder() {
  35. return DYNAMIC_POINTER_FACTORY_ORDER;
  36. }
  37. public NodePointer createNodePointer(
  38. QName name,
  39. Object bean,
  40. Locale locale)
  41. {
  42. JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
  43. if (bi.isDynamic()) {
  44. DynamicPropertyHandler handler =
  45. ValueUtils.getDynamicPropertyHandler(
  46. bi.getDynamicPropertyHandlerClass());
  47. return new DynamicPointer(name, bean, handler, locale);
  48. }
  49. return null;
  50. }
  51. public NodePointer createNodePointer(
  52. NodePointer parent,
  53. QName name,
  54. Object bean)
  55. {
  56. if (bean == null) {
  57. return new NullPointer(parent, name);
  58. }
  59. JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
  60. if (bi.isDynamic()) {
  61. DynamicPropertyHandler handler =
  62. ValueUtils.getDynamicPropertyHandler(
  63. bi.getDynamicPropertyHandlerClass());
  64. return new DynamicPointer(parent, name, bean, handler);
  65. }
  66. return null;
  67. }
  68. }