| 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.List; |
| 21 |
|
|
| 22 |
|
import javax.xml.bind.annotation.XmlAccessType; |
| 23 |
|
import javax.xml.bind.annotation.XmlAccessorType; |
| 24 |
|
import javax.xml.bind.annotation.XmlElement; |
| 25 |
|
import javax.xml.bind.annotation.XmlElementRef; |
| 26 |
|
import javax.xml.bind.annotation.XmlRootElement; |
| 27 |
|
import javax.xml.bind.annotation.XmlTransient; |
| 28 |
|
|
| 29 |
|
import org.apache.camel.Processor; |
| 30 |
|
import org.apache.camel.impl.RouteContext; |
| 31 |
|
import org.apache.camel.processor.CatchProcessor; |
| 32 |
|
import org.apache.camel.util.ObjectHelper; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@XmlRootElement(name = "catch") |
| 38 |
|
@XmlAccessorType(XmlAccessType.FIELD) |
| 39 |
0 |
public class CatchType extends ProcessorType { |
| 40 |
|
@XmlElementRef |
| 41 |
6 |
private List<InterceptorType> interceptors = new ArrayList<InterceptorType>(); |
| 42 |
|
@XmlElement(name = "exception") |
| 43 |
6 |
private List<String> exceptions = new ArrayList<String>(); |
| 44 |
|
@XmlElementRef |
| 45 |
6 |
private List<ProcessorType> outputs = new ArrayList<ProcessorType>(); |
| 46 |
|
@XmlTransient |
| 47 |
|
private List<Class> exceptionClasses; |
| 48 |
|
|
| 49 |
0 |
public CatchType() { |
| 50 |
0 |
} |
| 51 |
|
|
| 52 |
0 |
public CatchType(List<Class> exceptionClasses) { |
| 53 |
0 |
this.exceptionClasses = exceptionClasses; |
| 54 |
0 |
} |
| 55 |
|
|
| 56 |
6 |
public CatchType(Class exceptionType) { |
| 57 |
6 |
exceptionClasses = new ArrayList<Class>(); |
| 58 |
6 |
exceptionClasses.add(exceptionType); |
| 59 |
6 |
} |
| 60 |
|
|
| 61 |
|
@Override |
| 62 |
|
public String toString() { |
| 63 |
0 |
return "Catch[ " + getExceptionClasses() + " -> " + getOutputs() + "]"; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
@Override |
| 67 |
|
public CatchProcessor createProcessor(RouteContext routeContext) throws Exception { |
| 68 |
6 |
Processor childProcessor = routeContext.createProcessor(this); |
| 69 |
6 |
return new CatchProcessor(getExceptionClasses(), childProcessor); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
public List<InterceptorType> getInterceptors() { |
| 73 |
0 |
return interceptors; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public void setInterceptors(List<InterceptorType> interceptors) { |
| 77 |
0 |
this.interceptors = interceptors; |
| 78 |
0 |
} |
| 79 |
|
|
| 80 |
|
public List<ProcessorType> getOutputs() { |
| 81 |
12 |
return outputs; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public void setOutputs(List<ProcessorType> outputs) { |
| 85 |
0 |
this.outputs = outputs; |
| 86 |
0 |
} |
| 87 |
|
|
| 88 |
|
public List<Class> getExceptionClasses() { |
| 89 |
6 |
if (exceptionClasses == null) { |
| 90 |
0 |
exceptionClasses = createExceptionClasses(); |
| 91 |
|
} |
| 92 |
6 |
return exceptionClasses; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
public void setExceptionClasses(List<Class> exceptionClasses) { |
| 96 |
0 |
this.exceptionClasses = exceptionClasses; |
| 97 |
0 |
} |
| 98 |
|
|
| 99 |
|
public List<String> getExceptions() { |
| 100 |
0 |
return exceptions; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
public void setExceptions(List<String> exceptions) { |
| 104 |
0 |
this.exceptions = exceptions; |
| 105 |
0 |
} |
| 106 |
|
|
| 107 |
|
protected List<Class> createExceptionClasses() { |
| 108 |
0 |
List<String> list = getExceptions(); |
| 109 |
0 |
List<Class> answer = new ArrayList<Class>(list.size()); |
| 110 |
0 |
for (String name : list) { |
| 111 |
0 |
Class type = ObjectHelper.loadClass(name, getClass().getClassLoader()); |
| 112 |
0 |
answer.add(type); |
| 113 |
0 |
} |
| 114 |
0 |
return answer; |
| 115 |
|
} |
| 116 |
|
} |