    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 * A generic mechanism for accessing collections of name/value pairs. Examples of such collections are HashMap, Properties, ServletContext. In order to add
    022 * support for a new such collection type to JXPath, perform the following two steps:
    023 * <ol>
    024 * <li>Build an implementation of the DynamicPropertyHandler interface for the desired collection type.</li>
    025 * <li>Invoke the static method {@link JXPathIntrospector#registerDynamicClass JXPathIntrospector.registerDynamicClass(class, handlerClass)}</li>
    026 * </ol>
    027 * JXPath allows access to dynamic properties using these three formats:
    028 * <ul>
    029 * <li>{@code "myMap/myKey"}</li>
    030 * <li>{@code "myMap[@name = 'myKey']"}</li>
    031 * <li>{@code "myMap[name(.) = 'myKey']"}</li>
    032 * </ul>
    033 */
    034public interface DynamicPropertyHandler {
    035
    036    /**
    037     * Returns the value of the specified dynamic property.
    038     *
    039     * @param object       to search
    040     * @param propertyName to retrieve
    041     * @return Object
    042     */
    043    Object getProperty(Object object, String propertyName);
    044
    045    /**
    046     * Returns a list of dynamic property names for the supplied object.
    047     *
    048     * @param object to inspect
    049     * @return String[]
    050     */
    051    String[] getPropertyNames(Object object);
    052
    053    /**
    054     * Modifies the value of the specified dynamic property.
    055     *
    056     * @param object       to modify
    057     * @param propertyName to modify
    058     * @param value        to set
    059     */
    060    void setProperty(Object object, String propertyName, Object value);
    061}