01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.externalizer;
12:
13: import javax.jdo.PersistenceManager;
14:
15: /**
16: * Externalizers convert an object to/from some other object for storage. This
17: * is done when the object is stored/retrieved from the data store. The
18: * transformation takes place on the "client side" in the context of
19: * a PersistenceManager so references to PC instances can be converted
20: * into OIDs and so on.
21: * <p/>
22: * If the class implementing this Interface has a constructor that accepts
23: * a single Class argument then this will be invoked with the target field
24: * type. Throw an IllegalArgumentException if this type is not suitable.
25: * Otherwise the default constructor is used.
26: *
27: * @see SerializedExternalizer
28: * @see TypeAsBytesExternalizer
29: * @see TypeAsStringExternalizer
30: */
31: public interface Externalizer {
32:
33: /**
34: * Convert to an object for storage.
35: */
36: public Object toExternalForm(PersistenceManager pm, Object o);
37:
38: /**
39: * Create from an object read from storage.
40: */
41: public Object fromExternalForm(PersistenceManager pm, Object o);
42:
43: /**
44: * Return the class that we convert to/from. This is used to decide
45: * how to map the field (e.g. what sort of database column to create).
46: */
47: public Class getExternalType();
48:
49: }
|