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