1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
25 | |
|
26 | |
public class EndpointFactoryBean extends EndpointURIEndpointBuilder |
27 | |
implements FactoryBean, MuleContextAware, Initialisable |
28 | |
{ |
29 | |
|
30 | |
|
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 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
38 | |
|
39 | |
private String type; |
40 | |
|
41 | |
public EndpointFactoryBean() |
42 | |
{ |
43 | 0 | super(); |
44 | 0 | } |
45 | |
|
46 | |
public Object getObject() throws Exception |
47 | |
{ |
48 | 0 | if (ENDPOINT_TYPE_RECEIVER.equals(type)) |
49 | |
{ |
50 | 0 | logger.debug("Endpont type is \"receiver\", building inbound endpoint"); |
51 | 0 | return muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(this); |
52 | |
} |
53 | 0 | else if (ENDPOINT_TYPE_SENDER.equals(type)) |
54 | |
{ |
55 | 0 | logger.debug("Endpont type is \"sender\", building inbound endpoint"); |
56 | 0 | return muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint(this); |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | throw new IllegalArgumentException("The endpoint type: " + type + "is not recognized."); |
61 | |
} |
62 | |
} |
63 | |
|
64 | |
public Class getObjectType() |
65 | |
{ |
66 | |
|
67 | 0 | return ImmutableEndpoint.class; |
68 | |
} |
69 | |
|
70 | |
public boolean isSingleton() |
71 | |
{ |
72 | 0 | return true; |
73 | |
} |
74 | |
|
75 | |
public void initialise() throws InitialisationException |
76 | |
{ |
77 | |
|
78 | 0 | } |
79 | |
|
80 | |
public void setType(String type) |
81 | |
{ |
82 | 0 | this.type = type; |
83 | 0 | } |
84 | |
|
85 | |
} |