001/*
002 * Created on 21-Apr-2004
003 */
004package ca.uhn.hl7v2.protocol.impl;
005
006import ca.uhn.hl7v2.protocol.ApplicationRouter;
007import ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData;
008
009import java.util.Objects;
010
011/**
012 * A default implementation of <code>ApplicationRouter.AppRoutingData</code>. 
013 * 
014 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
015 * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
016 */
017public class AppRoutingDataImpl implements ApplicationRouter.AppRoutingData {
018
019    private final String myMessageType;
020    private final String myTriggerEvent;
021    private final String myProcessingId;
022    private final String myVersionId;
023     
024    /**
025     * Creates a new instance with args used as values that will be returned 
026     * by the corresponding getters.
027     */
028    public AppRoutingDataImpl(String theMessageType, String theTriggerEvent, 
029                String theProcessingId, String theVersionId) {
030        myMessageType = theMessageType;
031        myTriggerEvent = theTriggerEvent;
032        myProcessingId = theProcessingId;
033        myVersionId = theVersionId;
034    }
035
036    /**
037     * @see ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData#getMessageType()
038     */
039    public String getMessageType() {
040        return myMessageType;
041    }
042
043    /**
044     * @see ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData#getTriggerEvent()
045     */
046    public String getTriggerEvent() {
047        return myTriggerEvent;
048    }
049
050    /** 
051     * @see ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData#getProcessingId()
052     */
053    public String getProcessingId() {
054        return myProcessingId;
055    }
056
057    /** 
058     * @see ca.uhn.hl7v2.protocol.ApplicationRouter.AppRoutingData#getVersion()
059     */
060    public String getVersion() {
061        return myVersionId;
062    }
063
064    @Override
065    public boolean equals(Object o) {
066        if (this == o) return true;
067        if (!(o instanceof AppRoutingDataImpl)) return false;
068
069        AppRoutingDataImpl that = (AppRoutingDataImpl) o;
070
071        if (!Objects.equals(myMessageType, that.myMessageType))
072            return false;
073        if (!Objects.equals(myProcessingId, that.myProcessingId))
074            return false;
075        if (!Objects.equals(myTriggerEvent, that.myTriggerEvent))
076            return false;
077        return Objects.equals(myVersionId, that.myVersionId);
078    }
079
080    @Override
081    public int hashCode() {
082        int result = myMessageType != null ? myMessageType.hashCode() : 0;
083        result = 31 * result + (myTriggerEvent != null ? myTriggerEvent.hashCode() : 0);
084        result = 31 * result + (myProcessingId != null ? myProcessingId.hashCode() : 0);
085        result = 31 * result + (myVersionId != null ? myVersionId.hashCode() : 0);
086        return result;
087    }
088
089    /**
090     * Returns an instance of AppRoutingData which accepts all
091     * message types, versions, etc.
092     */
093        public static AppRoutingData withAll() {
094                return new AppRoutingDataImpl("*","*", "*", "*");
095        }
096
097}