Menu

#85 Provide some 'type safety' to receivingapplication interface

2.3
closed-fixed
None
5
2014-12-16
2014-02-13
No

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);
}

}

Discussion

  • Christian Ohr

    Christian Ohr - 2014-02-13

    What do you use "T" for?
    Do you have separate ReceivingApplication classes by concrete message type?

     
  • Jens Villadsen

    Jens Villadsen - 2014-02-13

    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>{

    @Override
    protected Message processMessage(ADT_A01 message) {
        // TODO Auto-generated method stub
        return null;
    }
    

    }

     
  • Mathieu

    Mathieu - 2014-11-07

    +1 for this feature, I use it too

     
  • Christian Ohr

    Christian Ohr - 2014-12-15
    • Group: Future --> 2.3
     
  • Christian Ohr

    Christian Ohr - 2014-12-16

    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.

     
  • Christian Ohr

    Christian Ohr - 2014-12-16
    • status: open --> closed-fixed
    • assigned_to: Christian Ohr
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.