1 19 package org.netbeans.modules.j2ee.jboss4.ide.ui; 20 21 import java.io.File ; 22 import java.util.Properties ; 23 import org.openide.filesystems.FileLock; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileSystem; 26 import org.openide.filesystems.Repository; 27 import org.openide.ErrorManager; 28 29 33 public class JBPluginProperties { 34 35 public static final String PROPERTY_DISPLAY_NAME ="displayName"; public static final String PROPERTY_SERVER = "server"; public static final String PROPERTY_DEPLOY_DIR = "deploy-dir"; public static final String PROPERTY_SERVER_DIR = "server-dir"; public static final String PROPERTY_ROOT_DIR = "root-dir"; public static final String PROPERTY_HOST = "host"; public static final String PROPERTY_PORT = "port"; 43 44 private static JBPluginProperties pluginProperties = null; 45 private String installLocation; 46 private String domainLocation; 47 48 49 public static JBPluginProperties getInstance(){ 50 if(pluginProperties==null){ 51 pluginProperties = new JBPluginProperties(); 52 } 53 return pluginProperties; 54 } 55 56 57 58 59 private JBPluginProperties() { 60 java.io.InputStream inStream = null; 61 try { 62 try { 63 propertiesFile = getPropertiesFile(); 64 if (null != propertiesFile) 65 inStream = propertiesFile.getInputStream(); 66 } catch (java.io.FileNotFoundException e) { 67 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 68 } catch (java.io.IOException e) { 69 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 70 } finally { 71 loadPluginProperties(inStream); 72 if (null != inStream) 73 inStream.close(); 74 } 75 } catch (java.io.IOException e) { 76 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 77 } 78 79 } 80 81 void loadPluginProperties(java.io.InputStream inStream) { 82 Properties inProps = new Properties (); 83 if (null != inStream) 84 try { 85 inProps.load(inStream); 86 } catch (java.io.IOException e) { 87 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 88 } 89 String loc = inProps.getProperty(INSTALL_ROOT_KEY); 90 if (loc!=null){ setInstallLocation(loc); 92 } 93 } 94 95 private static final String INSTALL_ROOT_KEY = "installRoot"; public static final String INSTALL_ROOT_PROP_NAME = "com.sun.aas.installRoot"; 98 99 private FileObject propertiesFile = null; 100 101 private FileObject getPropertiesFile() throws java.io.IOException { 102 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 103 FileObject dir = fs.findResource("J2EE"); 104 FileObject retVal = null; 105 if (null != dir) { 106 retVal = dir.getFileObject("jb","properties"); if (null == retVal) { 108 retVal = dir.createData("jb","properties"); } 110 } 111 return retVal; 112 } 113 114 115 public void saveProperties(){ 116 Properties outProp = new Properties (); 117 String installRoot = getInstallLocation(); 118 if (installRoot != null) 119 outProp.setProperty(INSTALL_ROOT_KEY, installRoot); 120 121 FileLock l = null; 122 java.io.OutputStream outStream = null; 123 try { 124 if (null != propertiesFile) { 125 try { 126 l = propertiesFile.lock(); 127 outStream = propertiesFile.getOutputStream(l); 128 if (null != outStream) 129 outProp.store(outStream, ""); 130 } catch (java.io.IOException e) { 131 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 132 } finally { 133 if (null != outStream) 134 outStream.close(); 135 if (null != l) 136 l.releaseLock(); 137 } 138 } 139 } catch (java.io.IOException e) { 140 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 141 } 142 } 143 144 public boolean isCurrentServerLocationValid(){ 145 if (getInstallLocation()!=null) 146 return 147 JBPluginUtils.isGoodJBServerLocation4x(new File (getInstallLocation())) || 148 JBPluginUtils.isGoodJBServerLocation5x(new File (getInstallLocation())); 149 else 150 return false; 151 } 152 153 154 public void setInstallLocation(String installLocation){ 155 if ( installLocation.endsWith("/") || installLocation.endsWith("\\") ){ 156 installLocation = installLocation.substring(0, installLocation.length() - 1 ); 157 } 158 159 this.installLocation = installLocation; 160 } 161 162 public String getInstallLocation(){ 163 return this.installLocation; 164 } 165 166 public void setDomainLocation(String domainLocation) { 167 if ( domainLocation.endsWith("/") || domainLocation.endsWith("\\") ){ 168 domainLocation = domainLocation.substring(0, domainLocation.length() - 1 ); 169 } 170 171 this.domainLocation = domainLocation; 172 } 173 174 public String getDomainLocation() { 175 return domainLocation; 176 } 177 } | Popular Tags |