View Javadoc

1   package org.codehaus.xfire.annotations.soap;
2   
3   import org.codehaus.xfire.soap.SoapConstants;
4   
5   /***
6    * Represents an common representation of a soap binding annotation. Specifies the mapping of the Web Service onto the
7    * SOAP message protocol.
8    *
9    * @author Arjen Poutsma
10   */
11  public class SOAPBindingAnnotation
12  {
13      private int style = STYLE_DOCUMENT;
14      private int use = USE_LITERAL;
15      private int parameterStyle = PARAMETER_STYLE_WRAPPED;
16      /***
17       * Constant used to specify a document binding style. This is the default document style.
18       */
19      public final static int STYLE_DOCUMENT = 0;
20      /***
21       * Constant used to specify a rpc binding style.
22       */
23      public final static int STYLE_RPC = 1;
24  
25      /***
26       * Constant used to specify a literal binding use. This is the default use.
27       */
28      public final static int USE_LITERAL = 0;
29      /***
30       * Constant used to specify a encoded binding use.
31       */
32      public final static int USE_ENCODED = 1;
33  
34      /***
35       * Constant used to specify a bare parameter binding style.
36       */
37      public final static int PARAMETER_STYLE_BARE = 0;
38      /***
39       * Constant used to specify a wrapped parameter binding style. This is the default parameter style.
40       */
41      public final static int PARAMETER_STYLE_WRAPPED = 1;
42  
43      /***
44       * Returns the SOAP binding style, which defines the encoding style for messages send to and from the Web Service.
45       * The returned value is one of {@link #STYLE_DOCUMENT} or {@link #STYLE_RPC}.
46       *
47       * @return the SOAP binding style.
48       */
49      public int getStyle()
50      {
51          return style;
52      }
53  
54      /***
55       * Returns a <code>String</code> representation of the SOAP binding style. The returned value is one of {@link
56       * SoapConstants#STYLE_DOCUMENT} or {@link SoapConstants#STYLE_RPC}.
57       *
58       * @return the SOAP binding style as a <code>String</code>.
59       * @see SoapConstants
60       */
61      public String getStyleString()
62      {
63          if (style == SOAPBindingAnnotation.STYLE_DOCUMENT
64                  && parameterStyle == SOAPBindingAnnotation.PARAMETER_STYLE_WRAPPED)
65          {
66              return SoapConstants.STYLE_WRAPPED;
67          }
68          else if (style == SOAPBindingAnnotation.STYLE_DOCUMENT)
69          {
70              return SoapConstants.STYLE_DOCUMENT;
71          }
72          else if (style == SOAPBindingAnnotation.STYLE_RPC)
73          {
74              return SoapConstants.STYLE_RPC;
75          }
76          else
77          {
78              throw new IllegalStateException("Invalid style set: " + style);
79          }
80      }
81  
82      /***
83       * Sets the SOAP binding style, which defines the encoding style for messages send to and from the Web Service. The
84       * given parameter must be one of {@link #STYLE_DOCUMENT} or {@link #STYLE_RPC}.
85       *
86       * @param style the new binding style.
87       * @throws IllegalArgumentException if <code>style</code> is not a valid style.
88       */
89      public void setStyle(int style)
90      {
91          if (style == SOAPBindingAnnotation.STYLE_DOCUMENT || style == SOAPBindingAnnotation.STYLE_RPC)
92          {
93              this.style = style;
94          }
95          else
96          {
97              throw new IllegalArgumentException("Invalid style: " + style);
98          }
99      }
100 
101     /***
102      * Returns the SOAP binding use, which defines the formatting style for messages sent to and from the Web Service.
103      * The returned value is one of {@link #USE_LITERAL} or {@link #USE_ENCODED}.
104      *
105      * @return the SOAP binding use.
106      */
107     public int getUse()
108     {
109         return use;
110     }
111 
112     /***
113      * Returns a <code>String</code> representation of the SOAP binding use. The returned value is one of {@link
114      * SoapConstants#USE_ENCODED} or {@link SoapConstants#USE_LITERAL}.
115      *
116      * @return the SOAP binding use as a <code>String</code>.
117      * @see SoapConstants
118      */
119     public String getUseString()
120     {
121         if (use == SOAPBindingAnnotation.USE_ENCODED)
122         {
123             return SoapConstants.USE_ENCODED;
124         }
125         else if (use == SOAPBindingAnnotation.USE_LITERAL)
126         {
127             return SoapConstants.USE_LITERAL;
128         }
129         else
130         {
131             throw new IllegalStateException("Invalid use set: " + use);
132         }
133 
134     }
135 
136     /***
137      * Sets the SOAP binding use, which defines the formatting style for messages sent to and from the Web Service. The
138      * given parameter must be one of {@link #USE_LITERAL} or {@link #USE_ENCODED}.
139      *
140      * @param use the new binding use.
141      * @throws IllegalArgumentException if <code>use</code> is not a valid use.
142      */
143     public void setUse(int use)
144     {
145         if (use == SOAPBindingAnnotation.USE_ENCODED || use == SOAPBindingAnnotation.USE_LITERAL)
146         {
147             this.use = use;
148         }
149         else
150         {
151             throw new IllegalArgumentException("Invalid use: " + use);
152         }
153     }
154 
155     /***
156      * Returns the SOAP parameter binding style. This style determines whether method parameters represent the entire
157      * message body, or whether the parameters are elements wrapped inside a top-level element named after the
158      * operation.
159      * <p/>
160      * The returned value is one of {@link #PARAMETER_STYLE_BARE} or {@link #PARAMETER_STYLE_WRAPPED}.
161      *
162      * @return the SOAP parameter binding style.
163      */
164     public int getParameterStyle()
165     {
166         return parameterStyle;
167     }
168 
169     /***
170      * Sets the SOAP parameter binding style. This style determines whether method parameters represent the entire
171      * message body, or whether the parameters are elements wrapped inside a top-level element named after the
172      * operation
173      * <p/>
174      * The given parameter must be one of {@link #PARAMETER_STYLE_BARE} or {@link #PARAMETER_STYLE_WRAPPED}.
175      *
176      * @param parameterStyle the new SOAP parameter binding style.
177      * @throws IllegalArgumentException if <code>parameterStyle</code> is not a valid parameter style.
178      */
179     public void setParameterStyle(int parameterStyle)
180     {
181         if (parameterStyle == SOAPBindingAnnotation.PARAMETER_STYLE_BARE ||
182                 parameterStyle == SOAPBindingAnnotation.PARAMETER_STYLE_WRAPPED)
183         {
184             this.parameterStyle = parameterStyle;
185         }
186         else
187         {
188             throw new IllegalArgumentException("Invalid parameter style: " + parameterStyle);
189         }
190     }
191 }