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 18 package org.apache.commons.jxpath; 19 20 /** 21 * A generic mechanism for accessing collections of name/value pairs. Examples of such collections are HashMap, Properties, ServletContext. In order to add 22 * support for a new such collection type to JXPath, perform the following two steps: 23 * <ol> 24 * <li>Build an implementation of the DynamicPropertyHandler interface for the desired collection type.</li> 25 * <li>Invoke the static method {@link JXPathIntrospector#registerDynamicClass JXPathIntrospector.registerDynamicClass(class, handlerClass)}</li> 26 * </ol> 27 * JXPath allows access to dynamic properties using these three formats: 28 * <ul> 29 * <li>{@code "myMap/myKey"}</li> 30 * <li>{@code "myMap[@name = 'myKey']"}</li> 31 * <li>{@code "myMap[name(.) = 'myKey']"}</li> 32 * </ul> 33 */ 34 public interface DynamicPropertyHandler { 35 36 /** 37 * Returns the value of the specified dynamic property. 38 * 39 * @param object to search 40 * @param propertyName to retrieve 41 * @return Object 42 */ 43 Object getProperty(Object object, String propertyName); 44 45 /** 46 * Returns a list of dynamic property names for the supplied object. 47 * 48 * @param object to inspect 49 * @return String[] 50 */ 51 String[] getPropertyNames(Object object); 52 53 /** 54 * Modifies the value of the specified dynamic property. 55 * 56 * @param object to modify 57 * @param propertyName to modify 58 * @param value to set 59 */ 60 void setProperty(Object object, String propertyName, Object value); 61 }