1 package org.picocontainer.defaults; 2 3 import java.util.Map ; 4 5 12 public class MapFactory { 13 private static final String JDK14 = "java.util.LinkedHashMap"; 14 private static final String COMMONS = "org.apache.commons.collections.map.LinkedMap"; 15 private static final String NON_ORDERED = "java.util.HashMap"; 16 17 private Class clazz; 18 19 public MapFactory() { 20 try { 21 clazz = Class.forName(JDK14); 22 } catch (ClassNotFoundException e) { 23 try { 24 clazz = Class.forName(COMMONS); 25 } catch (ClassNotFoundException e1) { 26 try { 27 clazz = Class.forName(NON_ORDERED); 28 } catch (ClassNotFoundException e2) { 29 throw new IllegalStateException ("What kind of JRE is this ? No " + NON_ORDERED + " class was found."); 30 } 31 } 32 } 33 } 34 35 public Map newInstance() { 36 try { 37 return (Map ) clazz.newInstance(); 38 } catch (InstantiationException e) { 39 throw new RuntimeException ("Could not instantiate " + clazz + " : " + e.getMessage()); 40 } catch (IllegalAccessException e) { 41 throw new RuntimeException ("Could not instantiate " + clazz + " : " + e.getMessage()); 42 } 43 } 44 } 45 | Popular Tags |