001package ca.uhn.hl7v2.protocol; 002 003import java.util.Map; 004 005import ca.uhn.hl7v2.HL7Exception; 006import ca.uhn.hl7v2.app.Application; 007import ca.uhn.hl7v2.app.ApplicationException; 008import ca.uhn.hl7v2.model.Message; 009 010/** 011 * Wraps a legacy HAPI {@link Application} to convert it to a new 012 * style {@link ReceivingApplication} 013 */ 014public class ApplicationWrapper implements ReceivingApplication<Message> { 015 016 private final Application application; 017 018 /** 019 * Constructor 020 * 021 * @param theApplication The application to wrap 022 */ 023 public ApplicationWrapper(Application theApplication) { 024 this.application = theApplication; 025 } 026 027 /** 028 * {@inheritDoc} 029 */ 030 public Message processMessage(Message theMessage, Map<String, Object> theMetadata) throws ReceivingApplicationException, HL7Exception { 031 try { 032 return this.application.processMessage(theMessage); 033 } catch (ApplicationException e) { 034 throw new ReceivingApplicationException(e); 035 } 036 } 037 038 /** 039 * {@inheritDoc} 040 */ 041 public boolean canProcess(Message theMessage) { 042 return this.application.canProcess(theMessage); 043 } 044 045}