KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > symbolTable > BindingEntry


1 /*
2  * Copyright 2001-2004 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.axis.wsdl.symbolTable;
17
18 import org.apache.axis.constants.Style;
19 import org.apache.axis.constants.Use;
20
21 import javax.wsdl.Binding;
22 import javax.wsdl.Operation;
23 import javax.wsdl.extensions.soap.SOAPFault;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 /**
30  * This class represents a WSDL binding. It encompasses the WSDL4J Binding object so it can
31  * reside in the SymbolTable. It also adds a few bits of information that are a nuisance to get
32  * from the WSDL4J Binding object: binding type, binding style, input/output/fault body types.
33  */

34 public class BindingEntry extends SymTabEntry {
35
36     // Binding types
37

38     /** Field TYPE_SOAP */
39     public static final int TYPE_SOAP = 0;
40
41     /** Field TYPE_HTTP_GET */
42     public static final int TYPE_HTTP_GET = 1;
43
44     /** Field TYPE_HTTP_POST */
45     public static final int TYPE_HTTP_POST = 2;
46
47     /** Field TYPE_UNKNOWN */
48     public static final int TYPE_UNKNOWN = 3;
49
50     // Binding Operation use types
51

52     /** Field USE_ENCODED */
53     public static final int USE_ENCODED = 0;
54
55     /** Field USE_LITERAL */
56     public static final int USE_LITERAL = 1;
57
58     /** Field binding */
59     private Binding binding;
60
61     /** Field bindingType */
62     private int bindingType;
63
64     /** Field bindingStyle */
65     private Style bindingStyle;
66
67     /** Field hasLiteral */
68     private boolean hasLiteral;
69
70     /** Field attributes */
71     private HashMap JavaDoc attributes;
72
73     // operation to parameter info (Parameter)
74

75     /** Field parameters */
76     private HashMap JavaDoc parameters = new HashMap JavaDoc();
77
78     // BindingOperation to faults (ArrayList of FaultBodyType)
79

80     /** Field faults */
81     private HashMap JavaDoc faults = new HashMap JavaDoc();
82
83     // This is a map of a map. It's a map keyed on operation name whose values
84
// are maps keyed on parameter name. The ultimate values are simple Strings.
85

86     /** Field mimeTypes */
87     private Map JavaDoc mimeTypes;
88
89     // This is a map of a map. It's a map keyed on operation name whose values
90
// are maps keyed on part name. The ultimate values are simple
91
// Booleans.
92

93     /** Field headerParts */
94     private Map JavaDoc headerParts;
95
96     // List of operations at need to use DIME
97

98     /** Field dimeOps */
99     private ArrayList JavaDoc dimeOps = new ArrayList JavaDoc();
100
101     /**
102      * Construct a BindingEntry from a WSDL4J Binding object and the additional binding info:
103      * binding type, binding style, whether there is any literal binding, and the attributes which
104      * contain the input/output/fault body type information.
105      *
106      * @param binding
107      * @param bindingType
108      * @param bindingStyle
109      * @param hasLiteral
110      * @param attributes
111      * @param mimeTypes
112      * @param headerParts
113      */

114     public BindingEntry(Binding binding, int bindingType, Style bindingStyle,
115                         boolean hasLiteral, HashMap JavaDoc attributes, Map JavaDoc mimeTypes,
116                         Map JavaDoc headerParts) {
117
118         super(binding.getQName());
119
120         this.binding = binding;
121         this.bindingType = bindingType;
122         this.bindingStyle = bindingStyle;
123         this.hasLiteral = hasLiteral;
124
125         if (attributes == null) {
126             this.attributes = new HashMap JavaDoc();
127         } else {
128             this.attributes = attributes;
129         }
130
131         if (mimeTypes == null) {
132             this.mimeTypes = new HashMap JavaDoc();
133         } else {
134             this.mimeTypes = mimeTypes;
135         }
136
137         if (headerParts == null) {
138             this.headerParts = new HashMap JavaDoc();
139         } else {
140             this.headerParts = headerParts;
141         }
142     } // ctor
143

144     /**
145      * This is a minimal constructor. Everything will be set up with
146      * defaults. If the defaults aren't desired, then the appropriate
147      * setter method should be called. The defaults are:
148      * bindingType = TYPE_UNKNOWN
149      * bindingStyle = DOCUMENT
150      * hasLiteral = false
151      * operation inputBodyTypes = USE_ENCODED
152      * operation outputBodyTypes = USE_ENCODED
153      * operation faultBodyTypes = USE_ENCODED
154      * mimeTypes = null
155      * <p/>
156      * The caller of this constructor should
157      * also call the various setter methods to fully fill out this object:
158      * setBindingType, setBindingStyle, setHasLiteral, setAttribute,
159      * setMIMEType.
160      *
161      * @param binding
162      */

163     public BindingEntry(Binding binding) {
164
165         super(binding.getQName());
166
167         this.binding = binding;
168         this.bindingType = TYPE_UNKNOWN;
169         this.bindingStyle = Style.DOCUMENT;
170         this.hasLiteral = false;
171         this.attributes = new HashMap JavaDoc();
172         this.mimeTypes = new HashMap JavaDoc();
173         this.headerParts = new HashMap JavaDoc();
174     } // ctor
175

176     /**
177      * Get the Parameters object for the given operation.
178      *
179      * @param operation
180      * @return
181      */

182     public Parameters getParameters(Operation operation) {
183         return (Parameters) parameters.get(operation);
184     } // getParameters
185

186     /**
187      * Get all of the parameters for all operations.
188      *
189      * @return
190      */

191     public HashMap JavaDoc getParameters() {
192         return parameters;
193     } // getParameters
194

195     /**
196      * Set the parameters for all operations
197      *
198      * @param parameters
199      */

200     public void setParameters(HashMap JavaDoc parameters) {
201         this.parameters = parameters;
202     }
203
204     /**
205      * Get the mime mapping for the given parameter name.
206      * If there is none, this returns null.
207      *
208      * @param operationName
209      * @param parameterName
210      * @return
211      */

212     public MimeInfo getMIMEInfo(String JavaDoc operationName, String JavaDoc parameterName) {
213
214         Map JavaDoc opMap = (Map JavaDoc) mimeTypes.get(operationName);
215
216         if (opMap == null) {
217             return null;
218         } else {
219             return (MimeInfo) opMap.get(parameterName);
220         }
221     } // getMIMEType
222

223     /**
224      * Get the MIME types map.
225      *
226      * @return
227      */

228     public Map JavaDoc getMIMETypes() {
229         return mimeTypes;
230     } // getMIMETypes
231

232     /**
233      * Set the mime mapping for the given parameter name.
234      *
235      * @param operationName
236      * @param parameterName
237      * @param type
238      * @param dims
239      */

240     public void setMIMEInfo(String JavaDoc operationName, String JavaDoc parameterName,
241                             String JavaDoc type, String JavaDoc dims) {
242
243         Map JavaDoc opMap = (Map JavaDoc) mimeTypes.get(operationName);
244
245         if (opMap == null) {
246             opMap = new HashMap JavaDoc();
247
248             mimeTypes.put(operationName, opMap);
249         }
250
251         opMap.put(parameterName, new MimeInfo(type, dims));
252     } // setMIMEType
253

254     /**
255      * Mark the operation as a DIME operation
256      *
257      * @param operationName
258      */

259     public void setOperationDIME(String JavaDoc operationName) {
260
261         if (dimeOps.indexOf(operationName) == -1) {
262             dimeOps.add(operationName);
263         }
264     }
265
266     /**
267      * Check if this operation should use DIME
268      *
269      * @param operationName
270      * @return
271      */

272     public boolean isOperationDIME(String JavaDoc operationName) {
273         return (dimeOps.indexOf(operationName) >= 0);
274     }
275
276     /**
277      * Is this part an input header part?.
278      *
279      * @param operationName
280      * @param partName
281      * @return
282      */

283     public boolean isInHeaderPart(String JavaDoc operationName, String JavaDoc partName) {
284         return (headerPart(operationName, partName) & IN_HEADER) > 0;
285     } // isInHeaderPart
286

287     /**
288      * Is this part an output header part?.
289      *
290      * @param operationName
291      * @param partName
292      * @return
293      */

294     public boolean isOutHeaderPart(String JavaDoc operationName, String JavaDoc partName) {
295         return (headerPart(operationName, partName) & OUT_HEADER) > 0;
296     } // isInHeaderPart
297

298     /** Get the flag indicating what sort of header this part is. */
299     public static final int NO_HEADER = 0;
300
301     /** Field IN_HEADER */
302     public static final int IN_HEADER = 1;
303
304     /** Field OUT_HEADER */
305     public static final int OUT_HEADER = 2;
306
307     /**
308      * Get the mime mapping for the given part name.
309      * If there is none, this returns null.
310      *
311      * @param operationName
312      * @param partName
313      * @return flag indicating kind of header
314      */

315     private int headerPart(String JavaDoc operationName, String JavaDoc partName) {
316
317         Map JavaDoc opMap = (Map JavaDoc) headerParts.get(operationName);
318
319         if (opMap == null) {
320             return NO_HEADER;
321         } else {
322             Integer JavaDoc I = (Integer JavaDoc) opMap.get(partName);
323
324             return (I == null)
325                     ? NO_HEADER
326                     : I.intValue();
327         }
328     } // headerPart
329

330     /**
331      * Get the header parameter map.
332      *
333      * @return
334      */

335     public Map JavaDoc getHeaderParts() {
336         return headerParts;
337     } // getHeaderParts
338

339     /**
340      * Set the header part mapping for the given part name.
341      *
342      * @param operationName
343      * @param partName
344      * @param headerFlags
345      */

346     public void setHeaderPart(String JavaDoc operationName, String JavaDoc partName,
347                               int headerFlags) {
348
349         Map JavaDoc opMap = (Map JavaDoc) headerParts.get(operationName);
350
351         if (opMap == null) {
352             opMap = new HashMap JavaDoc();
353
354             headerParts.put(operationName, opMap);
355         }
356
357         Integer JavaDoc I = (Integer JavaDoc) opMap.get(partName);
358         int i = (I == null)
359                 ? headerFlags
360                 : (I.intValue() | headerFlags);
361
362         opMap.put(partName, new Integer JavaDoc(i));
363     } // setHeaderPart
364

365     /**
366      * Get this entry's WSDL4J Binding object.
367      *
368      * @return
369      */

370     public Binding getBinding() {
371         return binding;
372     } // getBinding
373

374     /**
375      * Get this entry's binding type. One of BindingEntry.TYPE_SOAP, BindingEntry.TYPE_HTTP_GET,
376      * BindingEntry.TYPE_HTTP_POST.
377      *
378      * @return
379      */

380     public int getBindingType() {
381         return bindingType;
382     } // getBindingType
383

384     /**
385      * Set this entry's binding type.
386      *
387      * @param bindingType
388      */

389     protected void setBindingType(int bindingType) {
390
391         if ((bindingType >= TYPE_SOAP) && (bindingType <= TYPE_UNKNOWN)) {
392         }
393
394         this.bindingType = bindingType;
395     } // setBindingType
396

397     /**
398      * Get this entry's binding style.
399      *
400      * @return
401      */

402     public Style getBindingStyle() {
403         return bindingStyle;
404     } // getBindingStyle
405

406     /**
407      * Set this entry's binding style.
408      *
409      * @param bindingStyle
410      */

411     protected void setBindingStyle(Style bindingStyle) {
412         this.bindingStyle = bindingStyle;
413     } // setBindingStyle
414

415     /**
416      * Do any of the message stanzas contain a soap:body which uses literal?
417      *
418      * @return
419      */

420     public boolean hasLiteral() {
421         return hasLiteral;
422     } // hasLiteral
423

424     /**
425      * Set the literal flag.
426      *
427      * @param hasLiteral
428      */

429     protected void setHasLiteral(boolean hasLiteral) {
430         this.hasLiteral = hasLiteral;
431     } // setHashLiteral
432

433     /**
434      * Get the input body type for the given operation.
435      *
436      * @param operation
437      * @return
438      */

439     public Use getInputBodyType(Operation operation) {
440
441         OperationAttr attr = (OperationAttr) attributes.get(operation);
442
443         if (attr == null) {
444             return Use.ENCODED; // should really create an exception for this.
445
} else {
446             return attr.getInputBodyType();
447         }
448     } // getInputBodyType
449

450     /**
451      * Set the input body type for the given operation.
452      *
453      * @param operation
454      * @param inputBodyType
455      */

456     protected void setInputBodyType(Operation operation, Use inputBodyType) {
457
458         OperationAttr attr = (OperationAttr) attributes.get(operation);
459
460         if (attr == null) {
461             attr = new OperationAttr();
462
463             attributes.put(operation, attr);
464         }
465
466         attr.setInputBodyType(inputBodyType);
467
468         if (inputBodyType == Use.LITERAL) {
469             setHasLiteral(true);
470         }
471     } // setInputBodyType
472

473     /**
474      * Get the output body type for the given operation.
475      *
476      * @param operation
477      * @return
478      */

479     public Use getOutputBodyType(Operation operation) {
480
481         OperationAttr attr = (OperationAttr) attributes.get(operation);
482
483         if (attr == null) {
484             return Use.ENCODED; // should really create an exception for this.
485
} else {
486             return attr.getOutputBodyType();
487         }
488     } // getOutputBodyType
489

490     /**
491      * Set the output body type for the given operation.
492      *
493      * @param operation
494      * @param outputBodyType
495      */

496     protected void setOutputBodyType(Operation operation, Use outputBodyType) {
497
498         OperationAttr attr = (OperationAttr) attributes.get(operation);
499
500         if (attr == null) {
501             attr = new OperationAttr();
502
503             attributes.put(operation, attr);
504         }
505
506         attr.setOutputBodyType(outputBodyType);
507
508         if (outputBodyType == Use.LITERAL) {
509             setHasLiteral(true);
510         }
511     } // setOutputBodyType
512

513     /**
514      * Set the body type for the given operation. If input is true,
515      * then this is the inputBodyType, otherwise it's the outputBodyType.
516      * (NOTE: this method exists to enable reusing some SymbolTable code.
517      *
518      * @param operation
519      * @param bodyType
520      * @param input
521      */

522     protected void setBodyType(Operation operation, Use bodyType,
523                                boolean input) {
524
525         if (input) {
526             setInputBodyType(operation, bodyType);
527         } else {
528             setOutputBodyType(operation, bodyType);
529         }
530     } // setBodyType
531

532     /**
533      * Get the fault body type for the given fault of the given operation.
534      *
535      * @param operation
536      * @param faultName
537      * @return Use.ENCODED or Use.LITERAL
538      */

539     public Use getFaultBodyType(Operation operation, String JavaDoc faultName) {
540
541         OperationAttr attr = (OperationAttr) attributes.get(operation);
542
543         if (attr == null) {
544             return Use.ENCODED; // should really create an exception for this.
545
} else {
546             HashMap JavaDoc m = attr.getFaultBodyTypeMap();
547             SOAPFault soapFault = (SOAPFault) m.get(faultName);
548
549             // This should never happen (error thrown in SymbolTable)
550
if (soapFault == null) {
551                 return Use.ENCODED;
552             }
553
554             String JavaDoc use = soapFault.getUse();
555
556             if ("literal".equals(use)) {
557                 return Use.LITERAL;
558             }
559
560             return Use.ENCODED;
561         }
562     }
563
564     /**
565      * Return the map of BindingOperations to ArraList of FaultBodyType
566      *
567      * @return
568      */

569     public HashMap JavaDoc getFaults() {
570         return faults;
571     }
572
573     /**
574      * Method setFaults
575      *
576      * @param faults
577      */

578     public void setFaults(HashMap JavaDoc faults) {
579         this.faults = faults;
580     }
581
582     /**
583      * Get a {@link Set} of comprised {@link Operation} objects.
584      *
585      * @return
586      */

587     public Set JavaDoc getOperations() {
588         return attributes.keySet();
589     }
590
591     /**
592      * Set the fault body type map for the given operation.
593      *
594      * @param operation
595      * @param faultBodyTypeMap
596      */

597     protected void setFaultBodyTypeMap(Operation operation,
598                                        HashMap JavaDoc faultBodyTypeMap) {
599
600         OperationAttr attr = (OperationAttr) attributes.get(operation);
601
602         if (attr == null) {
603             attr = new OperationAttr();
604
605             attributes.put(operation, attr);
606         }
607
608         attr.setFaultBodyTypeMap(faultBodyTypeMap);
609     } // setInputBodyTypeMap
610

611     /**
612      * Contains attributes for Operations
613      * - Body type: encoded or literal
614      */

615     protected static class OperationAttr {
616
617         /** Field inputBodyType */
618         private Use inputBodyType;
619
620         /** Field outputBodyType */
621         private Use outputBodyType;
622
623         /** Field faultBodyTypeMap */
624         private HashMap JavaDoc faultBodyTypeMap;
625
626         /**
627          * Constructor OperationAttr
628          *
629          * @param inputBodyType
630          * @param outputBodyType
631          * @param faultBodyTypeMap
632          */

633         public OperationAttr(Use inputBodyType, Use outputBodyType,
634                              HashMap JavaDoc faultBodyTypeMap) {
635
636             this.inputBodyType = inputBodyType;
637             this.outputBodyType = outputBodyType;
638             this.faultBodyTypeMap = faultBodyTypeMap;
639         }
640
641         /**
642          * Constructor OperationAttr
643          */

644         public OperationAttr() {
645
646             this.inputBodyType = Use.ENCODED;
647             this.outputBodyType = Use.ENCODED;
648             this.faultBodyTypeMap = null;
649         }
650
651         /**
652          * Method getInputBodyType
653          *
654          * @return
655          */

656         public Use getInputBodyType() {
657             return inputBodyType;
658         }
659
660         /**
661          * Method setInputBodyType
662          *
663          * @param inputBodyType
664          */

665         protected void setInputBodyType(Use inputBodyType) {
666             this.inputBodyType = inputBodyType;
667         }
668
669         /**
670          * Method getOutputBodyType
671          *
672          * @return
673          */

674         public Use getOutputBodyType() {
675             return outputBodyType;
676         }
677
678         /**
679          * Method setOutputBodyType
680          *
681          * @param outputBodyType
682          */

683         protected void setOutputBodyType(Use outputBodyType) {
684             this.outputBodyType = outputBodyType;
685         }
686
687         /**
688          * Method getFaultBodyTypeMap
689          *
690          * @return
691          */

692         public HashMap JavaDoc getFaultBodyTypeMap() {
693             return faultBodyTypeMap;
694         }
695
696         /**
697          * Method setFaultBodyTypeMap
698          *
699          * @param faultBodyTypeMap
700          */

701         protected void setFaultBodyTypeMap(HashMap JavaDoc faultBodyTypeMap) {
702             this.faultBodyTypeMap = faultBodyTypeMap;
703         }
704     } // class OperationAttr
705
} // class BindingEntry
706
Popular Tags