Object toMarshall = extension;
// In case the configuration should NOT be exported as a module, wrap the configurations
// in a "alfresco-configuration" element instead
if(!asExtension) {
toMarshall = new AlfrescoConfiguration();
((AlfrescoConfiguration) toMarshall).setConfigurations(extension.getModules().get(0).getConfigurations());
}
Marshaller marshaller = moduleJaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(toMarshall, out);