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