1 8 9 package com.sleepycat.bind.tuple; 10 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import com.sleepycat.bind.EntryBinding; 15 import com.sleepycat.je.DatabaseEntry; 16 17 43 public abstract class TupleBinding extends TupleBase implements EntryBinding { 44 45 private static final Map primitives = new HashMap (); 46 static { 47 addPrimitive(String .class, String .class, new StringBinding()); 48 addPrimitive(Character .class, Character.TYPE, new CharacterBinding()); 49 addPrimitive(Boolean .class, Boolean.TYPE, new BooleanBinding()); 50 addPrimitive(Byte .class, Byte.TYPE, new ByteBinding()); 51 addPrimitive(Short .class, Short.TYPE, new ShortBinding()); 52 addPrimitive(Integer .class, Integer.TYPE, new IntegerBinding()); 53 addPrimitive(Long .class, Long.TYPE, new LongBinding()); 54 addPrimitive(Float .class, Float.TYPE, new FloatBinding()); 55 addPrimitive(Double .class, Double.TYPE, new DoubleBinding()); 56 } 57 58 private static void addPrimitive(Class cls1, Class cls2, 59 TupleBinding binding) { 60 primitives.put(cls1, binding); 61 primitives.put(cls2, binding); 62 } 63 64 67 public TupleBinding() { 68 } 69 70 public Object entryToObject(DatabaseEntry entry) { 72 73 return entryToObject(entryToInput(entry)); 74 } 75 76 public void objectToEntry(Object object, DatabaseEntry entry) { 78 79 TupleOutput output = getTupleOutput(object); 80 objectToEntry(object, output); 81 outputToEntry(output, entry); 82 } 83 84 91 public abstract Object entryToObject(TupleInput input); 92 93 101 public abstract void objectToEntry(Object object, TupleOutput output); 102 103 128 public static TupleBinding getPrimitiveBinding(Class cls) { 129 130 return (TupleBinding) primitives.get(cls); 131 } 132 } 133 | Popular Tags |