FileReader r = new FileReader(messageFile);
char[] cbuf = new char[(int) fileLength];
System.out.println("Reading message file ... " + r.read(cbuf) + " of " + fileLength + " chars");
r.close();
String messString = String.valueOf(cbuf);
Message mess = parser.parse(messString);
System.out.println("Got message of type " + mess.getClass().getName());
ca.uhn.hl7v2.parser.XMLParser xp = new XMLParser() {
public Message parseDocument(Document XMLMessage, String version) throws HL7Exception {
return null;
}
public Document encodeDocument(Message source) throws HL7Exception {
return null;
}
public String getVersion(String message) throws HL7Exception {
return null;
}
@Override
public String doEncode(Segment structure, EncodingCharacters encodingCharacters) throws HL7Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String doEncode(Type type, EncodingCharacters encodingCharacters) throws HL7Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void parse(Type type, String string, EncodingCharacters encodingCharacters) throws HL7Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void parse(Segment segment, String string, EncodingCharacters encodingCharacters) throws HL7Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected Message doParseForSpecificPackage(String theMessage, String theVersion, String thePackageName) throws HL7Exception, EncodingNotSupportedException {
throw new UnsupportedOperationException("Not supported yet.");
}
};
//loop through segment children of message, encode, print to console
String[] structNames = mess.getNames();
for (int i = 0; i < structNames.length; i++) {
Structure[] reps = mess.getAll(structNames[i]);
for (int j = 0; j < reps.length; j++) {
if (Segment.class.isAssignableFrom(reps[j].getClass())) { //ignore groups
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.newDocument(); //new doc for each segment
Element root = doc.createElement(reps[j].getClass().getName());