Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
FromType |
|
| 0.0;0 |
1 | /** |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.camel.model; |
|
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.Endpoint; |
|
26 | import org.apache.camel.impl.RouteContext; |
|
27 | ||
28 | /** |
|
29 | * Represents an XML <to/> element |
|
30 | * |
|
31 | * @version $Revision: $ |
|
32 | */ |
|
33 | @XmlRootElement(name = "from") |
|
34 | @XmlAccessorType(XmlAccessType.FIELD) |
|
35 | public class FromType { |
|
36 | @XmlAttribute |
|
37 | private String uri; |
|
38 | @XmlAttribute |
|
39 | private String ref; |
|
40 | @XmlTransient |
|
41 | private Endpoint endpoint; |
|
42 | ||
43 | 33 | public FromType() { |
44 | 33 | } |
45 | ||
46 | 273 | public FromType(String uri) { |
47 | 273 | setUri(uri); |
48 | 273 | } |
49 | ||
50 | 0 | public FromType(Endpoint endpoint) { |
51 | 0 | this.endpoint = endpoint; |
52 | 0 | } |
53 | ||
54 | @Override |
|
55 | public String toString() { |
|
56 | 132 | return "From[" + description(getUri(), getRef(), getEndpoint()) + "]"; |
57 | } |
|
58 | ||
59 | public Endpoint resolveEndpoint(RouteContext context) { |
|
60 | 267 | if (endpoint == null) { |
61 | 267 | endpoint = context.resolveEndpoint(getUri(), getRef()); |
62 | } |
|
63 | 267 | return endpoint; |
64 | } |
|
65 | ||
66 | // Properties |
|
67 | // ----------------------------------------------------------------------- |
|
68 | public String getUri() { |
|
69 | 432 | return uri; |
70 | } |
|
71 | ||
72 | /** |
|
73 | * Sets the URI of the endpoint to use |
|
74 | * |
|
75 | * @param uri the endpoint URI to use |
|
76 | */ |
|
77 | public void setUri(String uri) { |
|
78 | 273 | this.uri = uri; |
79 | 273 | } |
80 | ||
81 | public String getRef() { |
|
82 | 399 | return ref; |
83 | } |
|
84 | ||
85 | /** |
|
86 | * Sets the name of the endpoint within the registry (such as the Spring |
|
87 | * ApplicationContext or JNDI) to use |
|
88 | * |
|
89 | * @param ref the reference name to use |
|
90 | */ |
|
91 | public void setRef(String ref) { |
|
92 | 0 | this.ref = ref; |
93 | 0 | } |
94 | ||
95 | public Endpoint getEndpoint() { |
|
96 | 132 | return endpoint; |
97 | } |
|
98 | ||
99 | public void setEndpoint(Endpoint endpoint) { |
|
100 | 0 | this.endpoint = endpoint; |
101 | 0 | } |
102 | ||
103 | // Implementation methods |
|
104 | // ----------------------------------------------------------------------- |
|
105 | protected static String description(String uri, String ref, Endpoint endpoint) { |
|
106 | 327 | if (endpoint != null) { |
107 | 0 | return endpoint.getEndpointUri(); |
108 | 327 | } else if (uri != null) { |
109 | 327 | return uri; |
110 | 0 | } else if (ref != null) { |
111 | 0 | return "ref:" + ref; |
112 | } else { |
|
113 | 0 | return "no uri or ref supplied!"; |
114 | } |
|
115 | } |
|
116 | } |