Created
June 26, 2014 15:24
-
-
Save pferraro/720fc28d138357f18827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InfinispanSubsystemXMLReader implements XMLElementReader<List<ModelNode>> { | |
private final Namespace namespace; | |
InfinispanSubsystemXMLReader(Namespace namespace) { | |
this.namespace = namespace; | |
} | |
@Override | |
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operationList) throws XMLStreamException { | |
Map<PathAddress, ModelNode> operations = new LinkedHashMap<>(); | |
PathAddress address = PathAddress.pathAddress(InfinispanSubsystemResourceDefinition.PATH); | |
ModelNode operation = Util.createAddOperation(address); | |
operations.put(address, operation); | |
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { | |
Element element = Element.forName(reader.getLocalName()); | |
switch (element) { | |
case CACHE_CONTAINER: { | |
this.parseContainer(reader, address, operations); | |
break; | |
} | |
default: { | |
throw ParseUtils.unexpectedElement(reader); | |
} | |
} | |
} | |
operationList.addAll(operations.values()); | |
} | |
private void parseContainer(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException { | |
String name = require(reader, Attribute.NAME); | |
PathAddress address = subsystemAddress.append(CacheContainerResourceDefinition.pathElement(name)); | |
ModelNode operation = Util.createAddOperation(address); | |
operations.put(address, operation); | |
for (int i = 0; i < reader.getAttributeCount(); i++) { | |
ParseUtils.requireNoNamespaceAttribute(reader, i); | |
String value = reader.getAttributeValue(i); | |
Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); | |
switch (attribute) { | |
case NAME: { | |
// Already read | |
break; | |
} | |
case ALIASES: { | |
if (this.namespace.since(Namespace.INFINISPAN_1_1)) { | |
for (String alias: reader.getListAttributeValue(i)) { | |
operation.get(ModelKeys.ALIASES).add(alias); | |
} | |
break; | |
} | |
} | |
case DEFAULT_CACHE: { | |
CacheContainerResourceDefinition.DEFAULT_CACHE.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
case JNDI_NAME: { | |
CacheContainerResourceDefinition.JNDI_NAME.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
case START: { | |
if (this.namespace.since(Namespace.INFINISPAN_1_1)) { | |
CacheContainerResourceDefinition.START.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
} | |
case LISTENER_EXECUTOR: { | |
CacheContainerResourceDefinition.LISTENER_EXECUTOR.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
case EVICTION_EXECUTOR: { | |
CacheContainerResourceDefinition.EVICTION_EXECUTOR.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
case REPLICATION_QUEUE_EXECUTOR: { | |
CacheContainerResourceDefinition.REPLICATION_QUEUE_EXECUTOR.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
case STATISTICS_ENABLED: { | |
if (this.namespace.since(Namespace.INFINISPAN_2_0)) { | |
CacheContainerResourceDefinition.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
} | |
case MODULE: { | |
if (this.namespace.since(Namespace.INFINISPAN_1_3)) { | |
CacheContainerResourceDefinition.MODULE.parseAndSetParameter(value, operation, reader); | |
break; | |
} | |
} | |
default: { | |
throw ParseUtils.unexpectedAttribute(reader, i); | |
} | |
} | |
} | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment