0
|
1 /*
|
|
2 * (c) Copyright IBM Corp 2001, 2005
|
|
3 */
|
|
4
|
|
5 package edu.uga.cs.lsdis.meteors.wadls;
|
|
6
|
|
7 import java.net.URI;
|
|
8 import java.util.*;
|
|
9
|
|
10 import javax.wadls.*;
|
|
11 import javax.wadls.extensions.*;
|
|
12 import javax.wadls.extensions.ExtensionRegistry;
|
|
13 import javax.xml.namespace.*;
|
|
14 import org.w3c.dom.*;
|
|
15
|
|
16 /**
|
|
17 * This class represents a WSDLS definition.
|
|
18 *
|
|
19 * @author Zixin Wu (wuzixin@uga.edu)
|
|
20 * @author Paul Fremantle
|
|
21 * @author Nirmal Mukhi
|
|
22 * @author Matthew J. Duftler
|
|
23 * @author namelessNerd
|
|
24 */
|
|
25 public class ApplicationImpl implements Application
|
|
26 {
|
|
27 protected String documentBaseURI = null;
|
|
28 protected QName name = null;
|
|
29 protected String targetNamespace = null;
|
|
30 protected Map namespaces = new HashMap();
|
|
31 protected Map includes = new HashMap();
|
|
32 protected Params params = null;
|
|
33 protected Grammars grammars = null;
|
|
34 protected Map resources = new HashMap();
|
|
35 protected Element docEl = null;
|
|
36 protected String resourcespath=null;
|
|
37 protected List extElements = new Vector();
|
|
38
|
|
39 // added by namelessNerd
|
|
40 protected List modelReferenceList= new ArrayList();
|
|
41 protected List ontologyNamespaces= new ArrayList();
|
|
42 // end namelessNerd additions
|
|
43
|
|
44 protected ExtensionRegistry extReg = null;
|
|
45
|
|
46 public static final long serialVersionUID = 1;
|
|
47
|
|
48 /**
|
|
49 * Get all the Parts which has a modelReference with the specified namespace and concept.
|
|
50 * @param namespace The namespace of the modelReference
|
|
51 * @param concept The concept of the modelReference
|
|
52 * @return All the Parts which has a modelReference with the specified namespace and concept.
|
|
53 */
|
|
54
|
|
55 /**
|
|
56 * Get all the Operations which has a modelReference with the specified namespace and concept.
|
|
57 * @param namespace The namespace of the modelReference
|
|
58 * @param concept The concept of the modelReference
|
|
59 * @return All the Operations which has a modelReference with the specified namespace and concept.
|
|
60 */
|
|
61 public List getMethodsByModelReference(URI namespace, String concept){
|
|
62 //TODO not implemented yet.
|
|
63 return null;
|
|
64 }
|
|
65
|
|
66
|
|
67 /**
|
|
68 * Get all the XSD Elements which has a modelReference with the specified namespace and concept.
|
|
69 * @param namespace The namespace of the modelReference
|
|
70 * @param concept The concept of the modelReference
|
|
71 * @return All the XSD Elements which has a modelReference with the specified namespace and concept.
|
|
72 */
|
|
73 public List getXSDElementsByModelReference(URI namespace, String concept){
|
|
74 //TODO not implemented yet.
|
|
75 return null;
|
|
76 }
|
|
77
|
|
78 /**
|
|
79 * Get all the XSD ComplexTypes which has a modelReference with the specified namespace and concept.
|
|
80 * @param namespace The namespace of the modelReference
|
|
81 * @param concept The concept of the modelReference
|
|
82 * @return All the XSD ComplexTypes which has a modelReference with the specified namespace and concept.
|
|
83 */
|
|
84 public List getXSDComplexTypeByModelReference(URI namespace, String concept){
|
|
85 //TODO not implemented yet.
|
|
86 return null;
|
|
87 }
|
|
88
|
|
89
|
|
90 /**
|
|
91 * Set the document base URI of this definition. Can be used to
|
|
92 * represent the origin of the Definition, and can be exploited
|
|
93 * when resolving relative URIs (e.g. in <import>s).
|
|
94 *
|
|
95 * @param documentBaseURI the document base URI of this definition
|
|
96 */
|
|
97
|
|
98 /**
|
|
99 * Create a new modelReference.
|
|
100 *
|
|
101 * @return the newly created modelReference.
|
|
102 */
|
|
103 public ModelReference createModelReference(){
|
|
104 return new ModelReferenceImpl();
|
|
105 }
|
|
106
|
|
107
|
|
108
|
|
109 /**
|
|
110 * Create a new precondition.
|
|
111 *
|
|
112 * @return the newly created precondition
|
|
113 */
|
|
114 public PreCondition createPreCondition(){
|
|
115 return new OperationAddOnImpl();
|
|
116 }
|
|
117
|
|
118 /**
|
|
119 * Create a new effect.
|
|
120 *
|
|
121 * @return the newly created effect
|
|
122 */
|
|
123 public Effect createEffect(){
|
|
124 return new OperationAddOnImpl();
|
|
125 }
|
|
126
|
|
127 public void setDocumentBaseURI(String documentBaseURI)
|
|
128 {
|
|
129 this.documentBaseURI = documentBaseURI;
|
|
130 }
|
|
131
|
|
132
|
|
133 /**
|
|
134 * Get the document base URI of this definition.
|
|
135 *
|
|
136 * @return the document base URI
|
|
137 */
|
|
138 public String getDocumentBaseURI()
|
|
139 {
|
|
140 return documentBaseURI;
|
|
141 }
|
|
142
|
|
143 public void setResourcesPath(String resourcespath)
|
|
144 {
|
|
145 this.resourcespath = resourcespath;
|
|
146 }
|
|
147
|
|
148
|
|
149 /**
|
|
150 * Get the document base URI of this definition.
|
|
151 *
|
|
152 * @return the document base URI
|
|
153 */
|
|
154 public String getResourcesPath()
|
|
155 {
|
|
156 return resourcespath;
|
|
157 }
|
|
158
|
|
159 /**
|
|
160 * Set the name of this definition.
|
|
161 *
|
|
162 * @param name the desired name
|
|
163 */
|
|
164 public void setQName(QName name)
|
|
165 {
|
|
166 this.name = name;
|
|
167 }
|
|
168
|
|
169 /**
|
|
170 * Get the name of this definition.
|
|
171 *
|
|
172 * @return the definition name
|
|
173 */
|
|
174 public QName getQName()
|
|
175 {
|
|
176 return name;
|
|
177 }
|
|
178
|
|
179 /**
|
|
180 * Set the target namespace in which WSDL elements are defined.
|
|
181 *
|
|
182 * @param targetNamespace the target namespace
|
|
183 */
|
|
184 public void setTargetNamespace(String targetNamespace)
|
|
185 {
|
|
186 this.targetNamespace = targetNamespace;
|
|
187 }
|
|
188
|
|
189 /**
|
|
190 * Get the target namespace in which the WSDL elements
|
|
191 * are defined.
|
|
192 *
|
|
193 * @return the target namespace
|
|
194 */
|
|
195 public String getTargetNamespace()
|
|
196 {
|
|
197 return targetNamespace;
|
|
198 }
|
|
199
|
|
200 /**
|
|
201 * Get the target namespace in which the WSDL elements
|
|
202 * are defined.
|
|
203 *
|
|
204 * @return the target namespace
|
|
205 */
|
|
206 public List getAllModelReference()
|
|
207 {
|
|
208 // grabModel
|
|
209 return modelReferenceList;
|
|
210 }
|
|
211
|
|
212 /**
|
|
213 * This is a way to add a namespace association to a definition.
|
|
214 * It is similar to adding a namespace prefix declaration to the
|
|
215 * top of a <wsdl:definition> element. This has nothing to do
|
|
216 * with the <wsdl:import> element; there are separate methods for
|
|
217 * dealing with information described by <wsdl:import> elements.
|
|
218 *
|
|
219 * @param prefix the prefix to use for this namespace (when
|
|
220 * rendering this information as XML). Use null or an empty string
|
|
221 * to describe the default namespace (i.e. xmlns="...").
|
|
222 * @param namespaceURI the namespace URI to associate the prefix
|
|
223 * with. If you use null, the namespace association will be removed.
|
|
224 */
|
|
225 public void addNamespace(String prefix, String namespaceURI)
|
|
226 {
|
|
227 if (prefix == null)
|
|
228 {
|
|
229 prefix = "";
|
|
230 }
|
|
231
|
|
232 if (namespaceURI != null)
|
|
233 {
|
|
234 namespaces.put(prefix, namespaceURI);
|
|
235 }
|
|
236 else
|
|
237 {
|
|
238 namespaces.remove(prefix);
|
|
239 }
|
|
240 }
|
|
241
|
|
242 /**
|
|
243 * Get the namespace URI associated with this prefix. Or null if
|
|
244 * there is no namespace URI associated with this prefix. This is
|
|
245 * unrelated to the <wsdl:import> element.
|
|
246 *
|
|
247 * @see #addNamespace(String, String)
|
|
248 * @see #getPrefix(String)
|
|
249 */
|
|
250 public String getNamespace(String prefix)
|
|
251 {
|
|
252 if (prefix == null)
|
|
253 {
|
|
254 prefix = "";
|
|
255 }
|
|
256
|
|
257 return (String)namespaces.get(prefix);
|
|
258 }
|
|
259
|
|
260 /**
|
|
261 * Get a prefix associated with this namespace URI. Or null if
|
|
262 * there are no prefixes associated with this namespace URI. This is
|
|
263 * unrelated to the <wsdl:import> element.
|
|
264 *
|
|
265 * @see #addNamespace(String, String)
|
|
266 * @see #getNamespace(String)
|
|
267 */
|
|
268 public String getPrefix(String namespaceURI)
|
|
269 {
|
|
270 if (namespaceURI == null)
|
|
271 {
|
|
272 return null;
|
|
273 }
|
|
274
|
|
275 Iterator entryIterator = namespaces.entrySet().iterator();
|
|
276
|
|
277 while (entryIterator.hasNext())
|
|
278 {
|
|
279 Map.Entry entry = (Map.Entry)entryIterator.next();
|
|
280 String prefix = (String)entry.getKey();
|
|
281 String assocNamespaceURI = (String)entry.getValue();
|
|
282
|
|
283 if (namespaceURI.equals(assocNamespaceURI))
|
|
284 {
|
|
285 return prefix;
|
|
286 }
|
|
287 }
|
|
288
|
|
289 return null;
|
|
290 }
|
|
291
|
|
292 /**
|
|
293 * Get all namespace associations in this definition. The keys are
|
|
294 * the prefixes, and the namespace URIs are the values. This is
|
|
295 * unrelated to the <wsdl:import> element.
|
|
296 *
|
|
297 * @see #addNamespace(String, String)
|
|
298 */
|
|
299 public Map getNamespaces()
|
|
300 {
|
|
301 return namespaces;
|
|
302 }
|
|
303
|
|
304 /**
|
|
305 * Set the types section.
|
|
306 */
|
|
307 public void setParams(Params params)
|
|
308 {
|
|
309 this.params = params;
|
|
310 }
|
|
311
|
|
312 public void setGrammars(Grammars grammars)
|
|
313 {
|
|
314 this.grammars = grammars;
|
|
315 }
|
|
316 /**
|
|
317 * Get the types section.
|
|
318 *
|
|
319 * @return the types section
|
|
320 */
|
|
321 public Params getParams()
|
|
322 {
|
|
323 return params;
|
|
324 }
|
|
325
|
|
326 public Grammars getGrammars()
|
|
327 {
|
|
328 return grammars;
|
|
329 }
|
|
330
|
|
331 /**
|
|
332 * Add an import to this WADL description.
|
|
333 *
|
|
334 * @param importDef the import to be added
|
|
335 */
|
|
336 public void addInclude(Include includeApp)
|
|
337 {
|
|
338 String namespaceURI = includeApp.getNamespaceURI();
|
|
339 List includeList = (List)includes.get(namespaceURI);
|
|
340
|
|
341 if (includeList == null)
|
|
342 {
|
|
343 includeList = new Vector();
|
|
344
|
|
345 includes.put(namespaceURI, includeList);
|
|
346 }
|
|
347
|
|
348 includeList.add(includeApp);
|
|
349 }
|
|
350
|
|
351 /**
|
|
352 * Get the list of imports for the specified namespaceURI.
|
|
353 *
|
|
354 * @param namespaceURI the namespaceURI associated with the
|
|
355 * desired imports.
|
|
356 * @return a list of the corresponding imports, or null if
|
|
357 * there weren't any matching imports
|
|
358 */
|
|
359 public List getIncludes(String namespaceURI)
|
|
360 {
|
|
361 return (List)includes.get(namespaceURI);
|
|
362 }
|
|
363
|
|
364 /**
|
|
365 * Get a map of lists containing all the imports defined here.
|
|
366 * The map's keys are the namespaceURIs, and the map's values
|
|
367 * are lists. There is one list for each namespaceURI for which
|
|
368 * imports have been defined.
|
|
369 */
|
|
370 public Map getIncludes()
|
|
371 {
|
|
372 return includes;
|
|
373 }
|
|
374
|
|
375
|
|
376 /**
|
|
377 * Add a portType to this WSDL description.
|
|
378 *
|
|
379 * @param portType the portType to be added
|
|
380 */
|
|
381 public void addResource(Resource portType)
|
|
382 {
|
|
383 resources.put(portType.getQName(), portType);
|
|
384
|
|
385 }
|
|
386
|
|
387 /**
|
|
388 * Get the specified portType. Also checks imported documents.
|
|
389 *
|
|
390 * @param name the name of the desired portType.
|
|
391 * @return the corresponding portType, or null if there wasn't
|
|
392 * any matching portType
|
|
393 */
|
|
394 public Resource getResource(QName name)
|
|
395 {
|
|
396 Resource resource = (Resource)resources.get(name);
|
|
397
|
|
398 if (resource == null && name != null)
|
|
399 {
|
|
400 resource = (Resource)getFromIncludes(Constants.ELEM_RESOURCE, name);
|
|
401 }
|
|
402
|
|
403 return resource;
|
|
404 }
|
|
405
|
|
406 /**
|
|
407 * Remove the specified portType from this definition.
|
|
408 *
|
|
409 * @param name the name of the portType to remove
|
|
410 * @return the portType previously associated with this qname, if there
|
|
411 * was one; may return null
|
|
412 */
|
|
413 public Resource removeResource(QName name)
|
|
414 {
|
|
415 return (Resource)resources.remove(name);
|
|
416 }
|
|
417
|
|
418 /**
|
|
419 * Get all the portTypes defined here.
|
|
420 */
|
|
421 public Map getResources()
|
|
422 {
|
|
423 return resources;
|
|
424 }
|
|
425
|
|
426
|
|
427 /**
|
|
428 * Set the documentation element for this document. This dependency
|
|
429 * on org.w3c.dom.Element should eventually be removed when a more
|
|
430 * appropriate way of representing this information is employed.
|
|
431 *
|
|
432 * @param docEl the documentation element
|
|
433 */
|
|
434 public void setDocumentationElement(Element docEl)
|
|
435 {
|
|
436 this.docEl = docEl;
|
|
437 }
|
|
438
|
|
439 /**
|
|
440 * Get the documentation element. This dependency on org.w3c.dom.Element
|
|
441 * should eventually be removed when a more appropriate way of
|
|
442 * representing this information is employed.
|
|
443 *
|
|
444 * @return the documentation element
|
|
445 */
|
|
446 public Element getDocumentationElement()
|
|
447 {
|
|
448 return docEl;
|
|
449 }
|
|
450
|
|
451 /**
|
|
452 * Get all the extensibility elements defined here.
|
|
453 */
|
|
454 public List getExtensibilityElements()
|
|
455 {
|
|
456 return extElements;
|
|
457 }
|
|
458
|
|
459
|
|
460 /**
|
|
461 * Create a new import.
|
|
462 *
|
|
463 * @return the newly created import
|
|
464 */
|
|
465 public Include createInclude()
|
|
466 {
|
|
467 return new IncludeImpl();
|
|
468 }
|
|
469
|
|
470 /**
|
|
471 * Create a new input.
|
|
472 *
|
|
473 * @return the newly created input
|
|
474 */
|
|
475 public Request createRequest()
|
|
476 {
|
|
477 return new RequestImpl();
|
|
478 }
|
|
479
|
|
480
|
|
481 /**
|
|
482 * Create a new operation.
|
|
483 *
|
|
484 * @return the newly created operation
|
|
485 */
|
|
486 public Method createMethod()
|
|
487 {
|
|
488 return new MethodImpl();
|
|
489 }
|
|
490
|
|
491 /**
|
|
492 * Create a new output.
|
|
493 *
|
|
494 * @return the newly created output
|
|
495 */
|
|
496 public Response createResponse()
|
|
497 {
|
|
498 return new ResponseImpl();
|
|
499 }
|
|
500
|
|
501 /**
|
|
502 * Create a new port type.
|
|
503 *
|
|
504 * @return the newly created port type
|
|
505 */
|
|
506 public Resource createResource()
|
|
507 {
|
|
508 return new ResourceImpl();
|
|
509 }
|
|
510
|
|
511 /**
|
|
512 * Create a new types section.
|
|
513 *
|
|
514 * @return the newly created types section
|
|
515 */
|
|
516 public Params createParams()
|
|
517 {
|
|
518 return new ParamsImpl(this);
|
|
519 }
|
|
520 public Grammars createGrammars()
|
|
521 {
|
|
522 return new GrammarsImpl(this);
|
|
523 }
|
|
524
|
|
525 private Object getFromIncludes(String typeOfApplication, QName name)
|
|
526 {
|
|
527 Object ret = null;
|
|
528 List includeList = getIncludes(name.getNamespaceURI());
|
|
529
|
|
530 if (includeList != null)
|
|
531 {
|
|
532 Iterator includeIterator = includeList.iterator();
|
|
533
|
|
534 while (includeIterator.hasNext())
|
|
535 {
|
|
536 Include includeApp = (Include)includeIterator.next();
|
|
537
|
|
538 if (includeApp != null)
|
|
539 {
|
|
540 Application includedApp = includeApp.getApplication();
|
|
541
|
|
542 if (includedApp != null)
|
|
543 {
|
|
544 /*
|
|
545 These object comparisons will work fine because
|
|
546 this private method is only called from within
|
|
547 this class, using only the pre-defined constants
|
|
548 from the Constants class as the typeOfDefinition
|
|
549 argument.
|
|
550 */
|
|
551 if (typeOfApplication == Constants.ELEM_RESOURCE)
|
|
552 {
|
|
553 ret = includedApp.getResource(name);
|
|
554 }
|
|
555
|
|
556 if (ret != null)
|
|
557 {
|
|
558 return ret;
|
|
559 }
|
|
560 }
|
|
561 }
|
|
562 }
|
|
563 }
|
|
564
|
|
565 return ret;
|
|
566 }
|
|
567
|
|
568 public String toString()
|
|
569 {
|
|
570 StringBuffer strBuf = new StringBuffer();
|
|
571
|
|
572 strBuf.append("Definition: name=" + name +
|
|
573 " targetNamespace=" + targetNamespace);
|
|
574
|
|
575 if (includes != null)
|
|
576 {
|
|
577 Iterator includeIterator = includes.values().iterator();
|
|
578
|
|
579 while (includeIterator.hasNext())
|
|
580 {
|
|
581 strBuf.append("\n" + includeIterator.next());
|
|
582 }
|
|
583 }
|
|
584
|
|
585 if (params != null)
|
|
586 {
|
|
587 strBuf.append("\n" + params);
|
|
588 }
|
|
589
|
|
590
|
|
591
|
|
592 if (resources != null)
|
|
593 {
|
|
594 Iterator resourceIterator = resources.values().iterator();
|
|
595
|
|
596 while (resourceIterator.hasNext())
|
|
597 {
|
|
598 strBuf.append("\n" + resourceIterator.next());
|
|
599 }
|
|
600 }
|
|
601
|
|
602
|
|
603 return strBuf.toString();
|
|
604 }
|
|
605
|
|
606 }
|