1 19 package org.netbeans.spi.java.classpath.support; 20 21 import org.netbeans.spi.java.classpath.PathResourceImplementation; 22 import org.netbeans.spi.java.classpath.ClassPathImplementation; 23 24 import java.net.URL ; 25 import java.beans.PropertyChangeListener ; 26 import java.beans.PropertyChangeEvent ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Arrays ; 31 32 36 public abstract class CompositePathResourceBase implements PathResourceImplementation { 37 38 private URL [] roots; 39 private ClassPathImplementation model; 40 private ArrayList <PropertyChangeListener > pListeners; 41 42 46 public final URL [] getRoots() { 47 if (this.roots == null) { 48 synchronized (this) { 49 if (this.roots == null) { 50 initContent (); 51 List <URL > result = new ArrayList <URL > (); 52 for (PathResourceImplementation pri : this.model.getResources()) { 53 result.addAll (Arrays.asList(pri.getRoots())); 54 } 55 this.roots = result.toArray (new URL [result.size()]); 56 } 57 } 58 } 59 return this.roots; 60 } 61 62 63 67 public final ClassPathImplementation getContent() { 68 initContent (); 69 return this.model; 70 } 71 72 77 public synchronized final void addPropertyChangeListener(PropertyChangeListener listener) { 78 if (this.pListeners == null) 79 this.pListeners = new ArrayList <PropertyChangeListener > (); 80 this.pListeners.add (listener); 81 } 82 83 87 public synchronized final void removePropertyChangeListener(PropertyChangeListener listener) { 88 if (this.pListeners == null) 89 return; 90 this.pListeners.remove (listener); 91 } 92 93 99 protected final void firePropertyChange (String propName, Object oldValue, Object newValue) { 100 PropertyChangeListener [] _listeners; 101 synchronized (this) { 102 if (this.pListeners == null) 103 return; 104 _listeners = this.pListeners.toArray(new PropertyChangeListener [this.pListeners.size()]); 105 } 106 PropertyChangeEvent event = new PropertyChangeEvent (this, propName, oldValue, newValue); 107 for (PropertyChangeListener l : _listeners) { 108 l.propertyChange (event); 109 } 110 } 111 112 119 protected abstract ClassPathImplementation createContent (); 120 121 122 private synchronized void initContent () { 123 if (this.model == null) { 124 ClassPathImplementation cp = createContent (); 125 assert cp != null; 126 cp.addPropertyChangeListener (new PropertyChangeListener () { 127 public void propertyChange (PropertyChangeEvent event) { 128 roots = null; 129 firePropertyChange (PROP_ROOTS, null,null); 130 } 131 }); 132 this.model = cp; 133 } 134 } 135 } 136 | Popular Tags |