1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.strategy;
18
19 import org.apache.commons.betwixt.expression.Context;
20
21 /***
22 * Pluggable strategy for id storage management.
23 * It is possible to use this strategy for innovative
24 * active storage storage strategies as well as passive ones.
25 * For example, it is possible to have some beans map to
26 * references without ever being fully mapped.
27 *
28 * @author <a href="mailto:christian@wilde-welt.de">Christian Aust </a>
29 * @since 0.7
30 */
31 public abstract class IdStoringStrategy {
32
33 /***
34 * Default storage strategy
35 *
36 * @see DefaultIdStoringStrategy
37 */
38 public static IdStoringStrategy DEFAULT = new DefaultIdStoringStrategy();
39
40 /***
41 * Retrieves a reference for the given instance.
42 * If a not null value is returned from this method,
43 * then the bean content will not be written.
44 * Use {@link org.apache.commons.betwixt.io.IDGenerator} strategy to vary the values
45 * written for a bean.
46 *
47 * @param context
48 * current context, not null
49 * @param bean
50 * the instance, not null
51 * @return id as String when this bean has already been reference,
52 * or null to indicate that this bean is not yet reference
53 */
54 public abstract String getReferenceFor(Context context, Object bean);
55
56 /***
57 * Stores an instance reference for later retrieval.
58 * This method is shared by writing and reading.
59 *
60 * @param context
61 * current context, not null
62 * @param bean
63 * the instance, not null
64 * @param id
65 * the id to use
66 */
67 public abstract void setReference(Context context, Object bean, String id);
68
69 /***
70 * Gets an object matching the given reference.
71 * @param context <code>Context</code>, not null
72 * @param id the reference id
73 * @return an bean matching the given reference,
74 * or null if there is no bean matching the given reference
75 */
76 public abstract Object getReferenced(Context context, String id);
77
78 /***
79 * Reset to the initial state.
80 *
81 */
82 public abstract void reset();
83
84 }