KickJava   Java API By Example, From Geeks To Geeks.

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


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.WSDLInterface;
19 import org.apache.wsdl.WSDLOperation;
20
21 import javax.xml.namespace.QName JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * @author Chathura Herath
29  */

30 public class WSDLInterfaceImpl extends ExtensibleComponentImpl
31         implements WSDLInterface {
32     /**
33      * Field name
34      */

35     private QName JavaDoc name;
36
37     /**
38      * Field superInterfaces
39      */

40     private HashMap JavaDoc superInterfaces = new HashMap JavaDoc();
41
42     /**
43      * Field faults
44      */

45     private List JavaDoc faults = new LinkedList JavaDoc();
46
47     /**
48      * Field operations
49      */

50     private HashMap JavaDoc operations = new HashMap JavaDoc();
51
52     /**
53      * Field styleDefault
54      */

55     private String JavaDoc styleDefault;
56
57     /**
58      * Method getDefinedOperations
59      *
60      * @return
61      */

62     public HashMap JavaDoc getDefinedOperations() {
63         return this.operations;
64     }
65
66     /**
67      * Will return a map of all this <code>WSDLOperation</code>s that
68      * are defined and inherited from super interfaces.
69      *
70      * @return
71      */

72     public HashMap JavaDoc getAllOperations() {
73         HashMap JavaDoc all = this.operations;
74         if (this.superInterfaces.size() == 0) {
75             return all;
76         } else {
77             Iterator JavaDoc superIterator =
78                     this.superInterfaces.values().iterator();
79             Iterator JavaDoc operationIterator;
80             WSDLInterface superInterface;
81             WSDLOperation superInterfaceOperation;
82             Iterator JavaDoc thisIterator = all.values().iterator();
83             WSDLOperation thisOperation;
84             boolean tobeAdded = false;
85             while (superIterator.hasNext()) {
86                 superInterface = (WSDLInterface) superIterator.next();
87                 operationIterator =
88                 superInterface.getAllOperations().values().iterator();
89                 while (operationIterator.hasNext()) {
90                     superInterfaceOperation =
91                     (WSDLOperation) operationIterator.next();
92                     tobeAdded = true;
93                     while (thisIterator.hasNext()) {
94                         thisOperation = (WSDLOperation) thisIterator.next();
95                         if ((thisOperation.getName() == superInterfaceOperation.getName())
96                                 && !tobeAdded) {
97                             if (thisOperation.getTargetnamespace().equals(
98                                     superInterfaceOperation.getTargetnamespace())) {
99
100                                 // Both are the same Operation; the one inherited and
101
// the one that is already in the map(may or maynot be inherited)
102
tobeAdded = false;
103                             } else {
104
105                                 // same name but target namespces dont match
106
// TODO Think this is an error
107
throw new WSDLProcessingException(
108                                         "The Interface " + this.getName()
109                                                 + " has more than one Operation that has the same name but not the same interface ");
110                             }
111                         }
112                     }
113                     if (tobeAdded) {
114
115                         // This one is not in the list already developped
116
all.put(superInterfaceOperation.getName().getLocalPart(),
117                                 superInterfaceOperation);
118                     }
119                 }
120             }
121             return all;
122         }
123     }
124
125     /**
126      * @return
127      */

128     public List JavaDoc getFaults() {
129         return faults;
130     }
131
132     /**
133      * @return
134      */

135     public QName JavaDoc getName() {
136         return name;
137     }
138
139     /**
140      * @return
141      */

142     public HashMap JavaDoc getOperations() {
143         return operations;
144     }
145
146     /**
147      * Retruns the <code>WSDLOperation</code>
148      *
149      * @param nCName
150      * @return
151      */

152     public WSDLOperation getOperation(String JavaDoc nCName) {
153         return (WSDLOperation)this.operations.get(nCName);
154         
155     }
156
157     /**
158      * @return
159      */

160     public HashMap JavaDoc getSuperInterfaces() {
161         return superInterfaces;
162     }
163
164     /**
165      * Method getSuperInterface
166      *
167      * @param qName
168      * @return
169      */

170     public WSDLInterface getSuperInterface(QName JavaDoc qName) {
171         return (WSDLInterface) this.superInterfaces.get(qName);
172     }
173
174     /**
175      * The Targetnamespace is that of the namespace URI of the QName of
176      * this component.
177      *
178      * @return URI as a String if the name is set otherwise will return null.
179      */

180     public String JavaDoc getTargetnamespace() {
181         if (null == this.name) {
182             return null;
183         }
184         return this.name.getNamespaceURI();
185     }
186
187     /**
188      * @param list
189      */

190     public void setFaults(List JavaDoc list) {
191         faults = list;
192     }
193
194     /**
195      * @param qName
196      */

197     public void setName(QName JavaDoc qName) {
198         name = qName;
199     }
200
201     /**
202      * @param list
203      */

204     public void setOperations(HashMap JavaDoc list) {
205         operations = list;
206     }
207
208     /**
209      * The operation is added by its ncname. If operation is null
210      * it will not be added. If the Operation name is null a
211      * <code>WSDLProcessingException</code> will be thrown.
212      *
213      * @param operation
214      */

215     public void setOperation(WSDLOperation operation) {
216         if (null == operation) {
217             return;
218         }
219         if (null == operation.getName()) {
220             throw new WSDLProcessingException(
221                     "The Operation name cannot be null (required)");
222         }
223         this.operations.put(operation.getName().getLocalPart(), operation);
224     }
225
226     /**
227      * @param list
228      */

229     public void setSuperInterfaces(HashMap JavaDoc list) {
230         superInterfaces = list;
231     }
232
233     /**
234      * The Inteface will be added to the list of super interfaces keyed with
235      * the QName.
236      *
237      * @param interfaceComponent WSDLInterface Object
238      */

239     public void addSuperInterface(WSDLInterface interfaceComponent) {
240         this.superInterfaces.put(interfaceComponent.getName(),
241                 interfaceComponent);
242     }
243
244     /**
245      * Will return the StyleDefault if exist , otherwise will return null
246      *
247      * @return
248      */

249     public String JavaDoc getStyleDefault() {
250         return styleDefault;
251     }
252
253     /**
254      * Method setStyleDefault
255      *
256      * @param styleDefault
257      */

258     public void setStyleDefault(String JavaDoc styleDefault) {
259         this.styleDefault = styleDefault;
260     }
261 }
262
Popular Tags