/*
 *
 *  * 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 java.util.Locale;
import java.util.ResourceBundle;

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;

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

    private SimpleMapAttributeDefinition(final Builder builder) {
        super(builder);
        this.valueType = builder.valueType;
    }

    @Override
    protected void addValueTypeDescription(ModelNode node, ResourceBundle bundle) {
        node.get(ModelDescriptionConstants.VALUE_TYPE).set(valueType);
        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(valueType);
        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(valueType);
        node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(new ModelNode(isAllowExpression()));
    }

    public static final class Builder extends MapAttributeDefinition.Builder<Builder, SimpleMapAttributeDefinition> {
        private ModelType valueType = ModelType.STRING;

        public Builder(final String name, boolean optional) {
            super(name, optional);
            setDefaults();
        }

        public Builder(final String name, final ModelType valueType, final boolean optional) {
            super(name, optional);
            this.valueType = valueType;
            setDefaults();
        }

        private void setDefaults(){
            setAttributeParser(AttributeParser.PROPERTIES_PARSER);
            setAttributeMarshaller(AttributeMarshaller.PROPERTIES_MARSHALLER);
        }

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

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

        public Builder setValueType(ModelType valueType) {
            this.valueType = valueType;
            return this;
        }

        @Override
        public SimpleMapAttributeDefinition build() {
            if (elementValidator == null) {
                elementValidator = new ModelTypeValidator(valueType);
            }
            return new SimpleMapAttributeDefinition(this);
        }
    }
}

@@ -1171,16 +1171,38 @@
 eBundle;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -1412,16 +1412,66 @@
 idator;%0A
+import org.jboss.as.controller.registry.Resource;%0A
 import o
@@ -2863,32 +2863,32 @@
 set(valueType);%0A
-
         node.get
@@ -2979,24 +2979,1501 @@
 )));%0A    %7D%0A%0A
+    @Override%0A    public void addCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue) %7B%0A        handleCapabilityRequirements(context, resource, attributeValue, false);%0A    %7D%0A%0A    @Override%0A    public void removeCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue) %7B%0A        handleCapabilityRequirements(context, resource, attributeValue, true);%0A    %7D%0A%0A    private void handleCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue, boolean remove) %7B%0A        CapabilityReferenceRecorder refRecorder = getReferenceRecorder();%0A        if (refRecorder != null && attributeValue.isDefined()) %7B%0A            Set%3CString%3E KeyList = attributeValue.keys();%0A            String%5B%5D attributeValues = new String%5BKeyList.size()%5D;%0A            int position = 0;%0A            for (String key : KeyList) %7B%0A                ModelNode current = attributeValue.get(key);%0A                if (current.isDefined() == false %7C%7C current.getType().equals(ModelType.EXPRESSION)) %7B%0A                    return;%0A                %7D%0A                attributeValues%5Bposition++%5D = current.asString();%0A            %7D%0A            if (remove) %7B%0A                refRecorder.removeCapabilityRequirements(context, resource, getName(), attributeValues);%0A            %7D else %7B%0A                refRecorder.addCapabilityRequirements(context, resource, getName(), attributeValues);%0A            %7D%0A        %7D%0A    %7D%0A%0A
     public s

Update SimpleMapAttributeDefinition to record capabilities based on the values.