1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.model;
17
18 import groovy.lang.Closure;
19 import groovy.transform.stc.ClosureParams;
20 import groovy.transform.stc.SimpleType;
21 import org.apache.camel.Expression;
22 import org.apache.camel.Processor;
23 import org.apache.camel.spi.RouteContext;
24 import org.openehealth.ipf.platform.camel.core.adapter.ProcessorAdapter;
25 import org.openehealth.ipf.platform.camel.core.adapter.StaticParams;
26 import org.openehealth.ipf.platform.camel.core.closures.DelegatingExpression;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlTransient;
31
32
33
34
35 @XmlAccessorType(XmlAccessType.FIELD)
36 public abstract class ProcessorAdapterDefinition extends DelegateDefinition {
37
38 @XmlTransient
39 private Expression inputExpression;
40 @XmlTransient
41 private Expression paramsExpression;
42
43
44
45
46
47
48 public ProcessorAdapterDefinition input(Expression inputExpression) {
49 this.inputExpression = inputExpression;
50 return this;
51 }
52
53
54
55
56
57
58 public ProcessorAdapterDefinition input(@ClosureParams(value = SimpleType.class, options = { "org.apache.camel.Expression"})
59 Closure inputExpression) {
60 this.inputExpression = new DelegatingExpression(inputExpression);
61 return this;
62 }
63
64
65
66
67
68
69 public ProcessorAdapterDefinition params(Expression paramsExpression) {
70 this.paramsExpression = paramsExpression;
71 return this;
72 }
73
74
75
76
77
78
79 public ProcessorAdapterDefinition params(@ClosureParams(value = SimpleType.class, options = { "org.apache.camel.Expression"})
80 Closure paramsExpression) {
81 this.paramsExpression = new DelegatingExpression(paramsExpression);
82 return this;
83 }
84
85
86
87
88
89
90 public ProcessorAdapterDefinition staticParams(Object... params) {
91 paramsExpression = new StaticParams(params);
92 return this;
93 }
94
95 public ParamsDefinition params() {
96 return new ParamsDefinition(this);
97 }
98
99 @Override
100 protected Processor doCreateDelegate(RouteContext routeContext) {
101 ProcessorAdapter adapter = doCreateProcessor(routeContext);
102 if (inputExpression != null) {
103 adapter.input(inputExpression);
104 }
105 if (paramsExpression != null) {
106 adapter.params(paramsExpression);
107 }
108 return adapter;
109 }
110
111 protected abstract ProcessorAdapter doCreateProcessor(RouteContext routeContext);
112
113 }