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.Processor;
19  import org.apache.camel.model.OutputDefinition;
20  import org.apache.camel.spi.Metadata;
21  import org.apache.camel.spi.RouteContext;
22  import org.openehealth.ipf.platform.camel.core.process.Validation;
23  
24  import javax.xml.bind.annotation.*;
25  
26  /**
27   * @author Martin Krasser
28   */
29  @Metadata(label = "ipf,eip,transformation")
30  @XmlRootElement(name = "validation")
31  @XmlAccessorType(XmlAccessType.FIELD)
32  public class ValidationDefinition extends OutputDefinition<ValidationDefinition>{
33  
34      @XmlTransient
35      private final Processor responseGeneratorProcessor;
36      @XmlAttribute
37      private final String responseGeneratorUri;
38  
39      public ValidationDefinition() {
40          this(null, null);
41      }
42  
43      public ValidationDefinition(String responseGeneratorUri) {
44          this(null, responseGeneratorUri);
45      }
46      
47      public ValidationDefinition(Processor responseGeneratorProcessor) {
48          this(responseGeneratorProcessor, null);
49      }
50      
51      private ValidationDefinition(Processor responseGeneratorProcessor, String responseGeneratorUri) {
52          this.responseGeneratorProcessor = responseGeneratorProcessor;
53          this.responseGeneratorUri = responseGeneratorUri;
54      }
55      
56      @Override
57      public Processor createProcessor(RouteContext routeContext) throws Exception {
58          Validation validation = createValidationProcessor(routeContext);
59          validation.setProcessor(createChildProcessor(routeContext, false));
60          return validation;
61      }
62      
63      private Validation createValidationProcessor(RouteContext routeContext) throws Exception {
64          if (responseGeneratorUri != null) {
65              return new Validation(routeContext.resolveEndpoint(responseGeneratorUri).createProducer());
66          } else {
67              return new Validation(responseGeneratorProcessor);
68          }
69      }
70      
71  }