View Javadoc

1   package ca.uhn.hl7v2.validation.app;
2   
3   import ca.uhn.hl7v2.HL7Exception;
4   import ca.uhn.hl7v2.model.Message;
5   import ca.uhn.hl7v2.validation.ValidationException;
6   import ca.uhn.hl7v2.validation.impl.ConformanceProfileRule;
7   
8   /**
9    * <p>Tests messages against conformance profiles.  A constant profile
10   * can be used, or each message can be tested against the profiles
11   * that it declares.</p>
12   * <p>Note that profiles are referenced by ID, and that the ca.uhn.hl7v2.conf.store
13   * package is used to get the actual profiles. </p>
14   * @author Bryan Tripp
15   * @deprecated
16   */
17  public class ProfileTestApplication extends TestApplication {
18      
19      private String profileID;
20      private ConformanceProfileRule rule;
21      
22      /**
23       * Creates a new instance of ProfileTestApplication that tests using profiles 
24       * declared in each message (if any)
25       */
26      public ProfileTestApplication() {
27          rule = new ConformanceProfileRule();
28      }
29      
30      /**
31       * Creates a new instance of ProfileTestApplication.
32       * @param profileID the ID of the profile against which to test messages;
33       *      null means use profiles declared in the message (if any)
34       */
35      public ProfileTestApplication(String profileID) {
36          this.profileID = profileID;
37          rule = new ConformanceProfileRule(profileID);
38      }
39      
40      /**
41       * Returns true if this Application wishes to accept the message.  By returning
42       * true, this Application declares itself the recipient of the message, accepts
43       * responsibility for it, and must be able to respond appropriately to the sending system.
44       */
45      public boolean canProcess(Message in) {
46          return true;
47      }
48      
49      /**
50       * Tests the message against a profile or profiles.  A constant profile
51       * is used if one was provided to the constructor, otherwise any profiles
52       * declared in the message are used.
53       */
54      public HL7Exception[] test(Message in) throws HL7Exception {
55          ValidationException[] errors = rule.test(in);
56          
57          HL7Exception[] result = new HL7Exception[errors.length];
58          for (int i = 0; i < errors.length; i++) {
59              Throwable t = errors[i].getCause();
60              if ((t != null) && (t instanceof HL7Exception)) {
61                  result[i] = (HL7Exception) t;
62              } else {
63                  result[i] = new HL7Exception(errors[i]);
64              }            
65          }
66          
67          return result;
68      }
69      
70      public String getProfileID() {
71          return this.profileID;
72      }
73  }