1 19 20 package org.netbeans.modules.j2ee.deployment.devmodules.api; 21 22 import java.awt.Image ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.io.File ; 26 import java.net.URL ; 27 import java.util.ArrayList ; 28 import java.util.Hashtable ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Set ; 32 import org.netbeans.api.java.platform.JavaPlatform; 33 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 34 import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl; 35 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider; 36 import org.netbeans.spi.project.libraries.LibraryImplementation; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 import org.openide.filesystems.URLMapper; 40 import org.openide.util.Utilities; 41 42 43 50 public final class J2eePlatform { 51 52 53 public static final String PROP_DISPLAY_NAME = "displayName"; 55 public static final String PROP_LIBRARIES = "libraries"; 57 public static final String PROP_CLASSPATH = "classpath"; 59 public static final String PROP_PLATFORM_ROOTS = "platformRoots"; 61 62 68 public static final String TOOL_APP_CLIENT_RUNTIME = "appClientRuntime"; 70 74 public static final String TOOL_JSR109 = "jsr109"; 76 80 public static final String TOOL_WSCOMPILE = "wscompile"; 82 86 public static final String TOOL_WSIMPORT = "wsimport"; 88 92 public static final String TOOL_WSGEN = "wsgen"; 94 98 public static final String TOOL_WSIT = "wsit"; 100 104 public static final String TOOL_JWSDP = "jwsdp"; 106 110 public static final String TOOL_KEYSTORE = "keystore"; 112 116 public static final String TOOL_KEYSTORE_CLIENT = "keystoreClient"; 118 122 public static final String TOOL_TRUSTSTORE = "truststore"; 124 128 public static final String TOOL_TRUSTSTORE_CLIENT = "truststoreClient"; 130 134 public static final String TOOL_PROP_MAIN_CLASS = "main.class"; 136 140 public static final String TOOL_PROP_MAIN_CLASS_ARGS = "main.class.args"; 142 146 public static final String TOOL_PROP_JVM_OPTS = "jvm.opts"; 148 153 public static final String CLIENT_PROP_DIST_ARCHIVE = "client.dist.archive"; 155 private static final String DEFAULT_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/Servers.png"; 157 private J2eePlatformImpl impl; 158 private File [] classpathCache; 159 private String currentClasspath; 160 private ServerInstance serverInstance; 161 162 private PropertyChangeListener librariesChangeListener = new PropertyChangeListener () { 164 public void propertyChange(PropertyChangeEvent evt) { 165 if (evt.getPropertyName().equals(LibraryImplementation.PROP_CONTENT)) { 166 classpathCache = null; 167 String newClassPath = getClasspathAsString(); 168 if (currentClasspath == null || !currentClasspath.equals(newClassPath)) { 169 currentClasspath = newClassPath; 170 impl.firePropertyChange(PROP_CLASSPATH, null, null); 171 } 172 } 173 } 174 }; 175 176 181 private J2eePlatform(ServerInstance aServerInstance, J2eePlatformImpl aImpl) { 182 impl = aImpl; 183 serverInstance = aServerInstance; 184 addPropertyChangeListener(new PropertyChangeListener () { 186 public void propertyChange(PropertyChangeEvent evt) { 187 if (evt.getPropertyName().equals(PROP_LIBRARIES)) { 188 LibraryImplementation[] libs = getLibraries(); 189 for (int i = 0; i < libs.length; i++) { 190 libs[i].removePropertyChangeListener(librariesChangeListener); 191 libs[i].addPropertyChangeListener(librariesChangeListener); 192 } 193 194 classpathCache = null; 195 String newClassPath = getClasspathAsString(); 196 if (currentClasspath == null || !currentClasspath.equals(newClassPath)) { 197 currentClasspath = newClassPath; 198 impl.firePropertyChange(PROP_CLASSPATH, null, null); 199 } 200 } 201 } 202 }); 203 LibraryImplementation[] libs = getLibraries(); 204 for (int i = 0; i < libs.length; i++) { 205 libs[i].addPropertyChangeListener(librariesChangeListener); 206 } 207 currentClasspath = getClasspathAsString(); 208 } 209 210 static J2eePlatform create(ServerInstance serInst) { 211 J2eePlatform result = serInst.getJ2eePlatform(); 212 if (result == null) { 213 J2eePlatformImpl platformImpl = serInst.getJ2eePlatformImpl(); 214 if (platformImpl != null) { 215 result = new J2eePlatform(serInst, platformImpl); 216 serInst.setJ2eePlatform(result); 217 } 218 } 219 return result; 220 } 221 222 227 public File [] getClasspathEntries() { 228 if (classpathCache == null) { 229 LibraryImplementation[] libraries = impl.getLibraries(); 230 List classpath = new ArrayList (); 231 for (int i = 0; i < libraries.length; i++) { 232 List classpathList = libraries[i].getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH); 233 for (Iterator iter = classpathList.iterator(); iter.hasNext();) { 234 URL url = (URL )iter.next(); 235 if ("jar".equals(url.getProtocol())) { url = FileUtil.getArchiveFile(url); 237 } 238 FileObject fo = URLMapper.findFileObject(url); 239 if (fo != null) { 240 File f = FileUtil.toFile(fo); 241 if (f != null) { 242 classpath.add(f); 243 } 244 } 245 } 246 } 247 classpathCache = (File [])classpath.toArray(new File [classpath.size()]); 248 } 249 return classpathCache; 250 } 251 252 259 public File [] getToolClasspathEntries(String toolName) { 260 return impl.getToolClasspathEntries(toolName); 261 } 262 263 281 public String getToolProperty(String toolName, String propertyName) { 282 return impl.getToolProperty(toolName, propertyName); 283 } 284 285 293 public boolean isToolSupported(String toolName) { 294 return impl.isToolSupported(toolName); 295 } 296 297 private LibraryImplementation[] getLibraries() { 299 return impl.getLibraries(); 300 } 301 302 307 public String getDisplayName() { 308 return serverInstance.getDisplayName(); 311 } 312 313 319 public Image getIcon() { 320 Image result = impl.getIcon(); 321 if (result == null) 322 result = Utilities.loadImage(DEFAULT_ICON); 323 324 return result; 325 } 326 327 333 public File [] getPlatformRoots() { 334 return impl.getPlatformRoots(); 335 } 336 337 344 public Set getSupportedSpecVersions() { 345 return impl.getSupportedSpecVersions(); 346 } 347 348 356 public Set <String > getSupportedSpecVersions(Object moduleType) { 357 return impl.getSupportedSpecVersions(moduleType); 358 } 359 360 367 public Set getSupportedModuleTypes() { 368 return impl.getSupportedModuleTypes(); 369 } 370 371 379 public Set getSupportedJavaPlatformVersions() { 380 return impl.getSupportedJavaPlatformVersions(); 381 } 382 383 390 public boolean supportsProfiling() { 391 return true; 392 } 393 394 403 public JavaPlatform getJavaPlatform() { 404 return impl.getJavaPlatform(); 405 } 406 407 413 public void addPropertyChangeListener(PropertyChangeListener l) { 414 impl.addPropertyChangeListener(l); 415 } 416 417 422 public void removePropertyChangeListener(PropertyChangeListener l) { 423 impl.removePropertyChangeListener(l); 424 } 425 426 public String toString() { 427 return impl.getDisplayName() + " [" + getClasspathAsString() + "]"; } 429 430 private String getClasspathAsString() { 431 File [] classpathEntr = getClasspathEntries(); 432 StringBuffer classpath = new StringBuffer (); 433 final String PATH_SEPARATOR = System.getProperty("path.separator"); for (int i = 0; i < classpathEntr.length; i++) { 435 classpath.append(classpathEntr[i].getAbsolutePath()); 436 if (i + 1 < classpathEntr.length) { 437 classpath.append(PATH_SEPARATOR); 438 } 439 } 440 return classpath.toString(); 441 } 442 } 443 | Popular Tags |