1 19 package org.netbeans.modules.web.project; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import javax.xml.namespace.QName ; 26 import org.netbeans.api.java.classpath.ClassPath; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 29 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 30 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent; 31 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription; 32 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices; 33 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 34 import org.netbeans.modules.j2ee.metadata.ClassPathSupport; 35 import org.netbeans.modules.schema2beans.BaseBean; 36 import org.netbeans.modules.serviceapi.InterfaceDescription; 37 import org.netbeans.modules.serviceapi.ServiceInterface; 38 import org.netbeans.modules.serviceapi.ServiceLink; 39 import org.netbeans.modules.websvc.spi.webservices.WebServicesSupportImpl; 40 import org.netbeans.modules.serviceapi.ServiceComponent; 41 import org.netbeans.modules.serviceapi.ServiceModule; 42 import org.netbeans.modules.serviceapi.wsdl.WSDL11Description; 43 import org.netbeans.modules.web.project.classpath.ClassPathProviderImpl; 44 import org.netbeans.modules.xml.wsdl.model.PortType; 45 import org.openide.filesystems.FileObject; 46 import org.openide.loaders.DataObject; 47 import org.openide.loaders.DataObjectNotFoundException; 48 import org.openide.nodes.Node; 49 50 54 public class ServiceModuleImpl extends ServiceModule { 55 private WebProject project; 56 57 58 public ServiceModuleImpl(WebProject webProject) { 59 this.project = webProject; 60 } 61 62 private WebServicesSupportImpl getWebServiceSupport() { 63 return project.getLookup().lookup(WebServicesSupportImpl.class); 64 } 65 66 69 public String getName() { 70 return project.getName(); 71 } 72 73 76 public Collection <ServiceComponent> getServiceComponents() { 77 ArrayList <ServiceComponent> ret = new ArrayList <ServiceComponent>(); 78 Webservices wss = getWebservices(); 79 80 if (wss != null) { 81 WebserviceDescription[] descriptions = wss.getWebserviceDescription(); 82 if (descriptions == null) return ret; 83 for (WebserviceDescription wsd : descriptions) { 84 PortComponent[] portComponents = wsd.getPortComponent(); 85 if (portComponents == null) continue; 86 String wsdlPath = wsd.getWsdlFile(); 87 assert wsdlPath != null; 88 for (PortComponent pc : portComponents) { 89 ret.add(new ProviderComponent(wsdlPath, pc)); 90 } 91 } 92 93 for (Servlet s : getWebApp().getServlet()) { 94 s.getServletClass(); 95 } 96 } 97 return ret; 98 } 99 100 public static QName convertSchema2BeansQName(org.netbeans.modules.schema2beans.QName q) { 101 return new QName (q.getNamespaceURI(), q.getLocalPart()); 102 } 103 104 private class ProviderComponent extends Component { 105 private PortComponent portComponent; 106 private String wsdlFilePath; 107 108 private ProviderComponent(String wsdlFilePath, PortComponent pc) { 109 this.wsdlFilePath = wsdlFilePath; 110 portComponent = pc; 111 } 112 113 public String getWsdlFilePath() { 114 return wsdlFilePath; 115 } 116 117 public List <ServiceInterface> getServiceProviders() { 118 QName portQName = convertSchema2BeansQName(portComponent.getWsdlPort()); 119 Description def = new Description(getWsdlFilePath(), portQName); 120 throw new UnsupportedOperationException ("Not supported yet."); 121 } 122 123 @Override 124 public String getImplClassName() { 125 String link = portComponent.getServiceImplBean().getServletLink(); 126 return getWebServiceSupport().getImplementationBean(link); 127 } 128 129 } 130 131 private abstract class Component extends ServiceComponent { 132 133 public List <ServiceInterface> getServiceProviders() { 134 return Collections.emptyList(); 135 } 136 137 public List <ServiceInterface> getServiceConsumers() { 138 return Collections.emptyList(); 139 } 140 141 public Collection <ServiceLink> getServiceLinks() { 142 return Collections.emptyList(); 143 } 144 145 public abstract String getImplClassName(); 146 147 public Node getNode() { 148 FileObject fo = getSourcesClassPath().findResource(getImplClassName()); 149 assert fo != null; 150 try { 151 DataObject dobj = DataObject.find(fo); 152 assert dobj != null; 153 return dobj.getNodeDelegate(); 154 } catch(DataObjectNotFoundException ex) { 155 assert false : "DataObjectNotFoundException: " + ex.getMessage(); 156 return null; 157 } 158 } 159 160 public ServiceInterface createServiceInterface(InterfaceDescription description, 161 boolean provider) { 162 if (provider) return null; 163 throw new UnsupportedOperationException ("Not supported yet."); 164 } 165 166 public ServiceInterface createServiceInterface(ServiceInterface other) { 167 throw new UnsupportedOperationException ("Not supported yet."); 168 } 169 170 public void removeServiceInterface(ServiceInterface serviceInterface) { 171 throw new UnsupportedOperationException ("Not supported yet."); 172 } 173 174 @Override 175 public int hashCode() { 176 return getImplClassName().hashCode(); 177 } 178 179 @Override 180 public boolean equals(Object obj) { 181 if (! (obj instanceof Component)) return false; 182 Component other = (Component) obj; 183 return this.getImplClassName().equals(other.getImplClassName()); 184 } 185 } 186 187 private class Interface implements ServiceInterface { 188 Component component; 189 Description description; 190 boolean isProvider = true; 191 192 Interface(Component parent, Description description, boolean isProvider) { 193 this(parent, description); 194 this.isProvider = isProvider; 195 } 196 197 private Interface(Component parent, Description description) { 198 this.component = parent; 199 this.description = description; 200 } 201 202 public Description getInterfaceDescription() { 203 return description; 204 } 205 206 public ServiceComponent getServiceComponent() { 207 return component; 208 } 209 210 public boolean canConnect(ServiceInterface other) { 211 if (! (other.getInterfaceDescription() instanceof WSDL11Description)) { 212 return false; 213 } 214 WSDL11Description otherDescription = (WSDL11Description) other.getInterfaceDescription(); 215 return other.isProvider() != isProvider() && 216 otherDescription.getInterfaceQName().equals(getQName()); 217 } 218 219 public boolean isProvider() { 220 return isProvider; 221 } 222 223 public Node getNode() { 224 throw new UnsupportedOperationException ("Not supported yet."); 226 } 227 228 public QName getQName() { 229 return getInterfaceDescription().getInterfaceQName(); 230 } 231 } 232 233 private class Description extends WSDL11Description { 234 private String pathToWSDL; 235 private QName portTypeQName; 236 237 Description(String pathToWSDL, QName portTypeQName) { 238 this.pathToWSDL = pathToWSDL; 239 this.portTypeQName = portTypeQName; 240 } 241 242 @Override 243 public QName getInterfaceQName() { 244 return portTypeQName; 245 } 246 247 public String getDisplayName() { 248 return portTypeQName.getLocalPart(); 249 } 250 251 public PortType getInterface() { 252 throw new UnsupportedOperationException ("Not supported yet."); 254 } 255 } 256 257 private Webservices getWebservices() { 258 BaseBean bb = project.getWebModule().getDeploymentDescriptor(J2eeModule.WEBSERVICES_XML); 259 if (bb instanceof Webservices) { 260 return (Webservices) bb; 261 } 262 return null; 263 } 264 265 private WebApp getWebApp() { 266 BaseBean bb = project.getWebModule().getDeploymentDescriptor(J2eeModule.WEB_XML); 267 if (bb instanceof WebApp) { 268 return (WebApp) bb; 269 } 270 assert false : "Failed to get WebApp"; 271 return null; 272 } 273 274 277 278 public void addServiceComponent(ServiceComponent component) { 279 throw new UnsupportedOperationException ("Not supported yet."); 280 } 281 282 285 public void removeServiceComponent(ServiceComponent component) { 286 throw new UnsupportedOperationException ("Not supported yet."); 287 } 288 289 292 public Project getProject() { 293 return project; 294 } 295 296 private ClassPath sourcesClassPath; 297 private ClassPath getSourcesClassPath() { 298 synchronized (this) { 299 if (sourcesClassPath == null) { 300 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)project.getLookup().lookup(ClassPathProviderImpl.class); 301 sourcesClassPath = ClassPathSupport.createWeakProxyClassPath(new ClassPath[] { 302 cpProvider.getProjectSourcesClassPath(ClassPath.SOURCE), 303 }); 304 } 305 return sourcesClassPath; 306 } 307 } 308 } 309 | Popular Tags |