    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</code> interface for
    028     * configuration nodes.
    029     *
    030     * @since 1.3
    031     * @author Oliver Heger
    032     * @version $Id: ConfigurationNodePointerFactory.java 439648 2006-09-02 20:42:10Z oheger $
    033     */
    034    public class ConfigurationNodePointerFactory implements NodePointerFactory
    035    {
    036        /** Constant for the order of this factory. */
    037        public static final int CONFIGURATION_NODE_POINTER_FACTORY_ORDER = 200;
    038
    039        /**
    040         * Returns the order of this factory between other factories.
    041         *
    042         * @return this order's factory
    043         */
    044        public int getOrder()
    045        {
    046            return CONFIGURATION_NODE_POINTER_FACTORY_ORDER;
    047        }
    048
    049        /**
    050         * Creates a node pointer for the specified bean. If the bean is a
    051         * configuration node, a corresponding pointer is returned.
    052         *
    053         * @param name the name of the node
    054         * @param bean the bean
    055         * @param locale the locale
    056         * @return a pointer for a configuration node if the bean is such a node
    057         */
    058        public NodePointer createNodePointer(QName name, Object bean, Locale locale)
    059        {
    060            if (bean instanceof ConfigurationNode)
    061            {
    062                return new ConfigurationNodePointer((ConfigurationNode) bean,
    063                        locale);
    064            }
    065            return null;
    066        }
    067
    068        /**
    069         * Creates a node pointer for the specified bean. If the bean is a
    070         * configuration node, a corresponding pointer is returned.
    071         *
    072         * @param parent the parent node
    073         * @param name the name
    074         * @param bean the bean
    075         * @return a pointer for a configuration node if the bean is such a node
    076         */
    077        public NodePointer createNodePointer(NodePointer parent, QName name,
    078                Object bean)
    079        {
    080            if (bean instanceof ConfigurationNode)
    081            {
    082                return new ConfigurationNodePointer(parent,
    083                        (ConfigurationNode) bean);
    084            }
    085            return null;
    086        }
    087    }