View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Martin Krasser
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  }