All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.as.console.client.shared.general.validation.LoopbackValidation Maven / Gradle / Ivy

Go to download

Bundles the core AS7 console as a GWT module. Includes minor customizations to support extensions.

There is a newer version: 0.7.0.Final
Show newest version
package org.jboss.as.console.client.shared.general.validation;

import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.shared.general.model.Interface;

import java.util.Map;
import java.util.Set;

/**
 * Validates the loopback constraints
 *
 * @author Heiko Braun
 * @date 11/15/11
 */
class LoopbackValidation extends AbstractValidationStep {

    private static final String LOOPBACK = "loopback";
    private static final String LOOPBACK_ADDRESS = "loopbackAddress";

    @Override
    public boolean doesApplyTo(Interface entity, Map changedValues) {
        Map clean = clearChangeset(changedValues);

        boolean hasSetValues = entity.isLoopback() || isSet(entity.getLoopbackAddress());
        boolean relevantChanges = false;

        Set keys = clean.keySet();
        for(String key : keys)
        {
            if(key.equals(LOOPBACK) || key.equals(LOOPBACK_ADDRESS))
            {
                relevantChanges = true;
                break;
            }
        }

        return hasSetValues || relevantChanges;
    }

    @Override
    protected DecisionTree buildDecisionTree(Interface entity, Map changedValues) {

        final Map changeset = clearChangeset(changedValues);

        final DecisionTree tree =  new DecisionTree(entity);

        // INET ADDRESS
        tree.createRoot(1,"Is Loopback set?", new Decision() {
            @Override
            public boolean evaluate(Interface entity) {
                return entity.isLoopback();
            }
        });
        tree.yes(1, 2, "Anything conflicts with Loopback?", new Decision() {
            @Override
            public boolean evaluate(Interface entity) {
                Map properties = asProperties(entity);
                properties.remove(LOOPBACK);
                return !isEmpty(properties);
            }
        });
        tree.no(1, 3, "Is Loopback Address set?", new Decision() {
            @Override
            public boolean evaluate(Interface entity) {
                return isSet(entity.getLoopbackAddress());
            }
        });

        tree.no(2, 4, "Success: Loopback", SUCCESS);
        tree.yes(2, 5, Console.CONSTANTS.interfaces_err_loopback_set(), FAILURE);


        tree.yes(3, 6, "Anything conflicts with Loopback Address?", new Decision() {
            @Override
            public boolean evaluate(Interface entity) {
                Map properties = asProperties(entity);
                properties.remove(LOOPBACK_ADDRESS);
                return !isEmpty(properties);
            }
        });
        tree.no(3, 7, Console.CONSTANTS.interfaces_err_loopback_nor_address_set(), FAILURE);

        tree.yes(6, 8, Console.CONSTANTS.interfaces_err_loopback_address_set(), FAILURE);
        tree.no(6, 9, "Success: Loopback address", SUCCESS);

        return tree;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy