View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.configuration.tree.xpath;
18  
19  import java.util.Locale;
20  
21  import org.apache.commons.configuration.tree.ConfigurationNode;
22  import org.apache.commons.jxpath.ri.QName;
23  import org.apache.commons.jxpath.ri.model.NodePointer;
24  import org.apache.commons.jxpath.ri.model.NodePointerFactory;
25  
26  /**
27   * Implementation of the {@code NodePointerFactory} interface for
28   * configuration nodes.
29   *
30   * @since 1.3
31   * @author <a
32   * href="http://commons.apache.org/configuration/team-list.html">Commons
33   * Configuration team</a>
34   * @version $Id: ConfigurationNodePointerFactory.java 1206498 2011-11-26 17:01:58Z oheger $
35   */
36  public class ConfigurationNodePointerFactory implements NodePointerFactory
37  {
38      /** Constant for the order of this factory. */
39      public static final int CONFIGURATION_NODE_POINTER_FACTORY_ORDER = 200;
40  
41      /**
42       * Returns the order of this factory between other factories.
43       *
44       * @return this order's factory
45       */
46      public int getOrder()
47      {
48          return CONFIGURATION_NODE_POINTER_FACTORY_ORDER;
49      }
50  
51      /**
52       * Creates a node pointer for the specified bean. If the bean is a
53       * configuration node, a corresponding pointer is returned.
54       *
55       * @param name the name of the node
56       * @param bean the bean
57       * @param locale the locale
58       * @return a pointer for a configuration node if the bean is such a node
59       */
60      public NodePointer createNodePointer(QName name, Object bean, Locale locale)
61      {
62          if (bean instanceof ConfigurationNode)
63          {
64              return new ConfigurationNodePointer((ConfigurationNode) bean,
65                      locale);
66          }
67          return null;
68      }
69  
70      /**
71       * Creates a node pointer for the specified bean. If the bean is a
72       * configuration node, a corresponding pointer is returned.
73       *
74       * @param parent the parent node
75       * @param name the name
76       * @param bean the bean
77       * @return a pointer for a configuration node if the bean is such a node
78       */
79      public NodePointer createNodePointer(NodePointer parent, QName name,
80              Object bean)
81      {
82          if (bean instanceof ConfigurationNode)
83          {
84              return new ConfigurationNodePointer(parent,
85                      (ConfigurationNode) bean);
86          }
87          return null;
88      }
89  }