01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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;
16:
17: import java.io.Serializable;
18: import java.util.List;
19:
20: import org.apache.tapestry.corelib.components.Loop;
21:
22: /**
23: * Used by {@link Loop} and similar components to extract out an identifier, here termed a "primary
24: * key", that can be stored on the client and later used to recover the same, or equivalent, server
25: * side object.
26: *
27: * @param <K>
28: * the type of the primary key, used to identify the value (which must be serializable)
29: * @param <V>
30: * the type of value identified by the key
31: */
32: public interface PrimaryKeyEncoder<K extends Serializable, V> {
33: /**
34: * Given a particular value, this method extracts and returns the primary key that identifies
35: * the value. The key will later be converted back into a value using
36: * {@link #toValue(Serializable)}.
37: *
38: * @param value
39: * whose primary key is needed
40: * @return the key for the value
41: */
42: K toKey(V value);
43:
44: /**
45: * Invoked as part of a form submission to alert the encoder that a series of keys may be
46: * converted back to values. This is advisory only, and the keys passed to
47: * {@link #toValue(Serializable)} may not include all keys in the list, or may include keys not
48: * in the list. In general, though, the keys passed in will match the actual keys to be
49: * converted, giving the encoder a chance to efficiently fetch the necessary value objects as a
50: * group.
51: */
52: void prepareForKeys(List<K> keys);
53:
54: /**
55: * For a particular primary key, previously obtained via {@link #toKey(Object)}, this method
56: * returns the same or equivalent object.
57: *
58: * @param key
59: * used to identify the object
60: * @return the value object for the key
61: */
62: V toValue(K key);
63: }
|