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