01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.conf;
20:
21: import org.apache.openjpa.lib.conf.Configurable;
22: import org.apache.openjpa.lib.conf.Configuration;
23:
24: /**
25: * Responsible for marshalling and unmarshalling objects between memory and
26: * durable cache.
27: *
28: * @since 1.1.0
29: */
30: public interface CacheMarshaller {
31:
32: /**
33: * Load and return an instance of the type handled by this marshaller.
34: * If the type implements {@link Configurable}, then this method will invoke
35: * {@link Configurable#setConfiguration},
36: * {@link Configurable#startConfiguration()}, and
37: * {@link Configurable#endConfiguration()} on the instance before returning.
38: */
39: public Object load();
40:
41: /**
42: * Store <code>o</code> into the cache.
43: */
44: public void store(Object o);
45:
46: /**
47: * The id that this marshaller is responsible for.
48: * A value for this parameter is required.
49: */
50: public void setId(String id);
51:
52: /**
53: * The id that this marshaller is responsible for.
54: */
55: public String getId();
56:
57: /**
58: * The {@link ValidationPolicy} that this marshaller should use.
59: * A value for this parameter is required. The class will be instantiated
60: * via the {@link org.apache.openjpa.lib.conf.Configurations} mechanism, ensuring that if the class
61: * implements {@link Configurable} or {@link org.apache.openjpa.lib.conf.GenericConfigurable}, it will
62: * be taken through the appropriate lifecycle.
63: */
64: public void setValidationPolicy(String policy)
65: throws InstantiationException, IllegalAccessException;
66:
67: /**
68: * Validation policies are responsible for computing whether or not a
69: * cached data structure is valid for the current context.
70: * <p/>
71: * <code>getValidCachedData(getCacheableData(o), conf)</code> should
72: * return an object equivalent to <code>o</code> in the expected case.
73: * <p/>
74: * Implementations of this class will often also implement
75: * {@link Configurable} in order to receive the current
76: * {@link Configuration}.
77: */
78: public interface ValidationPolicy {
79: /**
80: * Returns an object that this policy considers to be valid, based
81: * on <code>o</code>. If <code>o</code> is not valid, this method
82: * will return <code>null</code>.
83: */
84: public Object getValidData(Object o);
85:
86: /**
87: * Return an object that the {@link CacheMarshaller} should store.
88: */
89: public Object getCacheableData(Object o);
90: }
91: }
|