1 19 20 package org.netbeans.modules.websvc.jaxwsmodel.project.metadata; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.Timer ; 27 import java.util.TimerTask ; 28 import org.netbeans.api.java.classpath.ClassPath; 29 import org.netbeans.api.java.project.JavaProjectConstants; 30 import org.netbeans.api.project.FileOwnerQuery; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectUtils; 33 import org.netbeans.api.project.SourceGroup; 34 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils; 43 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 44 import org.netbeans.modules.websvc.api.jaxws.project.config.Service; 45 import org.netbeans.modules.websvc.api.jaxws.project.config.ServiceAlreadyExistsExeption; 46 import org.openide.filesystems.FileObject; 47 import org.openide.filesystems.FileUtil; 48 49 53 public class JAXWSNNListener { 56 private static final ArrayList <String > supportedAnnotations; 57 static { 58 supportedAnnotations = new ArrayList <String >(); 59 supportedAnnotations.add("javax.jws.WebService"); } 61 62 private static final String WS_NAME = "name"; private static final String WSDL_LOCATION_NN_ATTRIBUTE = "wsdlLocation"; 65 private JaxWsModel jaxWSmodel; 66 private ClassPath cp; 67 68 private Timer timer = new Timer (); 70 private TimerTask ttask = createTimerTask(); 71 72 73 public JAXWSNNListener(JaxWsModel jaxWSmodel, ClassPath cp) { 74 this.jaxWSmodel = jaxWSmodel; 75 this.cp = cp; 76 } 77 78 public ClassPath getClassPath() { 79 return cp; 80 } 81 82 public Collection <String > getSupportedAnnotations() { 83 return supportedAnnotations; 84 } 85 86 public Collection <String > getPrimaryAnnotations() { 87 return Collections.<String >emptyList(); 88 } 89 90 135 public void classRemoved(String fqn) { 136 Service serviceToRemove = jaxWSmodel.findServiceByImplementationClass(fqn); 140 if (serviceToRemove != null && serviceToRemove.getWsdlUrl() == null) { 141 jaxWSmodel.removeServiceByClassName(fqn); 142 requestModelUpdate(); 143 } 144 } 145 146 165 private boolean isInSourceGroup(FileObject fo) { 166 Project project = FileOwnerQuery.getOwner(jaxWSmodel.getJaxWsFile()); 167 SourceGroup[] sourceGroups = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 168 for(int i = 0; i < sourceGroups.length; i++) { 169 if(FileUtil.isParentOf(sourceGroups[i].getRootFolder(), fo)) return true; 170 } 171 return false; 172 } 173 174 private void requestModelUpdate() { 175 synchronized (ttask) { 176 ttask.cancel(); 177 ttask = createTimerTask(); 179 timer.schedule(ttask, 100); 180 } 181 } 182 183 private TimerTask createTimerTask() { 184 return new TimerTask () { 185 public void run() { 186 synchronized (ttask) { 187 try { 188 jaxWSmodel.write(); 190 }catch(IOException ioe) { 191 requestModelUpdate(); 193 } 194 } 195 } 196 }; 197 } 198 199 209 } 210 | Popular Tags |