File file = new File(fileName);
// file.canWrite() always returns false here since the file hasn't been created on disk yet
//if ( !file.canWrite() )
//throw new IOException("The specified file \"" + file.getAbsolutePath() + "\" is not writable by this process.");
XmlStringBuilder builder = new XmlStringBuilder();
builder.addElement(ROOT);
builder.addElement(HEADERS);
Set<JmsHeader> headers = jmsHeaders.getDefinedHeaders();
for ( JmsHeader header : headers ) {
DataElement de = jmsHeaders.getHeader(header);
builder.addElement(HEADER);
builder.addAttribute(TYPE, de.getType().toString());
builder.addAttribute(NAME, header.getName());
builder.setElementValue(de.toString());
builder.closeElement();
}
builder.closeElement();
builder.addElement(PROPERTIES);
Set<String> properties = jmsProperties.getPropertyNames();
for (String name : properties) {
DataElement de = jmsProperties.getProperty(name);
builder.addElement(PROPERTY);
builder.addAttribute(TYPE, de.getType().toString());
builder.addAttribute(NAME, name);
builder.setElementValue(de.toString());
builder.closeElement();
}
builder.closeAllElements();
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
fileWriter.write(builder.getXml());
}
finally {
KongaIoUtils.close(fileWriter);
}
}