View Javadoc

1   /*
2    * $Id: CxfPayloadToArguments.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf;
12  
13  import org.mule.api.endpoint.OutboundEndpoint;
14  import org.mule.transport.NullPayload;
15  
16  /**
17   * This enum defines the strategies to convert a Payload to an array of arguments
18   * that will be used to call the webservice in
19   * {@link CxfOutboundMessageProcessor#doSendWithClient(org.mule.api.MuleEvent)} and in
20   * {@link CxfOutboundMessageProcessor#doSendWithProxy(org.mule.api.MuleEvent)}.
21   */
22  public enum CxfPayloadToArguments
23  {
24      /**
25       * In this strategy, if the payload is of type {@link NullPayload} it will be
26       * send as a parameter just like any other object.
27       */
28      NULL_PAYLOAD_AS_PARAMETER(CxfConstants.PAYLOAD_TO_ARGUMENTS_NULL_PAYLOAD_AS_PARAMETER)
29      {
30  
31      },
32      /**
33       * In this strategy, if the payload is of type {@link NullPayload} it will not be
34       * send as a parameter. The array of arguments in this case will be empty. For
35       * the rest of the objects it behaves just like
36       * {@link #NULL_PAYLOAD_AS_PARAMETER} (it will delegate to
37       * {@link CxfPayloadToArguments#payloadToArrayOfArguments(Object)}).
38       */
39      NULL_PAYLOAD_AS_VOID(CxfConstants.PAYLOAD_TO_ARGUMENTS_NULL_PAYLOAD_AS_VOID)
40      {
41          @Override
42          public Object[] payloadToArrayOfArguments(Object payload)
43          {
44              if (payload instanceof NullPayload)
45              {
46                  return new Object[]{};
47              }
48              else
49              {
50                  return super.payloadToArrayOfArguments(payload);
51              }
52          }
53      };
54  
55      /**
56       * This is the value that is needed to be configured in the endpoint under
57       * property {@link CxfConstants#PAYLOAD_TO_ARGUMENTS} so this
58       * {@link CxfPayloadToArguments} is selected on method
59       * {@link #getPayloadToArgumentsForEndpoint(OutboundEndpoint)}.
60       */
61      private final String payloadToArgumentsParameterValue;
62  
63      private CxfPayloadToArguments(String payloadToArgumentsParameterValue)
64      {
65          this.payloadToArgumentsParameterValue = payloadToArgumentsParameterValue;
66      }
67  
68      /**
69       * This method is the one that converts the payload in an array of arguments. In
70       * this default implementation if the payload is already an array of
71       * {@link Object objects} that array will be returned. Otherwise, an array with
72       * one element, the payload, will be returned.
73       * 
74       * @param payload the payload to convert to array of arguments.
75       * @return the array of arguments
76       */
77      public Object[] payloadToArrayOfArguments(Object payload)
78      {
79          Object[] args;
80          if (payload instanceof Object[])
81          {
82              args = (Object[]) payload;
83          }
84          else
85          {
86              args = new Object[]{payload};
87          }
88          return args;
89      }
90  
91      public String getPayloadToArgumentsParameterValue()
92      {
93          return payloadToArgumentsParameterValue;
94      }
95  }