001package ca.uhn.hl7v2.hoh.raw.api;
002
003import java.io.IOException;
004import java.io.Writer;
005
006import ca.uhn.hl7v2.hoh.api.IResponseSendable;
007import ca.uhn.hl7v2.hoh.encoder.EncodingStyle;
008import ca.uhn.hl7v2.hoh.encoder.ResponseCode;
009
010public class RawSendable implements IResponseSendable<String> {
011
012        private final String myRawMessage;
013        private final EncodingStyle myEncodingStyle;
014        private ResponseCode myResponseCode;
015
016        /**
017         * Constructor
018         * 
019         * @param theRawMessage
020         *            The message to return
021         */
022        public RawSendable(String theRawMessage) {
023                if (theRawMessage == null) {
024                        throw new NullPointerException("Raw Message may not be null");
025                }
026                myRawMessage = theRawMessage;
027                myEncodingStyle = EncodingStyle.detect(myRawMessage);
028        }
029
030        public void writeMessage(Writer theWriter) throws IOException {
031                theWriter.write(myRawMessage);
032                theWriter.flush();
033        }
034
035        public EncodingStyle getEncodingStyle() {
036                return myEncodingStyle;
037        }
038
039        public ResponseCode getResponseCode() {
040                if (myResponseCode == null) {
041                        myResponseCode = ResponseCode.detect(myRawMessage);
042                }
043                return myResponseCode;
044        }
045
046        public String getMessage() {
047                return myRawMessage;
048        }
049
050}