Building XML Multi Configurations
An XmlMultiConfiguration instance can be assembled and modified using the associated builder API. The previous examples of parsing XML multi-configuration documents are all just simple invocations of the richer builder API.
Multi-configurations can be built from scratch:
XmlMultiConfiguration multiConfiguration = XmlMultiConfiguration.fromNothing() //1
.withManager("bar", barConfiguration) //2
.withManager("foo").variant("heap", heapConfiguration).variant("offheap", offheapConfiguration) //3
.build(); //4
1 | Start with an empty set of configurations. |
2 | Add a configuration without variants. |
3 | Add a configuration with two different variants: heap and offheap. |
4 | Build the final configuration instance. |
Multi-configurations can also be built from existing configurations:
XmlMultiConfiguration modified = XmlMultiConfiguration.from(multiConfiguration) //1
.withManager("foo") //2
.build();
1 | Starting with an existing XmlMultiConfiguration. |
2 | Remove the configuration with identity "foo". |
Once built, a multi-configuration can be retrieved in an XML format:
String xmlString = multiConfiguration.asRenderedDocument(); //1
Document xmlDocument = multiConfiguration.asDocument(); //2
1 | Retrieve the XML as a rendered string. |
2 | Retrieve the XML as a DOM (org.w3c.Document). |