1 19 20 package org.netbeans.modules.derby.bundled; 21 22 import java.io.File ; 23 import org.netbeans.modules.derby.spi.support.DerbySupport; 24 import org.openide.modules.InstalledFileLocator; 25 import org.openide.modules.ModuleInstall; 26 27 31 public class DerbyModule extends ModuleInstall { 32 33 private static final String INST_DIR = "db-derby-10.1.3.1-bin"; 35 public void restored() { 36 if (DerbySupport.getLocation().length() <= 0) { 37 DerbySupport.setLocation(getDefaultInstallLocation()); 39 } 40 } 41 42 public void uninstalled() { 43 String location = DerbySupport.getLocation(); 44 if (location == null) { 45 return; 46 } 47 String defaultLocation = getDefaultInstallLocation(); 48 if (defaultLocation == null) { 49 return; 51 } 52 if (unshlashify(location).equals(unshlashify(defaultLocation))) { 53 DerbySupport.setLocation(null); 54 } 55 } 56 57 private static String getDefaultInstallLocation() { 58 File location = InstalledFileLocator.getDefault().locate(INST_DIR, null, false); 59 return (location != null) ? location.getAbsolutePath() : null; } 61 62 private static String unshlashify(String path) { 63 assert path != null; 64 int slash = path.length() - 1; 65 while (slash >= 0) { 66 if (path.charAt(slash) == File.separatorChar) { 67 path = path.substring(0, slash); 68 slash--; 69 } else { 70 break; 71 } 72 } 73 return path; 74 } 75 } 76 | Popular Tags |