final Set<String> names = new HashSet<String>();
while (reader.nextTag() != END_ELEMENT) {
requireNamespace(reader, expectedNs);
Element serverGroup = Element.forName(reader.getLocalName());
if (Element.SERVER_GROUP != serverGroup) {
throw unexpectedElement(reader);
}
String name = null;
String profile = null;
Boolean managementSubsystemEndpoint = null;
// Handle attributes
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final String value = reader.getAttributeValue(i);
if (!isNoNamespaceAttribute(reader, i)) {
throw ParseUtils.unexpectedAttribute(reader, i);
} else {
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
if (name != null) {
throw ParseUtils.duplicateAttribute(reader, attribute.getLocalName());
}
if (!names.add(value)) {
throw ParseUtils.duplicateNamedElement(reader, value);
}
name = value;
break;
}
case PROFILE: {
if (profile != null) {
throw ParseUtils.duplicateAttribute(reader, attribute.getLocalName());
}
profile = value;
break;
} case MANAGEMENT_SUBSYSTEM_ENDPOINT: {
if (managementSubsystemEndpoint != null) {
throw ParseUtils.duplicateAttribute(reader, attribute.getLocalName());
}
managementSubsystemEndpoint = Boolean.valueOf(value);
break;
}
default:
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(Attribute.NAME));
}
if (profile == null) {
throw missingRequired(reader, Collections.singleton(Attribute.PROFILE));
}
final ModelNode groupAddress = new ModelNode().set(address);
groupAddress.add(ModelDescriptionConstants.SERVER_GROUP, name);
final ModelNode group = new ModelNode();
group.get(OP).set(ADD);
group.get(OP_ADDR).set(groupAddress);
group.get(PROFILE).set(profile);
if (managementSubsystemEndpoint != null) {
group.get(MANAGEMENT_SUBSYSTEM_ENDPOINT).set(managementSubsystemEndpoint);
}
list.add(group);
// Handle elements
boolean sawDeployments = false;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
requireNamespace(reader, expectedNs);
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case JVM: {
JvmXml.parseJvm(reader, groupAddress, expectedNs, list, new HashSet<String>());
break;
}
case SOCKET_BINDING_GROUP: {
parseSocketBindingGroupRef(reader, groupAddress, list);
break;
}
case DEPLOYMENTS: {
if (sawDeployments) {
throw MESSAGES.alreadyDefined(element.getLocalName(), reader.getLocation());
}
sawDeployments = true;
parseDeployments(reader, groupAddress, expectedNs, list, true);
break;
}