View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath;
18  
19  /**
20   * A generic mechanism for accessing collections of name/value pairs.
21   * Examples of such collections are HashMap, Properties,
22   * ServletContext.  In order to add support for a new such collection
23   * type to JXPath, perform the following two steps:
24   * <ol>
25   * <li>Build an implementation of the DynamicPropertyHandler interface
26   * for the desired collection type.</li>
27   * <li>Invoke the static method {@link JXPathIntrospector#registerDynamicClass
28   * JXPathIntrospector.registerDynamicClass(class, handlerClass)}</li>
29   * </ol>
30   * JXPath allows access to dynamic properties using these three formats:
31   * <ul>
32   * <li><code>"myMap/myKey"</code></li>
33   * <li><code>"myMap[@name = 'myKey']"</code></li>
34   * <li><code>"myMap[name(.) = 'myKey']"</code></li>
35   * </ul>
36   *
37   * @author Dmitri Plotnikov
38   * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
39   */
40  public interface DynamicPropertyHandler {
41  
42      /**
43       * Returns a list of dynamic property names for the supplied object.
44       * @param object to inspect
45       * @return String[]
46       */
47      String[] getPropertyNames(Object object);
48  
49      /**
50       * Returns the value of the specified dynamic property.
51       * @param object to search
52       * @param propertyName to retrieve
53       * @return Object
54       */
55      Object getProperty(Object object, String propertyName);
56  
57      /**
58       * Modifies the value of the specified dynamic property.
59       * @param object to modify
60       * @param propertyName to modify
61       * @param value to set
62       */
63      void setProperty(Object object, String propertyName, Object value);
64  }