00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 2000-2005 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: TupleMarshalledBinding.java,v 12.1 2005/01/31 19:27:32 mark Exp $ 00008 */ 00009 00010 package com.sleepycat.bind.tuple; 00011 00012 import com.sleepycat.util.RuntimeExceptionWrapper; 00013 00024 public class TupleMarshalledBinding extends TupleBinding { 00025 00026 private Class cls; 00027 00038 public TupleMarshalledBinding(Class cls) { 00039 00040 this.cls = cls; 00041 00042 /* The class will be used to instantiate the object. */ 00043 if (!MarshalledTupleEntry.class.isAssignableFrom(cls)) { 00044 throw new IllegalArgumentException(cls.toString() + 00045 " does not implement MarshalledTupleEntry"); 00046 } 00047 } 00048 00049 // javadoc is inherited 00050 public Object entryToObject(TupleInput input) { 00051 00052 try { 00053 MarshalledTupleEntry obj = 00054 (MarshalledTupleEntry) cls.newInstance(); 00055 obj.unmarshalEntry(input); 00056 return obj; 00057 } catch (IllegalAccessException e) { 00058 throw new RuntimeExceptionWrapper(e); 00059 } catch (InstantiationException e) { 00060 throw new RuntimeExceptionWrapper(e); 00061 } 00062 } 00063 00064 // javadoc is inherited 00065 public void objectToEntry(Object object, TupleOutput output) { 00066 00067 MarshalledTupleEntry obj = (MarshalledTupleEntry) object; 00068 obj.marshalEntry(output); 00069 } 00070 }