01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * Retrieves a reference for the given instance.
55: * If a not null value is returned from this method,
56: * then the bean content will not be written.
57: * Use {@link org.apache.commons.betwixt.io.IDGenerator} strategy to vary the values
58: * written for a bean.
59: *
60: * @param context
61: * current context, not null
62: * @param bean
63: * the instance, not null
64: * @return id as String when this bean has already been reference,
65: * or null to indicate that this bean is not yet reference
66: */
67: public abstract String getReferenceFor(Context context, Object bean);
68:
69: /**
70: * Stores an instance reference for later retrieval.
71: * This method is shared by writing and reading.
72: *
73: * @param context
74: * current context, not null
75: * @param bean
76: * the instance, not null
77: * @param id
78: * the id to use
79: */
80: public abstract void setReference(Context context, Object bean,
81: 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: }
|