Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

TupleBinding.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: TupleBinding.java,v 12.2 2005/08/01 20:25:16 mark Exp $
00008  */
00009 
00010 package com.sleepycat.bind.tuple;
00011 
00012 import java.util.HashMap;
00013 import java.util.Map;
00014 
00015 import com.sleepycat.bind.EntryBinding;
00016 import com.sleepycat.db.DatabaseEntry;
00017 
00037 public abstract class TupleBinding extends TupleBase implements EntryBinding {
00038 
00039     private static final Map primitives = new HashMap();
00040     static {
00041         addPrimitive(String.class, String.class, new StringBinding());
00042         addPrimitive(Character.class, Character.TYPE, new CharacterBinding());
00043         addPrimitive(Boolean.class, Boolean.TYPE, new BooleanBinding());
00044         addPrimitive(Byte.class, Byte.TYPE, new ByteBinding());
00045         addPrimitive(Short.class, Short.TYPE, new ShortBinding());
00046         addPrimitive(Integer.class, Integer.TYPE, new IntegerBinding());
00047         addPrimitive(Long.class, Long.TYPE, new LongBinding());
00048         addPrimitive(Float.class, Float.TYPE, new FloatBinding());
00049         addPrimitive(Double.class, Double.TYPE, new DoubleBinding());
00050     }
00051 
00052     private static void addPrimitive(Class cls1, Class cls2,
00053                                      TupleBinding binding) {
00054         primitives.put(cls1, binding);
00055         primitives.put(cls2, binding);
00056     }
00057 
00061     public TupleBinding() {
00062     }
00063 
00064     // javadoc is inherited
00065     public Object entryToObject(DatabaseEntry entry) {
00066 
00067         return entryToObject(entryToInput(entry));
00068     }
00069 
00070     // javadoc is inherited
00071     public void objectToEntry(Object object, DatabaseEntry entry) {
00072 
00073         TupleOutput output = getTupleOutput(object);
00074         objectToEntry(object, output);
00075         outputToEntry(output, entry);
00076     }
00077 
00085     public abstract Object entryToObject(TupleInput input);
00086 
00095     public abstract void objectToEntry(Object object, TupleOutput output);
00096 
00117     public static TupleBinding getPrimitiveBinding(Class cls) {
00118 
00119         return (TupleBinding) primitives.get(cls);
00120     }
00121 }

Generated on Sun Dec 25 12:14:30 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2