View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.model.resolvers;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.transformer.TransformerException;
11  import org.mule.util.ClassUtils;
12  
13  /**
14   * Will resolver entry point methods on a service service that accept a single array.
15   * i.e.
16   * <code>public Object eat(Fruit[] fruit)</code>
17   * <p/>
18   * This resolver will NOT resolve method entry points such as -
19   * <code>public Object eat(Fruit[] fruit, Banana banana)</code>
20   * <p/>
21   * If you require to mix an array type with complex types you need to specify an inbound transformer that return a
22   * multi-dimensional array of arguments i.e.
23   * <code>new Object[]{new Fruit[]{new Apple(), new Orange()}, new Banana()};</code>
24   */
25  public class ArrayEntryPointResolver extends AbstractArgumentEntryPointResolver
26  {
27      @Override
28      protected Class<?>[] getMethodArgumentTypes(Object[] payload)
29      {
30          return ClassUtils.getClassTypes(payload);
31      }
32  
33      @Override
34      protected Object[] getPayloadFromMessage(MuleEventContext context) throws TransformerException
35      {
36          Object temp = context.getMessage().getPayload();
37          if (temp instanceof Object[])
38          {
39              return new Object[]{temp};
40          }
41          else
42          {
43              // Payload type not supported by this resolver
44              return null;
45          }
46      }
47  }