1 2 3 4 package net.nutch.io; 5 6 import java.util.HashMap ; 7 import java.io.IOException ; 8 9 13 public class WritableName { 14 private static HashMap NAME_TO_CLASS = new HashMap (); 15 private static HashMap CLASS_TO_NAME = new HashMap (); 16 17 static { WritableName.setName(NullWritable.class, "null"); 19 WritableName.setName(LongWritable.class, "long"); 20 WritableName.setName(UTF8.class, "UTF8"); 21 WritableName.setName(MD5Hash.class, "MD5Hash"); 22 WritableName.setName(net.nutch.db.Page.class, "Page"); 23 WritableName.setName(net.nutch.db.Link.class, "Link"); 24 WritableName.setName 25 (net.nutch.pagedb.FetchListEntry.class, "FetchListEntry"); 26 WritableName.setName 27 (net.nutch.fetcher.FetcherOutput.class, "FetcherOutput"); 28 WritableName.setName(net.nutch.protocol.Content.class, "Content"); 29 WritableName.setName(net.nutch.parse.ParseText.class, "ParseText"); 30 WritableName.setName(net.nutch.parse.ParseData.class, "ParseData"); 31 } 32 33 private WritableName() {} 35 37 public static synchronized void setName(Class writableClass, String name) { 38 CLASS_TO_NAME.put(writableClass, name); 39 NAME_TO_CLASS.put(name, writableClass); 40 } 41 42 43 public static synchronized void addName(Class writableClass, String name) { 44 NAME_TO_CLASS.put(name, writableClass); 45 } 46 47 48 public static synchronized String getName(Class writableClass) { 49 String name = (String )CLASS_TO_NAME.get(writableClass); 50 if (name != null) 51 return name; 52 return writableClass.getName(); 53 } 54 55 56 public static synchronized Class getClass(String name) throws IOException { 57 Class writableClass = (Class )NAME_TO_CLASS.get(name); 58 if (writableClass != null) 59 return writableClass; 60 try { 61 return Class.forName(name); 62 } catch (ClassNotFoundException e) { 63 throw new IOException (e.toString()); 64 } 65 } 66 67 } 68 | Popular Tags |