KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsdl > impl > WSDLDescriptionImpl


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.wsdl.impl;
17
18 import org.apache.wsdl.*;
19 import org.apache.wsdl.extensions.ExtensionFactory;
20 import org.apache.wsdl.extensions.impl.ExtensionFactoryImpl;
21
22 import javax.xml.namespace.QName JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * @author chathura@opensource.lk
30  */

31 public class WSDLDescriptionImpl extends ComponentImpl
32         implements WSDLDescription {
33     /**
34      * The name token of WSDL 1.1 Definition.
35      */

36     private QName JavaDoc wsdl1DefinitionName;
37
38     // TODO local name and the naspace name to be made static or through a Constant class.
39
// The attribute information items
40
// TODO required; thus check it up
41

42     /**
43      * Field targetNameSpace
44      */

45     private String JavaDoc targetNameSpace;
46
47     // private NamespaceMappings[] namespaceDefinitions;
48
// TODO The object structure of some external xml data binding is going to be pluged here eventually.
49

50     /**
51      * Field types
52      */

53     private WSDLTypes types;
54
55     /**
56      * This List will be a list of <code>WSDLInterface</code> objects.
57      */

58     private Map JavaDoc wsdlInterfaces = new HashMap JavaDoc();
59
60     /**
61      * This <code>HashMap </code> is a Map of <code>WSDLBinding </code> objects.
62      */

63     private Map JavaDoc bindings = new HashMap JavaDoc();
64
65     /**
66      * This <code>HashMap </code> is a list of <code>WSDLService </code> objects.
67      * Support of multiple is backed by the requirements in the specification.
68      */

69     private Map JavaDoc services = new HashMap JavaDoc();
70
71     /**
72      * WSDL imports
73      */

74     private ArrayList JavaDoc imports = new ArrayList JavaDoc();
75
76     /**
77      * WSDL Includes.
78      */

79     private ArrayList JavaDoc includes = new ArrayList JavaDoc();
80
81     /**
82      * Will keep a map of all the Namespaces associated with the
83      * Definition Component and will be keyed by the Namespace prefix.
84      */

85     private Map JavaDoc namespaces = new HashMap JavaDoc();
86
87     /**
88      * Returns a Map of <code>WSDLBindings</code> Objects keyed by the <code>QName</code>
89      * of the Binding.
90      *
91      * @return
92      */

93     public Map JavaDoc getBindings() {
94         return bindings;
95     }
96
97     /**
98      * Sets the whole new set of Bindings to the WSDLDefinition.
99      *
100      * @param bindings
101      */

102     public void setBindings(Map JavaDoc bindings) {
103
104         // if(this.bindings.size() > 0) throw new WSDLProcessingException("WSDLBimding Map already contains " +
105
// "one or more bindings. Trying to assign a new map will loose those Bindings.");
106
this.bindings = bindings;
107     }
108
109     /**
110      * The WSDLBinding Will be added to the map keyed with its own QName.
111      * If the WSDLBinding is null it will not be added.
112      * If the WSDLBinding is not null and Binding name is null then
113      * WSDLProcessingException will be thrown
114      *
115      * @param binding <code>WSDLBinding</code> Object
116      */

117     public void addBinding(WSDLBinding binding) {
118         if (null == binding) {
119             return;
120         }
121         if (null == binding.getName()) {
122             throw new WSDLProcessingException(
123                     "The WSDLBinding name cannot be null(Required)");
124         }
125         this.bindings.put(binding.getName(), binding);
126     }
127
128     /**
129      * Retrives the <code>WSDLBinding</code> by its QName. Wil return null
130      * if <code>WSDLBinding</code> is not found.
131      *
132      * @param qName The QName of the Binding.
133      * @return
134      */

135     public WSDLBinding getBinding(QName JavaDoc qName) {
136         return (WSDLBinding) this.bindings.get(qName);
137     }
138
139     /**
140      * The Interface component will be added to the map keyed with its own name.
141      * If the Interface is null it will not be added.
142      * If the interface name is null an WSDLProcessingException will be thrown
143      *
144      * @param interfaceComponent
145      */

146     public void addInterface(WSDLInterface interfaceComponent) {
147         if (null == interfaceComponent) {
148             return;
149         }
150         if (null == interfaceComponent.getName()) {
151             throw new WSDLProcessingException(
152                     "PortType/Interface name cannot be null(Required) ");
153         }
154         this.wsdlInterfaces.put(interfaceComponent.getName(),
155                 interfaceComponent);
156     }
157
158     /**
159      * The Interface Component will be returned if it exsists,
160      * otherwise null will be returned.
161      *
162      * @param qName qName of the Interface.
163      * @return The Interface Component with the relavent QName
164      */

165     public WSDLInterface getInterface(QName JavaDoc qName) {
166         return (WSDLInterface) this.wsdlInterfaces.get(qName);
167     }
168
169     /**
170      * Method getServices
171      *
172      * @return
173      */

174     public Map JavaDoc getServices() {
175         return services;
176     }
177
178     /**
179      * Method setServices
180      *
181      * @param services
182      */

183     public void setServices(Map JavaDoc services) {
184         this.services = services;
185     }
186
187     /**
188      * Will return the <code>WSDLService </code> if found otherwise return null.
189      *
190      * @param qName <code>QName</code> of the Service
191      * @return The Service with the relavent QName
192      */

193     public WSDLService getService(QName JavaDoc qName) {
194         return (WSDLService) this.services.get(qName);
195     }
196
197     /**
198      * Will add the <code>WSDLService</code> to the Map.
199      * If object is null it will not be added.
200      * If the <code>WSDLService</code> name is null a <code>WSDLProcessingException</code>
201      * will be thrown.(its required)
202      *
203      * @param service
204      */

205     public void addService(WSDLService service) {
206         if (null == service) {
207             return;
208         }
209         if (null == service.getName()) {
210             throw new WSDLProcessingException(
211                     "The WSDLService name cannot be null (Required)");
212         }
213         this.services.put(service.getName(), service);
214     }
215
216     /**
217      * Method getTargetNameSpace
218      *
219      * @return
220      */

221     public String JavaDoc getTargetNameSpace() {
222         return targetNameSpace;
223     }
224
225     /**
226      * Method setTargetNameSpace
227      *
228      * @param targetNameSpace
229      */

230     public void setTargetNameSpace(String JavaDoc targetNameSpace) {
231         this.targetNameSpace = targetNameSpace;
232     }
233
234     /**
235      * Method getWsdlInterfaces
236      *
237      * @return
238      */

239     public Map JavaDoc getWsdlInterfaces() {
240         return wsdlInterfaces;
241     }
242
243     /**
244      * Method setWsdlInterfaces
245      *
246      * @param wsdlInterfaces
247      */

248     public void setWsdlInterfaces(Map JavaDoc wsdlInterfaces) {
249         this.wsdlInterfaces = wsdlInterfaces;
250     }
251
252     /**
253      * Method getTypes
254      *
255      * @return
256      */

257     public WSDLTypes getTypes() {
258         return types;
259     }
260
261     /**
262      * Method setTypes
263      *
264      * @param types
265      */

266     public void setTypes(WSDLTypes types) {
267         this.types = types;
268     }
269
270     /**
271      * Gets the name attribute of the WSDL 1.1 Definitions Element
272      *
273      * @return
274      */

275     public QName JavaDoc getWSDL1DefinitionName() {
276         return wsdl1DefinitionName;
277     }
278
279     /**
280      * Sets the name attribute of the WSDL 1.1 Definitions Element
281      *
282      * @param wsdl1DefinitionName
283      */

284     public void setWSDL1DefinitionName(QName JavaDoc wsdl1DefinitionName) {
285         this.wsdl1DefinitionName = wsdl1DefinitionName;
286     }
287
288     /**
289      * Will return all the Namespaces associated with the Definition
290      * Component and will be keyed by the Napespace Prefix.
291      *
292      * @return
293      */

294     public Map JavaDoc getNamespaces() {
295         return namespaces;
296     }
297
298     /**
299      * Sets the Namespaces associated with the Difinition Component
300      * and they should be keyed by its Namespace Prefix.
301      *
302      * @param namespaces
303      */

304     public void setNamespaces(Map JavaDoc namespaces) {
305         this.namespaces = namespaces;
306     }
307
308     /**
309      * Will return the Namespace URI as a String if there exists an
310      * Namespace URI associated with the given prefix, in the Definition
311      * Component, Will return null if not found.
312      *
313      * @param prefix Prefix defined in the Definitions elemet in the WSDL file
314      * @return The Namespace URI for the prefix.
315      */

316     public String JavaDoc getNamespace(String JavaDoc prefix) {
317         if (null == prefix) {
318             return null;
319         }
320         return (String JavaDoc) this.namespaces.get(prefix);
321     }
322
323     /**
324      * Returns the WSDL Imports in an <code>ArrayList</code>
325      *
326      * @return
327      */

328     public ArrayList JavaDoc getImports() {
329         return imports;
330     }
331
332     /**
333      * Sets the imports as an <code>ArrayList</code>
334      *
335      * @param imports
336      */

337     public void setImports(ArrayList JavaDoc imports) {
338         this.imports = imports;
339     }
340
341     /**
342      * Adds an import to the list.
343      *
344      * @param wsdlImport
345      */

346     public void addImports(WSDLImport wsdlImport) {
347         this.imports.add(wsdlImport);
348     }
349
350     /**
351      * Returns the Includes as an <code>ArrayList</code>
352      *
353      * @return
354      */

355     public ArrayList JavaDoc getIncludes() {
356         return includes;
357     }
358
359     /**
360      * Sets the includes as an <code>Arraylist</code>
361      *
362      * @param includes
363      */

364     public void setIncludes(ArrayList JavaDoc includes) {
365         this.includes = includes;
366     }
367
368     /**
369      * Adds the WSDL Include to the list.
370      *
371      * @param wsdlInclude
372      */

373     public void addInclude(WSDLInclude wsdlInclude) {
374         this.includes.add(wsdlInclude);
375     }
376
377     /**
378      * @return A new instance of type <code>WSDLDescription</code>
379      */

380     public WSDLDescription createDescription() {
381         return new WSDLDescriptionImpl();
382     }
383
384     /**
385      * @return A new instance of type <code>WSDLService</code>
386      */

387     public WSDLService createService() {
388         return new WSDLServiceImpl();
389     }
390
391     /**
392      * @return A new instance of type <code>WSDLInterface</code>
393      */

394     public WSDLInterface createInterface() {
395         return new WSDLInterfaceImpl();
396     }
397
398     /**
399      * @return A new instance of type <code>WSDLTypes</code>
400      */

401     public WSDLTypes createTypes() {
402         return new WSDLTypesImpl();
403     }
404
405     /**
406      * @return A new instance of type <code>WSDLBinding</code>
407      */

408     public WSDLBinding createBinding() {
409         return new WSDLBindingImpl();
410     }
411
412     /**
413      * @return A new instance of type <code>WSDLOperation</code>
414      */

415     public WSDLOperation createOperation() {
416         return new WSDLOperationImpl();
417     }
418
419     /**
420      * @return A new instance of type <code>WSDLEndpoint</code>
421      */

422     public WSDLEndpoint createEndpoint() {
423         return new WSDLEndpointImpl();
424     }
425
426
427     /**
428      * @return A new instance of type <code>WSDLFeature</code>
429      */

430     public WSDLFeature createFeature() {
431         return new WSDLFeatureImpl();
432     }
433
434     /**
435      * @return A new instance of type <code>WSDLImport</code>
436      */

437     public WSDLImport createImport() {
438         return new WSDLImportImpl();
439     }
440
441     /**
442      * @return A new instance of type <code>WSDLInclude</code>
443      */

444     public WSDLInclude createInclude() {
445         return new WSDLIncludeImpl();
446     }
447
448     /**
449      * Method createProperty
450      *
451      * @return
452      */

453     public WSDLProperty createProperty() {
454         return new WSDLPropertyImpl();
455     }
456     
457     public MessageReference createMessageReference(){
458         return new MessageReferenceImpl();
459     }
460     
461     public WSDLBindingMessageReference createWSDLBindingMessageReference(){
462         return new WSDLBindingMessageReferenceImpl();
463     }
464     
465     public WSDLBindingOperation createWSDLBindingOperation(){
466         return new WSDLBindingOperationImpl();
467     }
468     
469     /**
470      *
471      * @return A new Instance of <code>ExtensionFactory</code> that
472      * is capable of creating the correct <code>ExtensibilityElement</code>
473      * given a <code>QName</code>.
474      */

475     public ExtensionFactory createExtensionFactory(){
476         return new ExtensionFactoryImpl();
477     }
478
479     
480     public WSDLBinding getFirstBinding(){
481         Iterator JavaDoc bindingIterator = this.bindings.values().iterator();
482         if(bindingIterator.hasNext()){
483             return (WSDLBinding)bindingIterator.next();
484         }
485         throw new WSDLProcessingException("No Binding Components are available");
486     }
487     
488     public WSDLExtensibilityAttribute createWSDLExtensibilityAttribute(){
489         return new WSDLExtensibilityAttributeImpl();
490     }
491     
492     public WSDLFaultReference createFaultReference(){
493         return new WSDLFaultReferenceImpl();
494     }
495     
496     public WSDLBindingFault createBindingFault(){
497         return new WSDLBindingFaultImpl();
498     }
499 }
500
Popular Tags