001 package ca.uhn.hl7v2.validation.app;
002
003 import java.util.ArrayList;
004 import java.util.Arrays;
005 import java.util.List;
006
007 import ca.uhn.hl7v2.model.*;
008 import ca.uhn.hl7v2.HL7Exception;
009
010 /**
011 * A composite test application that delegates to multiple other test applications
012 * and returns a combined list of problems.
013 * @author Bryan Tripp
014 * @deprecated
015 */
016 public class MultiTestApplication extends TestApplication {
017
018 private List<TestApplication> tests;
019
020 /** Creates a new instance of MultiTestApplication */
021 public MultiTestApplication() {
022 tests = new ArrayList<TestApplication>(20);
023 }
024
025 /**
026 * Returns true if ANY of the delegates can accept the message.
027 */
028 public boolean canProcess(Message in) {
029 boolean can = false;
030 for (int i = 0; !can && i < tests.size(); i++) {
031 can = tests.get(i).canProcess(in);
032 }
033 return can;
034 }
035
036 /** Tests the message by passing it to all test apps that have been registered
037 * using addTest().
038 * @return exceptions that describe any identified problems with the message
039 */
040 public HL7Exception[] test(Message in) throws HL7Exception {
041 List<HL7Exception> problems = new ArrayList<HL7Exception>(40);
042 for (int i = 0; i < tests.size(); i++) {
043 TestApplication app = (TestApplication) tests.get(i);
044 HL7Exception[] shortList = app.test(in);
045 problems.addAll(Arrays.asList(shortList));
046 }
047 return problems.toArray(new HL7Exception[0]);
048 }
049
050 /**
051 * Registers a test app so that messages will be tested against it.
052 */
053 public void addTest(TestApplication test) {
054 tests.add(test);
055 }
056
057 }