| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.model; |
| 18 |
|
|
| 19 |
|
import java.util.ArrayList; |
| 20 |
|
import java.util.Collection; |
| 21 |
|
import java.util.Collections; |
| 22 |
|
import java.util.List; |
| 23 |
|
|
| 24 |
|
import javax.xml.bind.annotation.XmlAccessType; |
| 25 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
| 26 |
|
import javax.xml.bind.annotation.XmlElement; |
| 27 |
|
import javax.xml.bind.annotation.XmlElementRef; |
| 28 |
|
import javax.xml.bind.annotation.XmlRootElement; |
| 29 |
|
|
| 30 |
|
import org.apache.camel.Endpoint; |
| 31 |
|
import org.apache.camel.Predicate; |
| 32 |
|
import org.apache.camel.Processor; |
| 33 |
|
import org.apache.camel.impl.RouteContext; |
| 34 |
|
import org.apache.camel.processor.ChoiceProcessor; |
| 35 |
|
import org.apache.camel.processor.FilterProcessor; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@XmlRootElement(name = "choice") |
| 41 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
| 42 |
36 |
public class ChoiceType extends ProcessorType { |
| 43 |
|
@XmlElementRef |
| 44 |
36 |
private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); |
| 45 |
|
@XmlElementRef |
| 46 |
36 |
private List<WhenType> whenClauses = new ArrayList<WhenType>(); |
| 47 |
|
@XmlElement(required = false) |
| 48 |
|
private OtherwiseType otherwise; |
| 49 |
|
|
| 50 |
|
@Override |
| 51 |
|
public String toString() { |
| 52 |
15 |
return "Choice[ " + getWhenClauses() + " " + getOtherwise() + "]"; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
@Override |
| 56 |
|
public Processor createProcessor(RouteContext routeContext) throws Exception { |
| 57 |
33 |
List<FilterProcessor> filters = new ArrayList<FilterProcessor>(); |
| 58 |
33 |
for (WhenType whenClaus : whenClauses) { |
| 59 |
48 |
filters.add(whenClaus.createProcessor(routeContext)); |
| 60 |
48 |
} |
| 61 |
33 |
Processor otherwiseProcessor = null; |
| 62 |
33 |
if (otherwise != null) { |
| 63 |
33 |
otherwiseProcessor = otherwise.createProcessor(routeContext); |
| 64 |
|
} |
| 65 |
33 |
return new ChoiceProcessor(filters, otherwiseProcessor); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
public ChoiceType when(Predicate predicate) { |
| 71 |
48 |
getWhenClauses().add(new WhenType(predicate)); |
| 72 |
48 |
return this; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
public OtherwiseType otherwise() { |
| 76 |
33 |
OtherwiseType answer = new OtherwiseType(); |
| 77 |
33 |
setOtherwise(answer); |
| 78 |
33 |
return answer; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
public ChoiceType proceed() { |
| 82 |
12 |
super.proceed(); |
| 83 |
12 |
return this; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
public ChoiceType to(Endpoint endpoint) { |
| 87 |
0 |
super.to(endpoint); |
| 88 |
0 |
return this; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
public ChoiceType to(Collection<Endpoint> endpoints) { |
| 92 |
0 |
super.to(endpoints); |
| 93 |
0 |
return this; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
public ChoiceType to(Endpoint... endpoints) { |
| 97 |
0 |
super.to(endpoints); |
| 98 |
0 |
return this; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public ChoiceType to(String uri) { |
| 102 |
36 |
super.to(uri); |
| 103 |
36 |
return this; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
public ChoiceType to(String... uris) { |
| 107 |
0 |
super.to(uris); |
| 108 |
0 |
return this; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
public List<WhenType> getWhenClauses() { |
| 114 |
66 |
return whenClauses; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
public void setWhenClauses(List<WhenType> whenClauses) { |
| 118 |
0 |
this.whenClauses = whenClauses; |
| 119 |
0 |
} |
| 120 |
|
|
| 121 |
|
public List<ProcessorType> getOutputs() { |
| 122 |
48 |
if (otherwise != null) { |
| 123 |
0 |
return otherwise.getOutputs(); |
| 124 |
48 |
} else if (whenClauses.isEmpty()) { |
| 125 |
0 |
return Collections.EMPTY_LIST; |
| 126 |
|
} else { |
| 127 |
48 |
WhenType when = whenClauses.get(whenClauses.size() - 1); |
| 128 |
48 |
return when.getOutputs(); |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
public OtherwiseType getOtherwise() { |
| 133 |
18 |
return otherwise; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
public void setOtherwise(OtherwiseType otherwise) { |
| 137 |
33 |
this.otherwise = otherwise; |
| 138 |
33 |
} |
| 139 |
|
|
| 140 |
|
public List<InterceptorType> getInterceptors() { |
| 141 |
30 |
return interceptors; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
public void setInterceptors(List<InterceptorType> interceptors) { |
| 145 |
0 |
this.interceptors = interceptors; |
| 146 |
0 |
} |
| 147 |
|
} |