1 8 9 package com.sleepycat.bind.tuple; 10 11 import com.sleepycat.util.RuntimeExceptionWrapper; 12 13 26 public class TupleTupleMarshalledBinding extends TupleTupleBinding { 27 28 private Class cls; 29 30 41 public TupleTupleMarshalledBinding(Class cls) { 42 43 this.cls = cls; 44 45 if (!MarshalledTupleKeyEntity.class.isAssignableFrom(cls)) { 48 throw new IllegalArgumentException (cls.toString() + 49 " does not implement MarshalledTupleKeyEntity"); 50 } 51 if (!MarshalledTupleEntry.class.isAssignableFrom(cls)) { 52 throw new IllegalArgumentException (cls.toString() + 53 " does not implement MarshalledTupleEntry"); 54 } 55 } 56 57 public Object entryToObject(TupleInput keyInput, TupleInput dataInput) { 59 60 MarshalledTupleEntry obj; 63 try { 64 obj = (MarshalledTupleEntry) cls.newInstance(); 65 } catch (IllegalAccessException e) { 66 throw new RuntimeExceptionWrapper(e); 67 } catch (InstantiationException e) { 68 throw new RuntimeExceptionWrapper(e); 69 } 70 if (dataInput != null) { obj.unmarshalEntry(dataInput); 72 } 73 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) obj; 74 if (keyInput != null) { entity.unmarshalPrimaryKey(keyInput); 76 } 77 return entity; 78 } 79 80 public void objectToKey(Object object, TupleOutput output) { 82 83 MarshalledTupleKeyEntity entity = (MarshalledTupleKeyEntity) object; 84 entity.marshalPrimaryKey(output); 85 } 86 87 public void objectToData(Object object, TupleOutput output) { 89 90 MarshalledTupleEntry entity = (MarshalledTupleEntry) object; 91 entity.marshalEntry(output); 92 } 93 } 94 | Popular Tags |