com.biocomfort.TO.data_consumer
Class RestMeasurementProcessor

java.lang.Object
  extended by com.biocomfort.TO.data_consumer.RestMeasurementProcessor
All Implemented Interfaces:
MeasurementProcessor
Direct Known Subclasses:
RestBloodGlucoseMeasurementProcessor, RestBloodPressureMeasurementProcessor, RestWeightMeasurementProcessor

public abstract class RestMeasurementProcessor
extends java.lang.Object
implements MeasurementProcessor

The abstract class RestMeasurementProcessor transforms measurement data into a XML string, sends it as POST data to a restful web service and validates the received answer of the server. The data transformation into the XML string and the last part of the URL path to which the transformed data is sent are defined in concrete classes that extend this class.


Constructor Summary
RestMeasurementProcessor(java.lang.String urlPath, java.lang.String urlPathPostfix)
          Constructs a RestMeasurementProcessor object with specifying the URL path and the URL path postfix by the given parameters urlPath and urlPathPostfix.
 
Method Summary
protected  java.text.SimpleDateFormat getXMLDateFormat()
          Returns a SimpleDateFormat that defines the format of dates for the transformation process of measurement data to XML strings, implemented within the method transformDataToXmlString(TO).
protected static java.lang.String getXMLStringFromDocument(org.w3c.dom.Document document)
          Returns a String object that represents the XML data and structure of the given document parameter.
 void processMeasurementAndWait(MedicalDeviceTO medicalDevice, TO data)
          Transforms the given measurement data into a XML string, sends it as POST data to a restful web service and validates the received answer of the server.
protected abstract  java.lang.String transformDataToXmlString(TO data)
          Returns a String object that represents the given measurement data, formated as a valid XML document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestMeasurementProcessor

public RestMeasurementProcessor(java.lang.String urlPath,
                                java.lang.String urlPathPostfix)
Constructs a RestMeasurementProcessor object with specifying the URL path and the URL path postfix by the given parameters urlPath and urlPathPostfix.

Parameters:
urlPath - the URL path
urlPathPostfix - the URL path postfix
Method Detail

processMeasurementAndWait

public void processMeasurementAndWait(MedicalDeviceTO medicalDevice,
                                      TO data)
                               throws java.lang.Exception
Transforms the given measurement data into a XML string, sends it as POST data to a restful web service and validates the received answer of the server. The concrete XML transformation of the measurement data is defined within the abstract method transformDataToXmlString and must be implemented by subclasses that extends this class.

This method is synchronous and will block the currently running thread until the server has confirmed the receipt of the data. In case that an error occurs this method will be interrupted and throws an Exception.

Specified by:
processMeasurementAndWait in interface MeasurementProcessor
Parameters:
medicalDevice - the medical device that sends the data
data - the received measurement data
Throws:
java.lang.Exception - if an error occured

transformDataToXmlString

protected abstract java.lang.String transformDataToXmlString(TO data)
Returns a String object that represents the given measurement data, formated as a valid XML document. This is an abstract method and must be implemented by subclasses that extends this class.

The methods getXMLDateFormat() and getXMLStringFromDocument(Document) can help subclasses to transform the data.

Parameters:
data - the measurement data of a medical device
Returns:
a string representation of the data formated as XML
See Also:
getXMLDateFormat(), getXMLStringFromDocument(Document)

getXMLDateFormat

protected java.text.SimpleDateFormat getXMLDateFormat()
Returns a SimpleDateFormat that defines the format of dates for the transformation process of measurement data to XML strings, implemented within the method transformDataToXmlString(TO).

This is a helper method for classes that extends this abstract class.

Returns:
a SimpleDateFormat that defines the transformation of dates
See Also:
transformDataToXmlString(TO)

getXMLStringFromDocument

protected static java.lang.String getXMLStringFromDocument(org.w3c.dom.Document document)
                                                    throws javax.xml.transform.TransformerException
Returns a String object that represents the XML data and structure of the given document parameter.

This is a helper method for classes that extends this abstract class.

Parameters:
document - the document containing the XML data
Returns:
a string representation of the given document
Throws:
javax.xml.transform.TransformerException - if an error occured while transforming the data
See Also:
transformDataToXmlString(TO)