|
Lines 25-31
Link Here
|
| 25 |
|
25 |
|
| 26 |
import javax.xml.namespace.QName; |
26 |
import javax.xml.namespace.QName; |
| 27 |
|
27 |
|
| 28 |
import org.apache.muse.util.xml.XmlUtils; |
|
|
| 29 |
import org.eclipse.core.resources.IFile; |
28 |
import org.eclipse.core.resources.IFile; |
| 30 |
import org.eclipse.core.runtime.CoreException; |
29 |
import org.eclipse.core.runtime.CoreException; |
| 31 |
import org.eclipse.core.runtime.IProgressMonitor; |
30 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
Lines 72-1064
Link Here
|
| 72 |
public class WsdlUtils |
71 |
public class WsdlUtils |
| 73 |
{ |
72 |
{ |
| 74 |
|
73 |
|
| 75 |
public static final String RESOURCE_PROPERTIES_ELEMENT_KEY = "ResourceProperties"; |
74 |
public static final String RESOURCE_PROPERTIES_ELEMENT_KEY = "ResourceProperties"; |
| 76 |
|
75 |
|
| 77 |
public static final String METADATA_DESCRIPTOR_LOCATION_KEY = "metadataDescriptorLocation"; |
76 |
public static final String METADATA_DESCRIPTOR_LOCATION_KEY = "metadataDescriptorLocation"; |
| 78 |
|
77 |
|
| 79 |
public static final String METADATA_DESCRIPTOR_KEY = "metadataDescriptor"; |
78 |
public static final String METADATA_DESCRIPTOR_KEY = "metadataDescriptor"; |
| 80 |
|
79 |
|
| 81 |
/** |
80 |
/** |
| 82 |
* Returns the EMF based object Definition of the given WSDL file. |
81 |
* Returns the EMF based object Definition of the given WSDL file. |
| 83 |
* |
82 |
* |
| 84 |
* @param wsdlFile |
83 |
* @param wsdlFile |
| 85 |
* Any WSDL file available in eclipse workbench |
84 |
* Any WSDL file available in eclipse workbench |
| 86 |
* |
85 |
* |
| 87 |
* @return EMF based Definition object |
86 |
* @return EMF based Definition object |
| 88 |
* @throws Exception |
87 |
* @throws Exception |
| 89 |
*/ |
88 |
*/ |
| 90 |
public static Definition getWSDLDefinition(IFile wsdlFile) throws Exception |
89 |
public static Definition getWSDLDefinition(IFile wsdlFile) throws Exception |
| 91 |
{ |
90 |
{ |
| 92 |
URI wsdlURI = URI.createPlatformResourceURI(wsdlFile.getFullPath() |
91 |
URI wsdlURI = URI.createPlatformResourceURI(wsdlFile.getFullPath() |
| 93 |
.toString()); |
92 |
.toString()); |
| 94 |
return getWSDLDefinition(wsdlURI); |
93 |
return getWSDLDefinition(wsdlURI); |
| 95 |
} |
94 |
} |
| 96 |
|
95 |
|
| 97 |
/** |
96 |
/** |
| 98 |
* Returns the EMF based Definition object of the given URI of any WSDL |
97 |
* Returns the EMF based Definition object of the given URI of any WSDL |
| 99 |
* file. |
98 |
* file. |
| 100 |
* |
99 |
* |
| 101 |
* @param wsdlURI |
100 |
* @param wsdlURI |
| 102 |
* URI of any WSDL file available in eclipse workbench |
101 |
* URI of any WSDL file available in eclipse workbench |
| 103 |
* |
102 |
* |
| 104 |
* @return EMF based Definition object |
103 |
* @return EMF based Definition object |
| 105 |
* @throws Exception |
104 |
* @throws Exception |
| 106 |
*/ |
105 |
*/ |
| 107 |
public static Definition getWSDLDefinition(URI wsdlURI) throws Exception |
106 |
public static Definition getWSDLDefinition(URI wsdlURI) throws Exception |
| 108 |
{ |
107 |
{ |
| 109 |
ResourceSet resourceSet = new ResourceSetImpl(); |
108 |
ResourceSet resourceSet = new ResourceSetImpl(); |
| 110 |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
109 |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| 111 |
.put("*.wsdl", new CustomWSDLResourceFactoryImpl()); |
110 |
.put("*.wsdl", new CustomWSDLResourceFactoryImpl()); |
| 112 |
WSDLResourceImpl wsdlMainResource = (WSDLResourceImpl) resourceSet |
111 |
WSDLResourceImpl wsdlMainResource = (WSDLResourceImpl) resourceSet |
| 113 |
.createResource(URI.createURI("*.wsdl")); |
112 |
.createResource(URI.createURI("*.wsdl")); |
| 114 |
wsdlMainResource.setURI(wsdlURI); |
113 |
wsdlMainResource.setURI(wsdlURI); |
| 115 |
java.util.Map map = new Hashtable(); |
114 |
java.util.Map map = new Hashtable(); |
| 116 |
map.put(WSDLResourceImpl.CONTINUE_ON_LOAD_ERROR, Boolean.valueOf(true)); |
115 |
map.put(WSDLResourceImpl.CONTINUE_ON_LOAD_ERROR, Boolean.valueOf(true)); |
| 117 |
try |
116 |
try |
| 118 |
{ |
117 |
{ |
| 119 |
wsdlMainResource.load(map); |
118 |
wsdlMainResource.load(map); |
| 120 |
} catch (Exception ex) |
119 |
} catch (Exception ex) |
| 121 |
{ |
120 |
{ |
| 122 |
WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_, ex); |
121 |
WsdmToolingLog.logError(Messages.IMPROPER_WSDL_FILE_ERROR_, ex); |
| 123 |
throw ex; |
122 |
throw ex; |
| 124 |
} |
123 |
} |
| 125 |
|
124 |
|
| 126 |
Definition definition = null; |
125 |
Definition definition = null; |
| 127 |
for (Iterator resources = resourceSet.getResources().iterator(); resources |
126 |
for (Iterator resources = resourceSet.getResources().iterator(); resources |
| 128 |
.hasNext();) |
127 |
.hasNext();) |
| 129 |
{ |
128 |
{ |
| 130 |
Object resource = resources.next(); |
129 |
Object resource = resources.next(); |
| 131 |
if (resource instanceof WSDLResourceImpl) |
130 |
if (resource instanceof WSDLResourceImpl) |
| 132 |
{ |
131 |
{ |
| 133 |
WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resource; |
132 |
WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resource; |
| 134 |
definition = wsdlResource.getDefinition(); |
133 |
definition = wsdlResource.getDefinition(); |
| 135 |
if (definition.getTargetNamespace() == null) // Not a proper |
134 |
if (definition.getTargetNamespace() == null) // Not a proper |
| 136 |
// WSDL file |
135 |
// WSDL file |
| 137 |
throw new Exception(Messages.IMPROPER_WSDL_FILE_ERROR_); |
136 |
throw new Exception(Messages.IMPROPER_WSDL_FILE_ERROR_); |
|
|
137 |
return definition; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
return null; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Returns the WSDL Operation defined inside given port type index. If WSDL |
| 146 |
* file does not contain port type then it will return null. If the given |
| 147 |
* port type index is less than 0 then it will return null. If the given |
| 148 |
* port type index is greater than the available port types then it will |
| 149 |
* return null. |
| 150 |
* |
| 151 |
* @param definition |
| 152 |
* WSDL Definition object. |
| 153 |
* |
| 154 |
* @param portTypeIndex |
| 155 |
* Port type index. |
| 156 |
* |
| 157 |
* @return Operations available in given port type index. |
| 158 |
*/ |
| 159 |
public static Operation[] getWSDLOperation(Definition definition, |
| 160 |
int portTypeIndex) |
| 161 |
{ |
| 162 |
PortType portType = getPortType(definition, portTypeIndex); |
| 163 |
if (portType == null) |
| 164 |
return null; |
| 165 |
return (Operation[]) portType.getOperations().toArray(); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Returns the WSDL Operation defined inside first port type. |
| 170 |
* |
| 171 |
* @param definition |
| 172 |
* WSDL Definition object. |
| 173 |
* |
| 174 |
* @return Operations available inside first port type. |
| 175 |
*/ |
| 176 |
public static Operation[] getWSDLOperation(Definition definition) |
| 177 |
{ |
| 178 |
return getWSDLOperation(definition, 0); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Returns the Port Type defined inside given WSDL Definition object. If |
| 183 |
* WSDL file does not contain port type then it will return null. If the |
| 184 |
* given port type index is less than 0 then it will return null. If the |
| 185 |
* given port type index is greater than the available port types then it |
| 186 |
* will return null. |
| 187 |
* |
| 188 |
* @param definition |
| 189 |
* WSDL Definition object. |
| 190 |
* |
| 191 |
* @param portTypeIndex |
| 192 |
* Port type index. |
| 193 |
* |
| 194 |
* @return Port Type defined inside given WSDL Definition object. |
| 195 |
*/ |
| 196 |
public static PortType getPortType(Definition definition, int portTypeIndex) |
| 197 |
{ |
| 198 |
if (portTypeIndex < 0) |
| 199 |
{ |
| 200 |
WsdmToolingLog |
| 201 |
.logWarning(Messages.PORT_TYPE_INDEX_LESS_THAN_0_ERROR_); |
| 202 |
return null; |
| 203 |
} |
| 204 |
List portTypeList = definition.getEPortTypes(); |
| 205 |
if (portTypeList == null || portTypeList.size() == 0) |
| 206 |
{ |
| 207 |
// Don't log message in Error log it will go to problems view while |
| 208 |
// validating mcap files |
| 209 |
// WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 210 |
return null; |
| 211 |
} |
| 212 |
if (portTypeIndex > portTypeList.size()) |
| 213 |
{ |
| 214 |
WsdmToolingLog.logWarning(NLS.bind( |
| 215 |
Messages.PORT_TYPE_INDEX_CANT_MORE_ERROR_, Integer |
| 216 |
.toString(portTypeList.size()))); |
| 217 |
return null; |
| 218 |
} |
| 219 |
PortType portType = (PortType) portTypeList.get(portTypeIndex); |
| 220 |
return portType; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Returns the first Port Type defined inside given WSDL Definition object. |
| 225 |
* |
| 226 |
* @param definition |
| 227 |
* WSDL Definition object. |
| 228 |
* |
| 229 |
* @return First Port Type defined inside given WSDL Definition object. |
| 230 |
*/ |
| 231 |
public static PortType getPortType(Definition definition) |
| 232 |
{ |
| 233 |
return getPortType(definition, 0); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Returns the name of given WSDL Operation object. |
| 238 |
* |
| 239 |
* @param operation |
| 240 |
* WSDL Operation object. |
| 241 |
* |
| 242 |
* @return Name of WSDL Operation object. |
| 243 |
*/ |
| 244 |
public static String getOperationName(Operation operation) |
| 245 |
{ |
| 246 |
return operation.getName(); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Create new WSDL Definition object. |
| 251 |
* |
| 252 |
* @param targetNamespace |
| 253 |
* TargetNamespace to be used for new WSDL Definition. |
| 254 |
* |
| 255 |
* @param prefix |
| 256 |
* TargetNamespace prefix to be used. |
| 257 |
* |
| 258 |
* @param name |
| 259 |
* Name for WSDL Definition. It will appear as "name" attribute |
| 260 |
* inside "deinition" element. |
| 261 |
* |
| 262 |
* @param location |
| 263 |
* WSDL File location. |
| 264 |
* |
| 265 |
* @return new WSDL Definition object. |
| 266 |
*/ |
| 267 |
public static Definition createNewWSDLDefinition(String targetNamespace, |
| 268 |
String prefix, String name, String location) |
| 269 |
{ |
| 270 |
Definition definition = WSDLFactory.eINSTANCE.createDefinition(); |
| 271 |
definition.setTargetNamespace(targetNamespace); |
| 272 |
definition.addNamespace("xsd", XsdUtils.XMLSCHEMA_2001_URI); |
| 273 |
definition.addNamespace("soap", WsdlConstants.SOAP_NAMESPACE_URI); |
| 274 |
definition.addNamespace("wsdl", WsdlConstants.WSDL_NAMESPACE_URI); |
| 275 |
definition.setLocation(location); |
| 276 |
definition.setEncoding("UTF-8"); |
| 277 |
definition.setQName(new QName(targetNamespace, name)); |
| 278 |
if (prefix != null) |
| 279 |
definition.addNamespace(prefix, targetNamespace); |
| 280 |
else |
| 281 |
definition.addNamespace("tns", targetNamespace); |
| 282 |
definition.updateElement(true); |
| 138 |
return definition; |
283 |
return definition; |
| 139 |
} |
|
|
| 140 |
} |
284 |
} |
| 141 |
|
285 |
|
| 142 |
return null; |
286 |
/** |
| 143 |
} |
287 |
* Saves an WSDL Definition object into ResourceSet and returns the |
|
|
288 |
* ByteArrayOutputStream of the saved object. |
| 289 |
* |
| 290 |
* @param definition |
| 291 |
* WSDL Definition object to be saved. |
| 292 |
* |
| 293 |
* @param fileURI |
| 294 |
* URI String of the file to which WSDL Definition object will be |
| 295 |
* saved. |
| 296 |
* |
| 297 |
* @param resourceSet |
| 298 |
* ResourceSet used for saving it, if null ResourceSet specified |
| 299 |
* then the method will create new ResourceSet. |
| 300 |
* |
| 301 |
* @return ByteArrayOutputStream representation of the saved object. |
| 302 |
* @throws IOException |
| 303 |
*/ |
| 304 |
public static ByteArrayOutputStream saveWSDLDefinition( |
| 305 |
Definition definition, String fileURI, ResourceSet resourceSet) |
| 306 |
throws IOException |
| 307 |
{ |
| 308 |
if (resourceSet == null) |
| 309 |
{ |
| 310 |
resourceSet = new ResourceSetImpl(); |
| 311 |
} |
| 312 |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| 313 |
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
| 314 |
new CustomWSDLResourceFactoryImpl()); |
| 315 |
URI wsdlFileURI = URI.createPlatformResourceURI(fileURI); |
| 316 |
Resource resource = resourceSet.createResource(wsdlFileURI); |
| 317 |
resource.getContents().add(definition); |
| 318 |
Map options = new HashMap(); |
| 319 |
ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); |
| 320 |
try |
| 321 |
{ |
| 322 |
resource.save(baOutputStream, options); |
| 323 |
} catch (IOException e) |
| 324 |
{ |
| 325 |
WsdmToolingLog |
| 326 |
.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e); |
| 327 |
throw e; |
| 328 |
} |
| 329 |
return baOutputStream; |
| 330 |
} |
| 144 |
|
331 |
|
| 145 |
/** |
332 |
/** |
| 146 |
* Returns the WSDL Operation defined inside given port type index. If |
333 |
* Saves an WSDL Definition into IFile in formatted representation. |
| 147 |
* WSDL file does not contain port type then it will return null. If the |
334 |
* |
| 148 |
* given port type index is less than 0 then it will return null. If the |
335 |
* @param definition |
| 149 |
* given port type index is greater than the available port types then |
336 |
* WSDL Definition object to be saved. |
| 150 |
* it will return null. |
337 |
* |
| 151 |
* |
338 |
* @param wsdlFile |
| 152 |
* @param definition |
339 |
* Eclipse file to which WSDL Definition object will be saved. |
| 153 |
* WSDL Definition object. |
340 |
* |
| 154 |
* |
341 |
* @param monitor |
| 155 |
* @param portTypeIndex |
342 |
* Progress monitor. |
| 156 |
* Port type index. |
343 |
* @throws IOException |
| 157 |
* |
344 |
* @throws CoreException |
| 158 |
* @return Operations available in given port type index. |
345 |
*/ |
| 159 |
*/ |
346 |
public static void serializeAndFormatWSDL(Definition definition, |
| 160 |
public static Operation[] getWSDLOperation(Definition definition, |
347 |
IFile wsdlFile, IProgressMonitor monitor) throws IOException, |
| 161 |
int portTypeIndex) |
348 |
CoreException |
| 162 |
{ |
349 |
{ |
| 163 |
PortType portType = getPortType(definition, portTypeIndex); |
350 |
String fileURI = wsdlFile.getFullPath().toString(); |
| 164 |
if (portType == null) |
351 |
ByteArrayOutputStream baos = saveWSDLDefinition(definition, fileURI, |
| 165 |
return null; |
352 |
null); |
| 166 |
return (Operation[]) portType.getOperations().toArray(); |
353 |
String serializedString = CapUtils.getSerializedDocument(baos |
| 167 |
} |
354 |
.toString()); |
| 168 |
|
355 |
ByteArrayInputStream baInputStream = new ByteArrayInputStream( |
| 169 |
/** |
356 |
serializedString.getBytes()); |
| 170 |
* Returns the WSDL Operation defined inside first port type. |
357 |
try |
| 171 |
* |
358 |
{ |
| 172 |
* @param definition |
359 |
if (wsdlFile.exists()) |
| 173 |
* WSDL Definition object. |
360 |
wsdlFile.setContents(baInputStream, IFile.FORCE, monitor); |
| 174 |
* |
361 |
else |
| 175 |
* @return Operations available inside first port type. |
362 |
wsdlFile.create(baInputStream, IFile.FORCE, monitor); |
| 176 |
*/ |
363 |
} catch (CoreException e) |
| 177 |
public static Operation[] getWSDLOperation(Definition definition) |
364 |
{ |
| 178 |
{ |
365 |
WsdmToolingLog |
| 179 |
return getWSDLOperation(definition, 0); |
366 |
.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e); |
| 180 |
} |
367 |
throw e; |
| 181 |
|
|
|
| 182 |
/** |
| 183 |
* Returns the Port Type defined inside given WSDL Definition object. If |
| 184 |
* WSDL file does not contain port type then it will return null. If the |
| 185 |
* given port type index is less than 0 then it will return null. If the |
| 186 |
* given port type index is greater than the available port types then |
| 187 |
* it will return null. |
| 188 |
* |
| 189 |
* @param definition |
| 190 |
* WSDL Definition object. |
| 191 |
* |
| 192 |
* @param portTypeIndex |
| 193 |
* Port type index. |
| 194 |
* |
| 195 |
* @return Port Type defined inside given WSDL Definition object. |
| 196 |
*/ |
| 197 |
public static PortType getPortType(Definition definition, int portTypeIndex) |
| 198 |
{ |
| 199 |
if (portTypeIndex < 0) |
| 200 |
{ |
| 201 |
WsdmToolingLog |
| 202 |
.logWarning(Messages.PORT_TYPE_INDEX_LESS_THAN_0_ERROR_); |
| 203 |
return null; |
| 204 |
} |
| 205 |
List portTypeList = definition.getEPortTypes(); |
| 206 |
if (portTypeList == null || portTypeList.size() == 0) |
| 207 |
{ |
| 208 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 209 |
//WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 210 |
return null; |
| 211 |
} |
| 212 |
if (portTypeIndex > portTypeList.size()) |
| 213 |
{ |
| 214 |
WsdmToolingLog.logWarning(NLS.bind( |
| 215 |
Messages.PORT_TYPE_INDEX_CANT_MORE_ERROR_, Integer |
| 216 |
.toString(portTypeList.size()))); |
| 217 |
return null; |
| 218 |
} |
| 219 |
PortType portType = (PortType) portTypeList.get(portTypeIndex); |
| 220 |
return portType; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Returns the first Port Type defined inside given WSDL Definition |
| 225 |
* object. |
| 226 |
* |
| 227 |
* @param definition |
| 228 |
* WSDL Definition object. |
| 229 |
* |
| 230 |
* @return First Port Type defined inside given WSDL Definition object. |
| 231 |
*/ |
| 232 |
public static PortType getPortType(Definition definition) |
| 233 |
{ |
| 234 |
return getPortType(definition, 0); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Returns the name of given WSDL Operation object. |
| 239 |
* |
| 240 |
* @param operation |
| 241 |
* WSDL Operation object. |
| 242 |
* |
| 243 |
* @return Name of WSDL Operation object. |
| 244 |
*/ |
| 245 |
public static String getOperationName(Operation operation) |
| 246 |
{ |
| 247 |
return operation.getName(); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Create new WSDL Definition object. |
| 252 |
* |
| 253 |
* @param targetNamespace |
| 254 |
* TargetNamespace to be used for new WSDL Definition. |
| 255 |
* |
| 256 |
* @param prefix |
| 257 |
* TargetNamespace prefix to be used. |
| 258 |
* |
| 259 |
* @param name |
| 260 |
* Name for WSDL Definition. It will appear as "name" |
| 261 |
* attribute inside "deinition" element. |
| 262 |
* |
| 263 |
* @param location |
| 264 |
* WSDL File location. |
| 265 |
* |
| 266 |
* @return new WSDL Definition object. |
| 267 |
*/ |
| 268 |
public static Definition createNewWSDLDefinition(String targetNamespace, |
| 269 |
String prefix, String name, String location) |
| 270 |
{ |
| 271 |
Definition definition = WSDLFactory.eINSTANCE.createDefinition(); |
| 272 |
definition.setTargetNamespace(targetNamespace); |
| 273 |
definition.addNamespace("xsd", XsdUtils.XMLSCHEMA_2001_URI); |
| 274 |
definition.addNamespace("soap", WsdlConstants.SOAP_NAMESPACE_URI); |
| 275 |
definition.addNamespace("wsdl", WsdlConstants.WSDL_NAMESPACE_URI); |
| 276 |
definition.setLocation(location); |
| 277 |
definition.setEncoding("UTF-8"); |
| 278 |
definition.setQName(new QName(targetNamespace, name)); |
| 279 |
if (prefix != null) |
| 280 |
definition.addNamespace(prefix, targetNamespace); |
| 281 |
else |
| 282 |
definition.addNamespace("tns", targetNamespace); |
| 283 |
definition.updateElement(true); |
| 284 |
return definition; |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Saves an WSDL Definition object into ResourceSet and returns the |
| 289 |
* ByteArrayOutputStream of the saved object. |
| 290 |
* |
| 291 |
* @param definition |
| 292 |
* WSDL Definition object to be saved. |
| 293 |
* |
| 294 |
* @param fileURI |
| 295 |
* URI String of the file to which WSDL Definition object |
| 296 |
* will be saved. |
| 297 |
* |
| 298 |
* @param resourceSet |
| 299 |
* ResourceSet used for saving it, if null ResourceSet |
| 300 |
* specified then the method will create new ResourceSet. |
| 301 |
* |
| 302 |
* @return ByteArrayOutputStream representation of the saved object. |
| 303 |
* @throws IOException |
| 304 |
*/ |
| 305 |
public static ByteArrayOutputStream saveWSDLDefinition( |
| 306 |
Definition definition, String fileURI, ResourceSet resourceSet) throws IOException |
| 307 |
{ |
| 308 |
if (resourceSet == null) |
| 309 |
{ |
| 310 |
resourceSet = new ResourceSetImpl(); |
| 311 |
} |
| 312 |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| 313 |
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
| 314 |
new CustomWSDLResourceFactoryImpl()); |
| 315 |
URI wsdlFileURI = URI.createPlatformResourceURI(fileURI); |
| 316 |
Resource resource = resourceSet.createResource(wsdlFileURI); |
| 317 |
resource.getContents().add(definition); |
| 318 |
Map options = new HashMap(); |
| 319 |
ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); |
| 320 |
try |
| 321 |
{ |
| 322 |
resource.save(baOutputStream, options); |
| 323 |
} catch (IOException e) |
| 324 |
{ |
| 325 |
WsdmToolingLog |
| 326 |
.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e); |
| 327 |
throw e; |
| 328 |
} |
| 329 |
return baOutputStream; |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Saves an WSDL Definition into IFile in formatted representation. |
| 334 |
* |
| 335 |
* @param definition |
| 336 |
* WSDL Definition object to be saved. |
| 337 |
* |
| 338 |
* @param wsdlFile |
| 339 |
* Eclipse file to which WSDL Definition object will be |
| 340 |
* saved. |
| 341 |
* |
| 342 |
* @param monitor |
| 343 |
* Progress monitor. |
| 344 |
* @throws IOException |
| 345 |
* @throws CoreException |
| 346 |
*/ |
| 347 |
public static void serializeAndFormatWSDL(Definition definition, |
| 348 |
IFile wsdlFile, IProgressMonitor monitor) throws IOException, CoreException |
| 349 |
{ |
| 350 |
String fileURI = wsdlFile.getFullPath().toString(); |
| 351 |
ByteArrayOutputStream baos = saveWSDLDefinition(definition, fileURI, |
| 352 |
null); |
| 353 |
String serializedString = CapUtils.getSerializedDocument(baos |
| 354 |
.toString()); |
| 355 |
ByteArrayInputStream baInputStream = new ByteArrayInputStream( |
| 356 |
serializedString.getBytes()); |
| 357 |
try |
| 358 |
{ |
| 359 |
if (wsdlFile.exists()) |
| 360 |
wsdlFile.setContents(baInputStream, IFile.FORCE, monitor); |
| 361 |
else |
| 362 |
wsdlFile.create(baInputStream, IFile.FORCE, monitor); |
| 363 |
} catch (CoreException e) |
| 364 |
{ |
| 365 |
WsdmToolingLog |
| 366 |
.logError(Messages.FAILED_TO_SAVE_MCAP_FILE_ERROR_, e); |
| 367 |
throw e; |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* It will return the XSD Schema defined inside WSDL Types. If no WSDL |
| 373 |
* Types are defined then this method will create new WSDL Types and |
| 374 |
* will create new XSDSchema and return it. If WSDL Types are defined |
| 375 |
* but no XSDSchema is defined then it will create new XSDSchema and |
| 376 |
* return it. |
| 377 |
* |
| 378 |
* @param definition |
| 379 |
* WSDL Definition object. |
| 380 |
* |
| 381 |
* @param tns |
| 382 |
* XSDSchema targetnamespace to be searched. |
| 383 |
* |
| 384 |
* @return XSDSchema object. |
| 385 |
*/ |
| 386 |
public static XSDSchema createOrFindSchema(Definition definition, String tns) |
| 387 |
{ |
| 388 |
XSDSchema[] schemas = getXSDSchemas(definition); |
| 389 |
if (schemas == null) |
| 390 |
{ |
| 391 |
// No WSDL Types found |
| 392 |
Types types = WSDLFactory.eINSTANCE.createTypes(); |
| 393 |
definition.setETypes(types); |
| 394 |
types.setEnclosingDefinition(definition); |
| 395 |
} |
| 396 |
else |
| 397 |
{ |
| 398 |
// Some schemas exists |
| 399 |
for (int i = 0; i < schemas.length; i++) |
| 400 |
{ |
| 401 |
if (schemas[i].getTargetNamespace().equals(tns)) |
| 402 |
return schemas[i]; |
| 403 |
} |
| 404 |
} |
| 405 |
XSDSchema schema = XsdUtils.createNewXSDSchema(tns); |
| 406 |
XSDSchemaExtensibilityElement schemaElement = WSDLFactory.eINSTANCE |
| 407 |
.createXSDSchemaExtensibilityElement(); |
| 408 |
schemaElement.setEnclosingDefinition(definition); |
| 409 |
schemaElement.setSchema(schema); |
| 410 |
definition.getTypes().addExtensibilityElement(schemaElement); |
| 411 |
return schema; |
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* Returns the XSDSchema of WSDL Definition based on the namespace |
| 416 |
* passed. |
| 417 |
*/ |
| 418 |
public static XSDSchema getSchema(Definition definition, String tns) |
| 419 |
{ |
| 420 |
XSDSchema[] schemas = getXSDSchemas(definition); |
| 421 |
if (schemas == null) |
| 422 |
return null; |
| 423 |
for (int i = 0; i < schemas.length; i++) |
| 424 |
{ |
| 425 |
String schemaTns = schemas[i].getTargetNamespace(); |
| 426 |
if (schemaTns != null |
| 427 |
&& schemas[i].getTargetNamespace().equals(tns)) |
| 428 |
return schemas[i]; |
| 429 |
} |
| 430 |
|
| 431 |
// Some of the schemas in WSDL could be defined as |
| 432 |
// <xsd:schema> |
| 433 |
// <xsd:import namespace="http://docs.oasis-open.org/wsrf/rp-2" |
| 434 |
// schemaLocation="WS-ResourceProperties-1_2.xsd" /> |
| 435 |
// </xsd:schema> |
| 436 |
// We have to handle such type of case |
| 437 |
|
| 438 |
for (int i = 0; i < schemas.length; i++) |
| 439 |
{ |
| 440 |
XSDImport[] imports = XsdUtils.getAllXSDImports(schemas[i]); |
| 441 |
for (int j = 0; j < imports.length; j++) |
| 442 |
{ |
| 443 |
if (imports[j].getNamespace().equals(tns)) |
| 444 |
return imports[j].getResolvedSchema(); |
| 445 |
} |
| 446 |
|
| 447 |
XSDInclude[] includes = XsdUtils.getAllXSDIncludes(schemas[i]); |
| 448 |
for (int k = 0; k < includes.length; k++) |
| 449 |
{ |
| 450 |
if (includes[k].getResolvedSchema().getTargetNamespace() |
| 451 |
.equals(tns)) |
| 452 |
return includes[k].getResolvedSchema(); |
| 453 |
} |
| 454 |
} |
| 455 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 456 |
//WsdmToolingLog.logWarning(NLS.bind(Messages.NO_SCHEMA_FOUND_FOR_NS_WARN_, tns)); |
| 457 |
return null; |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Returns the array of XSDSchema defined in WSDL Definition. |
| 462 |
*/ |
| 463 |
public static XSDSchema[] getXSDSchemas(Definition def) |
| 464 |
{ |
| 465 |
List schemaList = new ArrayList(); |
| 466 |
Types types = (Types) def.getTypes(); |
| 467 |
if (types == null) |
| 468 |
{ |
| 469 |
WsdmToolingLog.logWarning(Messages.NO_TYPES_FOUND_ERROR_); |
| 470 |
return null; |
| 471 |
} |
| 472 |
List extList = types.getExtensibilityElements(); |
| 473 |
XSDSchemaExtensibilityElement schemaElement = null; |
| 474 |
Iterator it = extList.iterator(); |
| 475 |
while (it.hasNext()) |
| 476 |
{ |
| 477 |
Object object = it.next(); |
| 478 |
if (object instanceof XSDSchemaExtensibilityElement) |
| 479 |
{ |
| 480 |
schemaElement = (XSDSchemaExtensibilityElement) object; |
| 481 |
XSDSchema schema = schemaElement.getSchema(); |
| 482 |
schemaList.add(schema); |
| 483 |
} |
| 484 |
} |
| 485 |
return (XSDSchema[]) schemaList.toArray(new XSDSchema[0]); |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Returns XSDElementDeclaration for return type of operation. |
| 490 |
*/ |
| 491 |
public static XSDElementDeclaration getReturnTypeElement(Operation operation) |
| 492 |
{ |
| 493 |
if (operation.getEOutput() == null) |
| 494 |
return null; |
| 495 |
if (operation.getEOutput().getEMessage() == null) |
| 496 |
return null; |
| 497 |
List parts = operation.getEOutput().getEMessage().getEParts(); |
| 498 |
if (parts == null || parts.size() == 0) |
| 499 |
return null; |
| 500 |
Part part_0 = (Part) parts.get(0); |
| 501 |
return part_0.getElementDeclaration(); |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* Returns Message part for return type of operation. |
| 506 |
*/ |
| 507 |
public static Part getReturnTypeMessagePart(Operation operation) |
| 508 |
{ |
| 509 |
if (operation.getEOutput() == null) |
| 510 |
return null; |
| 511 |
if (operation.getEOutput().getEMessage() == null) |
| 512 |
return null; |
| 513 |
List parts = operation.getEOutput().getEMessage().getEParts(); |
| 514 |
if (parts == null || parts.size() == 0) |
| 515 |
return null; |
| 516 |
Part part_0 = (Part) parts.get(0); |
| 517 |
return part_0; |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Returns the operation parameters as XSDElementDeclaration. |
| 522 |
*/ |
| 523 |
public static XSDElementDeclaration[] getOperationParams(Operation operation) |
| 524 |
{ |
| 525 |
XSDElementDeclaration[] empty_param = new XSDElementDeclaration[0]; |
| 526 |
if (operation.getEInput() == null) |
| 527 |
return empty_param; |
| 528 |
if (operation.getEInput().getEMessage() == null) |
| 529 |
return empty_param; |
| 530 |
List parts = operation.getEInput().getEMessage().getEParts(); |
| 531 |
if (parts == null || parts.size() == 0) |
| 532 |
return empty_param; |
| 533 |
|
| 534 |
Part part_0 = (Part) operation.getEInput().getEMessage().getEParts() |
| 535 |
.get(0); |
| 536 |
XSDElementDeclaration element = part_0.getElementDeclaration(); |
| 537 |
XSDTypeDefinition typeDefinition = element.getTypeDefinition(); |
| 538 |
if (typeDefinition == null) |
| 539 |
return empty_param; |
| 540 |
if (typeDefinition instanceof XSDComplexTypeDefinition) |
| 541 |
{ |
| 542 |
XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) typeDefinition; |
| 543 |
XSDModelGroup modelGroup = XsdUtils |
| 544 |
.getXSDModelGroup(complexTypeDefinition); |
| 545 |
return XsdUtils.getElementDeclarations(modelGroup); |
| 546 |
} |
| 547 |
return new XSDElementDeclaration[] { element }; |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* Returns the namespace of given prefix. |
| 552 |
*/ |
| 553 |
public static String getNamespace(Definition definition, String prefix) |
| 554 |
{ |
| 555 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 556 |
for (int i = 0; i < map.getLength(); i++) |
| 557 |
{ |
| 558 |
if (map.item(i) instanceof Attr) |
| 559 |
{ |
| 560 |
Attr attribute = (Attr) map.item(i); |
| 561 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 562 |
{ |
| 563 |
String pfx = attribute.getNodeName().substring( |
| 564 |
"xmlns:".length()); |
| 565 |
if (pfx.equals(prefix)) |
| 566 |
return attribute.getNodeValue(); |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
WsdmToolingLog.logWarning(NLS.bind( |
| 571 |
Messages.NO_NS_FOUND_FOR_PREFIX_WARN_, prefix)); |
| 572 |
return null; |
| 573 |
} |
| 574 |
|
| 575 |
/** |
| 576 |
* Returns the prefix for given namespace in WSDL Definition. |
| 577 |
*/ |
| 578 |
public static String getPrefix(Definition definition, String namespace) |
| 579 |
{ |
| 580 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 581 |
for (int i = 0; i < map.getLength(); i++) |
| 582 |
{ |
| 583 |
if (map.item(i) instanceof Attr) |
| 584 |
{ |
| 585 |
Attr attribute = (Attr) map.item(i); |
| 586 |
if (attribute.getNodeValue().equals(namespace)) |
| 587 |
{ |
| 588 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 589 |
{ |
| 590 |
String prefix = attribute.getNodeName().substring( |
| 591 |
"xmlns:".length()); |
| 592 |
return prefix; |
| 593 |
} |
| 594 |
} |
368 |
} |
| 595 |
} |
|
|
| 596 |
} |
369 |
} |
| 597 |
WsdmToolingLog.logWarning(NLS.bind( |
370 |
|
| 598 |
Messages.NO_PREFIX_FOUND_FOR_NS_WARN_, namespace)); |
371 |
/** |
| 599 |
return null; |
372 |
* It will return the XSD Schema defined inside WSDL Types. If no WSDL Types |
| 600 |
} |
373 |
* are defined then this method will create new WSDL Types and will create |
| 601 |
|
374 |
* new XSDSchema and return it. If WSDL Types are defined but no XSDSchema |
| 602 |
/** |
375 |
* is defined then it will create new XSDSchema and return it. |
| 603 |
* Returns true if perticular namespace defined inside WSDL definition. |
376 |
* |
| 604 |
*/ |
377 |
* @param definition |
| 605 |
public static boolean isNamespaceDefined(Definition definition, |
378 |
* WSDL Definition object. |
| 606 |
String namespace) |
379 |
* |
| 607 |
{ |
380 |
* @param tns |
| 608 |
if (getPrefix(definition, namespace) == null) |
381 |
* XSDSchema targetnamespace to be searched. |
| 609 |
return false; |
382 |
* |
| 610 |
return true; |
383 |
* @return XSDSchema object. |
| 611 |
} |
384 |
*/ |
| 612 |
|
385 |
public static XSDSchema createOrFindSchema(Definition definition, String tns) |
| 613 |
/** |
|
|
| 614 |
* Returns the WSDL targetnamespace prefix. |
| 615 |
*/ |
| 616 |
public static String getTargetNamespacePrefix(Definition def) |
| 617 |
{ |
| 618 |
return getPrefix(def, def.getTargetNamespace()); |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Returns ResourcePropertyElement from WSDL Definition. |
| 623 |
*/ |
| 624 |
public static XSDElementDeclaration getResourcePropertyElement( |
| 625 |
Definition definition, String resourceProperties) |
| 626 |
{ |
| 627 |
String rpNsPrefix = null; |
| 628 |
String elementName = resourceProperties; |
| 629 |
if (resourceProperties.indexOf(":") != -1) |
| 630 |
{ |
| 631 |
rpNsPrefix = resourceProperties.substring(0, resourceProperties |
| 632 |
.indexOf(":")); |
| 633 |
elementName = resourceProperties.substring(resourceProperties |
| 634 |
.indexOf(":") + 1); |
| 635 |
} |
| 636 |
XSDSchema xsdSchema = null; |
| 637 |
if (rpNsPrefix == null) |
| 638 |
{ |
| 639 |
xsdSchema = getSchema(definition, definition.getTargetNamespace()); |
| 640 |
} |
| 641 |
else |
| 642 |
{ |
| 643 |
String ns = getNamespace(definition, rpNsPrefix); |
| 644 |
xsdSchema = getSchema(definition, ns); |
| 645 |
} |
| 646 |
|
| 647 |
XSDElementDeclaration resourcePropertyElement = XsdUtils |
| 648 |
.getXSDElementDeclarationOfName(xsdSchema, elementName); |
| 649 |
if (resourcePropertyElement == null) |
| 650 |
WsdmToolingLog.logMessage(Messages.NO_RP_ELEMENT_ERROR_); |
| 651 |
return resourcePropertyElement; |
| 652 |
} |
| 653 |
|
| 654 |
/** |
| 655 |
* Returns the MetadataMap from WSDL port type.<br> |
| 656 |
* This map contain values for resource properties, metadatadescriptor |
| 657 |
* and metadatadescriptorlocation. |
| 658 |
* @throws CoreException |
| 659 |
* @throws IOException |
| 660 |
* @throws SAXException |
| 661 |
*/ |
| 662 |
public static Map getMetadataFromPortType(IFile wsdlFile) throws CoreException, IOException, SAXException |
| 663 |
{ |
| 664 |
Map map = new HashMap(); |
| 665 |
InputStream is = null; |
| 666 |
Document document = null; |
| 667 |
try |
| 668 |
{ |
| 669 |
is = wsdlFile.getContents(); |
| 670 |
document = XmlUtils.createDocument(is); |
| 671 |
} catch (CoreException e) |
| 672 |
{ |
| 673 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 674 |
throw e; |
| 675 |
} catch (IOException e) |
| 676 |
{ |
| 677 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 678 |
throw e; |
| 679 |
} catch (SAXException e) |
| 680 |
{ |
| 681 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 682 |
throw e; |
| 683 |
} |
| 684 |
|
| 685 |
NodeList nlpt = document.getElementsByTagNameNS( |
| 686 |
WsdlConstants.WSDL_NAMESPACE_URI, "portType"); |
| 687 |
Element pte = (Element) nlpt.item(0); |
| 688 |
if (pte == null) |
| 689 |
WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 690 |
|
| 691 |
String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS, |
| 692 |
METADATA_DESCRIPTOR_KEY); |
| 693 |
if (metadataDescriptor == null || metadataDescriptor.equals("")) |
| 694 |
WsdmToolingLog.logMessage(Messages.NO_METADESCRIPTOR_WARN_); |
| 695 |
else |
| 696 |
map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor); |
| 697 |
|
| 698 |
String metadataDescriptorLocation = pte.getAttributeNS( |
| 699 |
WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY); |
| 700 |
if (metadataDescriptorLocation == null |
| 701 |
|| metadataDescriptorLocation.equals("")) |
| 702 |
WsdmToolingLog |
| 703 |
.logMessage(Messages.NO_METADESCRIPTOR_LOCATION_WARN_); |
| 704 |
else |
| 705 |
map.put(METADATA_DESCRIPTOR_LOCATION_KEY, |
| 706 |
metadataDescriptorLocation); |
| 707 |
|
| 708 |
String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS, |
| 709 |
RESOURCE_PROPERTIES_ELEMENT_KEY); |
| 710 |
if (resourceProperties == null || resourceProperties.equals("")) |
| 711 |
WsdmToolingLog.logMessage(Messages.NO_RP_ATTRIBUTE_WARN_); |
| 712 |
else |
| 713 |
map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties); |
| 714 |
|
| 715 |
return map; |
| 716 |
} |
| 717 |
|
| 718 |
/** |
| 719 |
* Returns the MetadataMap from WSDL port type.<br> |
| 720 |
* This map contain values for resource properties, metadatadescriptor |
| 721 |
* and metadatadescriptorlocation. |
| 722 |
*/ |
| 723 |
public static Map getMetadataFromPortType(Definition wsdlDefinition) |
| 724 |
{ |
| 725 |
Map map = new HashMap(); |
| 726 |
Element wsdlElement = wsdlDefinition.getElement(); |
| 727 |
|
| 728 |
NodeList nlpt = wsdlElement.getElementsByTagNameNS( |
| 729 |
WsdlConstants.WSDL_NAMESPACE_URI, "portType"); |
| 730 |
Element pte = (Element) nlpt.item(0); |
| 731 |
if (pte == null) |
| 732 |
{ |
| 733 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 734 |
//WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 735 |
return null; |
| 736 |
} |
| 737 |
|
| 738 |
String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS, |
| 739 |
METADATA_DESCRIPTOR_KEY); |
| 740 |
if (metadataDescriptor == null || metadataDescriptor.equals("")) |
| 741 |
{ |
| 742 |
metadataDescriptor = null; |
| 743 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 744 |
//WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_WARN_); |
| 745 |
} |
| 746 |
|
| 747 |
String metadataDescriptorLocation = pte.getAttributeNS( |
| 748 |
WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY); |
| 749 |
if (metadataDescriptorLocation == null |
| 750 |
|| metadataDescriptorLocation.equals("")) |
| 751 |
{ |
| 752 |
metadataDescriptorLocation = null; |
| 753 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 754 |
//WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_LOCATION_WARN_); |
| 755 |
} |
| 756 |
|
| 757 |
String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS, |
| 758 |
RESOURCE_PROPERTIES_ELEMENT_KEY); |
| 759 |
if (resourceProperties == null || resourceProperties.equals("")) |
| 760 |
{ |
| 761 |
resourceProperties = null; |
| 762 |
// Don't log message in Error log it will go to problems view while validating mcap files |
| 763 |
//WsdmToolingLog.logWarning(Messages.NO_RP_ATTRIBUTE_WARN_); |
| 764 |
} |
| 765 |
|
| 766 |
map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor); |
| 767 |
map.put(METADATA_DESCRIPTOR_LOCATION_KEY, metadataDescriptorLocation); |
| 768 |
map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties); |
| 769 |
|
| 770 |
return map; |
| 771 |
} |
| 772 |
|
| 773 |
/** |
| 774 |
* Returns the WSDLFileLocation from WSDL Definition. |
| 775 |
*/ |
| 776 |
public static String getWSDLFileLocation(Definition definition) |
| 777 |
{ |
| 778 |
if (definition.getLocation() != null |
| 779 |
&& !definition.getLocation().equals("")) |
| 780 |
return definition.getLocation(); |
| 781 |
Resource resource = definition.eResource(); |
| 782 |
if (resource == null) |
| 783 |
{ |
| 784 |
WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_); |
| 785 |
return null; |
| 786 |
} |
| 787 |
URI uri = resource.getURI(); |
| 788 |
if (uri == null) |
| 789 |
{ |
| 790 |
WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_); |
| 791 |
return null; |
| 792 |
} |
| 793 |
return uri.toString(); |
| 794 |
} |
| 795 |
|
| 796 |
/** |
| 797 |
* Creates or return existing prefix. If the passed newPrefix is null, |
| 798 |
* the it generates a unique prefix for the namespace. |
| 799 |
*/ |
| 800 |
public static String createOrFindPrefix(Definition definition, |
| 801 |
String namespace, String newPrefix) |
| 802 |
{ |
| 803 |
String prefix = getPrefix(definition, namespace); |
| 804 |
if (prefix != null) |
| 805 |
return prefix; |
| 806 |
if (newPrefix != null) |
| 807 |
definition.addNamespace(newPrefix, namespace); |
| 808 |
else |
| 809 |
{ |
| 810 |
newPrefix = generateNewPrefix(definition); |
| 811 |
definition.addNamespace(newPrefix, namespace); |
| 812 |
} |
| 813 |
return newPrefix; |
| 814 |
} |
| 815 |
|
| 816 |
private static String generateNewPrefix(Definition definition) |
| 817 |
{ |
| 818 |
int count = 0; |
| 819 |
String prefix = "pfx" + count; |
| 820 |
while (isPrefixDefined(definition, prefix)) |
| 821 |
{ |
| 822 |
prefix = "pfx" + count++; |
| 823 |
} |
| 824 |
return prefix; |
| 825 |
} |
| 826 |
|
| 827 |
private static boolean isPrefixDefined(Definition definition, String prefix) |
| 828 |
{ |
| 829 |
String[] namespaces = getAllDefinedNamespaces(definition); |
| 830 |
for (int i = 0; i < namespaces.length; i++) |
| 831 |
{ |
386 |
{ |
| 832 |
String pfx = getPrefix(definition, namespaces[i]); |
387 |
XSDSchema[] schemas = getXSDSchemas(definition); |
| 833 |
if (pfx.equals(prefix)) |
388 |
if (schemas == null) |
| 834 |
return true; |
389 |
{ |
|
|
390 |
// No WSDL Types found |
| 391 |
Types types = WSDLFactory.eINSTANCE.createTypes(); |
| 392 |
definition.setETypes(types); |
| 393 |
types.setEnclosingDefinition(definition); |
| 394 |
} |
| 395 |
else |
| 396 |
{ |
| 397 |
// Some schemas exists |
| 398 |
for (int i = 0; i < schemas.length; i++) |
| 399 |
{ |
| 400 |
if (schemas[i].getTargetNamespace().equals(tns)) |
| 401 |
return schemas[i]; |
| 402 |
} |
| 403 |
} |
| 404 |
XSDSchema schema = XsdUtils.createNewXSDSchema(tns); |
| 405 |
XSDSchemaExtensibilityElement schemaElement = WSDLFactory.eINSTANCE |
| 406 |
.createXSDSchemaExtensibilityElement(); |
| 407 |
schemaElement.setEnclosingDefinition(definition); |
| 408 |
schemaElement.setSchema(schema); |
| 409 |
definition.getTypes().addExtensibilityElement(schemaElement); |
| 410 |
return schema; |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* Returns the XSDSchema of WSDL Definition based on the namespace passed. |
| 415 |
*/ |
| 416 |
public static XSDSchema getSchema(Definition definition, String tns) |
| 417 |
{ |
| 418 |
XSDSchema[] schemas = getXSDSchemas(definition); |
| 419 |
if (schemas == null) |
| 420 |
return null; |
| 421 |
for (int i = 0; i < schemas.length; i++) |
| 422 |
{ |
| 423 |
String schemaTns = schemas[i].getTargetNamespace(); |
| 424 |
if (schemaTns != null |
| 425 |
&& schemas[i].getTargetNamespace().equals(tns)) |
| 426 |
return schemas[i]; |
| 427 |
} |
| 428 |
|
| 429 |
// Some of the schemas in WSDL could be defined as |
| 430 |
// <xsd:schema> |
| 431 |
// <xsd:import namespace="http://docs.oasis-open.org/wsrf/rp-2" |
| 432 |
// schemaLocation="WS-ResourceProperties-1_2.xsd" /> |
| 433 |
// </xsd:schema> |
| 434 |
// We have to handle such type of case |
| 435 |
|
| 436 |
for (int i = 0; i < schemas.length; i++) |
| 437 |
{ |
| 438 |
XSDImport[] imports = XsdUtils.getAllXSDImports(schemas[i]); |
| 439 |
for (int j = 0; j < imports.length; j++) |
| 440 |
{ |
| 441 |
if (imports[j].getNamespace().equals(tns)) |
| 442 |
return imports[j].getResolvedSchema(); |
| 443 |
} |
| 444 |
|
| 445 |
XSDInclude[] includes = XsdUtils.getAllXSDIncludes(schemas[i]); |
| 446 |
for (int k = 0; k < includes.length; k++) |
| 447 |
{ |
| 448 |
if (includes[k].getResolvedSchema().getTargetNamespace() |
| 449 |
.equals(tns)) |
| 450 |
return includes[k].getResolvedSchema(); |
| 451 |
} |
| 452 |
} |
| 453 |
// Don't log message in Error log it will go to problems view while |
| 454 |
// validating mcap files |
| 455 |
// WsdmToolingLog.logWarning(NLS.bind(Messages.NO_SCHEMA_FOUND_FOR_NS_WARN_, |
| 456 |
// tns)); |
| 457 |
return null; |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Returns the array of XSDSchema defined in WSDL Definition. |
| 462 |
*/ |
| 463 |
public static XSDSchema[] getXSDSchemas(Definition def) |
| 464 |
{ |
| 465 |
List schemaList = new ArrayList(); |
| 466 |
Types types = (Types) def.getTypes(); |
| 467 |
if (types == null) |
| 468 |
{ |
| 469 |
WsdmToolingLog.logWarning(Messages.NO_TYPES_FOUND_ERROR_); |
| 470 |
return null; |
| 471 |
} |
| 472 |
List extList = types.getExtensibilityElements(); |
| 473 |
XSDSchemaExtensibilityElement schemaElement = null; |
| 474 |
Iterator it = extList.iterator(); |
| 475 |
while (it.hasNext()) |
| 476 |
{ |
| 477 |
Object object = it.next(); |
| 478 |
if (object instanceof XSDSchemaExtensibilityElement) |
| 479 |
{ |
| 480 |
schemaElement = (XSDSchemaExtensibilityElement) object; |
| 481 |
XSDSchema schema = schemaElement.getSchema(); |
| 482 |
schemaList.add(schema); |
| 483 |
} |
| 484 |
} |
| 485 |
return (XSDSchema[]) schemaList.toArray(new XSDSchema[0]); |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Returns XSDElementDeclaration for return type of operation. |
| 490 |
*/ |
| 491 |
public static XSDElementDeclaration getReturnTypeElement(Operation operation) |
| 492 |
{ |
| 493 |
if (operation.getEOutput() == null) |
| 494 |
return null; |
| 495 |
if (operation.getEOutput().getEMessage() == null) |
| 496 |
return null; |
| 497 |
List parts = operation.getEOutput().getEMessage().getEParts(); |
| 498 |
if (parts == null || parts.size() == 0) |
| 499 |
return null; |
| 500 |
Part part_0 = (Part) parts.get(0); |
| 501 |
return part_0.getElementDeclaration(); |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* Returns Message part for return type of operation. |
| 506 |
*/ |
| 507 |
public static Part getReturnTypeMessagePart(Operation operation) |
| 508 |
{ |
| 509 |
if (operation.getEOutput() == null) |
| 510 |
return null; |
| 511 |
if (operation.getEOutput().getEMessage() == null) |
| 512 |
return null; |
| 513 |
List parts = operation.getEOutput().getEMessage().getEParts(); |
| 514 |
if (parts == null || parts.size() == 0) |
| 515 |
return null; |
| 516 |
Part part_0 = (Part) parts.get(0); |
| 517 |
return part_0; |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Returns the operation parameters as XSDElementDeclaration. |
| 522 |
*/ |
| 523 |
public static XSDElementDeclaration[] getOperationParams(Operation operation) |
| 524 |
{ |
| 525 |
XSDElementDeclaration[] empty_param = new XSDElementDeclaration[0]; |
| 526 |
if (operation.getEInput() == null) |
| 527 |
return empty_param; |
| 528 |
if (operation.getEInput().getEMessage() == null) |
| 529 |
return empty_param; |
| 530 |
List parts = operation.getEInput().getEMessage().getEParts(); |
| 531 |
if (parts == null || parts.size() == 0) |
| 532 |
return empty_param; |
| 533 |
|
| 534 |
Part part_0 = (Part) operation.getEInput().getEMessage().getEParts() |
| 535 |
.get(0); |
| 536 |
XSDElementDeclaration element = part_0.getElementDeclaration(); |
| 537 |
XSDTypeDefinition typeDefinition = element.getTypeDefinition(); |
| 538 |
if (typeDefinition == null) |
| 539 |
return empty_param; |
| 540 |
if (typeDefinition instanceof XSDComplexTypeDefinition) |
| 541 |
{ |
| 542 |
XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) typeDefinition; |
| 543 |
XSDModelGroup modelGroup = XsdUtils |
| 544 |
.getXSDModelGroup(complexTypeDefinition); |
| 545 |
return XsdUtils.getElementDeclarations(modelGroup); |
| 546 |
} |
| 547 |
return new XSDElementDeclaration[] { element }; |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* Returns the namespace of given prefix. |
| 552 |
*/ |
| 553 |
public static String getNamespace(Definition definition, String prefix) |
| 554 |
{ |
| 555 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 556 |
for (int i = 0; i < map.getLength(); i++) |
| 557 |
{ |
| 558 |
if (map.item(i) instanceof Attr) |
| 559 |
{ |
| 560 |
Attr attribute = (Attr) map.item(i); |
| 561 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 562 |
{ |
| 563 |
String pfx = attribute.getNodeName().substring( |
| 564 |
"xmlns:".length()); |
| 565 |
if (pfx.equals(prefix)) |
| 566 |
return attribute.getNodeValue(); |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
WsdmToolingLog.logWarning(NLS.bind( |
| 571 |
Messages.NO_NS_FOUND_FOR_PREFIX_WARN_, prefix)); |
| 572 |
return null; |
| 573 |
} |
| 574 |
|
| 575 |
/** |
| 576 |
* Returns the prefix for given namespace in WSDL Definition. |
| 577 |
*/ |
| 578 |
public static String getPrefix(Definition definition, String namespace) |
| 579 |
{ |
| 580 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 581 |
for (int i = 0; i < map.getLength(); i++) |
| 582 |
{ |
| 583 |
if (map.item(i) instanceof Attr) |
| 584 |
{ |
| 585 |
Attr attribute = (Attr) map.item(i); |
| 586 |
if (attribute.getNodeValue().equals(namespace)) |
| 587 |
{ |
| 588 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 589 |
{ |
| 590 |
String prefix = attribute.getNodeName().substring( |
| 591 |
"xmlns:".length()); |
| 592 |
return prefix; |
| 593 |
} |
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
WsdmToolingLog.logWarning(NLS.bind( |
| 598 |
Messages.NO_PREFIX_FOUND_FOR_NS_WARN_, namespace)); |
| 599 |
return null; |
| 835 |
} |
600 |
} |
| 836 |
return false; |
|
|
| 837 |
} |
| 838 |
|
601 |
|
| 839 |
/** |
602 |
/** |
| 840 |
* Returns all the namespaces defined in the WSDL file. |
603 |
* Returns true if perticular namespace defined inside WSDL definition. |
| 841 |
*/ |
604 |
*/ |
| 842 |
public static String[] getAllDefinedNamespaces(Definition definition) |
605 |
public static boolean isNamespaceDefined(Definition definition, |
| 843 |
{ |
606 |
String namespace) |
| 844 |
List namespaces = new ArrayList(); |
|
|
| 845 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 846 |
for (int i = 0; i < map.getLength(); i++) |
| 847 |
{ |
| 848 |
if (map.item(i) instanceof Attr) |
| 849 |
{ |
| 850 |
Attr attribute = (Attr) map.item(i); |
| 851 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 852 |
{ |
| 853 |
String ns = attribute.getNodeValue(); |
| 854 |
namespaces.add(ns); |
| 855 |
} |
| 856 |
} |
| 857 |
} |
| 858 |
return (String[]) namespaces.toArray(new String[namespaces.size()]); |
| 859 |
} |
| 860 |
|
| 861 |
/** |
| 862 |
* Returns the fault name of given faultElement. |
| 863 |
*/ |
| 864 |
public static String getFaultType(XSDElementDeclaration faultElement) |
| 865 |
{ |
| 866 |
String default_type = faultElement.getName(); |
| 867 |
XSDTypeDefinition typeDef = faultElement.getTypeDefinition(); |
| 868 |
if (typeDef == null) |
| 869 |
return default_type; |
| 870 |
if (!(typeDef instanceof XSDComplexTypeDefinition)) |
| 871 |
return default_type; |
| 872 |
XSDComplexTypeDefinition complexTypeDef = (XSDComplexTypeDefinition) typeDef; |
| 873 |
XSDDerivationMethod derivationMethod = complexTypeDef |
| 874 |
.getDerivationMethod(); |
| 875 |
if (derivationMethod == null) |
| 876 |
return default_type; |
| 877 |
if (!derivationMethod.equals(XSDDerivationMethod.EXTENSION_LITERAL)) |
| 878 |
return default_type; |
| 879 |
XSDTypeDefinition baseTypeDef = complexTypeDef.getBaseTypeDefinition(); |
| 880 |
if (baseTypeDef == null) |
| 881 |
return default_type; |
| 882 |
if (!(baseTypeDef instanceof XSDSimpleTypeDefinition)) |
| 883 |
return default_type; |
| 884 |
XSDSimpleTypeDefinition simpleBaseTypeDef = (XSDSimpleTypeDefinition) baseTypeDef; |
| 885 |
return simpleBaseTypeDef.getName(); |
| 886 |
} |
| 887 |
|
| 888 |
/** |
| 889 |
* Returns the XSD fault elements of given wsdl operation. |
| 890 |
*/ |
| 891 |
public static List getOperationFaultElements(Operation operation) |
| 892 |
{ |
| 893 |
List retVal = new ArrayList(); |
| 894 |
List faults = operation.getEFaults(); |
| 895 |
for (int i = 0; i < faults.size(); i++) |
| 896 |
{ |
| 897 |
Fault fault = (Fault) faults.get(i); |
| 898 |
XSDElementDeclaration faultElement = getFaultElement(fault); |
| 899 |
if (faultElement != null) |
| 900 |
retVal.add(faultElement); |
| 901 |
} |
| 902 |
return retVal; |
| 903 |
} |
| 904 |
|
| 905 |
/** |
| 906 |
* Retruns the XSD fault elements of given wsdl fault. |
| 907 |
*/ |
| 908 |
public static XSDElementDeclaration getFaultElement(Fault fault) |
| 909 |
{ |
| 910 |
Message msg = fault.getEMessage(); |
| 911 |
Part part_0 = (Part) msg.getEParts().get(0); |
| 912 |
XSDElementDeclaration element = part_0.getElementDeclaration(); |
| 913 |
return element; |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* Returns the message which contains the given XSDElementDeclaration. |
| 918 |
*/ |
| 919 |
public static Message getMessage(Definition definition, |
| 920 |
XSDElementDeclaration element) |
| 921 |
{ |
| 922 |
List msgs = definition.getEMessages(); |
| 923 |
for (int i = 0; i < msgs.size(); i++) |
| 924 |
{ |
| 925 |
Message msg = (Message) msgs.get(i); |
| 926 |
Part part = getPart(msg, element); |
| 927 |
if (part != null) |
| 928 |
return msg; |
| 929 |
} |
| 930 |
return null; |
| 931 |
} |
| 932 |
|
| 933 |
private static Part getPart(Message msg, XSDElementDeclaration element) |
| 934 |
{ |
| 935 |
List parts = msg.getEParts(); |
| 936 |
for (int i = 0; i < parts.size(); i++) |
| 937 |
{ |
| 938 |
Part part = (Part) parts.get(i); |
| 939 |
XSDElementDeclaration partElement = part.getElementDeclaration(); |
| 940 |
if (element.equals(partElement)) |
| 941 |
return part; |
| 942 |
} |
| 943 |
return null; |
| 944 |
} |
| 945 |
|
| 946 |
/** |
| 947 |
* Returns the Fault of given Message. |
| 948 |
*/ |
| 949 |
public static Fault getFault(Operation operation, Message message) |
| 950 |
{ |
| 951 |
List faults = operation.getEFaults(); |
| 952 |
for (int i = 0; i < faults.size(); i++) |
| 953 |
{ |
| 954 |
Fault fault = (Fault) faults.get(i); |
| 955 |
Message msg = fault.getEMessage(); |
| 956 |
if (message.equals(msg)) |
| 957 |
return fault; |
| 958 |
} |
| 959 |
return null; |
| 960 |
} |
| 961 |
|
| 962 |
/** |
| 963 |
* Returns the name of WSDL Definition. |
| 964 |
*/ |
| 965 |
public static String getName(Definition wsdlDef) |
| 966 |
{ |
| 967 |
return wsdlDef.getQName().getLocalPart(); |
| 968 |
} |
| 969 |
|
| 970 |
/** |
| 971 |
* Create a new WSDL Import element inside given Definition. If imported |
| 972 |
* namespace or wsdlLocation is null then it does nothing. If imported |
| 973 |
* namespace is already imported in one of the WSDL Import element of |
| 974 |
* the WSDL then it does nothing. |
| 975 |
* |
| 976 |
* @param definition |
| 977 |
* Given WSDL definition inside which this new WSDL |
| 978 |
* Import element will be added. |
| 979 |
* |
| 980 |
* @param namespace |
| 981 |
* Namespace to be imported. |
| 982 |
* |
| 983 |
* @param wsdlLocation |
| 984 |
* WSDL location to be imported. |
| 985 |
*/ |
| 986 |
public static void createWSDLImport(Definition definition, |
| 987 |
String namespace, String wsdlLocation) |
| 988 |
{ |
| 989 |
if (namespace == null || wsdlLocation == null) |
| 990 |
return; |
| 991 |
/* |
| 992 |
* if (definition.getTargetNamespace().equals(namespace)) return; |
| 993 |
*/ |
| 994 |
if (!isImportNSExists(definition, namespace)) |
| 995 |
{ |
| 996 |
Import wsdlImport = WSDLFactory.eINSTANCE.createImport(); |
| 997 |
wsdlImport.setEnclosingDefinition(definition); |
| 998 |
wsdlImport.setEDefinition(definition); |
| 999 |
wsdlImport.setLocationURI(wsdlLocation); |
| 1000 |
wsdlImport.setNamespaceURI(namespace); |
| 1001 |
definition.addImport(wsdlImport); |
| 1002 |
createOrFindPrefix(definition, namespace, null); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
/** |
| 1007 |
* Check if perticular import already exists in given WSDL definition. |
| 1008 |
*/ |
| 1009 |
public static boolean isImportNSExists(Definition definition, |
| 1010 |
String namespace) |
| 1011 |
{ |
| 1012 |
List imports = definition.getEImports(); |
| 1013 |
for (int i = 0; i < imports.size(); i++) |
| 1014 |
{ |
607 |
{ |
| 1015 |
Import wsdlImport = (Import) imports.get(i); |
608 |
if (getPrefix(definition, namespace) == null) |
| 1016 |
if (wsdlImport.getNamespaceURI().equals(namespace)) |
609 |
return false; |
| 1017 |
return true; |
610 |
return true; |
| 1018 |
} |
611 |
} |
| 1019 |
return false; |
|
|
| 1020 |
} |
| 1021 |
|
612 |
|
| 1022 |
/** |
613 |
/** |
| 1023 |
* Returns the absolute path of given WSDL defintion in the local file |
614 |
* Returns the WSDL targetnamespace prefix. |
| 1024 |
* system. |
615 |
*/ |
| 1025 |
* @throws CoreException |
616 |
public static String getTargetNamespacePrefix(Definition def) |
| 1026 |
*/ |
617 |
{ |
| 1027 |
public static String getLocalSystemWSDLLocation(Definition definition) throws CoreException |
618 |
return getPrefix(def, def.getTargetNamespace()); |
| 1028 |
{ |
619 |
} |
| 1029 |
String uriLocation = getWSDLFileLocation(definition); |
620 |
|
| 1030 |
String wsdlLocation = uriLocation; |
621 |
/** |
| 1031 |
try |
622 |
* Returns ResourcePropertyElement from WSDL Definition. |
| 1032 |
{ |
623 |
*/ |
| 1033 |
IFile wsdlFile = EclipseUtils.getIFile(uriLocation); |
624 |
public static XSDElementDeclaration getResourcePropertyElement( |
| 1034 |
wsdlLocation = wsdlFile.getLocation().toString(); |
625 |
Definition definition, String resourceProperties) |
| 1035 |
wsdlLocation = EclipseUtils.replaceAll(wsdlLocation, '\\', '/'); |
626 |
{ |
| 1036 |
} catch (CoreException e) |
627 |
String rpNsPrefix = null; |
| 1037 |
{ |
628 |
String elementName = resourceProperties; |
| 1038 |
WsdmToolingLog |
629 |
if (resourceProperties.indexOf(":") != -1) |
| 1039 |
.logError( |
630 |
{ |
| 1040 |
NLS |
631 |
rpNsPrefix = resourceProperties.substring(0, resourceProperties |
| 1041 |
.bind( |
632 |
.indexOf(":")); |
| 1042 |
org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages.FAILED_TO_FIND_LOCATION_FOR_XSD_ERROR_, |
633 |
elementName = resourceProperties.substring(resourceProperties |
| 1043 |
uriLocation), e); |
634 |
.indexOf(":") + 1); |
| 1044 |
throw e; |
635 |
} |
|
|
636 |
XSDSchema xsdSchema = null; |
| 637 |
if (rpNsPrefix == null) |
| 638 |
{ |
| 639 |
xsdSchema = getSchema(definition, definition.getTargetNamespace()); |
| 640 |
} |
| 641 |
else |
| 642 |
{ |
| 643 |
String ns = getNamespace(definition, rpNsPrefix); |
| 644 |
xsdSchema = getSchema(definition, ns); |
| 645 |
} |
| 646 |
|
| 647 |
XSDElementDeclaration resourcePropertyElement = XsdUtils |
| 648 |
.getXSDElementDeclarationOfName(xsdSchema, elementName); |
| 649 |
if (resourcePropertyElement == null) |
| 650 |
WsdmToolingLog.logMessage(Messages.NO_RP_ELEMENT_ERROR_); |
| 651 |
return resourcePropertyElement; |
| 652 |
} |
| 653 |
|
| 654 |
/** |
| 655 |
* Returns the MetadataMap from WSDL port type.<br> |
| 656 |
* This map contain values for resource properties, metadatadescriptor and |
| 657 |
* metadatadescriptorlocation. |
| 658 |
* |
| 659 |
* @throws CoreException |
| 660 |
* @throws IOException |
| 661 |
* @throws SAXException |
| 662 |
*/ |
| 663 |
public static Map getMetadataFromPortType(IFile wsdlFile) |
| 664 |
throws CoreException, IOException, SAXException |
| 665 |
{ |
| 666 |
Map map = new HashMap(); |
| 667 |
InputStream is = null; |
| 668 |
Document document = null; |
| 669 |
try |
| 670 |
{ |
| 671 |
is = wsdlFile.getContents(); |
| 672 |
document = CapUtils.createDocument(is); |
| 673 |
} catch (CoreException e) |
| 674 |
{ |
| 675 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 676 |
throw e; |
| 677 |
} catch (IOException e) |
| 678 |
{ |
| 679 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 680 |
throw e; |
| 681 |
} catch (SAXException e) |
| 682 |
{ |
| 683 |
WsdmToolingLog.logError(Messages.CANT_PARSE_XML_ERROR_, e); |
| 684 |
throw e; |
| 685 |
} |
| 686 |
|
| 687 |
NodeList nlpt = document.getElementsByTagNameNS( |
| 688 |
WsdlConstants.WSDL_NAMESPACE_URI, "portType"); |
| 689 |
Element pte = (Element) nlpt.item(0); |
| 690 |
if (pte == null) |
| 691 |
WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 692 |
|
| 693 |
String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS, |
| 694 |
METADATA_DESCRIPTOR_KEY); |
| 695 |
if (metadataDescriptor == null || metadataDescriptor.equals("")) |
| 696 |
WsdmToolingLog.logMessage(Messages.NO_METADESCRIPTOR_WARN_); |
| 697 |
else |
| 698 |
map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor); |
| 699 |
|
| 700 |
String metadataDescriptorLocation = pte.getAttributeNS( |
| 701 |
WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY); |
| 702 |
if (metadataDescriptorLocation == null |
| 703 |
|| metadataDescriptorLocation.equals("")) |
| 704 |
WsdmToolingLog |
| 705 |
.logMessage(Messages.NO_METADESCRIPTOR_LOCATION_WARN_); |
| 706 |
else |
| 707 |
map.put(METADATA_DESCRIPTOR_LOCATION_KEY, |
| 708 |
metadataDescriptorLocation); |
| 709 |
|
| 710 |
String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS, |
| 711 |
RESOURCE_PROPERTIES_ELEMENT_KEY); |
| 712 |
if (resourceProperties == null || resourceProperties.equals("")) |
| 713 |
WsdmToolingLog.logMessage(Messages.NO_RP_ATTRIBUTE_WARN_); |
| 714 |
else |
| 715 |
map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties); |
| 716 |
|
| 717 |
return map; |
| 718 |
} |
| 719 |
|
| 720 |
/** |
| 721 |
* Returns the MetadataMap from WSDL port type.<br> |
| 722 |
* This map contain values for resource properties, metadatadescriptor and |
| 723 |
* metadatadescriptorlocation. |
| 724 |
*/ |
| 725 |
public static Map getMetadataFromPortType(Definition wsdlDefinition) |
| 726 |
{ |
| 727 |
Map map = new HashMap(); |
| 728 |
Element wsdlElement = wsdlDefinition.getElement(); |
| 729 |
|
| 730 |
NodeList nlpt = wsdlElement.getElementsByTagNameNS( |
| 731 |
WsdlConstants.WSDL_NAMESPACE_URI, "portType"); |
| 732 |
Element pte = (Element) nlpt.item(0); |
| 733 |
if (pte == null) |
| 734 |
{ |
| 735 |
// Don't log message in Error log it will go to problems view while |
| 736 |
// validating mcap files |
| 737 |
// WsdmToolingLog.logWarning(Messages.PORT_TYPE_NOT_FOUND_ERROR_); |
| 738 |
return null; |
| 739 |
} |
| 740 |
|
| 741 |
String metadataDescriptor = pte.getAttributeNS(WsdmConstants.WSRMD_NS, |
| 742 |
METADATA_DESCRIPTOR_KEY); |
| 743 |
if (metadataDescriptor == null || metadataDescriptor.equals("")) |
| 744 |
{ |
| 745 |
metadataDescriptor = null; |
| 746 |
// Don't log message in Error log it will go to problems view while |
| 747 |
// validating mcap files |
| 748 |
// WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_WARN_); |
| 749 |
} |
| 750 |
|
| 751 |
String metadataDescriptorLocation = pte.getAttributeNS( |
| 752 |
WsdmConstants.WSRMD_NS, METADATA_DESCRIPTOR_LOCATION_KEY); |
| 753 |
if (metadataDescriptorLocation == null |
| 754 |
|| metadataDescriptorLocation.equals("")) |
| 755 |
{ |
| 756 |
metadataDescriptorLocation = null; |
| 757 |
// Don't log message in Error log it will go to problems view while |
| 758 |
// validating mcap files |
| 759 |
// WsdmToolingLog.logWarning(Messages.NO_METADESCRIPTOR_LOCATION_WARN_); |
| 760 |
} |
| 761 |
|
| 762 |
String resourceProperties = pte.getAttributeNS(WsdmConstants.WSRP_NS, |
| 763 |
RESOURCE_PROPERTIES_ELEMENT_KEY); |
| 764 |
if (resourceProperties == null || resourceProperties.equals("")) |
| 765 |
{ |
| 766 |
resourceProperties = null; |
| 767 |
// Don't log message in Error log it will go to problems view while |
| 768 |
// validating mcap files |
| 769 |
// WsdmToolingLog.logWarning(Messages.NO_RP_ATTRIBUTE_WARN_); |
| 770 |
} |
| 771 |
|
| 772 |
map.put(METADATA_DESCRIPTOR_KEY, metadataDescriptor); |
| 773 |
map.put(METADATA_DESCRIPTOR_LOCATION_KEY, metadataDescriptorLocation); |
| 774 |
map.put(RESOURCE_PROPERTIES_ELEMENT_KEY, resourceProperties); |
| 775 |
|
| 776 |
return map; |
| 777 |
} |
| 778 |
|
| 779 |
/** |
| 780 |
* Returns the WSDLFileLocation from WSDL Definition. |
| 781 |
*/ |
| 782 |
public static String getWSDLFileLocation(Definition definition) |
| 783 |
{ |
| 784 |
if (definition.getLocation() != null |
| 785 |
&& !definition.getLocation().equals("")) |
| 786 |
return definition.getLocation(); |
| 787 |
Resource resource = definition.eResource(); |
| 788 |
if (resource == null) |
| 789 |
{ |
| 790 |
WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_); |
| 791 |
return null; |
| 792 |
} |
| 793 |
URI uri = resource.getURI(); |
| 794 |
if (uri == null) |
| 795 |
{ |
| 796 |
WsdmToolingLog.logWarning(Messages.IMPROPER_WSDL_FILE_ERROR_); |
| 797 |
return null; |
| 798 |
} |
| 799 |
return uri.toString(); |
| 800 |
} |
| 801 |
|
| 802 |
/** |
| 803 |
* Creates or return existing prefix. If the passed newPrefix is null, the |
| 804 |
* it generates a unique prefix for the namespace. |
| 805 |
*/ |
| 806 |
public static String createOrFindPrefix(Definition definition, |
| 807 |
String namespace, String newPrefix) |
| 808 |
{ |
| 809 |
String prefix = getPrefix(definition, namespace); |
| 810 |
if (prefix != null) |
| 811 |
return prefix; |
| 812 |
if (newPrefix != null) |
| 813 |
definition.addNamespace(newPrefix, namespace); |
| 814 |
else |
| 815 |
{ |
| 816 |
newPrefix = generateNewPrefix(definition); |
| 817 |
definition.addNamespace(newPrefix, namespace); |
| 818 |
} |
| 819 |
return newPrefix; |
| 1045 |
} |
820 |
} |
| 1046 |
return wsdlLocation; |
|
|
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
821 |
|
|
|
822 |
private static String generateNewPrefix(Definition definition) |
| 823 |
{ |
| 824 |
int count = 0; |
| 825 |
String prefix = "pfx" + count; |
| 826 |
while (isPrefixDefined(definition, prefix)) |
| 827 |
{ |
| 828 |
prefix = "pfx" + count++; |
| 829 |
} |
| 830 |
return prefix; |
| 831 |
} |
| 1050 |
|
832 |
|
| 1051 |
class CustomWSDLResourceFactoryImpl extends ResourceFactoryImpl |
833 |
private static boolean isPrefixDefined(Definition definition, String prefix) |
| 1052 |
{ |
834 |
{ |
| 1053 |
public CustomWSDLResourceFactoryImpl() |
835 |
String[] namespaces = getAllDefinedNamespaces(definition); |
| 1054 |
{ |
836 |
for (int i = 0; i < namespaces.length; i++) |
| 1055 |
} |
837 |
{ |
|
|
838 |
String pfx = getPrefix(definition, namespaces[i]); |
| 839 |
if (pfx.equals(prefix)) |
| 840 |
return true; |
| 841 |
} |
| 842 |
return false; |
| 843 |
} |
| 1056 |
|
844 |
|
| 1057 |
public Resource createResource(URI uri) |
845 |
/** |
| 1058 |
{ |
846 |
* Returns all the namespaces defined in the WSDL file. |
| 1059 |
Resource result = new WSDLResourceImpl(uri); |
847 |
*/ |
| 1060 |
return result; |
848 |
public static String[] getAllDefinedNamespaces(Definition definition) |
| 1061 |
} |
849 |
{ |
|
|
850 |
List namespaces = new ArrayList(); |
| 851 |
NamedNodeMap map = definition.getElement().getAttributes(); |
| 852 |
for (int i = 0; i < map.getLength(); i++) |
| 853 |
{ |
| 854 |
if (map.item(i) instanceof Attr) |
| 855 |
{ |
| 856 |
Attr attribute = (Attr) map.item(i); |
| 857 |
if (attribute.getNodeName().startsWith("xmlns:")) |
| 858 |
{ |
| 859 |
String ns = attribute.getNodeValue(); |
| 860 |
namespaces.add(ns); |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
return (String[]) namespaces.toArray(new String[namespaces.size()]); |
| 865 |
} |
| 866 |
|
| 867 |
/** |
| 868 |
* Returns the fault name of given faultElement. |
| 869 |
*/ |
| 870 |
public static String getFaultType(XSDElementDeclaration faultElement) |
| 871 |
{ |
| 872 |
String default_type = faultElement.getName(); |
| 873 |
XSDTypeDefinition typeDef = faultElement.getTypeDefinition(); |
| 874 |
if (typeDef == null) |
| 875 |
return default_type; |
| 876 |
if (!(typeDef instanceof XSDComplexTypeDefinition)) |
| 877 |
return default_type; |
| 878 |
XSDComplexTypeDefinition complexTypeDef = (XSDComplexTypeDefinition) typeDef; |
| 879 |
XSDDerivationMethod derivationMethod = complexTypeDef |
| 880 |
.getDerivationMethod(); |
| 881 |
if (derivationMethod == null) |
| 882 |
return default_type; |
| 883 |
if (!derivationMethod.equals(XSDDerivationMethod.EXTENSION_LITERAL)) |
| 884 |
return default_type; |
| 885 |
XSDTypeDefinition baseTypeDef = complexTypeDef.getBaseTypeDefinition(); |
| 886 |
if (baseTypeDef == null) |
| 887 |
return default_type; |
| 888 |
if (!(baseTypeDef instanceof XSDSimpleTypeDefinition)) |
| 889 |
return default_type; |
| 890 |
XSDSimpleTypeDefinition simpleBaseTypeDef = (XSDSimpleTypeDefinition) baseTypeDef; |
| 891 |
return simpleBaseTypeDef.getName(); |
| 892 |
} |
| 893 |
|
| 894 |
/** |
| 895 |
* Returns the XSD fault elements of given wsdl operation. |
| 896 |
*/ |
| 897 |
public static List getOperationFaultElements(Operation operation) |
| 898 |
{ |
| 899 |
List retVal = new ArrayList(); |
| 900 |
List faults = operation.getEFaults(); |
| 901 |
for (int i = 0; i < faults.size(); i++) |
| 902 |
{ |
| 903 |
Fault fault = (Fault) faults.get(i); |
| 904 |
XSDElementDeclaration faultElement = getFaultElement(fault); |
| 905 |
if (faultElement != null) |
| 906 |
retVal.add(faultElement); |
| 907 |
} |
| 908 |
return retVal; |
| 909 |
} |
| 910 |
|
| 911 |
/** |
| 912 |
* Retruns the XSD fault elements of given wsdl fault. |
| 913 |
*/ |
| 914 |
public static XSDElementDeclaration getFaultElement(Fault fault) |
| 915 |
{ |
| 916 |
Message msg = fault.getEMessage(); |
| 917 |
Part part_0 = (Part) msg.getEParts().get(0); |
| 918 |
XSDElementDeclaration element = part_0.getElementDeclaration(); |
| 919 |
return element; |
| 920 |
} |
| 921 |
|
| 922 |
/** |
| 923 |
* Returns the message which contains the given XSDElementDeclaration. |
| 924 |
*/ |
| 925 |
public static Message getMessage(Definition definition, |
| 926 |
XSDElementDeclaration element) |
| 927 |
{ |
| 928 |
List msgs = definition.getEMessages(); |
| 929 |
for (int i = 0; i < msgs.size(); i++) |
| 930 |
{ |
| 931 |
Message msg = (Message) msgs.get(i); |
| 932 |
Part part = getPart(msg, element); |
| 933 |
if (part != null) |
| 934 |
return msg; |
| 935 |
} |
| 936 |
return null; |
| 937 |
} |
| 938 |
|
| 939 |
private static Part getPart(Message msg, XSDElementDeclaration element) |
| 940 |
{ |
| 941 |
List parts = msg.getEParts(); |
| 942 |
for (int i = 0; i < parts.size(); i++) |
| 943 |
{ |
| 944 |
Part part = (Part) parts.get(i); |
| 945 |
XSDElementDeclaration partElement = part.getElementDeclaration(); |
| 946 |
if (element.equals(partElement)) |
| 947 |
return part; |
| 948 |
} |
| 949 |
return null; |
| 950 |
} |
| 951 |
|
| 952 |
/** |
| 953 |
* Returns the Fault of given Message. |
| 954 |
*/ |
| 955 |
public static Fault getFault(Operation operation, Message message) |
| 956 |
{ |
| 957 |
List faults = operation.getEFaults(); |
| 958 |
for (int i = 0; i < faults.size(); i++) |
| 959 |
{ |
| 960 |
Fault fault = (Fault) faults.get(i); |
| 961 |
Message msg = fault.getEMessage(); |
| 962 |
if (message.equals(msg)) |
| 963 |
return fault; |
| 964 |
} |
| 965 |
return null; |
| 966 |
} |
| 967 |
|
| 968 |
/** |
| 969 |
* Returns the name of WSDL Definition. |
| 970 |
*/ |
| 971 |
public static String getName(Definition wsdlDef) |
| 972 |
{ |
| 973 |
return wsdlDef.getQName().getLocalPart(); |
| 974 |
} |
| 975 |
|
| 976 |
/** |
| 977 |
* Create a new WSDL Import element inside given Definition. If imported |
| 978 |
* namespace or wsdlLocation is null then it does nothing. If imported |
| 979 |
* namespace is already imported in one of the WSDL Import element of the |
| 980 |
* WSDL then it does nothing. |
| 981 |
* |
| 982 |
* @param definition |
| 983 |
* Given WSDL definition inside which this new WSDL Import |
| 984 |
* element will be added. |
| 985 |
* |
| 986 |
* @param namespace |
| 987 |
* Namespace to be imported. |
| 988 |
* |
| 989 |
* @param wsdlLocation |
| 990 |
* WSDL location to be imported. |
| 991 |
*/ |
| 992 |
public static void createWSDLImport(Definition definition, |
| 993 |
String namespace, String wsdlLocation) |
| 994 |
{ |
| 995 |
if (namespace == null || wsdlLocation == null) |
| 996 |
return; |
| 997 |
/* |
| 998 |
* if (definition.getTargetNamespace().equals(namespace)) return; |
| 999 |
*/ |
| 1000 |
if (!isImportNSExists(definition, namespace)) |
| 1001 |
{ |
| 1002 |
Import wsdlImport = WSDLFactory.eINSTANCE.createImport(); |
| 1003 |
wsdlImport.setEnclosingDefinition(definition); |
| 1004 |
wsdlImport.setEDefinition(definition); |
| 1005 |
wsdlImport.setLocationURI(wsdlLocation); |
| 1006 |
wsdlImport.setNamespaceURI(namespace); |
| 1007 |
definition.addImport(wsdlImport); |
| 1008 |
createOrFindPrefix(definition, namespace, null); |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
/** |
| 1013 |
* Check if perticular import already exists in given WSDL definition. |
| 1014 |
*/ |
| 1015 |
public static boolean isImportNSExists(Definition definition, |
| 1016 |
String namespace) |
| 1017 |
{ |
| 1018 |
List imports = definition.getEImports(); |
| 1019 |
for (int i = 0; i < imports.size(); i++) |
| 1020 |
{ |
| 1021 |
Import wsdlImport = (Import) imports.get(i); |
| 1022 |
if (wsdlImport.getNamespaceURI().equals(namespace)) |
| 1023 |
return true; |
| 1024 |
} |
| 1025 |
return false; |
| 1026 |
} |
| 1027 |
|
| 1028 |
/** |
| 1029 |
* Returns the absolute path of given WSDL defintion in the local file |
| 1030 |
* system. |
| 1031 |
* |
| 1032 |
* @throws CoreException |
| 1033 |
*/ |
| 1034 |
public static String getLocalSystemWSDLLocation(Definition definition) |
| 1035 |
throws CoreException |
| 1036 |
{ |
| 1037 |
String uriLocation = getWSDLFileLocation(definition); |
| 1038 |
String wsdlLocation = uriLocation; |
| 1039 |
try |
| 1040 |
{ |
| 1041 |
IFile wsdlFile = EclipseUtils.getIFile(uriLocation); |
| 1042 |
wsdlLocation = wsdlFile.getLocation().toString(); |
| 1043 |
wsdlLocation = EclipseUtils.replaceAll(wsdlLocation, '\\', '/'); |
| 1044 |
} catch (CoreException e) |
| 1045 |
{ |
| 1046 |
WsdmToolingLog |
| 1047 |
.logError( |
| 1048 |
NLS |
| 1049 |
.bind( |
| 1050 |
org.eclipse.tptp.wsdm.tooling.nls.messages.capability.property.internal.Messages.FAILED_TO_FIND_LOCATION_FOR_XSD_ERROR_, |
| 1051 |
uriLocation), e); |
| 1052 |
throw e; |
| 1053 |
} |
| 1054 |
return wsdlLocation; |
| 1055 |
} |
| 1062 |
} |
1056 |
} |
| 1063 |
|
1057 |
|
|
|
1058 |
class CustomWSDLResourceFactoryImpl extends ResourceFactoryImpl |
| 1059 |
{ |
| 1060 |
public CustomWSDLResourceFactoryImpl() |
| 1061 |
{ |
| 1062 |
} |
| 1064 |
|
1063 |
|
|
|
1064 |
public Resource createResource(URI uri) |
| 1065 |
{ |
| 1066 |
Resource result = new WSDLResourceImpl(uri); |
| 1067 |
return result; |
| 1068 |
} |
| 1069 |
} |