1 19 package org.netbeans.modules.j2ee.clientproject.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.spi.java.classpath.ClassPathImplementation; 31 import org.netbeans.spi.java.classpath.PathResourceImplementation; 32 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 33 import org.netbeans.modules.j2ee.clientproject.SourceRoots; 34 import org.netbeans.spi.project.support.ant.AntProjectHelper; 35 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 36 import org.openide.ErrorManager; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileStateInvalidException; 39 import org.openide.util.Utilities; 40 41 42 45 final class SourcePathImplementation implements ClassPathImplementation, PropertyChangeListener { 46 47 private static final String PROP_BUILD_DIR = "build.dir"; 49 private final PropertyChangeSupport support = new PropertyChangeSupport (this); 50 private List resources; 51 private final SourceRoots sourceRoots; 52 private final AntProjectHelper projectHelper; 53 private final PropertyEvaluator evaluator; 54 55 59 public SourcePathImplementation(SourceRoots sourceRoots) { 60 assert sourceRoots != null; 61 this.sourceRoots = sourceRoots; 62 this.projectHelper = null; 63 this.evaluator = null; 64 sourceRoots.addPropertyChangeListener (this); 65 } 66 67 72 public SourcePathImplementation(SourceRoots sourceRoots, AntProjectHelper projectHelper, PropertyEvaluator evaluator) { 73 assert sourceRoots != null && projectHelper != null && evaluator != null; 74 this.sourceRoots = sourceRoots; 75 sourceRoots.addPropertyChangeListener (this); 76 this.projectHelper = projectHelper; 77 this.evaluator = evaluator; 78 evaluator.addPropertyChangeListener (this); 79 } 80 81 public List getResources() { 82 synchronized (this) { 83 if (this.resources != null) { 84 return this.resources; 85 } 86 } 87 URL [] roots = sourceRoots.getRootURLs(); 88 String buildDir = null; 89 if (projectHelper != null) 90 buildDir = projectHelper.getStandardPropertyEvaluator().getProperty(PROP_BUILD_DIR); 91 synchronized (this) { 92 if (this.resources == null) { 93 List <PathResourceImplementation> result = new ArrayList <PathResourceImplementation>(roots.length); 94 for (int i = 0; i < roots.length; i++) { 95 PathResourceImplementation res = ClassPathSupport.createResource(roots[i]); 96 result.add (res); 97 } 98 if (projectHelper!=null) { 100 try { 101 if (buildDir != null) { 102 File f = new File (this.projectHelper.resolveFile (buildDir),"generated/wsclient"); URL url = f.toURI().toURL(); 105 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 109 result.add(ClassPathSupport.createResource(url)); 110 f = new File (projectHelper.resolveFile(buildDir),"generated/wsimport/client"); url = f.toURI().toURL(); 113 if (!f.exists()) { assert !url.toExternalForm().endsWith("/"); url = new URL (url.toExternalForm()+'/'); } 117 result.add(ClassPathSupport.createResource(url)); 118 } 119 } catch (MalformedURLException ex) { 120 ErrorManager.getDefault ().notify (ex); 121 } 122 } 123 this.resources = Collections.unmodifiableList(result); 124 } 125 return this.resources; 126 } 127 } 128 129 public void addPropertyChangeListener(PropertyChangeListener listener) { 130 support.addPropertyChangeListener (listener); 131 } 132 133 public void removePropertyChangeListener(PropertyChangeListener listener) { 134 support.removePropertyChangeListener (listener); 135 } 136 137 138 public void propertyChange(PropertyChangeEvent evt) { 139 if (SourceRoots.PROP_ROOTS.equals (evt.getPropertyName())) { 140 synchronized (this) { 141 this.resources = null; 142 } 143 this.support.firePropertyChange (PROP_RESOURCES,null,null); 144 } 145 else if (this.evaluator != null && evt.getSource() == this.evaluator && 146 (evt.getPropertyName() == null || PROP_BUILD_DIR.equals(evt.getPropertyName()))) { 147 synchronized (this) { 148 this.resources = null; 149 } 150 this.support.firePropertyChange (PROP_RESOURCES,null,null); 151 } 152 } 153 154 } 155 | Popular Tags |