1 19 20 package org.netbeans.modules.websvc.api.jaxws.project.config; 21 22 import java.beans.PropertyChangeListener ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import org.netbeans.api.project.FileOwnerQuery; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.schema2beans.BaseBean; 34 import org.netbeans.modules.websvc.jaxwsmodel.project.metadata.JAXWSNNMergerProvider; 35 import org.openide.ErrorManager; 36 import org.openide.filesystems.FileLock; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileSystem.AtomicAction; 39 40 44 public final class JaxWsModel { 45 private org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.JaxWs jaxws; 46 private FileObject fo; 47 private boolean nninitialized = false; 48 private Object initLock = new Object (); 49 private List <ServiceListener> serviceListeners; 50 51 JaxWsModel(org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.JaxWs jaxws) { 52 this(jaxws,null); 53 } 54 55 JaxWsModel(org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.JaxWs jaxws, FileObject fo) { 56 this.jaxws=jaxws; 57 this.fo=fo; 58 serviceListeners = new ArrayList <ServiceListener>(); 59 } 60 61 public Service[] getServices() { 62 initNNProvider(); 64 65 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Services services = jaxws.getServices(); 66 if (services==null) return new Service[]{}; 67 else { 68 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service[] org = services.getService(); 69 if (org==null) return new Service[]{}; 70 Service[] newServices = new Service[org.length]; 71 for (int i=0;i<org.length;i++) newServices[i] = new Service(org[i]); 72 return newServices; 73 } 74 } 75 76 public void setJsr109(Boolean jsr109){ 77 jaxws.setJsr109(jsr109); 78 } 79 80 public Boolean getJsr109(){ 81 return jaxws.getJsr109(); 82 } 83 84 private void initNNProvider() { 85 synchronized (initLock) { 86 if(!nninitialized) { 87 if(fo != null) { 88 nninitialized = true; 99 } 104 } 105 } 106 } 107 108 public Service findServiceByName(String name) { 109 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = findService(name); 110 return (service==null?null:new Service(service)); 111 } 112 113 public Service findServiceByImplementationClass(String wsClassName) { 114 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = _findServiceByClass(wsClassName); 115 return (service==null?null:new Service(service)); 116 } 117 118 private org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service findService(String name) { 119 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Services services = jaxws.getServices(); 120 if (services==null) return null; 121 else { 122 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service[] org = services.getService(); 123 if (org==null) return null; 124 for (int i=0;i<org.length;i++) { 125 if (name.equals(org[i].getName())) return org[i]; 126 } 127 return null; 128 } 129 } 130 131 private org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service _findServiceByClass(String wsClassName) { 132 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Services services = jaxws.getServices(); 133 if (services==null) return null; 134 else { 135 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service[] org = services.getService(); 136 if (org==null) return null; 137 for (int i=0;i<org.length;i++) { 138 if (wsClassName.equals(org[i].getImplementationClass())) return org[i]; 139 } 140 return null; 141 } 142 } 143 144 public boolean removeService(String name) { 145 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = findService(name); 146 if (name==null) return false; 147 else { 148 jaxws.getServices().removeService(service); 149 fireServiceRemoved(name); 150 return true; 151 } 152 } 153 154 public boolean removeServiceByClassName(String webserviceClassName) { 155 if (webserviceClassName != null) { 156 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = _findServiceByClass(webserviceClassName); 157 if (service != null) { 158 fireServiceRemoved(service.getName()); 159 jaxws.getServices().removeService(service); 160 return true; 161 } 162 } 163 return false; 164 } 165 166 public Service addService(String name, String implementationClass) 167 throws ServiceAlreadyExistsExeption { 168 169 if (findService(name)!=null) throw new ServiceAlreadyExistsExeption(name); 170 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = jaxws.getServices().newService(); 171 service.setName(name); 172 service.setImplementationClass(implementationClass); 173 jaxws.getServices().addService(service); 174 fireServiceAdded(name, implementationClass); 175 return new Service(service); 176 } 177 178 public Service addService(String name, String implementationClass, String wsdlUrl, String serviceName, String portName, String packageName) 179 throws ServiceAlreadyExistsExeption { 180 181 if (findService(name)!=null) throw new ServiceAlreadyExistsExeption(name); 182 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Service service = jaxws.getServices().newService(); 183 service.setName(name); 184 service.setImplementationClass(implementationClass); 185 service.setWsdlUrl(wsdlUrl); 186 service.setServiceName(serviceName); 187 service.setPortName(portName); 188 service.setPackageName(packageName); 189 jaxws.getServices().addService(service); 190 return new Service(service); 191 } 192 193 public Client[] getClients() { 194 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Clients clients = jaxws.getClients(); 195 if (clients==null) return new Client[]{}; 196 else { 197 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client[] org = clients.getClient(); 198 if (org==null) return new Client[]{}; 199 Client[] newClients = new Client[org.length]; 200 for (int i=0;i<org.length;i++) newClients[i] = new Client(org[i]); 201 return newClients; 202 } 203 } 204 205 public Client findClientByName(String name) { 206 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client client = findClient(name); 207 return (client==null?null:new Client(client)); 208 } 209 210 public Client findClientByWsdlUrl(String wsdlUrl) { 211 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Clients clients = jaxws.getClients(); 212 if (clients==null) return null; 213 else { 214 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client[] org = clients.getClient(); 215 if (org==null) return null; 216 for (int i=0;i<org.length;i++) { 217 if (wsdlUrl.equals(org[i].getWsdlUrl())) return new Client(org[i]); 218 } 219 return null; 220 } 221 } 222 223 private org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client findClient(String name) { 224 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Clients clients = jaxws.getClients(); 225 if (clients==null) return null; 226 else { 227 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client[] org = clients.getClient(); 228 if (org==null) return null; 229 for (int i=0;i<org.length;i++) { 230 if (name.equals(org[i].getName())) return org[i]; 231 } 232 return null; 233 } 234 } 235 236 public boolean removeClient(String name) { 237 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client client = findClient(name); 238 if (client==null) return false; 239 else { 240 jaxws.getClients().removeClient(client); 241 return true; 242 } 243 } 244 245 public Client addClient(String name, String wsdlUrl, String packageName) 246 throws ClientAlreadyExistsExeption { 247 248 if (findClient(name)!=null) throw new ClientAlreadyExistsExeption(name); 249 org.netbeans.modules.websvc.jaxwsmodel.project_config1_0.Client client = jaxws.getClients().newClient(); 250 client.setName(name); 251 client.setWsdlUrl(wsdlUrl); 252 if (packageName!=null) { 253 client.setPackageName(packageName); 254 client.setPackageNameForceReplace("true"); 255 } 256 jaxws.getClients().addClient(client); 257 return new Client(client); 258 } 259 260 public void addPropertyChangeListener(PropertyChangeListener l) { 261 jaxws.addPropertyChangeListener(l); 262 } 263 264 public void removePropertyChangeListener(PropertyChangeListener l) { 265 jaxws.removePropertyChangeListener(l); 266 } 267 268 public void merge(JaxWsModel newJaxWs) { 269 if (newJaxWs.jaxws!=null) 270 jaxws.merge(newJaxWs.jaxws,BaseBean.MERGE_UPDATE); 271 } 272 273 public void write(OutputStream os) throws IOException { 274 jaxws.write(os); 275 } 276 277 public FileObject getJaxWsFile() { 278 return fo; 279 } 280 281 public void setJaxWsFile(FileObject fo) { 282 this.fo=fo; 283 } 284 285 public void write() throws IOException { 286 if (fo!=null) { 287 fo.getFileSystem().runAtomicAction(new AtomicAction() { 288 public void run() { 289 FileLock lock=null; 290 try { 291 lock = fo.lock(); 292 OutputStream os = fo.getOutputStream(lock); 293 write(os); 294 os.close(); 295 } catch (IOException ex) { 296 ErrorManager.getDefault().notify(ex); 297 } finally { 298 if (lock!=null) lock.releaseLock(); 299 } 300 } 301 }); 302 } else throw new IOException ("No FileObject for writing specified"); } 304 305 315 public synchronized void addServiceListener(ServiceListener listener) { 316 if (listener!=null) 317 serviceListeners.add(listener); 318 } 319 320 public synchronized void removeServiceListener(ServiceListener listener) { 321 serviceListeners.remove(listener); 322 } 323 324 void fireServiceAdded(String name, String implementationClass) { 325 Iterator <ServiceListener> it = serviceListeners.iterator(); 326 while (it.hasNext()) it.next().serviceAdded(name, implementationClass); 327 } 328 329 void fireServiceRemoved(String name) { 330 Iterator <ServiceListener> it = serviceListeners.iterator(); 331 while (it.hasNext()) it.next().serviceRemoved(name); 332 } 333 334 public static interface ServiceListener { 335 336 public void serviceAdded(String name, String implementationClass); 337 338 public void serviceRemoved(String name); 339 340 } 341 342 } 343 | Popular Tags |