    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *     http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017    package org.apache.commons.configuration.tree.xpath;
    018
    019    import java.util.Locale;
    020
    021    import org.apache.commons.configuration.tree.ConfigurationNode;
    022    import org.apache.commons.jxpath.ri.QName;
    023    import org.apache.commons.jxpath.ri.model.NodePointer;
    024    import org.apache.commons.jxpath.ri.model.NodePointerFactory;
    025
    026    /**
    027     * Implementation of the {@code NodePointerFactory} interface for
    028     * configuration nodes.
    029     *
    030     * @since 1.3
    031     * @author <a
    032     * href="http://commons.apache.org/configuration/team-list.html">Commons
    033     * Configuration team</a>
    034     * @version $Id: ConfigurationNodePointerFactory.java 1206498 2011-11-26 17:01:58Z oheger $
    035     */
    036    public class ConfigurationNodePointerFactory implements NodePointerFactory
    037    {
    038        /** Constant for the order of this factory. */
    039        public static final int CONFIGURATION_NODE_POINTER_FACTORY_ORDER = 200;
    040
    041        /**
    042         * Returns the order of this factory between other factories.
    043         *
    044         * @return this order's factory
    045         */
    046        public int getOrder()
    047        {
    048            return CONFIGURATION_NODE_POINTER_FACTORY_ORDER;
    049        }
    050
    051        /**
    052         * Creates a node pointer for the specified bean. If the bean is a
    053         * configuration node, a corresponding pointer is returned.
    054         *
    055         * @param name the name of the node
    056         * @param bean the bean
    057         * @param locale the locale
    058         * @return a pointer for a configuration node if the bean is such a node
    059         */
    060        public NodePointer createNodePointer(QName name, Object bean, Locale locale)
    061        {
    062            if (bean instanceof ConfigurationNode)
    063            {
    064                return new ConfigurationNodePointer((ConfigurationNode) bean,
    065                        locale);
    066            }
    067            return null;
    068        }
    069
    070        /**
    071         * Creates a node pointer for the specified bean. If the bean is a
    072         * configuration node, a corresponding pointer is returned.
    073         *
    074         * @param parent the parent node
    075         * @param name the name
    076         * @param bean the bean
    077         * @return a pointer for a configuration node if the bean is such a node
    078         */
    079        public NodePointer createNodePointer(NodePointer parent, QName name,
    080                Object bean)
    081        {
    082            if (bean instanceof ConfigurationNode)
    083            {
    084                return new ConfigurationNodePointer(parent,
    085                        (ConfigurationNode) bean);
    086            }
    087            return null;
    088        }
    089    }