1 19 27 28 package org.netbeans.modules.websvc.wsdl.config; 29 30 import java.io.FileNotFoundException ; 31 import java.io.IOException ; 32 import java.lang.ref.WeakReference ; 33 import java.util.Collections ; 34 import java.util.List ; 35 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 36 import org.netbeans.modules.websvc.jaxrpc.PortInformation; 37 import org.netbeans.modules.websvc.jaxrpc.ServiceInformation; 38 import org.netbeans.modules.websvc.jaxrpc.nodes.WsCompileConfigCookie; 39 import org.openide.filesystems.FileObject; 40 import org.openide.loaders.DataObject; 41 import org.openide.loaders.DataObjectNotFoundException; 42 43 48 public class ServiceInformationImpl implements ServiceInformation { 49 50 private WeakReference portInformationHandlerRef = null; 51 private DataObject wsdlDataObj; 52 53 private boolean clientResolved, isClientWsdl; 58 59 61 public ServiceInformationImpl(DataObject dobj) { 62 wsdlDataObj = dobj; 63 } 64 65 public boolean isClientWsdl() { 66 if (!clientResolved) { 67 initClientWsdl(); 68 clientResolved=true; 69 } 70 return isClientWsdl; 71 } 72 73 private void initClientWsdl() { 74 isClientWsdl = false; 75 FileObject wsdlFO = wsdlDataObj.getPrimaryFile(); 76 77 FileObject parentFO = wsdlFO.getParent(); 79 if(parentFO != null) { 80 WebServicesClientSupport clientSupport = WebServicesClientSupport.getWebServicesClientSupport(wsdlFO); 82 if(clientSupport != null) { 83 FileObject wsdlFolder = clientSupport.getWsdlFolder(); 85 if(wsdlFolder != null && wsdlFolder.equals(parentFO)) { 86 isClientWsdl = true; 90 91 100 FileObject ddFolder = wsdlFolder.getParent(); 102 if(ddFolder != null) { 103 FileObject mappingFile = ddFolder.getFileObject(wsdlDataObj.getName() + "-mapping", "xml"); if(mappingFile != null) { 105 isClientWsdl = false; 106 } 107 } 108 } 109 } 110 } 111 } 112 113 public String getServicePackageName() { 114 String packageName = "unknown"; 117 FileObject configFO = null; 118 FileObject wsdlFO = wsdlDataObj.getPrimaryFile(); 119 FileObject parentFO = wsdlFO.getParent(); 120 if(parentFO != null && parentFO.isFolder()) { 121 configFO = parentFO.getFileObject(wsdlFO.getName() + WsCompileConfigDataObject.WSCOMPILE_CONFIG_FILENAME_SUFFIX, "xml"); 122 } 123 124 if(configFO != null) { 125 WsCompileConfigCookie configCookie = null; 126 try { 127 DataObject dobj = DataObject.find(configFO); 128 if (dobj instanceof WsCompileConfigCookie) 129 configCookie = (WsCompileConfigCookie) dobj; 130 } catch(DataObjectNotFoundException ex) { 131 } 134 135 if(configCookie != null) { 136 packageName = configCookie.getServicePackageName(); 137 } 138 } 139 140 return packageName; 141 142 } 198 199 public PortInformation getPortInformation() { 200 return parseWsdl(); 201 } 202 203 public List getServicePorts(String serviceName) { 204 List portList; 205 PortInformationHandler handler = parseWsdl(); 206 207 if(handler != null) { 208 PortInformation.ServiceInfo serviceInfo = handler.getServiceInfo(serviceName); 209 portList = serviceInfo.getPorts(); 210 } else { 211 portList = Collections.EMPTY_LIST; 212 } 213 214 return portList; 215 } 216 217 public String [] getServiceNames() { 218 String [] result; 219 PortInformationHandler handler = parseWsdl(); 220 221 if(handler != null) { 222 result = handler.getServiceNames(); 223 } else { 224 result = new String [0]; 225 } 226 227 return result; 228 } 229 230 public String getTargetNamespace() { 231 String result; 232 PortInformationHandler handler = parseWsdl(); 233 234 if(handler != null) { 235 result = handler.getTargetNamespace(); 236 } else { 237 result = null; } 239 240 return result; 241 } 242 243 private PortInformationHandler parseWsdl() { 244 PortInformationHandler handler = null; 245 246 synchronized (this) { 248 if(portInformationHandlerRef != null) { 249 handler = (PortInformationHandler) portInformationHandlerRef.get(); 250 if(handler != null) { 251 return handler; 252 } 253 } 254 } 255 256 List result = Collections.EMPTY_LIST; 257 FileObject primaryFile = wsdlDataObj.getPrimaryFile(); 258 handler = new PortInformationHandler(); 260 261 try { 262 org.xml.sax.XMLReader xmlReader = org.openide.xml.XMLUtil.createXMLReader(false,true); 263 xmlReader.setContentHandler(handler); 264 xmlReader.parse(new org.xml.sax.InputSource (primaryFile.getInputStream())); 265 synchronized (this) { 267 portInformationHandlerRef = new WeakReference (handler); 268 } 269 } catch(org.xml.sax.SAXException ex) { 270 handler = null; 272 } catch(FileNotFoundException ex) { 273 handler = null; 275 } catch(IOException ex) { 276 handler = null; 278 } 279 280 return handler; 281 } 282 } 283 | Popular Tags |