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<Message> {
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;
039        try {
040            result = myApplication.processMessage(theMessage);
041        } catch (ApplicationException e) {
042            throw new ReceivingApplicationException(e);
043        }
044        
045        return result;
046    }
047
048    /** 
049     * @see ca.uhn.hl7v2.protocol.ReceivingApplication#canProcess(ca.uhn.hl7v2.model.Message)
050     */
051    public boolean canProcess(Message theMessage) {
052        return myApplication.canProcess(theMessage);
053    }
054
055}