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 org.apache.camel.model.DataFormatDefinition;
19 import org.apache.camel.spi.DataFormat;
20 import org.apache.camel.spi.RouteContext;
21 import org.openehealth.ipf.commons.core.modules.api.Parser;
22 import org.openehealth.ipf.commons.core.modules.api.Renderer;
23 import org.openehealth.ipf.platform.camel.core.adapter.DataFormatAdapter;
24
25 import javax.xml.bind.annotation.XmlAccessType;
26 import javax.xml.bind.annotation.XmlAccessorType;
27 import javax.xml.bind.annotation.XmlAttribute;
28
29
30
31
32 @XmlAccessorType(XmlAccessType.FIELD)
33 public class DataFormatAdapterDefinition extends DataFormatDefinition {
34
35 @XmlAttribute
36 private final String parserBeanName;
37 @XmlAttribute
38 private final String rendererBeanName;
39
40 private DataFormatAdapterDefinition(String parserBeanName, String rendererBeanName) {
41 this.parserBeanName = parserBeanName;
42 this.rendererBeanName = rendererBeanName;
43 }
44
45 public static DataFormatAdapterDefinition forParserBean(String beanName) {
46 return new DataFormatAdapterDefinition(beanName, null);
47 }
48
49 public static DataFormatAdapterDefinition forRendererBean(String beanName) {
50 return new DataFormatAdapterDefinition(null, beanName);
51 }
52
53 @Override
54 public DataFormat getDataFormat(RouteContext routeContext) {
55 if (parserBeanName != null) {
56 return new DataFormatAdapter(routeContext.lookup(parserBeanName, Parser.class));
57 } else {
58 return new DataFormatAdapter(routeContext.lookup(rendererBeanName, Renderer.class));
59 }
60 }
61
62 }