Mercurial > repos > uga-galaxy-group > webservice_toolsuite_v1_1
comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/xml/WADLReaderImpl.java @ 0:049760c677de default tip
Galaxy WSExtensions added successfully
author | uga-galaxy-group |
---|---|
date | Tue, 05 Jul 2011 19:34:18 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:049760c677de |
---|---|
1 /* | |
2 * (c) Copyright IBM Corp 2001, 2005 | |
3 */ | |
4 | |
5 package edu.uga.cs.lsdis.meteors.wadls.xml; | |
6 | |
7 import java.io.*; | |
8 import java.net.*; | |
9 import java.util.*; | |
10 | |
11 import javax.xml.namespace.*; | |
12 import javax.xml.parsers.*; | |
13 import org.w3c.dom.*; | |
14 import org.xml.sax.*; | |
15 | |
16 import javax.wadls.*; | |
17 import javax.wadls.extensions.*; | |
18 import javax.wadls.extensions.schema.Schema; | |
19 import javax.wadls.extensions.schema.SchemaReference; | |
20 import javax.wadls.factory.*; | |
21 import javax.wadls.xml.*; | |
22 import javax.wadls.Effect; | |
23 import javax.wadls.PreCondition; | |
24 import javax.wadls.extensions.ExtensionRegistry; | |
25 | |
26 | |
27 | |
28 import javax.wadls.extensions.ExtensibilityElement; | |
29 import javax.wadls.extensions.ExtensionDeserializer; | |
30 import javax.wadls.factory.WADLFactory; | |
31 | |
32 import edu.uga.cs.lsdis.meteors.wadls.*; | |
33 import edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaConstants; | |
34 import edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaSerializer; | |
35 import edu.uga.cs.lsdis.meteors.wadls.util.*; | |
36 import edu.uga.cs.lsdis.meteors.wadls.util.xml.*; | |
37 import edu.uga.cs.lsdis.meteors.wadls.Constants; | |
38 import edu.uga.cs.lsdis.meteors.wadls.util.xml.QNameUtils; | |
39 import edu.uga.cs.lsdis.meteors.wadls.util.StringUtils; | |
40 import edu.uga.cs.lsdis.meteors.wadls.util.xml.XPathUtils; | |
41 import edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaDeserializer; | |
42 | |
43 | |
44 /** | |
45 * This class describes a collection of methods | |
46 * that enable conversion of a WSDL-S document (in XML, | |
47 * following the WSDL schema described in the WSDL | |
48 * specification) into a WSDL-S model. | |
49 * | |
50 * @author Zixin Wu (wuzixin@uga.edu) | |
51 * @author Matthew J. Duftler | |
52 * @author Nirmal Mukhi | |
53 */ | |
54 public class WADLReaderImpl implements WADLReader | |
55 { | |
56 | |
57 static { | |
58 Constants.setSemanticExtensionURI(Constants.SemanticExtensionType.SAWADL); | |
59 } | |
60 // Used for determining the style of operations. | |
61 private static final List STYLE_ONE_WAY = | |
62 Arrays.asList(new String[]{Constants.ELEM_INPUT}); | |
63 private static final List STYLE_REQUEST_RESPONSE = | |
64 Arrays.asList(new String[]{Constants.ELEM_INPUT, Constants.ELEM_OUTPUT}); | |
65 private static final List STYLE_SOLICIT_RESPONSE = | |
66 Arrays.asList(new String[]{Constants.ELEM_OUTPUT, Constants.ELEM_INPUT}); | |
67 private static final List STYLE_NOTIFICATION = | |
68 Arrays.asList(new String[]{Constants.ELEM_OUTPUT}); | |
69 | |
70 protected boolean verbose = true; | |
71 protected ExtensionRegistry extReg = null; | |
72 protected boolean importDocuments = true; | |
73 protected boolean parseSAWSDL = false; | |
74 protected String factoryImplName = null; | |
75 protected WADLLocator loc = null; | |
76 | |
77 //Contains all schemas used by this wsdl, either in-line or nested | |
78 //via wsdl imports or schema imports, includes or redefines | |
79 protected Map allSchemas = new Hashtable(); | |
80 | |
81 private String WORKING_SEMANTIC_NAMESPACE = Constants.NS_URI_SAWADL; | |
82 | |
83 | |
84 /** | |
85 * Sets the specified feature to the specified value. | |
86 * <p> | |
87 * The supported features are: | |
88 * <p> | |
89 * <table border=1> | |
90 * <tr> | |
91 * <th>Name</th> | |
92 * <th>Description</th> | |
93 * <th>Default Value</th> | |
94 * </tr> | |
95 * <tr> | |
96 * <td><center>javax.wsdls.verbose</center></td> | |
97 * <td>If set to true, status messages will be displayed.</td> | |
98 * <td><center>true</center></td> | |
99 * </tr> | |
100 * <tr> | |
101 * <td><center>javax.wsdls.importDocuments</center></td> | |
102 * <td>If set to true, imported WSDL documents will be | |
103 * retrieved and processed.</td> | |
104 * <td><center>true</center></td> | |
105 * </tr> | |
106 * </table> | |
107 * <p> | |
108 * All feature names must be fully-qualified, Java package style. All | |
109 * names starting with javax.wsdls. are reserved for features defined | |
110 * by the JWSDL specification. It is recommended that implementation- | |
111 * specific features be fully-qualified to match the package name | |
112 * of that implementation. For example: com.abc.featureName | |
113 * | |
114 * @param name the name of the feature to be set. | |
115 * @param value the value to set the feature to. | |
116 * @throws IllegalArgumentException if the feature name is not recognized. | |
117 * @see #getFeature(String) | |
118 */ | |
119 public void setFeature(String name, boolean value) | |
120 throws IllegalArgumentException | |
121 { | |
122 if (name == null) | |
123 { | |
124 throw new IllegalArgumentException("Feature name must not be null."); | |
125 } | |
126 | |
127 if (name.equals(Constants.FEATURE_VERBOSE)) | |
128 { | |
129 verbose = value; | |
130 } | |
131 else if (name.equals(Constants.FEATURE_IMPORT_DOCUMENTS)) | |
132 { | |
133 importDocuments = value; | |
134 } else if(name.equals(Constants.FEATURE_PARSE_SAWADL)) { | |
135 if(value) { | |
136 WORKING_SEMANTIC_NAMESPACE = Constants.NS_URI_SAWADL; | |
137 Constants.setSemanticExtensionURI(Constants.SemanticExtensionType.SAWADL); | |
138 } else { | |
139 WORKING_SEMANTIC_NAMESPACE = Constants.NS_URI_WADLS; | |
140 Constants.setSemanticExtensionURI(Constants.SemanticExtensionType.WADLS); | |
141 } | |
142 parseSAWSDL = value; | |
143 } | |
144 else | |
145 { | |
146 throw new IllegalArgumentException("Feature name '" + name + | |
147 "' not recognized."); | |
148 } | |
149 } | |
150 | |
151 /** | |
152 * Gets the value of the specified feature. | |
153 * | |
154 * @param name the name of the feature to get the value of. | |
155 * @throws IllegalArgumentException if the feature name is not recognized. | |
156 * @see #setFeature(String, boolean) | |
157 */ | |
158 public boolean getFeature(String name) throws IllegalArgumentException | |
159 { | |
160 if (name == null) | |
161 { | |
162 throw new IllegalArgumentException("Feature name must not be null."); | |
163 } | |
164 | |
165 if (name.equals(Constants.FEATURE_VERBOSE)) | |
166 { | |
167 return verbose; | |
168 } | |
169 else if (name.equals(Constants.FEATURE_IMPORT_DOCUMENTS)) | |
170 { | |
171 return importDocuments; | |
172 } | |
173 else | |
174 { | |
175 throw new IllegalArgumentException("Feature name '" + name + | |
176 "' not recognized."); | |
177 } | |
178 } | |
179 | |
180 public void setExtensionRegistry(ExtensionRegistry extReg) | |
181 { | |
182 this.extReg = extReg; | |
183 } | |
184 | |
185 /** | |
186 * Get the extension registry, if one was set. Default is | |
187 * null. | |
188 */ | |
189 public ExtensionRegistry getExtensionRegistry() | |
190 { | |
191 return extReg; | |
192 } | |
193 | |
194 /** | |
195 * Set the extension registry to be used when reading | |
196 * WSDL documents into a WSDL definition. If an | |
197 * extension registry is set, that is the extension | |
198 * registry that will be set as the extensionRegistry | |
199 * property of the definitions resulting from invoking | |
200 * readWSDL(...). Default is null. | |
201 * | |
202 * @param extReg the extension registry to use for new | |
203 * definitions | |
204 */ | |
205 | |
206 | |
207 | |
208 | |
209 /** | |
210 * Set a different factory implementation to use for | |
211 * creating definitions when reading WSDL documents. | |
212 * As some WSDLReader implementations may only be | |
213 * capable of creating definitions using the same | |
214 * factory implementation from which the reader was | |
215 * obtained, this method is optional. Default is null. | |
216 * | |
217 * @param factoryImplName the fully-qualified class name of the | |
218 * class which provides a concrete implementation of the abstract | |
219 * class WSDLFactory. | |
220 * @throws UnsupportedOperationException if this method | |
221 * is invoked on an implementation which does not | |
222 * support it. | |
223 */ | |
224 public void setFactoryImplName(String factoryImplName) | |
225 throws UnsupportedOperationException | |
226 { | |
227 this.factoryImplName = factoryImplName; | |
228 } | |
229 | |
230 /** | |
231 * Get the factoryImplName, if one was set. Default is null. | |
232 */ | |
233 public String getFactoryImplName() | |
234 { | |
235 return factoryImplName; | |
236 } | |
237 | |
238 protected Application parseApplications(String documentBaseURI, | |
239 Element defEl, | |
240 Map importedDefs) | |
241 throws WADLSException, URISyntaxException | |
242 { | |
243 checkElementName(defEl, Constants.Q_ELEM_DEFINITIONS); | |
244 | |
245 WADLFactory factory = (factoryImplName != null) | |
246 ? WADLFactory.newInstance(factoryImplName) | |
247 : WADLFactory.newInstance(); | |
248 Application def = factory.newApplication(); | |
249 | |
250 | |
251 | |
252 String name = DOMUtils.getAttribute(defEl, Constants.ATTR_NAME); | |
253 String targetNamespace = DOMUtils.getAttribute(defEl, | |
254 Constants.ATTR_TARGET_NAMESPACE); | |
255 System.out.println("Target Name Space:"+targetNamespace); | |
256 NamedNodeMap attrs = defEl.getAttributes(); | |
257 | |
258 if (documentBaseURI != null) | |
259 { | |
260 def.setDocumentBaseURI(documentBaseURI); | |
261 } | |
262 | |
263 if (name != null) | |
264 { | |
265 def.setQName(new QName(targetNamespace, name)); | |
266 } | |
267 | |
268 if (targetNamespace != null) | |
269 { | |
270 def.setTargetNamespace(targetNamespace); | |
271 } | |
272 | |
273 int size = attrs.getLength(); | |
274 | |
275 for (int i = 0; i < size; i++) | |
276 { | |
277 Attr attr = (Attr)attrs.item(i); | |
278 String namespaceURI = attr.getNamespaceURI(); | |
279 String localPart = attr.getLocalName(); | |
280 String value = attr.getValue(); | |
281 | |
282 | |
283 if (namespaceURI != null && namespaceURI.equals(Constants.NS_URI_XMLNS)) | |
284 { | |
285 if (localPart != null && !localPart.equals(Constants.ATTR_XMLNS)) | |
286 { | |
287 System.out.println("LocalPart is set to "+localPart+" and it's value is "+value); | |
288 def.addNamespace(localPart, value); | |
289 } | |
290 else | |
291 { | |
292 System.out.println("LocalPart is set to null and it's value is "+value); | |
293 def.addNamespace(null, value); | |
294 } | |
295 } | |
296 } | |
297 | |
298 Element tempEl = DOMUtils.getFirstChildElement(defEl); | |
299 System.out.println("%%%% "); | |
300 System.out.println("%%%% First Child: "+tempEl.getNodeName()); | |
301 | |
302 while (tempEl != null) | |
303 { | |
304 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
305 { | |
306 System.out.println("%%%% Documentation Element:"+tempEl.getTextContent()); | |
307 def.setDocumentationElement(tempEl); | |
308 } | |
309 else if (QNameUtils.matches(Constants.Q_ELEM_GRAMMARS, tempEl)) | |
310 { | |
311 System.out.println("%%%% Grammars element is parsed."); | |
312 def.setGrammars(parseGrammars(tempEl, def)); | |
313 } | |
314 else if (QNameUtils.matches(Constants.Q_ELEM_RESOURCES, tempEl)){ | |
315 | |
316 System.out.println("%%%% Resources Element is parsed."); | |
317 String path = DOMUtils.getAttribute(tempEl, Constants.ATTR_BASE); | |
318 def.setResourcesPath(path); | |
319 System.out.println("Resources path is:"+path); | |
320 Element tempEl1 = DOMUtils.getFirstChildElement(tempEl); | |
321 for (; tempEl1 != null; tempEl1 = DOMUtils.getNextSiblingElement(tempEl1)){ | |
322 if (QNameUtils.matches(Constants.Q_ELEM_RESOURCE, tempEl1)) | |
323 { | |
324 def.addResource(parseResource(tempEl1, def)); | |
325 } | |
326 } | |
327 | |
328 } | |
329 else{ | |
330 | |
331 } | |
332 | |
333 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
334 } | |
335 | |
336 return def; | |
337 } | |
338 | |
339 protected Include parseInclude(Element importEl, | |
340 Application def, | |
341 Map importedDefs) | |
342 throws WADLSException | |
343 { | |
344 Include importDef = def.createInclude(); | |
345 | |
346 try | |
347 { | |
348 String namespaceURI = DOMUtils.getAttribute(importEl, | |
349 Constants.ATTR_NAMESPACE); | |
350 String locationURI = DOMUtils.getAttribute(importEl, | |
351 Constants.ATTR_LOCATION); | |
352 String contextURI = null; | |
353 | |
354 if (namespaceURI != null) | |
355 { | |
356 importDef.setNamespaceURI(namespaceURI); | |
357 } | |
358 | |
359 if (locationURI != null) | |
360 { | |
361 importDef.setLocationURI(locationURI); | |
362 | |
363 if (importDocuments) | |
364 { | |
365 try | |
366 { | |
367 contextURI = def.getDocumentBaseURI(); | |
368 Application importedDef = null; | |
369 InputStream inputStream = null; | |
370 InputSource inputSource = null; | |
371 URL url = null; | |
372 | |
373 if (loc != null) | |
374 { | |
375 inputSource = loc.getImportInputSource(contextURI, locationURI); | |
376 | |
377 /* | |
378 We now have available the latest import URI. This might | |
379 differ from the locationURI so check the importedDefs for it | |
380 since it is this that we pass as the documentBaseURI later. | |
381 */ | |
382 String liu = loc.getLatestImportURI(); | |
383 | |
384 importedDef = (Application)importedDefs.get(liu); | |
385 } | |
386 else | |
387 { | |
388 URL contextURL = (contextURI != null) | |
389 ? StringUtils.getURL(null, contextURI) | |
390 : null; | |
391 | |
392 url = StringUtils.getURL(contextURL, locationURI); | |
393 importedDef = (Application)importedDefs.get(url.toString()); | |
394 | |
395 if (importedDef == null) | |
396 { | |
397 inputStream = StringUtils.getContentAsInputStream(url); | |
398 | |
399 if (inputStream != null) | |
400 { | |
401 inputSource = new InputSource(inputStream); | |
402 } | |
403 } | |
404 } | |
405 | |
406 if (importedDef == null) | |
407 { | |
408 if (inputSource == null) | |
409 { | |
410 throw new WADLSException(WADLSException.OTHER_ERROR, | |
411 "Unable to locate imported document " + | |
412 "at '" + locationURI + "'" + | |
413 (contextURI == null | |
414 ? "." | |
415 : ", relative to '" + contextURI + | |
416 "'.")); | |
417 } | |
418 | |
419 inputSource.setSystemId(url.toString()); | |
420 Document doc = getDocument(inputSource, url.toString()); | |
421 | |
422 if (inputStream != null) | |
423 { | |
424 inputStream.close(); | |
425 } | |
426 | |
427 Element documentElement = doc.getDocumentElement(); | |
428 | |
429 /* | |
430 Check if it's a wsdl document. | |
431 If it's not, don't retrieve and process it. | |
432 This should later be extended to allow other types of | |
433 documents to be retrieved and processed, such as schema | |
434 documents (".xsd"), etc... | |
435 */ | |
436 if (QNameUtils.matches(Constants.Q_ELEM_DEFINITIONS, | |
437 documentElement)) | |
438 { | |
439 if (verbose) | |
440 { | |
441 System.out.println("Retrieving document at '" + locationURI + | |
442 "'" + | |
443 (contextURI == null | |
444 ? "." | |
445 : ", relative to '" + contextURI + "'.")); | |
446 } | |
447 | |
448 String urlString = | |
449 (loc != null) | |
450 ? loc.getLatestImportURI() | |
451 : (url != null) | |
452 ? url.toString() | |
453 : locationURI; | |
454 | |
455 importedDef = readWADL(urlString, | |
456 documentElement, | |
457 importedDefs); | |
458 } | |
459 else | |
460 { | |
461 QName docElementQName = QNameUtils.newQName(documentElement); | |
462 | |
463 if (SchemaConstants.XSD_QNAME_LIST.contains(docElementQName)) | |
464 { | |
465 WADLFactory factory = | |
466 (factoryImplName != null) | |
467 ? WADLFactory.newInstance(factoryImplName) | |
468 : WADLFactory.newInstance(); | |
469 | |
470 importedDef = factory.newApplication(); | |
471 | |
472 | |
473 String urlString = | |
474 (loc != null) | |
475 ? loc.getLatestImportURI() | |
476 : (url != null) | |
477 ? url.toString() | |
478 : locationURI; | |
479 | |
480 importedDef.setDocumentBaseURI(urlString); | |
481 | |
482 Params types = importedDef.createParams(); | |
483 importedDef.setParams(types); | |
484 } | |
485 } | |
486 } | |
487 | |
488 if (importedDef != null) | |
489 { | |
490 importDef.setApplication(importedDef); | |
491 } | |
492 } | |
493 catch (WADLSException e) | |
494 { | |
495 throw e; | |
496 } | |
497 catch (Throwable t) | |
498 { | |
499 throw new WADLSException(WADLSException.OTHER_ERROR, | |
500 "Unable to resolve imported document at '" + | |
501 locationURI + | |
502 (contextURI == null | |
503 ? "'." : "', relative to '" + contextURI + "'") | |
504 , t); | |
505 } | |
506 } //end importDocs | |
507 } //end locationURI | |
508 | |
509 } | |
510 catch (WADLSException e) | |
511 { | |
512 if (e.getLocation() == null) | |
513 { | |
514 e.setLocation(XPathUtils.getXPathExprFromNode(importEl)); | |
515 } | |
516 else | |
517 { | |
518 //If definitions are being parsed recursively for nested imports | |
519 //the exception location must be built up recursively too so | |
520 //prepend this element's xpath to exception location. | |
521 String loc = XPathUtils.getXPathExprFromNode(importEl) + e.getLocation(); | |
522 e.setLocation(loc); | |
523 } | |
524 | |
525 throw e; | |
526 } | |
527 | |
528 Element tempEl = DOMUtils.getFirstChildElement(importEl); | |
529 | |
530 while (tempEl != null) | |
531 { | |
532 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
533 { | |
534 importDef.setDocumentationElement(tempEl); | |
535 } | |
536 else | |
537 { | |
538 DOMUtils.throwWADLException(tempEl); | |
539 } | |
540 | |
541 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
542 } | |
543 | |
544 | |
545 return importDef; | |
546 | |
547 } | |
548 | |
549 | |
550 | |
551 protected Grammars parseGrammars(Element typesEl, Application def) | |
552 throws WADLSException | |
553 { | |
554 Grammars grammars = def.createGrammars(); | |
555 List<String> schemaList =new Vector(); | |
556 List<Schema> docElement =new Vector(); | |
557 List<String> targetNS =new Vector(); | |
558 Element tempEl = DOMUtils.getFirstChildElement(typesEl); | |
559 QName tempElType; | |
560 | |
561 while (tempEl != null) | |
562 { | |
563 tempElType = QNameUtils.newQName(tempEl); | |
564 | |
565 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
566 { | |
567 grammars.setDocumentationElement(tempEl); | |
568 } | |
569 else if (QNameUtils.matches(Constants.Q_ELEM_INCLUDE, tempEl)) | |
570 { | |
571 String xsd = DOMUtils.getAttribute(tempEl, Constants.ELEM_HREF); | |
572 schemaList.add(xsd); | |
573 System.out.println("Xsd element in Grammars tag:"+xsd); | |
574 | |
575 docElement.add(parseSchema(tempEl,def)); | |
576 //targetNS.add(parseSchemaNS(tempEl,def)); | |
577 List remainingAttrs = DOMUtils.getAttributes(tempEl); | |
578 //the element qname indicates it is a schema. | |
579 String modelReference = DOMUtils.getAttributeNS(tempEl, | |
580 WORKING_SEMANTIC_NAMESPACE, | |
581 Constants.ATTR_MODELREF, | |
582 remainingAttrs); | |
583 System.out.println("XSD Element's model reference is:"+modelReference); | |
584 if (modelReference != null) | |
585 { | |
586 try { | |
587 parseModelReference(modelReference, def, grammars); | |
588 } catch (URISyntaxException e) { | |
589 // TODO Auto-generated catch block | |
590 e.printStackTrace(); | |
591 } | |
592 /*ModelReference mr = def.createModelReference(); | |
593 mr.valueOf(modelReference, def); | |
594 mr.setParent(preCondition); | |
595 preCondition.addModelReference(mr);*/ | |
596 } | |
597 | |
598 } | |
599 | |
600 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
601 } | |
602 grammars.setSchemas(this.allSchemas); | |
603 Map temp = grammars.getSchemas(); | |
604 System.out.println("Schemas added to grammars class:"+temp.size()); | |
605 return grammars; | |
606 } | |
607 | |
608 | |
609 protected Schema parseSchema(Element el,Application def) | |
610 throws WADLSException | |
611 { | |
612 /* | |
613 * This method returns ExtensibilityElement rather than Schema because we | |
614 * do not insist that a suitable XSD schema deserializer is registered. | |
615 * PopulatedExtensionRegistry registers SchemaDeserializer by default, but | |
616 * if the user chooses not to register a suitable deserializer then the | |
617 * UnknownDeserializer will be used, returning an UnknownExtensibilityElement. | |
618 */ | |
619 | |
620 | |
621 Schema schema = null; | |
622 SchemaReference schemaRef = null; | |
623 try | |
624 { | |
625 | |
626 QName elementType = QNameUtils.newQName(el); | |
627 | |
628 edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaDeserializer scDS = new edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaDeserializer(); | |
629 | |
630 //Now unmarshall the DOM element. | |
631 Schema ee = | |
632 scDS.unmarshall(elementType, el, def); | |
633 | |
634 if (ee instanceof Schema) | |
635 { | |
636 | |
637 schema = (Schema) ee; | |
638 } | |
639 String location = null; | |
640 | |
641 //Keep track of parsed schemas to avoid duplicating Schema objects | |
642 //through duplicate or circular references (eg: A imports B imports A). | |
643 if (schema.getDocumentBaseURI() != null) | |
644 { | |
645 | |
646 | |
647 this.allSchemas.put(schema.getDocumentBaseURI(), schema); | |
648 } | |
649 | |
650 ArrayList allSchemaRefs = new ArrayList(); | |
651 | |
652 Collection ic = schema.getImports().values(); | |
653 | |
654 | |
655 Iterator importsIterator = ic.iterator(); | |
656 while(importsIterator.hasNext()) | |
657 { | |
658 allSchemaRefs.addAll( (Collection) importsIterator.next() ); | |
659 } | |
660 | |
661 allSchemaRefs.addAll(schema.getIncludes()); | |
662 allSchemaRefs.addAll(schema.getRedefines()); | |
663 | |
664 //Then, retrieve the schema referred to by each schema reference. If the | |
665 //schema has been read in previously, use the existing schema object. | |
666 //Otherwise unmarshall the DOM element into a new schema object. | |
667 | |
668 ListIterator schemaRefIterator = allSchemaRefs.listIterator(); | |
669 | |
670 | |
671 while(schemaRefIterator.hasNext()){ | |
672 | |
673 try | |
674 { | |
675 schemaRef = (SchemaReference) schemaRefIterator.next(); | |
676 | |
677 if (schemaRef.getSchemaLocationURI() == null) | |
678 { | |
679 | |
680 //cannot get the referenced schema, so ignore this schema reference | |
681 continue; | |
682 } | |
683 | |
684 if (verbose) | |
685 { | |
686 System.out.println("change: Retrieving schema at '" + | |
687 schemaRef.getSchemaLocationURI() + | |
688 (schema.getDocumentBaseURI() == null | |
689 ? "'." | |
690 : "', relative to '" + | |
691 schema.getDocumentBaseURI() + "'.")); | |
692 } | |
693 | |
694 | |
695 InputStream inputStream = null; | |
696 InputSource inputSource = null; | |
697 | |
698 | |
699 | |
700 //This is the child schema referred to by the schemaReference | |
701 Schema referencedSchema = null; | |
702 | |
703 //This is the child schema's location obtained from the WSDLLocator or the URL | |
704 | |
705 | |
706 if (loc != null) | |
707 { | |
708 | |
709 //Try to get the referenced schema using the wsdl locator | |
710 inputSource = loc.getImportInputSource( | |
711 schema.getDocumentBaseURI(), schemaRef.getSchemaLocationURI()); | |
712 | |
713 if (inputSource == null) | |
714 { | |
715 throw new WADLSException(WADLSException.OTHER_ERROR, | |
716 "Unable to locate with a locator " | |
717 + "the schema referenced at '" | |
718 + schemaRef.getSchemaLocationURI() | |
719 + "' relative to document base '" | |
720 + schema.getDocumentBaseURI() + "'"); | |
721 } | |
722 location = loc.getLatestImportURI(); | |
723 | |
724 | |
725 //if a schema from this location has been read previously, use it. | |
726 referencedSchema = (Schema) this.allSchemas.get(location); | |
727 } | |
728 else | |
729 { | |
730 // We don't have a wsdl locator, so try to retrieve the schema by its URL | |
731 | |
732 String contextURI = schema.getDocumentBaseURI(); | |
733 URL contextURL = (contextURI != null) ? StringUtils.getURL(null, contextURI) : null; | |
734 //System.out.println("%%%% Context URL OF SCHEMA:"+contextURL); | |
735 URL url = StringUtils.getURL(contextURL, schemaRef.getSchemaLocationURI()); | |
736 //System.out.println("%%%%URL :"+url); | |
737 location = url.toExternalForm(); | |
738 //System.out.println("%%%% schema location:"+location); | |
739 //if a schema from this location has been retrieved previously, use it. | |
740 referencedSchema = (Schema) this.allSchemas.get(location); | |
741 | |
742 if (referencedSchema == null) | |
743 { | |
744 //System.out.println("%%%% Referenced Schema is equal to null"); | |
745 // We haven't read this schema in before so do it now | |
746 inputStream = url.openStream(); | |
747 | |
748 if (inputStream != null) | |
749 { | |
750 inputSource = new InputSource(inputStream); | |
751 } | |
752 | |
753 if (inputSource == null) | |
754 { | |
755 throw new WADLSException(WADLSException.OTHER_ERROR, | |
756 "Unable to locate with a url " | |
757 + "the document referenced at '" | |
758 + schemaRef.getSchemaLocationURI() | |
759 + "'" | |
760 + (contextURI == null ? "." : ", relative to '" | |
761 + contextURI + "'.")); | |
762 } | |
763 } | |
764 | |
765 } //end if loc | |
766 | |
767 // If we have not previously read the schema, get its DOM element now. | |
768 if (referencedSchema == null) | |
769 { | |
770 //System.out.println("%%%% Referenced Schema is equal to null 2"); | |
771 inputSource.setSystemId(location); | |
772 Document doc = getDocument(inputSource, location); | |
773 | |
774 if (inputStream != null) | |
775 { | |
776 inputStream.close(); | |
777 } | |
778 | |
779 Element documentElement = doc.getDocumentElement(); | |
780 NodeList nodeList = documentElement.getChildNodes(); | |
781 | |
782 /*for(int i=0; i<nodeList.getLength(); i++){ | |
783 Node childNode = nodeList.item(i); | |
784 System.out.println("Children$$$$ : "+childNode.getTextContent()); | |
785 // Do something with childNode... | |
786 }*/ | |
787 //System.out.println("#####Child Nodes:"+documentElement.getChildNodes()); | |
788 //System.out.println("%%%% documentElement:"+ documentElement.getNodeName()); | |
789 // If it's a schema doc process it, otherwise the schema reference remains null | |
790 | |
791 QName docElementQName = QNameUtils.newQName(documentElement); | |
792 | |
793 if (SchemaConstants.XSD_QNAME_LIST.contains(docElementQName)) | |
794 { | |
795 //We now need to call parseSchema recursively to parse the referenced | |
796 //schema. The document base URI of the referenced schema will be set to | |
797 //the document base URI of the current schema plus the schemaLocation in | |
798 //the schemaRef. We cannot explicitly pass in a new document base URI | |
799 //to the schema deserializer, so instead we will create a dummy | |
800 //Definition and set its documentBaseURI to the new document base URI. | |
801 //We can leave the other definition fields empty because we know | |
802 //that the SchemaDeserializer.unmarshall method uses the definition | |
803 //parameter only to get its documentBaseURI. If the unmarshall method | |
804 //implementation changes (ie: its use of definition changes) we may need | |
805 //to rethink this approach. | |
806 //System.out.println("%%%%%SchemaConstants.XSD_QNAME_LIST.contains(docElementQName)"+docElementQName.getLocalPart()); | |
807 | |
808 WADLFactory factory = (factoryImplName != null) | |
809 ? WADLFactory.newInstance(factoryImplName) | |
810 : WADLFactory.newInstance(); | |
811 Application dummyDef = factory.newApplication(); | |
812 | |
813 dummyDef.setDocumentBaseURI(location); | |
814 //System.out.println("%%%% End of Parse Schema"); | |
815 //By this point, we know we have a SchemaDeserializer registered | |
816 //so we can safely cast the ExtensibilityElement to a Schema. | |
817 referencedSchema = (Schema) parseSchema( documentElement, | |
818 dummyDef); | |
819 } | |
820 | |
821 } //end if referencedSchema | |
822 | |
823 schemaRef.setReferencedSchema(referencedSchema); | |
824 } | |
825 catch (WADLSException e) | |
826 { | |
827 throw e; | |
828 } | |
829 catch (Throwable t) | |
830 { | |
831 throw new WADLSException(WADLSException.OTHER_ERROR, | |
832 "An error occurred trying to resolve schema referenced at '" | |
833 + schemaRef.getSchemaLocationURI() | |
834 + "'" | |
835 + (schema.getDocumentBaseURI() == null ? "." : ", relative to '" | |
836 + schema.getDocumentBaseURI() + "'."), | |
837 t); | |
838 } | |
839 | |
840 } //end while loop | |
841 | |
842 return schema; | |
843 | |
844 } | |
845 catch (WADLSException e) | |
846 { | |
847 if (e.getLocation() == null) | |
848 { | |
849 e.setLocation(XPathUtils.getXPathExprFromNode(el)); | |
850 } | |
851 else | |
852 { | |
853 //If this method has been called recursively for nested schemas | |
854 //the exception location must be built up recursively too so | |
855 //prepend this element's xpath to exception location. | |
856 String loc = XPathUtils.getXPathExprFromNode(el) + e.getLocation(); | |
857 e.setLocation(loc); | |
858 } | |
859 | |
860 throw e; | |
861 } | |
862 | |
863 } | |
864 | |
865 | |
866 | |
867 | |
868 protected Resource parseResource(Element portTypeEl, Application def) | |
869 throws WADLSException, URISyntaxException | |
870 { | |
871 Resource portType = null; | |
872 String path = DOMUtils.getAttribute(portTypeEl, Constants.RESOURCE_ATTR_NAME); | |
873 List remainingAttrs = DOMUtils.getAttributes(portTypeEl); | |
874 //read modelReference | |
875 //String modelReference= null; | |
876 if (path != null) | |
877 { | |
878 QName resourceName = new QName(def.getTargetNamespace(), path); | |
879 System.out.println("Resource Path:"+path); | |
880 System.out.println("ResourceName:"+resourceName.toString()); | |
881 | |
882 portType = def.getResource(resourceName); | |
883 | |
884 if (portType == null) | |
885 { | |
886 portType = def.createResource(); | |
887 portType.setQName(resourceName); | |
888 } | |
889 } | |
890 else | |
891 { | |
892 portType = def.createResource(); | |
893 } | |
894 | |
895 // Whether it was retrieved or created, the definition has been found. | |
896 portType.setUndefined(false); | |
897 String modelReference = DOMUtils.getAttributeNS(portTypeEl, | |
898 WORKING_SEMANTIC_NAMESPACE, | |
899 Constants.ATTR_MODELREF, | |
900 remainingAttrs); | |
901 System.out.println("Resource modelreference:"+modelReference); | |
902 if (modelReference != null) | |
903 { | |
904 parseModelReference(modelReference, def, portType); | |
905 /*ModelReference mr = def.createModelReference(); | |
906 mr.valueOf(modelReference, def); | |
907 mr.setParent(preCondition); | |
908 preCondition.addModelReference(mr);*/ | |
909 } | |
910 | |
911 Element tempEl = DOMUtils.getFirstChildElement(portTypeEl); | |
912 | |
913 while (tempEl != null) | |
914 { | |
915 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
916 { | |
917 portType.setDocumentationElement(tempEl); | |
918 } | |
919 else if (QNameUtils.matches(Constants.Q_ELEM_OPERATION, tempEl)) | |
920 { | |
921 Method op = parseMethod(tempEl, portType, def); | |
922 | |
923 if (op != null) | |
924 { | |
925 portType.addMethod(op); | |
926 } | |
927 } | |
928 else | |
929 { | |
930 DOMUtils.throwWADLException(tempEl); | |
931 } | |
932 | |
933 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
934 } | |
935 | |
936 return portType; | |
937 } | |
938 | |
939 /** | |
940 * This is for Ajith and Kats. Just make sure we handle the SAWSDL and WSDLS namespaces properly. | |
941 * The point being that we still might have to support wsdls and hence we want to see if we can use this operation with an internal | |
942 * flag indicating if the parser is being used in the context of WSDLS or SAWSDL. | |
943 * @param opEl | |
944 * @param portType | |
945 * @param def | |
946 * @return | |
947 * @throws WADLSException | |
948 * @throws URISyntaxException | |
949 */ | |
950 protected Method parseMethod(Element opEl, | |
951 Resource portType, | |
952 Application def) | |
953 throws WADLSException, URISyntaxException | |
954 { | |
955 Method op = null; | |
956 List remainingAttrs = DOMUtils.getAttributes(opEl); | |
957 String name = DOMUtils.getAttribute(opEl, Constants.ID_NAME, remainingAttrs); | |
958 //read modelReference | |
959 //String modelReference= null; | |
960 | |
961 String parameterOrderStr = DOMUtils.getAttribute(opEl, | |
962 Constants.ATTR_PARAMETER_ORDER, | |
963 remainingAttrs); | |
964 | |
965 | |
966 Element tempEl = DOMUtils.getFirstChildElement(opEl); | |
967 List messageOrder = new Vector(); | |
968 Element docEl = null; | |
969 Request input = null; | |
970 Response output = null; | |
971 PreCondition preCondition = null; | |
972 Effect effect = null; | |
973 List extElements = new Vector(); | |
974 boolean retrieved = true; | |
975 | |
976 while (tempEl != null) | |
977 { | |
978 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
979 { | |
980 docEl = tempEl; | |
981 } | |
982 else if (QNameUtils.matches(Constants.Q_ELEM_INPUT, tempEl)) | |
983 { | |
984 input = parseRequest(tempEl, def); | |
985 | |
986 } | |
987 else if (QNameUtils.matches(Constants.Q_ELEM_PRECON, tempEl)) | |
988 { | |
989 preCondition = parsePreCondition(tempEl, def); | |
990 } | |
991 else if (QNameUtils.matches(Constants.Q_ELEM_EFFECT, tempEl)) | |
992 { | |
993 effect = parseEffect(tempEl, def); | |
994 | |
995 } | |
996 else if (QNameUtils.matches(Constants.Q_ELEM_OUTPUT, tempEl)) | |
997 { | |
998 output = parseResponse(tempEl, def); | |
999 } | |
1000 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
1001 } | |
1002 | |
1003 if (name != null) | |
1004 { | |
1005 String inputName = (input != null ? input.getName() : null); | |
1006 String outputName = (output != null ? output.getName() : null); | |
1007 | |
1008 op = portType.getMethod(name, inputName, outputName); | |
1009 | |
1010 if (op != null && !op.isUndefined()) | |
1011 { | |
1012 op = null; | |
1013 } | |
1014 | |
1015 if (op != null) | |
1016 { | |
1017 if (inputName == null) | |
1018 { | |
1019 Request tempIn = op.getRequest(); | |
1020 | |
1021 if (tempIn != null) | |
1022 { | |
1023 if (tempIn.getName() != null) | |
1024 { | |
1025 op = null; | |
1026 } | |
1027 } | |
1028 } | |
1029 } | |
1030 | |
1031 if (op != null) | |
1032 { | |
1033 if (outputName == null) | |
1034 { | |
1035 Response tempOut = op.getResponse(); | |
1036 | |
1037 if (tempOut != null) | |
1038 { | |
1039 if (tempOut.getName() != null) | |
1040 { | |
1041 op = null; | |
1042 } | |
1043 } | |
1044 } | |
1045 } | |
1046 | |
1047 if (op == null) | |
1048 { | |
1049 op = def.createMethod(); | |
1050 op.setName(name); | |
1051 retrieved = false; | |
1052 } | |
1053 } | |
1054 else | |
1055 { | |
1056 op = def.createMethod(); | |
1057 retrieved = false; | |
1058 } | |
1059 | |
1060 // Whether it was retrieved or created, the definition has been found. | |
1061 op.setUndefined(false); | |
1062 | |
1063 if (parameterOrderStr != null) | |
1064 { | |
1065 op.setParameterOrdering(StringUtils.parseNMTokens(parameterOrderStr)); | |
1066 } | |
1067 | |
1068 if (docEl != null) | |
1069 { | |
1070 op.setDocumentationElement(docEl); | |
1071 } | |
1072 | |
1073 if (input != null) | |
1074 { | |
1075 op.setRequest(input); | |
1076 } | |
1077 | |
1078 if (output != null) | |
1079 { | |
1080 op.setResponse(output); | |
1081 } | |
1082 | |
1083 if (preCondition != null) | |
1084 { | |
1085 op.setPreCondition(preCondition); | |
1086 } | |
1087 String modelReference = DOMUtils.getAttributeNS(opEl, | |
1088 WORKING_SEMANTIC_NAMESPACE, | |
1089 Constants.ATTR_MODELREF, | |
1090 remainingAttrs); | |
1091 System.out.println("Model Reference of method:"+modelReference); | |
1092 if (modelReference != null) | |
1093 { | |
1094 parseModelReference(modelReference, def, op); | |
1095 /*ModelReference mr = def.createModelReference(); | |
1096 mr.valueOf(modelReference, def); | |
1097 mr.setParent(preCondition); | |
1098 preCondition.addModelReference(mr);*/ | |
1099 } | |
1100 if (effect != null) | |
1101 { | |
1102 op.setEffect(effect); | |
1103 } | |
1104 | |
1105 | |
1106 if (retrieved) | |
1107 { | |
1108 op = null; | |
1109 } | |
1110 | |
1111 return op; | |
1112 } | |
1113 | |
1114 | |
1115 | |
1116 | |
1117 protected Request parseRequest(Element inputEl, Application def) | |
1118 throws WADLSException | |
1119 { | |
1120 Request input = def.createRequest(); | |
1121 List<String> inputXSDList = new ArrayList<String>(10); | |
1122 List<Param> paramList = new ArrayList<Param>(20); | |
1123 Element tempEl = DOMUtils.getFirstChildElement(inputEl); | |
1124 List remainingAttrs = DOMUtils.getAttributes(inputEl); | |
1125 String modelReference = DOMUtils.getAttributeNS(inputEl, | |
1126 WORKING_SEMANTIC_NAMESPACE, | |
1127 Constants.ATTR_MODELREF, | |
1128 remainingAttrs); | |
1129 System.out.println("Model reference for request:"+modelReference); | |
1130 if (modelReference != null) | |
1131 { | |
1132 try { | |
1133 parseModelReference(modelReference, def, input); | |
1134 } catch (URISyntaxException e) { | |
1135 // TODO Auto-generated catch block | |
1136 e.printStackTrace(); | |
1137 } | |
1138 /*ModelReference mr = def.createModelReference(); | |
1139 mr.valueOf(modelReference, def); | |
1140 mr.setParent(preCondition); | |
1141 preCondition.addModelReference(mr);*/ | |
1142 } | |
1143 while (tempEl != null) | |
1144 { | |
1145 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
1146 { | |
1147 input.setDocumentationElement(tempEl); | |
1148 } | |
1149 else if (QNameUtils.matches(Constants.Q_ELEM_REPRESENTATION, tempEl)) | |
1150 { | |
1151 String inputXSD = DOMUtils.getAttribute(tempEl, Constants.REQUEST_ELEMENT_NAME); | |
1152 //input.setName(inputXSD); | |
1153 inputXSDList.add(inputXSD); | |
1154 System.out.println("InPut XSD : "+inputXSD); | |
1155 } | |
1156 else if (QNameUtils.matches(Constants.Q_ELEM_PARAM, tempEl)) | |
1157 { | |
1158 System.out.println("New paramter is added to request"); | |
1159 Param param = new ParamImpl(); | |
1160 List remainingParamAttrs = DOMUtils.getAttributes(tempEl); | |
1161 String parammodelReference = DOMUtils.getAttributeNS(tempEl, | |
1162 WORKING_SEMANTIC_NAMESPACE, | |
1163 Constants.ATTR_MODELREF, | |
1164 remainingAttrs); | |
1165 String liftingschema = DOMUtils.getAttributeNS(tempEl, | |
1166 WORKING_SEMANTIC_NAMESPACE, | |
1167 Constants.ATTR_LIFTINGSCHEMAMAPPING, | |
1168 remainingAttrs); | |
1169 String loweringschema = DOMUtils.getAttributeNS(tempEl, | |
1170 WORKING_SEMANTIC_NAMESPACE, | |
1171 Constants.ATTR_LOWERINGSCHEMAMAPPING, | |
1172 remainingAttrs); | |
1173 | |
1174 param.setModelreference(parammodelReference); | |
1175 param.setLiftingschemamapping(liftingschema); | |
1176 param.setLoweringschemamapping(loweringschema); | |
1177 //param.setModelreference(liftingschema); | |
1178 //param.setModelreference(loweringschema); | |
1179 | |
1180 String style = DOMUtils.getAttribute(tempEl, Constants.PARAM_STYLE); | |
1181 System.out.println("Param Style:"+style); | |
1182 String type = DOMUtils.getAttribute(tempEl, Constants.PARAM_TYPE); | |
1183 System.out.println("Param Type:"+type); | |
1184 | |
1185 param.setName(DOMUtils.getAttribute(tempEl, Constants.PARAM_NAME)); | |
1186 param.setDefault1(DOMUtils.getAttribute(tempEl, Constants.PARAM_DEFAULT)); | |
1187 param.setRequired(DOMUtils.getAttribute(tempEl, Constants.PARAM_REQUIRED)); | |
1188 | |
1189 | |
1190 if(type!=null){ | |
1191 param.setType(type); | |
1192 } | |
1193 | |
1194 List<String> optionValue = new ArrayList<String>(30); | |
1195 Element paramoption = DOMUtils.getFirstChildElement(tempEl); | |
1196 | |
1197 | |
1198 for (; paramoption != null; paramoption = DOMUtils.getNextSiblingElement(paramoption)) | |
1199 { | |
1200 if(paramoption.getLocalName().toString().equals("option")){ | |
1201 optionValue.add(DOMUtils.getAttribute(paramoption, Constants.OPTION_VALUE)); | |
1202 System.out.println("Param Option Value:"+DOMUtils.getAttribute(paramoption, Constants.OPTION_VALUE)); | |
1203 } | |
1204 } | |
1205 | |
1206 param.setOptionvalue(optionValue); | |
1207 | |
1208 | |
1209 paramList.add(param); | |
1210 | |
1211 } | |
1212 else | |
1213 { | |
1214 DOMUtils.throwWADLException(tempEl); | |
1215 } | |
1216 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
1217 } | |
1218 | |
1219 input.setInputXSDList(inputXSDList); | |
1220 input.setParamList(paramList); | |
1221 return input; | |
1222 } | |
1223 | |
1224 protected Response parseResponse(Element outputEl, Application def) | |
1225 throws WADLSException | |
1226 { | |
1227 Response output = def.createResponse(); | |
1228 List<String> outputXSDList = new ArrayList<String>(10); | |
1229 List<Param> paramList = new ArrayList<Param>(20); | |
1230 String name = DOMUtils.getAttribute(outputEl, Constants.ATTR_NAME); | |
1231 QName messageName = getQualifiedAttributeValue(outputEl, | |
1232 Constants.ATTR_MESSAGE, | |
1233 Constants.ELEM_OUTPUT, | |
1234 def); | |
1235 | |
1236 if (name != null) | |
1237 { | |
1238 output.setName(name); | |
1239 } | |
1240 List remainingAttrs = DOMUtils.getAttributes(outputEl); | |
1241 String modelReference = DOMUtils.getAttributeNS(outputEl, | |
1242 WORKING_SEMANTIC_NAMESPACE, | |
1243 Constants.ATTR_MODELREF, | |
1244 remainingAttrs); | |
1245 System.out.println("Model reference for response:"+modelReference); | |
1246 if (modelReference != null) | |
1247 { | |
1248 try { | |
1249 parseModelReference(modelReference, def, output); | |
1250 } catch (URISyntaxException e) { | |
1251 // TODO Auto-generated catch block | |
1252 e.printStackTrace(); | |
1253 } | |
1254 /*ModelReference mr = def.createModelReference(); | |
1255 mr.valueOf(modelReference, def); | |
1256 mr.setParent(preCondition); | |
1257 preCondition.addModelReference(mr);*/ | |
1258 } | |
1259 Element tempEl = DOMUtils.getFirstChildElement(outputEl); | |
1260 | |
1261 while (tempEl != null) | |
1262 { | |
1263 if (QNameUtils.matches(Constants.Q_ELEM_DOCUMENTATION, tempEl)) | |
1264 { | |
1265 output.setDocumentationElement(tempEl); | |
1266 } | |
1267 else if (QNameUtils.matches(Constants.Q_ELEM_REPRESENTATION, tempEl)) | |
1268 { | |
1269 String outputXSD = DOMUtils.getAttribute(tempEl, Constants.REQUEST_ELEMENT_NAME); | |
1270 //output.setName(outputXSD); | |
1271 outputXSDList.add(outputXSD); | |
1272 System.out.println("OutPut XSD:"+outputXSD); | |
1273 | |
1274 } | |
1275 else if (QNameUtils.matches(Constants.Q_ELEM_PARAM, tempEl)) | |
1276 { | |
1277 Param param = new ParamImpl(); | |
1278 List remainingParamAttrs = DOMUtils.getAttributes(tempEl); | |
1279 String parammodelReference = DOMUtils.getAttributeNS(tempEl, | |
1280 WORKING_SEMANTIC_NAMESPACE, | |
1281 Constants.ATTR_MODELREF, | |
1282 remainingAttrs); | |
1283 String liftingschema = DOMUtils.getAttributeNS(tempEl, | |
1284 WORKING_SEMANTIC_NAMESPACE, | |
1285 Constants.ATTR_LIFTINGSCHEMAMAPPING, | |
1286 remainingAttrs); | |
1287 String loweringschema = DOMUtils.getAttributeNS(tempEl, | |
1288 WORKING_SEMANTIC_NAMESPACE, | |
1289 Constants.ATTR_LOWERINGSCHEMAMAPPING, | |
1290 remainingAttrs); | |
1291 | |
1292 param.setModelreference(parammodelReference); | |
1293 param.setModelreference(liftingschema); | |
1294 param.setModelreference(loweringschema); | |
1295 | |
1296 String style = DOMUtils.getAttribute(tempEl, Constants.PARAM_STYLE); | |
1297 String type = DOMUtils.getAttribute(tempEl, Constants.PARAM_TYPE); | |
1298 | |
1299 param.setName(DOMUtils.getAttribute(tempEl, Constants.PARAM_NAME)); | |
1300 param.setDefault1(DOMUtils.getAttribute(tempEl, Constants.PARAM_DEFAULT)); | |
1301 param.setRequired(DOMUtils.getAttribute(tempEl, Constants.PARAM_REQUIRED)); | |
1302 | |
1303 if(style.equalsIgnoreCase("query") && type!=null){ | |
1304 param.setType(type); | |
1305 } | |
1306 else{ | |
1307 List<String> optionValue = new ArrayList<String>(30); | |
1308 Element paramoption = DOMUtils.getFirstChildElement(tempEl); | |
1309 | |
1310 | |
1311 for (; paramoption != null; paramoption = DOMUtils.getNextSiblingElement(paramoption)) | |
1312 { | |
1313 optionValue.add(DOMUtils.getAttribute(paramoption, Constants.OPTION_VALUE)); | |
1314 } | |
1315 | |
1316 param.setOptionvalue(optionValue); | |
1317 } | |
1318 | |
1319 paramList.add(param); | |
1320 | |
1321 } | |
1322 | |
1323 else | |
1324 { | |
1325 DOMUtils.throwWADLException(tempEl); | |
1326 } | |
1327 | |
1328 tempEl = DOMUtils.getNextSiblingElement(tempEl); | |
1329 } | |
1330 | |
1331 output.setInputXSDList(outputXSDList); | |
1332 output.setParamList(paramList); | |
1333 | |
1334 return output; | |
1335 } | |
1336 | |
1337 protected PreCondition parsePreCondition(Element preConEl, Application def) | |
1338 throws WADLSException, URISyntaxException | |
1339 { | |
1340 PreCondition preCondition = def.createPreCondition(); | |
1341 | |
1342 //String name = DOMUtils.getAttribute(preConEl, Constants.ATTR_NAME); | |
1343 String attrModelReference = DOMUtils.getQualifiedValue(WORKING_SEMANTIC_NAMESPACE, Constants.ATTR_MODELREF, def); | |
1344 String modelReference = DOMUtils.getAttribute(preConEl, attrModelReference); | |
1345 String expression = DOMUtils.getAttribute(preConEl, Constants.ATTR_EXPRESSION); | |
1346 System.out.println("Pre Condition:"+expression); | |
1347 | |
1348 | |
1349 if (modelReference != null) | |
1350 { | |
1351 parseModelReference(modelReference, def, preCondition); | |
1352 /*ModelReference mr = def.createModelReference(); | |
1353 mr.valueOf(modelReference, def); | |
1354 mr.setParent(preCondition); | |
1355 preCondition.addModelReference(mr);*/ | |
1356 } | |
1357 | |
1358 if (expression != null) | |
1359 { | |
1360 preCondition.setExpression(expression); | |
1361 } | |
1362 | |
1363 | |
1364 // parseExtensibilityAttributes(preConEl, PreCondition.class, preCondition, def); | |
1365 | |
1366 return preCondition; | |
1367 } | |
1368 | |
1369 protected Effect parseEffect(Element effectEl, Application def) | |
1370 throws WADLSException, URISyntaxException | |
1371 { | |
1372 Effect effect = def.createEffect(); | |
1373 //String name = DOMUtils.getAttribute(effectEl, Constants.ATTR_NAME); | |
1374 String attrModelReference = DOMUtils.getQualifiedValue(WORKING_SEMANTIC_NAMESPACE, Constants.ATTR_MODELREF, def); | |
1375 String modelReference = DOMUtils.getAttribute(effectEl, attrModelReference); | |
1376 String expression = DOMUtils.getAttribute(effectEl, Constants.ATTR_EXPRESSION); | |
1377 System.out.println("EFFECT:"+expression); | |
1378 | |
1379 /*if (name != null) | |
1380 { | |
1381 effect.setName(name); | |
1382 }*/ | |
1383 | |
1384 if (modelReference != null) | |
1385 { | |
1386 parseModelReference(modelReference, def, effect); | |
1387 /*ModelReference mr = def.createModelReference(); | |
1388 mr.valueOf(modelReference, def); | |
1389 mr.setParent(effect); | |
1390 effect.addModelReference(mr);*/ | |
1391 } | |
1392 | |
1393 if (expression != null) | |
1394 { | |
1395 effect.setExpression(expression); | |
1396 } | |
1397 | |
1398 | |
1399 // parseExtensibilityAttributes(effectEl, Effect.class, effect, def); | |
1400 | |
1401 return effect; | |
1402 } | |
1403 | |
1404 /** | |
1405 * This method should be used for elements that support extension | |
1406 * attributes because it does not track unexpected remaining attributes. | |
1407 */ | |
1408 private static QName getQualifiedAttributeValue(Element el, | |
1409 String attrName, | |
1410 String elDesc, | |
1411 Application def) | |
1412 throws WADLSException | |
1413 { | |
1414 try | |
1415 { | |
1416 return DOMUtils.getQualifiedAttributeValue(el, | |
1417 attrName, | |
1418 elDesc, | |
1419 false, | |
1420 def); | |
1421 } | |
1422 catch (WADLSException e) | |
1423 { | |
1424 if (e.getFaultCode().equals(WADLSException.NO_PREFIX_SPECIFIED)) | |
1425 { | |
1426 String attrValue = DOMUtils.getAttribute(el, attrName); | |
1427 | |
1428 return new QName(attrValue); | |
1429 } | |
1430 else | |
1431 { | |
1432 throw e; | |
1433 } | |
1434 } | |
1435 } | |
1436 | |
1437 /** | |
1438 * This method should be used for elements that do not support extension | |
1439 * attributes because it tracks unexpected remaining attributes. | |
1440 */ | |
1441 private static QName getQualifiedAttributeValue(Element el, | |
1442 String attrName, | |
1443 String elDesc, | |
1444 Application def, | |
1445 List remainingAttrs) | |
1446 throws WADLSException | |
1447 { | |
1448 try | |
1449 { | |
1450 return DOMUtils.getQualifiedAttributeValue(el, | |
1451 attrName, | |
1452 elDesc, | |
1453 false, | |
1454 def, | |
1455 remainingAttrs); | |
1456 } | |
1457 catch (WADLSException e) | |
1458 { | |
1459 if (e.getFaultCode().equals(WADLSException.NO_PREFIX_SPECIFIED)) | |
1460 { | |
1461 String attrValue = DOMUtils.getAttribute(el, attrName, remainingAttrs); | |
1462 | |
1463 return new QName(attrValue); | |
1464 } | |
1465 else | |
1466 { | |
1467 throw e; | |
1468 } | |
1469 } | |
1470 } | |
1471 | |
1472 private static void checkElementName(Element el, QName qname) | |
1473 throws WADLSException | |
1474 { | |
1475 System.out.println("Element Name:"+el); | |
1476 System.out.println("Q Name:"+qname.toString()); | |
1477 if (!QNameUtils.matches(qname, el)) | |
1478 { | |
1479 WADLSException wsdlExc = new WADLSException(WADLSException.INVALID_WADL, | |
1480 "Expected element '" + | |
1481 qname + "'."); | |
1482 | |
1483 wsdlExc.setLocation(XPathUtils.getXPathExprFromNode(el)); | |
1484 | |
1485 throw wsdlExc; | |
1486 } | |
1487 } | |
1488 | |
1489 private static Document getDocument(InputSource inputSource, | |
1490 String desc) throws WADLSException | |
1491 { | |
1492 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
1493 | |
1494 factory.setNamespaceAware(true); | |
1495 factory.setValidating(false); | |
1496 | |
1497 try | |
1498 { | |
1499 DocumentBuilder builder = factory.newDocumentBuilder(); | |
1500 Document doc = builder.parse(inputSource); | |
1501 | |
1502 return doc; | |
1503 } | |
1504 catch (Throwable t) | |
1505 { | |
1506 throw new WADLSException(WADLSException.XSDPARSER_ERROR, | |
1507 "Problem parsing '" + desc + "'.", | |
1508 t); | |
1509 } | |
1510 } | |
1511 | |
1512 /** | |
1513 * Read the WSDL document accessible via the given input stream | |
1514 * @param wsdlIS a InputStream for a WSDL XML definition | |
1515 * @return the definition. | |
1516 * @throws WADLSException | |
1517 */ | |
1518 public Application readWADL(InputStream wsdlIS) | |
1519 throws WADLSException | |
1520 { | |
1521 try | |
1522 { | |
1523 InputSource inputSource = new InputSource(wsdlIS); | |
1524 Document doc = getDocument(inputSource, ""); | |
1525 | |
1526 wsdlIS.close(); | |
1527 | |
1528 //note that documentBaseURI will be null | |
1529 //importing wsdl or schema should use absolution path/URL | |
1530 Application def = readWADL(null, doc); | |
1531 | |
1532 return def; | |
1533 } | |
1534 catch (WADLSException e) | |
1535 { | |
1536 throw e; | |
1537 } | |
1538 catch (Throwable t) | |
1539 { | |
1540 throw new WADLSException(WADLSException.OTHER_ERROR, | |
1541 "Unable to resolve imported document at '", t); | |
1542 } | |
1543 } | |
1544 | |
1545 /** | |
1546 * Read the WSDL document accessible via the specified | |
1547 * URI into a WSDL definition. | |
1548 * | |
1549 * @param wsdlURI a URI (can be a filename or URL) pointing to a | |
1550 * WSDL XML definition. | |
1551 * @return the definition. | |
1552 */ | |
1553 public Application readWADL(String wsdlURI) throws WADLSException | |
1554 { | |
1555 return readWADL(null, wsdlURI); | |
1556 } | |
1557 | |
1558 /** | |
1559 * Read the WSDL document accessible via the specified | |
1560 * URI into a WSDL definition. | |
1561 * | |
1562 * @param contextURI the context in which to resolve the | |
1563 * wsdlURI, if the wsdlURI is relative. Can be null, in which | |
1564 * case it will be ignored. | |
1565 * @param wsdlURI a URI (can be a filename or URL) pointing to a | |
1566 * WSDL XML definition. | |
1567 * @return the definition. | |
1568 */ | |
1569 public Application readWADL(String contextURI, String wsdlURI) | |
1570 throws WADLSException | |
1571 { | |
1572 try | |
1573 { | |
1574 if (verbose) | |
1575 { | |
1576 System.out.println("Retrieving document at '" + wsdlURI + "'" + | |
1577 (contextURI == null | |
1578 ? "." | |
1579 : ", relative to '" + contextURI + "'.")); | |
1580 } | |
1581 | |
1582 URL contextURL = (contextURI != null) | |
1583 ? StringUtils.getURL(null, contextURI) | |
1584 : null; | |
1585 URL url = StringUtils.getURL(contextURL, wsdlURI); | |
1586 InputStream inputStream = url.openStream(); | |
1587 InputSource inputSource = new InputSource(inputStream); | |
1588 inputSource.setSystemId(url.toString()); | |
1589 Document doc = getDocument(inputSource, url.toString()); | |
1590 | |
1591 inputStream.close(); | |
1592 | |
1593 Application def = readWADL(url.toString(), doc); | |
1594 | |
1595 return def; | |
1596 } | |
1597 catch (WADLSException e) | |
1598 { | |
1599 throw e; | |
1600 } | |
1601 catch (Throwable t) | |
1602 { | |
1603 throw new WADLSException(WADLSException.OTHER_ERROR, | |
1604 "Unable to resolve imported document at '" + | |
1605 wsdlURI + | |
1606 (contextURI == null | |
1607 ? "'." | |
1608 : "', relative to '" + contextURI + "'.") | |
1609 , t); | |
1610 } | |
1611 } | |
1612 | |
1613 /** | |
1614 * Read the specified <wsdl:definitions> element into a WSDL | |
1615 * definition. | |
1616 * | |
1617 * @param documentBaseURI the document base URI of the WSDL definition | |
1618 * described by the element. Will be set as the documentBaseURI | |
1619 * of the returned Definition. Can be null, in which case it | |
1620 * will be ignored. | |
1621 * @param definitionsElement the <wsdl:definitions> element | |
1622 * @return the definition described by the element. | |
1623 * @throws URISyntaxException | |
1624 */ | |
1625 public Application readWADL(String documentBaseURI, | |
1626 Element definitionsElement) | |
1627 throws WADLSException, URISyntaxException | |
1628 { | |
1629 return readWADL(documentBaseURI, definitionsElement, null); | |
1630 } | |
1631 | |
1632 protected Application readWADL(String documentBaseURI, | |
1633 Element definitionsElement, | |
1634 Map importedDefs) | |
1635 throws WADLSException, URISyntaxException | |
1636 { | |
1637 return parseApplications(documentBaseURI, definitionsElement, importedDefs); | |
1638 } | |
1639 | |
1640 /** | |
1641 * Read the specified WSDL document into a WSDL definition. | |
1642 * | |
1643 * @param documentBaseURI the document base URI of the WSDL definition | |
1644 * described by the document. Will be set as the documentBaseURI | |
1645 * of the returned Definition. Can be null, in which case it | |
1646 * will be ignored. | |
1647 * @param wsdlDocument the WSDL document, an XML | |
1648 * document obeying the WSDL schema. | |
1649 * @return the definition described in the document. | |
1650 * @throws URISyntaxException | |
1651 */ | |
1652 public Application readWADL(String documentBaseURI, Document wsdlDocument) | |
1653 throws WADLSException, URISyntaxException | |
1654 { | |
1655 return readWADL(documentBaseURI, wsdlDocument.getDocumentElement()); | |
1656 } | |
1657 | |
1658 /** | |
1659 * Read a WSDL document into a WSDL definition. | |
1660 * | |
1661 * @param documentBaseURI the document base URI of the WSDL definition | |
1662 * described by the document. Will be set as the documentBaseURI | |
1663 * of the returned Definition. Can be null, in which case it | |
1664 * will be ignored. | |
1665 * @param inputSource an InputSource pointing to the | |
1666 * WSDL document, an XML document obeying the WSDL schema. | |
1667 * @return the definition described in the document pointed to | |
1668 * by the InputSource. | |
1669 * @throws URISyntaxException | |
1670 */ | |
1671 public Application readWADL(String documentBaseURI, InputSource inputSource) | |
1672 throws WADLSException, URISyntaxException | |
1673 { | |
1674 return readWADL(documentBaseURI, | |
1675 getDocument(inputSource, "- WSDL Document -")); | |
1676 } | |
1677 | |
1678 /** | |
1679 * Read a WSDL document into a WSDL definition. | |
1680 * | |
1681 * @param locator A WSDLLocator object used to provide InputSources | |
1682 * pointing to the wsdl file. | |
1683 * @return the definition described in the document | |
1684 * @throws URISyntaxException | |
1685 */ | |
1686 public Application readWADL(WADLLocator locator) throws WADLSException, URISyntaxException | |
1687 { | |
1688 InputSource is = locator.getBaseInputSource(); | |
1689 String base = locator.getBaseURI(); | |
1690 | |
1691 if (is == null) | |
1692 { | |
1693 throw new WADLSException(WADLSException.OTHER_ERROR, | |
1694 "Unable to locate document at '" + base + "'."); | |
1695 } | |
1696 | |
1697 this.loc = locator; | |
1698 | |
1699 if (verbose) | |
1700 { | |
1701 System.out.println("Retrieving document at '" + base + "'."); | |
1702 } | |
1703 | |
1704 return readWADL(base, is); | |
1705 } | |
1706 | |
1707 protected List<ModelReference> parseModelReference (String modelReference, Application def, ModelReferenceExtensible op) throws URISyntaxException,WADLSException{ | |
1708 List <ModelReference> modelReferenceList= new ArrayList<ModelReference>(); | |
1709 String [] modelRefs= modelReference.split("\\s"); | |
1710 ModelReference currentModelReference; | |
1711 for(int modelRefsIT= 0;modelRefsIT<modelRefs.length;modelRefsIT++){ | |
1712 currentModelReference= def.createModelReference(); | |
1713 currentModelReference.valueOf(modelRefs[modelRefsIT], def); | |
1714 currentModelReference.setParent(op); | |
1715 modelReferenceList.add(currentModelReference); | |
1716 op.addModelReference(currentModelReference); | |
1717 }// end for modelRefsIT | |
1718 | |
1719 return modelReferenceList; | |
1720 | |
1721 | |
1722 }// end method parseModelref | |
1723 | |
1724 protected List<ModelReference> parseModelReference(String modelReferences, Application def) throws URISyntaxException, WADLSException { | |
1725 return ModelReferenceImpl.getModelReferences(modelReferences, def); | |
1726 } | |
1727 } |