1 19 package org.netbeans.modules.j2ee.ejbjarproject.classpath; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 import java.util.Collections ; 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeSupport ; 29 import java.net.URL ; 30 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 31 import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; 32 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 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.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.openide.ErrorManager; 38 39 40 43 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { 44 45 private PropertyChangeSupport support = new PropertyChangeSupport (this); 46 private List resources; 47 private SourceRoots sourceRoots; 48 private AntProjectHelper projectHelper; 49 50 54 public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper) { 55 assert sourceRoots != null; 56 this.sourceRoots = sourceRoots; 57 this.projectHelper=projectHelper; 58 this.sourceRoots.addPropertyChangeListener (this); 59 } 60 61 public List getResources() { 62 synchronized (this) { 63 if (this.resources != null) { 64 return this.resources; 65 } 66 } 67 URL [] roots = this.sourceRoots.getRootURLs(); 68 String buildDir = projectHelper.getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.BUILD_DIR); 69 synchronized (this) { 70 if (this.resources == null) { 71 List result = new ArrayList (roots.length); 72 for (int i = 0; i < roots.length; i++) { 73 PathResourceImplementation res = ClassPathSupport.createResource(roots[i]); 74 result.add (res); 75 } 76 if (projectHelper!=null) { 78 try { 79 if (buildDir!=null) { 80 File f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); URL url = f.toURI().toURL(); 83 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 87 result.add(ClassPathSupport.createResource(url)); 88 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/service"); url = f.toURI().toURL(); 91 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 95 result.add(ClassPathSupport.createResource(url)); 96 } 97 } catch (MalformedURLException ex) { 98 ErrorManager.getDefault ().notify (ex); 99 } 100 } 101 this.resources = Collections.unmodifiableList(result); 102 } 103 } 104 return this.resources; 105 } 106 107 public void addPropertyChangeListener(PropertyChangeListener listener) { 108 support.addPropertyChangeListener (listener); 109 } 110 111 public void removePropertyChangeListener(PropertyChangeListener listener) { 112 support.removePropertyChangeListener (listener); 113 } 114 115 116 public void propertyChange(PropertyChangeEvent evt) { 117 if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) { 118 synchronized (this) { 119 this.resources = null; 120 } 121 this.support.firePropertyChange (PROP_RESOURCES,null,null); 122 } 123 } 124 125 } 126 | Popular Tags |