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 */
017package org.apache.commons.jxpath;
018
019/**
020 * The  {@link JXPathContext#createPath JXPathContext.createPath()} method of
021 * JXPathContext can create missing objects as it traverses an XPath; it
022 * utilizes an AbstractFactory for that purpose. Install a factory on
023 * JXPathContext by calling {@link JXPathContext#setFactory JXPathContext.
024 * setFactory()}.
025 * <p>
026 * All  methods of this class return false.  Override any of them to return true
027 * to indicate that the factory has successfully created the described object.
028 *
029 * @author Dmitri Plotnikov
030 * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
031 */
032public abstract class AbstractFactory {
033
034    /**
035     * The  parameters may describe a collection element or an individual
036     * object. It is up to the factory to infer which one it is. If it is a
037     * collection, the factory should check if the collection exists.  If not,
038     * it should create the collection. Then it should create the index'th
039     * element of the collection and return true.
040     * <p>
041     *
042     * @param context can be used to evaluate other XPaths, get to variables
043     * etc.
044     * @param pointer describes the location of the node to be created
045     * @param parent is the object that will serve as a parent of the new
046     * object
047     * @param name is the name of the child of the parent that needs to be
048     * created. In the case of DOM may be qualified.
049     * @param index is used if the pointer represents a collection element. You
050     * may need to expand or even create the collection to accommodate the new
051     * element.
052     *
053     * @return true if the object was successfully created
054     */
055    public boolean createObject(JXPathContext context, Pointer pointer,
056                                Object parent, String name, int index) {
057        return false;
058    }
059
060    /**
061     * Declare the specified variable
062     *
063     * @param context hosts variable pools. See
064     * {@link JXPathContext#getVariables() JXPathContext.getVariables()}
065     * @param name is the name of the variable without the "$" sign
066     *
067     * @return true if the variable was successfully defined
068     */
069    public boolean declareVariable(JXPathContext context, String name) {
070        return false;
071    }
072}