| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.spring; |
| 18 |
|
|
| 19 |
|
import javax.xml.bind.annotation.XmlAccessType; |
| 20 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
| 21 |
|
import javax.xml.bind.annotation.XmlAttribute; |
| 22 |
|
import javax.xml.bind.annotation.XmlRootElement; |
| 23 |
|
import javax.xml.bind.annotation.XmlTransient; |
| 24 |
|
|
| 25 |
|
import org.apache.camel.CamelContext; |
| 26 |
|
import org.apache.camel.Endpoint; |
| 27 |
|
import org.apache.camel.model.IdentifiedType; |
| 28 |
|
|
| 29 |
|
import org.springframework.beans.factory.FactoryBean; |
| 30 |
|
|
| 31 |
|
import static org.apache.camel.util.ObjectHelper.notNull; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@XmlRootElement(name = "endpoint") |
| 39 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
| 40 |
22 |
public class EndpointFactoryBean extends IdentifiedType implements FactoryBean { |
| 41 |
|
@XmlAttribute |
| 42 |
|
private String uri; |
| 43 |
|
@XmlTransient |
| 44 |
|
private CamelContext context; |
| 45 |
|
@XmlTransient |
| 46 |
|
private Endpoint endpoint; |
| 47 |
|
@XmlTransient |
| 48 |
|
private boolean singleton; |
| 49 |
|
|
| 50 |
|
public Object getObject() throws Exception { |
| 51 |
20 |
if (endpoint == null) { |
| 52 |
11 |
endpoint = createEndpoint(); |
| 53 |
|
} |
| 54 |
20 |
return endpoint; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
public Class getObjectType() { |
| 58 |
22 |
return Endpoint.class; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public boolean isSingleton() { |
| 62 |
31 |
return singleton; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
public CamelContext getContext() { |
| 66 |
0 |
return context; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
public void setContext(CamelContext context) { |
| 75 |
11 |
this.context = context; |
| 76 |
11 |
} |
| 77 |
|
|
| 78 |
|
public Endpoint getEndpoint() { |
| 79 |
0 |
return endpoint; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
public void setEndpoint(Endpoint endpoint) { |
| 83 |
0 |
this.endpoint = endpoint; |
| 84 |
0 |
} |
| 85 |
|
|
| 86 |
|
public void setSingleton(boolean singleton) { |
| 87 |
0 |
this.singleton = singleton; |
| 88 |
0 |
} |
| 89 |
|
|
| 90 |
|
public String getUri() { |
| 91 |
0 |
return uri; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
public void setUri(String uri) { |
| 100 |
11 |
this.uri = uri; |
| 101 |
11 |
} |
| 102 |
|
|
| 103 |
|
protected Endpoint createEndpoint() { |
| 104 |
11 |
notNull(context, "context"); |
| 105 |
11 |
notNull(uri, "uri"); |
| 106 |
11 |
return context.getEndpoint(uri); |
| 107 |
|
} |
| 108 |
|
} |