1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem. 2 versioninfo; 3 4 import java.io.RandomAccessFile ; 5 import java.io.IOException ; 6 import com.daffodilwoods.database.resource.DException; 7 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem. 8 DatabaseConstants; 9 import com.daffodilwoods.daffodildb.server.serversystem._Server; 10 11 public class VersionHandlerFactory { 12 13 14 public static VersionHandler getVersionHandler(RandomAccessFile file) throws 15 DException { 16 try { 17 file.seek(DatabaseConstants.VERSIONCODE); 18 byte[] bytes = new byte[DatabaseConstants.DATABASEVERSION.length()]; 19 file.read(bytes); 20 String str = new String (bytes); 21 if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_3_4 )) 22 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_4").newInstance(); 23 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_3_3)) 24 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_3").newInstance(); 25 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_3_2)){ 26 if(_Server.ISONEDOLLARDB ) 27 throw new DException("DSE2054", new Object []{"backward comptibility of old version databases "}); 28 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_2"). 29 newInstance(); 30 } 31 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_3_1)) 32 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_1").newInstance(); 33 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_3_0)) 34 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_0").newInstance(); 35 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_2_5)) 36 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler2_5").newInstance(); 37 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_2_4)) 38 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler2_5").newInstance(); 39 else if (str.equalsIgnoreCase(DatabaseConstants.DATABASEVERSION_VinesDB)) 40 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandlerVinesDB").newInstance(); 41 else 42 throw new DException("DSE2046", null); 43 } catch (IOException ex) { 44 throw new DException("DSE0", new Object [] {ex.getMessage()}); 45 } catch (ClassNotFoundException ex1) { 46 if(_Server.ISONEDOLLARDB ) 47 throw new DException("DSE2054", new Object []{"backward comptibility of old version databases "}); 48 throw new DException("DSE5591", null); 49 } catch (IllegalAccessException ex2) { 50 throw new DException("DSE5591", null); 51 } catch (InstantiationException ex3) { 52 if(_Server.ISONEDOLLARDB ) 53 throw new DException("DSE2054", new Object []{"backward comptibility of old version databases "}); 54 throw new DException("DSE5591", null); 55 } 56 } 57 58 59 public static VersionHandler getLatestVersionHandler() throws DException{ 60 try { 61 return (VersionHandler) Class.forName("com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler3_4"). 62 newInstance(); 63 } 64 catch (ClassNotFoundException ex) { 65 throw new DException("DSE5591", null); 66 } 67 catch (IllegalAccessException ex) { 68 throw new DException("DSE5591", null); 69 } 70 catch (InstantiationException ex) { 71 throw new DException("DSE5591", null); 72 } 73 } 74 } 75 | Popular Tags |