-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
FromDefinition.java
186 lines (159 loc) · 5.31 KB
/
FromDefinition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.model;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import org.apache.camel.Endpoint;
import org.apache.camel.NamedNode;
import org.apache.camel.builder.EndpointConsumerBuilder;
import org.apache.camel.spi.Metadata;
/**
* Act as a message source as input to a route
*/
@Metadata(label = "eip,routing")
@XmlRootElement(name = "from")
@XmlAccessorType(XmlAccessType.FIELD)
public class FromDefinition extends OptionalIdentifiedDefinition<FromDefinition> implements EndpointRequiredDefinition {
@XmlTransient
private RouteDefinition parent;
@XmlTransient
private Endpoint endpoint;
@XmlTransient
private EndpointConsumerBuilder endpointConsumerBuilder;
@XmlAttribute
@Metadata(required = true)
private String uri;
@XmlAttribute
private String variableReceive;
public FromDefinition() {
}
public FromDefinition(String uri) {
this();
setUri(uri);
}
public FromDefinition(Endpoint endpoint) {
this();
setEndpoint(endpoint);
}
public FromDefinition(EndpointConsumerBuilder endpointConsumerBuilder) {
this();
setEndpointConsumerBuilder(endpointConsumerBuilder);
}
FromDefinition copy() {
FromDefinition copy = new FromDefinition();
copy.parent = this.parent;
copy.endpoint = this.endpoint;
copy.endpointConsumerBuilder = this.endpointConsumerBuilder;
copy.uri = this.uri;
copy.variableReceive = this.variableReceive;
copy.setCamelContext(this.getCamelContext());
copy.setId(this.getId());
copy.setCustomId(this.getCustomId());
copy.setDescription(this.getDescription());
copy.setLineNumber(this.getLineNumber());
copy.setLocation(this.getLocation());
return copy;
}
@Override
public String toString() {
return "From[" + getLabel() + "]";
}
@Override
public String getShortName() {
return "from";
}
@Override
public String getLabel() {
String uri = getEndpointUri();
return uri != null ? uri : "no uri supplied";
}
@Override
public String getEndpointUri() {
if (uri != null) {
return uri;
} else if (endpoint != null) {
return endpoint.getEndpointUri();
} else if (endpointConsumerBuilder != null) {
return endpointConsumerBuilder.getUri();
} else {
return null;
}
}
@Override
public NamedNode getParent() {
return parent;
}
public void setParent(RouteDefinition parent) {
this.parent = parent;
}
// Properties
// -----------------------------------------------------------------------
public String getUri() {
return uri;
}
/**
* Sets the URI of the endpoint to use
*
* @param uri the endpoint URI to use
*/
public void setUri(String uri) {
clear();
this.uri = uri;
}
public String getVariableReceive() {
return variableReceive;
}
/**
* To use a variable to store a copy of the received message body (only body, not headers). This is handy for easy
* access to the received message body via variables.
*/
public void setVariableReceive(String variableReceive) {
this.variableReceive = variableReceive;
}
/**
* Gets tne endpoint if an {@link Endpoint} instance was set.
* <p/>
* This implementation may return <tt>null</tt> which means you need to use {@link #getEndpointUri()} to get
* information about the endpoint.
*
* @return the endpoint instance, or <tt>null</tt>
*/
public Endpoint getEndpoint() {
return endpoint;
}
public void setEndpoint(Endpoint endpoint) {
clear();
this.endpoint = endpoint;
}
public EndpointConsumerBuilder getEndpointConsumerBuilder() {
return endpointConsumerBuilder;
}
public void setEndpointConsumerBuilder(EndpointConsumerBuilder endpointConsumerBuilder) {
clear();
this.endpointConsumerBuilder = endpointConsumerBuilder;
}
// Implementation methods
// -----------------------------------------------------------------------
protected void clear() {
this.endpointConsumerBuilder = null;
this.endpoint = null;
this.uri = null;
}
}