1 19 package org.netbeans.modules.j2ee.clientproject.classpath; 20 21 import java.beans.PropertyChangeEvent ; 22 import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; 23 import org.netbeans.spi.java.classpath.ClassPathImplementation; 24 import org.netbeans.spi.java.classpath.PathResourceImplementation; 25 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 26 import org.netbeans.api.java.platform.JavaPlatform; 27 import org.netbeans.api.java.platform.JavaPlatformManager; 28 import org.netbeans.api.java.classpath.ClassPath; 29 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyChangeSupport ; 32 import java.util.List ; 33 import java.util.ArrayList ; 34 import java.util.Collections ; 35 import java.util.Iterator ; 36 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 37 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 38 import org.openide.util.WeakListeners; 39 40 final class BootClassPathImplementation implements ClassPathImplementation, PropertyChangeListener { 41 42 private static final String PLATFORM_ACTIVE = AppClientProjectProperties.JAVA_PLATFORM; private static final String ANT_NAME = "platform.ant.name"; private static final String J2SE = "j2se"; 46 private final PropertyEvaluator evaluator; 47 private JavaPlatformManager platformManager; 48 private String activePlatformName; 50 private boolean isActivePlatformValid; 52 private List <PathResourceImplementation> resourcesCache; 53 private PropertyChangeSupport support = new PropertyChangeSupport (this); 54 55 public BootClassPathImplementation(PropertyEvaluator evaluator) { 56 assert evaluator != null; 57 this.evaluator = evaluator; 58 evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator)); 59 } 60 61 public synchronized List getResources() { 62 if (this.resourcesCache == null) { 63 JavaPlatform jp = findActivePlatform (); 64 if (jp != null) { 65 ClassPath cp = jp.getBootstrapLibraries(); 67 List entries = cp.entries(); 68 List <PathResourceImplementation> result = new ArrayList <PathResourceImplementation>(entries.size()); 69 for (Iterator it = entries.iterator(); it.hasNext();) { 70 ClassPath.Entry entry = (ClassPath.Entry) it.next(); 71 result.add (ClassPathSupport.createResource(entry.getURL())); 72 } 73 resourcesCache = Collections.unmodifiableList (result); 74 } 75 else { 76 resourcesCache = Collections.emptyList(); 77 } 78 } 79 return this.resourcesCache; 80 } 81 82 public void addPropertyChangeListener(PropertyChangeListener listener) { 83 this.support.addPropertyChangeListener (listener); 84 } 85 86 public void removePropertyChangeListener(PropertyChangeListener listener) { 87 this.support.removePropertyChangeListener (listener); 88 } 89 90 private JavaPlatform findActivePlatform () { 91 if (this.platformManager == null) { 92 this.platformManager = JavaPlatformManager.getDefault(); 93 this.platformManager.addPropertyChangeListener(WeakListeners.propertyChange(this, this.platformManager)); 94 } 95 this.activePlatformName = evaluator.getProperty(PLATFORM_ACTIVE); 96 final JavaPlatform activePlatform = AppClientProjectUtil.getActivePlatform (this.activePlatformName); 97 this.isActivePlatformValid = activePlatform != null; 98 return activePlatform; 99 } 100 101 public void propertyChange(PropertyChangeEvent evt) { 102 if (evt.getSource() == this.evaluator && evt.getPropertyName().equals(PLATFORM_ACTIVE)) { 103 resetCache (); 105 } 106 else if (evt.getSource() == this.platformManager && JavaPlatformManager.PROP_INSTALLED_PLATFORMS.equals(evt.getPropertyName()) && activePlatformName != null) { 107 if (this.isActivePlatformValid) { 109 if (AppClientProjectUtil.getActivePlatform (this.activePlatformName) == null) { 110 this.resetCache(); 112 } 113 } 114 else { 115 if (AppClientProjectUtil.getActivePlatform (this.activePlatformName) != null) { 116 this.resetCache(); 117 } 118 } 119 } 120 } 121 122 125 private void resetCache () { 126 synchronized (this) { 127 resourcesCache = null; 128 } 129 support.firePropertyChange(PROP_RESOURCES, null, null); 130 } 131 132 } 133 | Popular Tags |