001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2000,2008 Oracle. All rights reserved.
005: *
006: * $Id: SerialSerialBinding.java,v 1.22.2.2 2008/01/07 15:14:05 cwl Exp $
007: */
008:
009: package com.sleepycat.bind.serial;
010:
011: import com.sleepycat.bind.EntityBinding;
012: import com.sleepycat.je.DatabaseEntry;
013:
014: /**
015: * An abstract <code>EntityBinding</code> that treats an entity's key entry and
016: * data entry as serialized objects.
017: *
018: * <p>This class takes care of serializing and deserializing the key and
019: * data entry automatically. Its three abstract methods must be implemented by
020: * a concrete subclass to convert the deserialized objects to/from an entity
021: * object.</p>
022: * <ul>
023: * <li> {@link #entryToObject(Object,Object)} </li>
024: * <li> {@link #objectToKey(Object)} </li>
025: * <li> {@link #objectToData(Object)} </li>
026: * </ul>
027: *
028: * @author Mark Hayes
029: */
030: public abstract class SerialSerialBinding implements EntityBinding {
031:
032: private SerialBinding keyBinding;
033: private SerialBinding dataBinding;
034:
035: /**
036: * Creates a serial-serial entity binding.
037: *
038: * @param classCatalog is the catalog to hold shared class information and
039: * for a database should be a {@link StoredClassCatalog}.
040: *
041: * @param keyClass is the key base class.
042: *
043: * @param dataClass is the data base class.
044: */
045: public SerialSerialBinding(ClassCatalog classCatalog,
046: Class keyClass, Class dataClass) {
047:
048: this (new SerialBinding(classCatalog, keyClass),
049: new SerialBinding(classCatalog, dataClass));
050: }
051:
052: /**
053: * Creates a serial-serial entity binding.
054: *
055: * @param keyBinding is the key binding.
056: *
057: * @param dataBinding is the data binding.
058: */
059: public SerialSerialBinding(SerialBinding keyBinding,
060: SerialBinding dataBinding) {
061:
062: this .keyBinding = keyBinding;
063: this .dataBinding = dataBinding;
064: }
065:
066: // javadoc is inherited
067: public Object entryToObject(DatabaseEntry key, DatabaseEntry data) {
068:
069: return entryToObject(keyBinding.entryToObject(key), dataBinding
070: .entryToObject(data));
071: }
072:
073: // javadoc is inherited
074: public void objectToKey(Object object, DatabaseEntry key) {
075:
076: object = objectToKey(object);
077: keyBinding.objectToEntry(object, key);
078: }
079:
080: // javadoc is inherited
081: public void objectToData(Object object, DatabaseEntry data) {
082:
083: object = objectToData(object);
084: dataBinding.objectToEntry(object, data);
085: }
086:
087: /**
088: * Constructs an entity object from deserialized key and data objects.
089: *
090: * @param keyInput is the deserialized key object.
091: *
092: * @param dataInput is the deserialized data object.
093: *
094: * @return the entity object constructed from the key and data.
095: */
096: public abstract Object entryToObject(Object keyInput,
097: Object dataInput);
098:
099: /**
100: * Extracts a key object from an entity object.
101: *
102: * @param object is the entity object.
103: *
104: * @return the deserialized key object.
105: */
106: public abstract Object objectToKey(Object object);
107:
108: /**
109: * Extracts a data object from an entity object.
110: *
111: * @param object is the entity object.
112: *
113: * @return the deserialized data object.
114: */
115: public abstract Object objectToData(Object object);
116: }
|