KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.wsdl.symbolTable;
57
58 import org.jboss.axis.enums.Style;
59 import org.jboss.axis.enums.Use;
60 import org.jboss.axis.utils.LinkedHashMap;
61
62 import javax.wsdl.Binding;
63 import javax.wsdl.Operation;
64 import javax.wsdl.extensions.soap.SOAPFault;
65 import javax.wsdl.extensions.soap.SOAPHeader;
66 import javax.xml.namespace.QName JavaDoc;
67 import java.util.ArrayList JavaDoc;
68 import java.util.HashMap JavaDoc;
69 import java.util.Map JavaDoc;
70 import java.util.Set JavaDoc;
71
72 /**
73  * This class represents a WSDL binding. It encompasses the WSDL4J Binding object so it can
74  * reside in the SymbolTable. It also adds a few bits of information that are a nuisance to get
75  * from the WSDL4J Binding object: binding type, binding style, input/output/fault body types.
76  */

77 public class BindingEntry extends SymTabEntry
78 {
79
80    // Binding types
81
public static final int TYPE_SOAP = 0;
82    public static final int TYPE_HTTP_GET = 1;
83    public static final int TYPE_HTTP_POST = 2;
84    public static final int TYPE_UNKNOWN = 3;
85
86    // Binding Operation use types
87
public static final int USE_ENCODED = 0;
88    public static final int USE_LITERAL = 1;
89
90    /**
91     * Get the flag indicating what sort of header this part is.
92     */

93    public static final int NO_HEADER = 0;
94    public static final int IN_HEADER = 1;
95    public static final int OUT_HEADER = 2;
96
97    private Binding binding;
98    private int bindingType;
99    private Style bindingStyle;
100    private boolean hasLiteral;
101    private Map attributes;
102    // operation to parameter info (Parameter)
103
private LinkedHashMap parameters = new LinkedHashMap();
104
105    // BindingOperation to faults (ArrayList of FaultBodyType)
106
private Map faults = new LinkedHashMap();
107
108    // This is a map of a map. It's a map keyed on operation name whose values
109
// are maps keyed on parameter name. The ultimate values are simple Strings.
110
private Map mimeTypes;
111
112    // This is a map of a map. It's a map keyed on operation name whose values
113
// are maps keyed on part name. The ultimate values are simple
114
// Booleans.
115
private Map headerParts;
116
117    // List of operations at need to use DIME
118
private ArrayList JavaDoc dimeOps = new ArrayList JavaDoc();
119
120    /**
121     * Construct a BindingEntry from a WSDL4J Binding object and the additional binding info:
122     * binding type, binding style, whether there is any literal binding, and the attributes which
123     * contain the input/output/fault body type information.
124     */

125    public BindingEntry(Binding binding, int bindingType, Style bindingStyle,
126                        boolean hasLiteral, HashMap attributes, Map mimeTypes,
127                        Map headerParts)
128    {
129       super(binding.getQName());
130       this.binding = binding;
131       this.bindingType = bindingType;
132       this.bindingStyle = bindingStyle;
133       this.hasLiteral = hasLiteral;
134       if (attributes == null)
135       {
136          this.attributes = new LinkedHashMap();
137       }
138       else
139       {
140          this.attributes = attributes;
141       }
142       if (mimeTypes == null)
143       {
144          this.mimeTypes = new LinkedHashMap();
145       }
146       else
147       {
148          this.mimeTypes = mimeTypes;
149       }
150       if (headerParts == null)
151       {
152          this.headerParts = new LinkedHashMap();
153       }
154       else
155       {
156          this.headerParts = headerParts;
157       }
158    } // ctor
159

160    /**
161     * This is a minimal constructor. Everything will be set up with
162     * defaults. If the defaults aren't desired, then the appropriate
163     * setter method should be called. The defaults are:
164     * bindingType = TYPE_UNKNOWN
165     * bindingStyle = DOCUMENT
166     * hasLiteral = false
167     * operation inputBodyTypes = USE_ENCODED
168     * operation outputBodyTypes = USE_ENCODED
169     * operation faultBodyTypes = USE_ENCODED
170     * mimeTypes = null
171     * <p/>
172     * The caller of this constructor should
173     * also call the various setter methods to fully fill out this object:
174     * setBindingType, setBindingStyle, setHasLiteral, setAttribute,
175     * setMIMEType.
176     */

177    public BindingEntry(Binding binding)
178    {
179       super(binding.getQName());
180       this.binding = binding;
181       this.bindingType = TYPE_UNKNOWN;
182       this.bindingStyle = Style.DOCUMENT;
183       this.hasLiteral = false;
184       this.attributes = new LinkedHashMap();
185       this.mimeTypes = new LinkedHashMap();
186       this.headerParts = new LinkedHashMap();
187    } // ctor
188

189    /**
190     * Get the Parameters object for the given operation.
191     */

192    public Parameters getParameters(Operation operation)
193    {
194       return (Parameters)parameters.get(operation);
195    } // getParameters
196

197    /**
198     * Get all of the parameters for all operations.
199     */

200    public Map getParameters()
201    {
202       return parameters;
203    } // getParameters
204

205    /**
206     * Set the parameters for all operations
207     */

208    public void setParameters(LinkedHashMap parameters)
209    {
210       this.parameters = parameters;
211    }
212
213    /**
214     * Get the mime mapping for the given parameter name.
215     * If there is none, this returns null.
216     */

217    public MimeInfo getMIMEInfo(String JavaDoc operationName, String JavaDoc parameterName)
218    {
219       Map opMap = (Map)mimeTypes.get(operationName);
220       if (opMap == null)
221       {
222          return null;
223       }
224       else
225       {
226          return (MimeInfo)opMap.get(parameterName);
227       }
228    } // getMIMEType
229

230    /**
231     * Get the MIME types map.
232     */

233    public Map getMIMETypes()
234    {
235       return mimeTypes;
236    } // getMIMETypes
237

238    /**
239     * Set the mime mapping for the given parameter name.
240     */

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

252    /**
253     * Mark the operation as a DIME operation
254     *
255     * @param operationName
256     */

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

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

279    public boolean isInHeaderPart(String JavaDoc operationName,
280                                  String JavaDoc partName)
281    {
282       return (headerPart(operationName, partName) & IN_HEADER) > 0;
283    } // isInHeaderPart
284

285    /**
286     * Is this part an output header part?.
287     */

288    public boolean isOutHeaderPart(String JavaDoc operationName,
289                                   String JavaDoc partName)
290    {
291       return (headerPart(operationName, partName) & OUT_HEADER) > 0;
292    } // isInHeaderPart
293

294    /**
295     * Get the mime mapping for the given part name.
296     * If there is none, this returns null.
297     *
298     * @param operationName
299     * @param partName
300     * @return flag indicating kind of header
301     */

302    private int headerPart(String JavaDoc operationName,
303                           String JavaDoc partName)
304    {
305       Map opMap = (Map)headerParts.get(operationName);
306       if (opMap == null)
307       {
308          return NO_HEADER;
309       }
310       else
311       {
312          HeaderPart headerPart = (HeaderPart)opMap.get(partName);
313          return headerPart == null ? NO_HEADER : headerPart.getFlags();
314       }
315    } // headerPart
316

317    /**
318     * Get the header parameter map.
319     */

320    public Map getHeaderParts()
321    {
322       return headerParts;
323    } // getHeaderParts
324

325    /**
326     * Set the soapHeader part mapping for the given part name.
327     */

328    public void setHeaderPart(String JavaDoc operationName, String JavaDoc partName, SOAPHeader soapHeader, int headerFlags)
329    {
330       Map opMap = (Map)headerParts.get(operationName);
331       if (opMap == null)
332       {
333          opMap = new LinkedHashMap();
334          headerParts.put(operationName, opMap);
335       }
336
337       // The soap:header might not be present if we are dealing with an unknown extension element
338
QName JavaDoc message = (soapHeader != null ? soapHeader.getMessage() : null);
339
340       HeaderPart headerPart = (HeaderPart)opMap.get(partName);
341       if (headerPart == null)
342          headerPart = new HeaderPart(partName, message, headerFlags);
343       else
344          headerPart = new HeaderPart(partName, message, headerFlags | headerPart.getFlags());
345
346       opMap.put(partName, headerPart);
347    } // setHeaderPart
348

349    /**
350     * Get this entry's WSDL4J Binding object.
351     */

352    public Binding getBinding()
353    {
354       return binding;
355    } // getBinding
356

357    /**
358     * Get this entry's binding type. One of BindingEntry.TYPE_SOAP, BindingEntry.TYPE_HTTP_GET,
359     * BindingEntry.TYPE_HTTP_POST.
360     */

361    public int getBindingType()
362    {
363       return bindingType;
364    } // getBindingType
365

366    /**
367     * Set this entry's binding type.
368     */

369    protected void setBindingType(int bindingType)
370    {
371       if (bindingType >= TYPE_SOAP && bindingType <= TYPE_UNKNOWN)
372       {
373       }
374       this.bindingType = bindingType;
375    } // setBindingType
376

377    /**
378     * Get this entry's binding style.
379     */

380    public Style getBindingStyle()
381    {
382       return bindingStyle;
383    } // getBindingStyle
384

385    /**
386     * Set this entry's binding style.
387     */

388    protected void setBindingStyle(Style bindingStyle)
389    {
390       this.bindingStyle = bindingStyle;
391    } // setBindingStyle
392

393    /**
394     * Do any of the message stanzas contain a soap:body which uses literal?
395     */

396    public boolean hasLiteral()
397    {
398       return hasLiteral;
399    } // hasLiteral
400

401    /**
402     * Set the literal flag.
403     */

404    protected void setHasLiteral(boolean hasLiteral)
405    {
406       this.hasLiteral = hasLiteral;
407    } // setHashLiteral
408

409    /**
410     * Get the input body type for the given operation.
411     */

412    public Use getInputBodyType(Operation operation)
413    {
414       OperationAttr attr = (OperationAttr)attributes.get(operation);
415       if (attr == null)
416       {
417          return Use.ENCODED; // should really create an exception for this.
418
}
419       else
420       {
421          return attr.getInputBodyType();
422       }
423    } // getInputBodyType
424

425    /**
426     * Set the input body type for the given operation.
427     */

428    protected void setInputBodyType(Operation operation, Use inputBodyType)
429    {
430       OperationAttr attr = (OperationAttr)attributes.get(operation);
431       if (attr == null)
432       {
433          attr = new OperationAttr();
434          attributes.put(operation, attr);
435       }
436       attr.setInputBodyType(inputBodyType);
437       if (inputBodyType == Use.LITERAL)
438       {
439          setHasLiteral(true);
440       }
441    } // setInputBodyType
442

443    /**
444     * Get the output body type for the given operation.
445     */

446    public Use getOutputBodyType(Operation operation)
447    {
448       OperationAttr attr = (OperationAttr)attributes.get(operation);
449       if (attr == null)
450       {
451          return Use.ENCODED; // should really create an exception for this.
452
}
453       else
454       {
455          return attr.getOutputBodyType();
456       }
457    } // getOutputBodyType
458

459    /**
460     * Set the output body type for the given operation.
461     */

462    protected void setOutputBodyType(Operation operation, Use outputBodyType)
463    {
464       OperationAttr attr = (OperationAttr)attributes.get(operation);
465       if (attr == null)
466       {
467          attr = new OperationAttr();
468          attributes.put(operation, attr);
469       }
470       attr.setOutputBodyType(outputBodyType);
471       if (outputBodyType == Use.LITERAL)
472       {
473          setHasLiteral(true);
474       }
475    } // setOutputBodyType
476

477    /**
478     * Set the body type for the given operation. If input is true,
479     * then this is the inputBodyType, otherwise it's the outputBodyType.
480     * (NOTE: this method exists to enable reusing some SymbolTable code.
481     */

482    protected void setBodyType(Operation operation, Use bodyType, boolean input)
483    {
484       if (input)
485       {
486          setInputBodyType(operation, bodyType);
487       }
488       else
489       {
490          setOutputBodyType(operation, bodyType);
491       }
492    } // setBodyType
493

494    /**
495     * Get the fault body type for the given fault of the given operation.
496     *
497     * @return Use.ENCODED or Use.LITERAL
498     */

499    public Use getFaultBodyType(Operation operation, String JavaDoc faultName)
500    {
501       OperationAttr attr = (OperationAttr)attributes.get(operation);
502       if (attr == null)
503       {
504          return Use.ENCODED; // should really create an exception for this.
505
}
506       else
507       {
508          Map m = attr.getFaultBodyTypeMap();
509          SOAPFault soapFault = (SOAPFault)m.get(faultName);
510
511          // This should never happen (error thrown in SymbolTable)
512
if (soapFault == null)
513          {
514             return Use.ENCODED;
515          }
516          String JavaDoc use = soapFault.getUse();
517          if ("literal".equals(use))
518          {
519             return Use.LITERAL;
520          }
521
522          return Use.ENCODED;
523       }
524    }
525
526    /**
527     * Return the map of BindingOperations to ArraList of FaultBodyType
528     */

529    public Map getFaults()
530    {
531       return faults;
532    }
533
534    public void setFaults(Map faults)
535    {
536       this.faults = faults;
537    }
538
539    /**
540     * Get a {@link Set} of comprised {@link Operation} objects.
541     */

542    public Set JavaDoc getOperations()
543    {
544       return attributes.keySet();
545    }
546
547    /**
548     * Set the fault body type map for the given operation.
549     */

550    protected void setFaultBodyTypeMap(Operation operation, Map faultBodyTypeMap)
551    {
552       OperationAttr attr = (OperationAttr)attributes.get(operation);
553       if (attr == null)
554       {
555          attr = new OperationAttr();
556          attributes.put(operation, attr);
557       }
558       attr.setFaultBodyTypeMap(faultBodyTypeMap);
559    } // setInputBodyTypeMap
560

561    /**
562     * Contains attributes for Operations
563     * - Body type: encoded or literal
564     */

565    protected static class OperationAttr
566    {
567       private Use inputBodyType;
568       private Use outputBodyType;
569       private Map faultBodyTypeMap;
570
571       public OperationAttr(Use inputBodyType, Use outputBodyType, Map faultBodyTypeMap)
572       {
573          this.inputBodyType = inputBodyType;
574          this.outputBodyType = outputBodyType;
575          this.faultBodyTypeMap = faultBodyTypeMap;
576       }
577
578       public OperationAttr()
579       {
580          this.inputBodyType = Use.ENCODED;
581          this.outputBodyType = Use.ENCODED;
582          this.faultBodyTypeMap = null;
583       }
584
585       public Use getInputBodyType()
586       {
587          return inputBodyType;
588       }
589
590       protected void setInputBodyType(Use inputBodyType)
591       {
592          this.inputBodyType = inputBodyType;
593       }
594
595       public Use getOutputBodyType()
596       {
597          return outputBodyType;
598       }
599
600       protected void setOutputBodyType(Use outputBodyType)
601       {
602          this.outputBodyType = outputBodyType;
603       }
604
605       public Map getFaultBodyTypeMap()
606       {
607          return faultBodyTypeMap;
608       }
609
610       protected void setFaultBodyTypeMap(Map faultBodyTypeMap)
611       {
612          this.faultBodyTypeMap = faultBodyTypeMap;
613       }
614    } // class OperationAttr
615

616    /** A header part that appears in a binding */
617    protected static class HeaderPart
618    {
619       private String JavaDoc part;
620       private QName JavaDoc message;
621       private int flags;
622
623       public HeaderPart(String JavaDoc part, QName JavaDoc message, int type)
624       {
625          this.part = part;
626          this.message = message;
627          this.flags = type;
628       }
629
630       public String JavaDoc getPartName()
631       {
632          return part;
633       }
634
635       public QName JavaDoc getMessageQName()
636       {
637          return message;
638       }
639
640       public int getFlags()
641       {
642          return flags;
643       }
644
645       public String JavaDoc toString()
646       {
647          return "[part=" + part + ",message=" + message + ",flags=" + flags + "]";
648       }
649    } // class HeaderPart
650

651 } // class BindingEntry
652
Popular Tags