View Javadoc

1   package ca.uhn.hl7v2.validation.app;
2   
3   import java.util.ArrayList;
4   import java.util.Arrays;
5   import java.util.List;
6   
7   import ca.uhn.hl7v2.model.*;
8   import ca.uhn.hl7v2.HL7Exception;
9   
10  /**
11   * A composite test application that delegates to multiple other test applications 
12   * and returns a combined list of problems.  
13   * @author Bryan Tripp
14   * @deprecated
15   */
16  public class MultiTestApplication extends TestApplication {
17      
18      private List<TestApplication> tests;
19      
20      /** Creates a new instance of MultiTestApplication */
21      public MultiTestApplication() {
22          tests = new ArrayList<TestApplication>(20);
23      }
24      
25      /**
26       * Returns true if ANY of the delegates can accept the message.  
27       */
28      public boolean canProcess(Message in) {
29          boolean can = false;
30          for (int i = 0; !can && i < tests.size(); i++) {
31              can = tests.get(i).canProcess(in);
32          }
33          return can;
34      }
35      
36      /** Tests the message by passing it to all test apps that have been registered 
37       * using addTest().  
38       * @return exceptions that describe any identified problems with the message
39       */
40      public HL7Exception[] test(Message in) throws HL7Exception {
41          List<HL7Exception> problems = new ArrayList<HL7Exception>(40);
42          for (int i = 0; i < tests.size(); i++) {
43              TestApplication app = (TestApplication) tests.get(i);
44              HL7Exception[] shortList = app.test(in);
45              problems.addAll(Arrays.asList(shortList));
46          }
47          return problems.toArray(new HL7Exception[0]);
48      }
49      
50      /**
51       * Registers a test app so that messages will be tested against it.
52       */
53      public void addTest(TestApplication test) {
54          tests.add(test);
55      }
56      
57  }