/*
 *
 *  * JBoss, Home of Professional Open Source.
 *  * Copyright 2012, Red Hat, Inc., and individual contributors
 *  * as indicated by the @author tags. See the copyright.txt file in the
 *  * distribution for a full listing of individual contributors.
 *  *
 *  * This is free software; you can redistribute it and/or modify it
 *  * under the terms of the GNU Lesser General Public License as
 *  * published by the Free Software Foundation; either version 2.1 of
 *  * the License, or (at your option) any later version.
 *  *
 *  * This software is distributed in the hope that it will be useful,
 *  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  * Lesser General Public License for more details.
 *  *
 *  * You should have received a copy of the GNU Lesser General Public
 *  * License along with this software; if not, write to the Free
 *  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 *  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 *
 */

package org.jboss.as.controller;

import static org.jboss.as.controller.parsing.Attribute.NAME;
import static org.jboss.as.controller.parsing.Element.PROPERTY;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.operations.validation.ModelTypeValidator;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.dmr.Property;

/**
 * {@link MapAttributeDefinition} for maps with keys of {@link ModelType#STRING}.
 *
 * @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a>
 * @since 7.2
 */
public class SimpleMapAttributeDefinition extends MapAttributeDefinition {

    private SimpleMapAttributeDefinition(final Builder builder) {
        super(builder);
    }

    @Override
    protected void addValueTypeDescription(ModelNode node, ResourceBundle bundle) {
        node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
        node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(new ModelNode(isAllowExpression()));
    }

    @Override
    protected void addAttributeValueTypeDescription(ModelNode node, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
        node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
        node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(new ModelNode(isAllowExpression()));
    }

    @Override
    protected void addOperationParameterValueTypeDescription(ModelNode node, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
        node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
        node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(new ModelNode(isAllowExpression()));
    }

    private static class MapAttributeMarshaller extends AttributeMarshaller {
        @Override
        public boolean isMarshallable(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault) {
            return resourceModel.isDefined() && resourceModel.hasDefined(attribute.getName());
        }

        @Override
        public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
            resourceModel = resourceModel.get(attribute.getXmlName());
            writer.writeStartElement(attribute.getName());
            marshalToElement(resourceModel, writer);
            writer.writeEndElement();
        }

        private void marshalToElement(ModelNode resourceModel, XMLStreamWriter writer) throws XMLStreamException {
            if (!resourceModel.isDefined()) { return; }
            for (Property property : resourceModel.asPropertyList()) {
                writer.writeStartElement(PROPERTY.getLocalName());
                writer.writeAttribute(NAME.getLocalName(), property.getName());
                writer.writeCharacters(property.getValue().asString());
                writer.writeEndElement();
            }
        }
    }

    public static final class Builder extends MapAttributeDefinition.Builder<Builder, SimpleMapAttributeDefinition> {
        public Builder(final String name, boolean allowNull) {
            super(name, allowNull);
        }

        public Builder(final SimpleMapAttributeDefinition basis) {
            super(basis);
        }

        public Builder(final PropertiesAttributeDefinition basis) {
            super(basis);
        }

        @Override
        public SimpleMapAttributeDefinition build() {
            if (elementValidator == null) {
                elementValidator = new ModelTypeValidator(ModelType.STRING, allowNull, allowExpression);
            }
            if (attributeMarshaller == null) {
                attributeMarshaller = new MapAttributeMarshaller();
            }
            return new SimpleMapAttributeDefinition(this);
        }
    }
}

@@ -1299,17 +1299,16 @@
 Bundle;%0A
-%0A
 import j
@@ -1946,16 +1946,55 @@
 nition %7B
+%0A    private final ModelType valueType;
 %0A%0A    pr
@@ -2073,24 +2073,68 @@
 r(builder);%0A
+        this.valueType = builder.valueType;%0A
     %7D%0A%0A    @
@@ -2285,32 +2285,25 @@
 PE).set(
-ModelType.STRING
+valueType
 );%0A     
@@ -2628,32 +2628,25 @@
 PE).set(
-ModelType.STRING
+valueType
 );%0A     
@@ -3002,32 +3002,25 @@
 PE).set(
-ModelType.STRING
+valueType
 );%0A     
@@ -4522,16 +4522,73 @@
 tion%3E %7B%0A
+        private ModelType valueType = ModelType.STRING;%0A%0A
         
@@ -4681,32 +4681,215 @@
 ll);%0A        %7D%0A%0A
+        public Builder(final String name, final ModelType valueType, final boolean allowNull) %7B%0A            super(name, allowNull);%0A            this.valueType = valueType;%0A        %7D%0A%0A
         public B
@@ -5073,32 +5073,167 @@
 is);%0A        %7D%0A%0A
+        public Builder setValueType(ModelType valueType) %7B%0A            this.valueType = valueType;%0A            return this;%0A        %7D%0A%0A
         @Overrid
@@ -5390,32 +5390,25 @@
 lidator(
-ModelType.STRING
+valueType
 , allowN

Add support for non string maps