1 19 20 package org.netbeans.modules.j2ee.oc4j.util; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.InetSocketAddress ; 25 import java.net.MalformedURLException ; 26 import java.net.Socket ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.List ; 30 import org.netbeans.api.java.platform.JavaPlatform; 31 import org.netbeans.api.java.platform.JavaPlatformManager; 32 import org.netbeans.api.java.platform.Specification; 33 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 34 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager; 35 import org.netbeans.modules.j2ee.oc4j.customizer.OC4JCustomizerSupport; 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.modules.InstalledFileLocator; 39 40 43 public class OC4JPluginProperties { 44 45 public static final String PROPERTY_DISPLAY_NAME = InstanceProperties.DISPLAY_NAME_ATTR; 46 public static final String PROPERTY_ADMIN_PORT = "adminPort"; public static final String PROPERTY_WEB_SITE = "webSite"; public static final String PROPERTY_OC4J_HOME = "oc4jHome"; public static final String PROPERTY_HOST = "host"; public static final String PROP_JAVA_PLATFORM = "java_platform"; public static final String PROP_JAVADOCS = "javadocs"; public static final String PLAT_PROP_ANT_NAME = "platform.ant.name"; 54 private InstanceProperties ip; 55 private OC4JDeploymentManager dm; 56 57 private static final int DEBUGPORT = 8787; 58 59 public OC4JPluginProperties(OC4JDeploymentManager dm) { 60 this.dm = dm; 61 ip = InstanceProperties.getInstanceProperties(dm.getUri()); 62 } 63 64 public String getOC4JHomeLocation() { 65 return ip.getProperty(PROPERTY_OC4J_HOME); 66 } 67 68 public JavaPlatform getJavaPlatform() { 69 String currentJvm = ip.getProperty(PROP_JAVA_PLATFORM); 70 JavaPlatformManager jpm = JavaPlatformManager.getDefault(); 71 JavaPlatform[] installedPlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); for (int i = 0; i < installedPlatforms.length; i++) { 73 String platformName = (String )installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME); 74 if (platformName != null && platformName.equals(currentJvm)) { 75 return installedPlatforms[i]; 76 } 77 } 78 return jpm.getDefaultPlatform(); 80 } 81 82 public InstanceProperties getInstanceProperties() { 83 return ip; 84 } 85 86 public List <URL > getClasses() { 87 List <URL > list = new ArrayList <URL >(); 88 File serverDir = new File (getOC4JHomeLocation()); 89 try{ 90 for(File file:new File (serverDir, "j2ee/home/applib").listFiles()) { 91 if(FileUtil.isArchiveFile(file.toURI().toURL())) 92 list.add(OC4JPluginUtils.fileToUrl(file)); 93 } 94 for(File file:new File (serverDir, "j2ee/home/lib").listFiles()) { 95 if(FileUtil.isArchiveFile(file.toURI().toURL())) 96 list.add(OC4JPluginUtils.fileToUrl(file)); 97 } 98 for(File file:new File (serverDir, "lib").listFiles()) { 99 if(FileUtil.isArchiveFile(file.toURI().toURL())) 100 list.add(OC4JPluginUtils.fileToUrl(file)); 101 } 102 for(File file:new File (serverDir, "webservices/lib").listFiles()) { 103 if(FileUtil.isArchiveFile(file.toURI().toURL())) 104 list.add(OC4JPluginUtils.fileToUrl(file)); 105 } 106 for(File file:new File (serverDir, "toplink/jlib").listFiles()) { 107 if(FileUtil.isArchiveFile(file.toURI().toURL())) 108 list.add(OC4JPluginUtils.fileToUrl(file)); 109 } 110 } catch(MalformedURLException ex) { 111 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 112 } 113 return list; 114 } 115 116 public List <URL > getJavadocs() { 117 String path = ip.getProperty(PROP_JAVADOCS); 118 if (path == null) { 119 ArrayList <URL > list = new ArrayList <URL >(); 120 try { 121 File j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee5-doc-api.zip", null, false); if (j2eeDoc != null) { 123 list.add(OC4JPluginUtils.fileToUrl(j2eeDoc)); 124 } 125 } catch (MalformedURLException e) { 126 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 127 } 128 return list; 129 } 130 return OC4JCustomizerSupport.tokenizePath(path); 131 } 132 133 public void setJavadocs(List <URL > path) { 134 ip.setProperty(PROP_JAVADOCS, OC4JCustomizerSupport.buildPath(path)); 135 dm.getOC4JPlatform().notifyLibrariesChanged(); 136 } 137 138 public int getDebugPort() { 139 return DEBUGPORT; 140 } 141 142 public static boolean isRunning(String host, int port) { 143 if(null == host) 144 return false; 145 146 try { 147 InetSocketAddress isa = new InetSocketAddress (host, port); 148 Socket socket = new Socket (); 149 socket.connect(isa, 1); 150 socket.close(); 151 return true; 152 } catch (IOException e) { 153 return false; 154 } 155 } 156 157 public static boolean isRunning(String host, String port) { 158 try { 159 return isRunning(host, Integer.parseInt(port)); 160 } catch(NumberFormatException e) { 161 if(OC4JDebug.isEnabled()) { 162 OC4JDebug.log("org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties", "HOST: " + host); 163 OC4JDebug.log("org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties", "PORT: " + port); 164 } 165 return false; 166 } 167 } 168 } | Popular Tags |