001/*
002 * Created on 16-May-2005
003 */
004package ca.uhn.hl7v2.protocol.impl;
005
006import java.util.Map;
007
008import ca.uhn.hl7v2.HL7Exception;
009import ca.uhn.hl7v2.app.Application;
010import ca.uhn.hl7v2.app.ApplicationException;
011import ca.uhn.hl7v2.model.Message;
012import ca.uhn.hl7v2.protocol.ReceivingApplication;
013import ca.uhn.hl7v2.protocol.ReceivingApplicationException;
014
015/**
016 * Wraps a ca.uhn.hl7v2.app.Application as a ca.uhn.hl7v2.protocol.ReceivingApplication. 
017 * ReceivingApplication replaces Application with HAPI 0.5.
018 *  
019 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
020 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
021 */
022public class AppWrapper implements ReceivingApplication {
023
024    private Application myApplication;
025    
026    /**
027     * @param theApplication an Application to wrap as a ReceivingApplication.  
028     */
029    public AppWrapper(Application theApplication) {
030        myApplication = theApplication;
031    }
032
033    /** 
034     * @see ca.uhn.hl7v2.protocol.ReceivingApplication#processMessage(ca.uhn.hl7v2.model.Message, java.util.Map)
035     */
036    public Message processMessage(Message theMessage, Map<String, Object> theMetadata) 
037            throws ReceivingApplicationException, HL7Exception {
038        Message result =  null;
039        
040        try {
041            result = myApplication.processMessage(theMessage);
042        } catch (ApplicationException e) {
043            throw new ReceivingApplicationException(e);
044        }
045        
046        return result;
047    }
048
049    /** 
050     * @see ca.uhn.hl7v2.protocol.ReceivingApplication#canProcess(ca.uhn.hl7v2.model.Message)
051     */
052    public boolean canProcess(Message theMessage) {
053        return myApplication.canProcess(theMessage);
054    }
055
056}