View Javadoc

1   /*
2    * $Id: EndpointFactoryBean.java 11517 2008-03-31 21:34:19Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.config.spring.factories;
12  
13  import org.mule.api.context.MuleContextAware;
14  import org.mule.api.endpoint.ImmutableEndpoint;
15  import org.mule.api.lifecycle.Initialisable;
16  import org.mule.api.lifecycle.InitialisationException;
17  import org.mule.endpoint.EndpointURIEndpointBuilder;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.springframework.beans.factory.FactoryBean;
22  
23  /**
24   * Endpoint factory bean which uses type attribute to determine endpoint type (Used by 1to2migration module)
25   */
26  public class EndpointFactoryBean extends EndpointURIEndpointBuilder
27      implements FactoryBean, MuleContextAware, Initialisable
28  {
29  
30      // as in ImmutableMuleEndpoint (but those not public)
31      public static final String ENDPOINT_TYPE_SENDER = "sender";
32      public static final String ENDPOINT_TYPE_RECEIVER = "receiver";
33  
34      public static final String ALWAYS_CREATE_STRING = "ALWAYS_CREATE";
35      public static final String NEVER_CREATE_STRING = "NEVER_CREATE";
36  
37      protected final Log logger = LogFactory.getLog(getClass());
38  
39      private String type;
40  
41      public EndpointFactoryBean()
42      {
43          super();
44      }
45  
46      public Object getObject() throws Exception
47      {
48          if (ENDPOINT_TYPE_RECEIVER.equals(type))
49          {
50              logger.debug("Endpont type is \"receiver\", building inbound endpoint");
51              return muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(this);
52          }
53          else if (ENDPOINT_TYPE_SENDER.equals(type))
54          {
55              logger.debug("Endpont type is \"sender\", building inbound endpoint");
56              return muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint(this);
57          }
58          else
59          {
60              throw new IllegalArgumentException("The endpoint type: " + type + "is not recognized.");
61          }
62      }
63  
64      public Class getObjectType()
65      {
66          // TODO MULE-2292 Use role-specific interface
67          return ImmutableEndpoint.class;
68      }
69  
70      public boolean isSingleton()
71      {
72          return true;
73      }
74  
75      public void initialise() throws InitialisationException
76      {
77          // nothing to do, subclasses may override
78      }
79  
80      public void setType(String type)
81      {
82          this.type = type;
83      }
84  
85  }