The following snippet might be useful for other than myself:
public abstract class ATypedApplication<T> implements ReceivingApplication
{
protected abstract Message processMessage(T message);
@Override public boolean canProcess(Message in) { return true; } @SuppressWarnings("unchecked") @Override public Message processMessage(Message paramMessage, Map<String, Object> paramMap) throws ReceivingApplicationException, HL7Exception { return processMessage((T) paramMessage); }
}
What do you use "T" for?
Do you have separate ReceivingApplication classes by concrete message type?
Yep - like the following:
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v25.message.ADT_A01;
public class SomeMessageHandler extends ATypedApplication<ADT_A01>{
}
+1 for this feature, I use it too
Now ReceivingApplication is parameterized regarding the type of the message (<T extends="" Message="">) and processMessage accepts type T. All references to this class have been parameterized as well. Additionally, there's an abstract ClassBasedReceivingApplication class that only accept message of a given class. This can be extended for more specific purposes.