View Javadoc

    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
    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(
    44          QName name,
    45          Object bean,
    46          Locale locale)
    47      {
    48          JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
    49          if (bi.isDynamic()) {
    50              DynamicPropertyHandler handler =
    51                  ValueUtils.getDynamicPropertyHandler(
    52                      bi.getDynamicPropertyHandlerClass());
    53              return new DynamicPointer(name, bean, handler, locale);
    54          }
    55          return null;
    56      }
    57
    58      public NodePointer createNodePointer(
    59          NodePointer parent,
    60          QName name,
    61          Object bean)
    62      {
    63          if (bean == null) {
    64              return new NullPointer(parent, name);
    65          }
    66
    67          JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
    68          if (bi.isDynamic()) {
    69              DynamicPropertyHandler handler =
    70                  ValueUtils.getDynamicPropertyHandler(
    71                      bi.getDynamicPropertyHandlerClass());
    72              return new DynamicPointer(parent, name, bean, handler);
    73          }
    74          return null;
    75      }
    76  }