| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.builder; |
| 18 |
|
|
| 19 |
|
import org.apache.camel.CamelContext; |
| 20 |
|
import org.apache.camel.Endpoint; |
| 21 |
|
import org.apache.camel.Predicate; |
| 22 |
|
import org.apache.camel.Route; |
| 23 |
|
import org.apache.camel.impl.DefaultCamelContext; |
| 24 |
|
import org.apache.camel.model.InterceptType; |
| 25 |
|
import org.apache.camel.model.OtherwiseType; |
| 26 |
|
import org.apache.camel.model.ProcessorType; |
| 27 |
|
import org.apache.camel.model.RouteType; |
| 28 |
|
import org.apache.camel.model.RoutesType; |
| 29 |
|
import org.apache.camel.model.ExceptionType; |
| 30 |
|
import org.apache.camel.processor.DelegateProcessor; |
| 31 |
|
|
| 32 |
|
import java.util.ArrayList; |
| 33 |
|
import java.util.List; |
| 34 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
public abstract class RouteBuilder extends BuilderSupport { |
| 45 |
267 |
private AtomicBoolean initalized = new AtomicBoolean(false); |
| 46 |
267 |
private RoutesType routeCollection = new RoutesType(); |
| 47 |
267 |
private List<Route> routes = new ArrayList<Route>(); |
| 48 |
|
|
| 49 |
|
protected RouteBuilder() { |
| 50 |
267 |
this(null); |
| 51 |
267 |
} |
| 52 |
|
|
| 53 |
|
protected RouteBuilder(CamelContext context) { |
| 54 |
267 |
super(context); |
| 55 |
267 |
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
public abstract void configure() throws Exception; |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
public RouteType from(String uri) { |
| 66 |
267 |
return routeCollection.from(uri); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
public RouteType from(Endpoint endpoint) { |
| 73 |
0 |
return routeCollection.from(endpoint); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
public RouteBuilder errorHandler(ErrorHandlerBuilder errorHandlerBuilder) { |
| 84 |
0 |
setErrorHandlerBuilder(errorHandlerBuilder); |
| 85 |
0 |
return this; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
public RouteBuilder inheritErrorHandler(boolean value) { |
| 97 |
0 |
routeCollection.setInheritErrorHandlerFlag(value); |
| 98 |
0 |
return this; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
public RouteBuilder intercept(DelegateProcessor interceptor) { |
| 105 |
0 |
routeCollection.intercept(interceptor); |
| 106 |
0 |
return this; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
public InterceptType intercept() { |
| 116 |
12 |
return routeCollection.intercept(); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
public OtherwiseType intercept(Predicate predicate) { |
| 124 |
12 |
return routeCollection.intercept(predicate); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
public ExceptionType exception(Class exceptionType) { |
| 131 |
18 |
return routeCollection.exception(exceptionType); |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
public CamelContext getContext() { |
| 137 |
273 |
CamelContext context = super.getContext(); |
| 138 |
273 |
if (context == null) { |
| 139 |
36 |
context = createContainer(); |
| 140 |
36 |
setContext(context); |
| 141 |
|
} |
| 142 |
273 |
return context; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
public List<Route> getRouteList() throws Exception { |
| 149 |
267 |
checkInitialized(); |
| 150 |
264 |
return routes; |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
protected void checkInitialized() throws Exception { |
| 156 |
267 |
if (initalized.compareAndSet(false, true)) { |
| 157 |
267 |
configure(); |
| 158 |
267 |
populateRoutes(routes); |
| 159 |
|
} |
| 160 |
264 |
} |
| 161 |
|
|
| 162 |
|
protected void populateRoutes(List<Route> routes) throws Exception { |
| 163 |
267 |
CamelContext camelContext = getContext(); |
| 164 |
267 |
if (camelContext == null) { |
| 165 |
0 |
throw new IllegalArgumentException("No CamelContext has been injected!"); |
| 166 |
|
} |
| 167 |
267 |
routeCollection.setCamelContext(camelContext); |
| 168 |
267 |
routeCollection.populateRoutes(routes); |
| 169 |
264 |
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
protected CamelContext createContainer() { |
| 175 |
36 |
return new DefaultCamelContext(); |
| 176 |
|
} |
| 177 |
|
} |