Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PropertyAccessor |
|
| 1.0;1 |
1 | package org.apache.commons.ognl; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.util.Map; | |
23 | ||
24 | /** | |
25 | * This interface defines methods for setting and getting a property from a target object. A "property" in this case is | |
26 | * a named data value that takes the generic form of an Object---the same definition as is used by beans. But the | |
27 | * operational semantics of the term will vary by implementation of this interface: a bean-style implementation will get | |
28 | * and set properties as beans do, by reflection on the target object's class, but other implementations are possible, | |
29 | * such as one that uses the property name as a key into a map. | |
30 | * <p> | |
31 | * An implementation of this interface will often require that its target objects all be of some particular type. For | |
32 | * example, the MapPropertyAccessor class requires that its targets all implement the java.util.Map interface. | |
33 | * <p> | |
34 | * Note that the "name" of a property is represented by a generic Object. Some implementations may require properties' | |
35 | * names to be Strings, while others may allow them to be other types---for example, ArrayPropertyAccessor treats Number | |
36 | * names as indexes into the target object, which must be an array. | |
37 | * | |
38 | * @author Luke Blanshard (blanshlu@netscape.net) | |
39 | * @author Drew Davidson (drew@ognl.org) | |
40 | */ | |
41 | public interface PropertyAccessor | |
42 | { | |
43 | ||
44 | /** | |
45 | * Extracts and returns the property of the given name from the given target object. | |
46 | * | |
47 | * @param context The current execution context. | |
48 | * @param target the object to get the property from | |
49 | * @param name the name of the property to get. | |
50 | * @return the current value of the given property in the given object | |
51 | * @exception OgnlException if there is an error locating the property in the given object | |
52 | */ | |
53 | Object getProperty( Map<String, Object> context, Object target, Object name ) | |
54 | throws OgnlException; | |
55 | ||
56 | /** | |
57 | * Sets the value of the property of the given name in the given target object. | |
58 | * | |
59 | * @param context The current execution context. | |
60 | * @param target the object to set the property in | |
61 | * @param name the name of the property to set | |
62 | * @param value the new value for the property. | |
63 | * @exception OgnlException if there is an error setting the property in the given object | |
64 | */ | |
65 | void setProperty( Map<String, Object> context, Object target, Object name, Object value ) | |
66 | throws OgnlException; | |
67 | ||
68 | /** | |
69 | * Returns a java string representing the textual method that should be called to access a particular element. (ie | |
70 | * "get") | |
71 | * | |
72 | * @param context The current execution context. | |
73 | * @param target The current object target on the expression tree being evaluated. | |
74 | * @param index The index object that will be placed inside the string to access the value. | |
75 | * @return The source accessor method to call. | |
76 | */ | |
77 | String getSourceAccessor( OgnlContext context, Object target, Object index ); | |
78 | ||
79 | /** | |
80 | * Returns a java string representing the textual method that should be called to set a particular element. (ie | |
81 | * "set") | |
82 | * | |
83 | * @param context The current execution context. | |
84 | * @param target The current object target on the expression tree being evaluated. | |
85 | * @param index The index object that will be placed inside the string to set the value. | |
86 | * @return The source setter method to call. | |
87 | */ | |
88 | String getSourceSetter( OgnlContext context, Object target, Object index ); | |
89 | } |