001package ca.uhn.hl7v2.hoh.relay;
002
003import org.springframework.beans.factory.InitializingBean;
004
005import ca.uhn.hl7v2.hoh.relay.listener.IRelayListener;
006import ca.uhn.hl7v2.hoh.relay.sender.IRelaySender;
007import ca.uhn.hl7v2.hoh.util.Validate;
008import ca.uhn.hl7v2.hoh.util.VersionLogger;
009import ca.uhn.hl7v2.protocol.impl.AppRoutingDataImpl;
010
011public class Binder implements InitializingBean {
012
013        private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Binder.class);
014
015    private static final String ourProductName = "HAPI HL7 over HTTP Relay " + VersionLogger.getVersion();
016
017        private String myMessageType = "*";
018        private String myProcessingId = "*";
019        private IRelayListener myRelayListener;
020        private IRelaySender myRelaySender;
021        private String myTriggerEvent = "*";
022        private String myVersionId = "*";
023        
024        /**
025         * {@inheritDoc}
026         */
027        public void afterPropertiesSet() throws Exception {
028                Validate.propertySet(myRelayListener, "listener");
029                Validate.propertySet(myRelaySender, "sender");
030
031                ourLog.info("Binding sender[{}] to listener[{}] for messages with profile[MsgType:{} / MsgTrigger:{} / Version:{} / Processing:{}]", new Object[] { myRelaySender.getBeanName(), myRelayListener.getBeanName(), myMessageType, myTriggerEvent, myVersionId, myProcessingId });
032
033                AppRoutingDataImpl appRoutingData = new AppRoutingDataImpl(myMessageType, myTriggerEvent, myProcessingId, myVersionId);
034                myRelayListener.registerApplication(appRoutingData, myRelaySender);
035        }
036
037        public void setListener(IRelayListener theRelayListener) {
038                myRelayListener = theRelayListener;
039        }
040
041        /**
042         * @param theRelaySender
043         *            the sender to set
044         */
045        public void setSender(IRelaySender theRelaySender) {
046                myRelaySender = theRelaySender;
047        }
048
049        /**
050         * Returns the product name
051         */
052        public static String getProductname() {
053                return ourProductName;
054        }
055
056}