View Javadoc
1   /*
2    * Copyright 2008 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.spi.Metadata;
19  import org.apache.camel.spi.RouteContext;
20  import org.openehealth.ipf.commons.core.modules.api.Parser;
21  import org.openehealth.ipf.platform.camel.core.adapter.ParserAdapter;
22  import org.openehealth.ipf.platform.camel.core.adapter.ProcessorAdapter;
23  
24  import javax.xml.bind.annotation.*;
25  
26  /**
27   * @author Martin Krasser
28   */
29  @Metadata(label = "ipf,eip,transformation")
30  @XmlRootElement(name = "parse")
31  @XmlAccessorType(XmlAccessType.FIELD)
32  public class ParserAdapterDefinition extends ProcessorAdapterDefinition {
33  
34      @XmlTransient
35      private Parser parser;
36      @XmlAttribute
37      private String parserBean;
38  
39      public ParserAdapterDefinition() {
40      }
41  
42      public ParserAdapterDefinition(Parser parser) {
43          this.parser = parser;
44      }
45      
46      public ParserAdapterDefinition(String parserBean) {
47          this.parserBean = parserBean;
48      }
49      
50      @Override
51      public String toString() {
52          return "ParserAdapter[" + getOutputs() + "]";
53      }
54  
55      @Override
56      public String getShortName() {
57          return "parserAdapter";
58      }
59  
60      @Override
61      protected ProcessorAdapter doCreateProcessor(RouteContext routeContext) {
62          if (parserBean != null) {
63              parser = routeContext.lookup(parserBean, Parser.class);
64          }
65          return new ParserAdapter(parser);
66      }
67  
68  }