Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IPrimaryKeyConverter |
|
| 1.0;1 |
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.components; | |
16 | ||
17 | /** | |
18 | * An interface for converting an objects to their primary keys and back. | |
19 | * Typically used to determine how to store a given object as a hidden value | |
20 | * when rendering a form. | |
21 | * <p> | |
22 | * This interface is used by the | |
23 | * {@link org.apache.tapestry.components.ForBean For component}. When a primary | |
24 | * key converter is available, it is used during the render, and as part of the | |
25 | * rewind phase that processes the form submission. | |
26 | * <p> | |
27 | * During rendering, {@link #getPrimaryKey(Object)} is invoked for each value. | |
28 | * This method is invoked just before the For's body is rendered. The resulting | |
29 | * primary key is written into the client as a hidden form field. | |
30 | * <p> | |
31 | * Likewise, during rewind, {@link #getValue(Object)} is invoked for each key, | |
32 | * to get back the same (or equivalent) object. Again, the method is invoked | |
33 | * just before the For's body is rendered. | |
34 | * <p> | |
35 | * The {@link org.apache.tapestry.util.DefaultPrimaryKeyConverter} uses this | |
36 | * relationship between a For component and its primary key converter to track | |
37 | * what the current value being rendered or rewound is. | |
38 | * | |
39 | * @author mb | |
40 | * @since 4.0 | |
41 | */ | |
42 | public interface IPrimaryKeyConverter | |
43 | { | |
44 | ||
45 | /** | |
46 | * Returns the primary key of the given value. | |
47 | * | |
48 | * @param objValue | |
49 | * the value for which a primary key needs to be extracted | |
50 | * @return the primary key of the value | |
51 | */ | |
52 | Object getPrimaryKey(Object value); | |
53 | ||
54 | /** | |
55 | * Returns the value corresponding the given primary key. | |
56 | * | |
57 | * @param objPrimaryKey | |
58 | * the primary key for which a value needs to be generated | |
59 | * @return the generated value corresponding to the given primary key | |
60 | */ | |
61 | Object getValue(Object primaryKey); | |
62 | ||
63 | } |