1 10 11 import javax.activation.*; 12 import java.util.StringTokenizer ; 13 import java.util.Hashtable ; 14 15 public class SimpleDCF implements DataContentHandlerFactory { 16 Hashtable entry_hash = new Hashtable (); 17 28 public SimpleDCF(String entries) { 29 StringTokenizer tok = new StringTokenizer (entries); 30 31 String entry; 32 System.out.println("SimpleDCH: new SimpleDCF being created"); 33 34 while(tok.hasMoreTokens()) { 36 int colon; 37 38 entry = tok.nextToken(); 39 System.out.println("full entry = " + entry); 40 41 colon = entry.indexOf(':'); 43 VectorEntry ve = new VectorEntry(entry.substring(0,colon), 44 entry.substring(colon + 1, 45 entry.length())); 46 System.out.println("adding element = " + ve); 47 entry_hash.put(ve.getMimeType(),ve); 48 } 49 } 50 51 54 public DataContentHandler createDataContentHandler(String mimeType){ 55 DataContentHandler dch = null; 56 57 System.out.print("SimpleDCF: trying to create a DCH"); 58 59 VectorEntry ve = (VectorEntry)entry_hash.get(mimeType); 60 if(ve != null) { 61 System.out.print("...found token"); 62 try { 63 64 dch = (DataContentHandler)Class.forName( 65 ve.getClassName()).newInstance(); 66 if(dch == null) 67 System.out.println("...FAILED!!!"); 68 else 69 System.out.println("...SUCCESS!!!"); 70 71 } catch(Exception e) { 72 System.out.println(e); 73 } 74 } 75 return dch; 76 } 77 } 78 79 class VectorEntry { 80 private String mimeType; 81 private String className; 82 83 public VectorEntry(String mimeType, String className) { 84 this.mimeType = mimeType; 85 this.className = className; 86 } 87 88 public String getMimeType() { return mimeType; } 89 public String getClassName() { return className; } 90 public String toString() { 91 return new String ("type: " + mimeType + " class name: " + className); 92 } 93 94 } 95 | Popular Tags |