1 19 20 package org.netbeans.modules.j2ee.metadata; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyChangeSupport ; 25 import java.io.File ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.HashSet ; 30 import java.util.List ; 31 import java.util.Set ; 32 import org.netbeans.api.java.classpath.ClassPath; 33 import org.netbeans.spi.java.classpath.ClassPathImplementation; 34 import org.netbeans.spi.java.classpath.PathResourceImplementation; 35 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.util.WeakListeners; 39 40 45 public class StrippedClassPathImpl implements ClassPathImplementation, PropertyChangeListener { 46 47 private final ClassPath orig; 48 private final Set <URL > appSrvRoots; 49 private final PropertyChangeSupport support; 50 private List <PathResourceImplementation> resources; 51 52 public StrippedClassPathImpl(final ClassPath orig, final File [] appSrvRoots) { 53 assert orig != null; 54 assert appSrvRoots != null; 55 this.orig = orig; 56 this.appSrvRoots = new HashSet <URL >(); 57 this.support = new PropertyChangeSupport (this); 58 for (File f : appSrvRoots) { 59 URL fileRoot = null; 60 try { 61 fileRoot = f.toURI().toURL(); 62 } catch (MalformedURLException ex) { 63 ErrorManager.getDefault().notify(ex); 64 } 65 if (FileUtil.isArchiveFile(fileRoot)) { 66 fileRoot = FileUtil.getArchiveRoot(fileRoot); 67 } 68 this.appSrvRoots.add(fileRoot); 69 } 70 this.orig.addPropertyChangeListener(WeakListeners.propertyChange(this, this.orig)); 71 } 72 73 public synchronized List <PathResourceImplementation> getResources() { 74 if (resources == null) { 75 this.resources = new ArrayList <PathResourceImplementation> (); 76 List <ClassPath.Entry> entries = orig.entries(); 77 for (ClassPath.Entry entry : entries) { 78 URL url = entry.getURL(); 79 if (!this.appSrvRoots.contains(url)) { 80 this.resources.add(ClassPathSupport.createResource(url)); 81 } 82 } 83 } 84 return this.resources; 85 } 86 87 public void addPropertyChangeListener(PropertyChangeListener listener) { 88 assert listener != null; 89 this.support.addPropertyChangeListener(listener); 90 } 91 92 public void removePropertyChangeListener(PropertyChangeListener listener) { 93 assert listener != null; 94 this.support.removePropertyChangeListener(listener); 95 } 96 97 public void propertyChange(PropertyChangeEvent event) { 98 synchronized (this) { 99 this.resources = null; 100 } 101 this.support.firePropertyChange(PROP_RESOURCES, null, null); 102 } 103 104 } 105 106 | Popular Tags |