1 9 10 11 package JSX.magic; 12 import java.util.*; 13 14 28 public class MagicClassFactory { 29 public static MagicClassI newInstance() { 30 Properties p = System.getProperties(); 31 32 39 String specVersion = p.getProperty("java.specification.version"); 40 String implVersion = p.getProperty("java.version"); 41 String implVendor = p.getProperty("java.vendor"); 42 43 String magicName = null; if (implVendor.equals("Sun Microsystems Inc.") && ( specVersion.equals("1.2") || specVersion.equals("1.3") ) ) 45 magicName = "JSX.magic.MagicClass13"; 47 if (implVendor.equals("Sun Microsystems Inc.") && specVersion.equals("1.4")) 48 magicName = "JSX.magic.MagicClass14"; 50 if (implVendor.equals("IBM Corporation") && specVersion.equals("1.3") && implVersion.equals("1.3.0 subset")) 51 magicName = "JSX.magic.MagicClass13_j9"; 53 if (implVendor.equals("Blackdown Java-Linux Team") && specVersion.equals("1.3") && implVersion.equals("1.3.1")) 54 magicName = "JSX.magic.MagicClass13"; 55 56 if (implVendor.equals("Blackdown Java-Linux Team") && specVersion.equals("1.4") && implVersion.equals("1.4.1")) 57 magicName = "JSX.magic.MagicClass14"; 59 if (implVendor.equals("Apple Computer, Inc.") && specVersion.equals("1.3") && implVersion.equals("1.3.1")) 60 magicName = "JSX.magic.MagicClass13"; 61 62 if (magicName==null) { 63 System.err.println("---ATTENTION!--- JSX could not recognize your implementation of java, which is:"); 64 System.err.println("\timplVendor='"+implVendor+"'"); 65 System.err.println("\tspecVersion='"+specVersion+"'"); 66 System.err.println("\timplVersion='"+implVersion+"'"); 67 68 String tryingVersion; if (specVersion.equals("1.2") || specVersion.equals("1.3")) { 70 tryingVersion = "1.3"; 71 magicName = "JSX.magic.MagicClass13"; } else if (specVersion.equals("1.4")) { 73 tryingVersion = "1.4"; 74 magicName = "JSX.magic.MagicClass14"; 75 } else { 76 tryingVersion = "1.4"; magicName = "JSX.magic.MagicClass14"; 78 } 79 System.err.println("In the meantime, JSX will try the standard implementation for Java "+tryingVersion+" - which will probably work"); 80 System.err.println("Please post the above information to: jsx-ideas@yahoogroups.com"); 81 System.err.println(" - in particular, please state whether the standard implementation worked or not, for both writing and reading."); 82 } 83 91 92 99 try { 103 return (MagicClassI) Class.forName(magicName).newInstance(); 104 } catch (InstantiationException cantMake) { 105 throw new InternalError ("Can't instantiate "+magicName); 106 } catch (ClassNotFoundException noClass) { 107 throw new InternalError ("Can't find "+magicName); 108 } catch (IllegalAccessException noAccess) { 109 throw new InternalError ("Not permitted to access "+magicName); 110 } 111 } 112 } 113 114 115 116 117 173
| Popular Tags
|