Search in sources :

Example 1 with ModelValidationStepHandler

use of org.wildfly.extension.picketlink.common.model.validator.ModelValidationStepHandler in project wildfly by wildfly.

the class IDMConfigAddStepHandler method configureModelValidators.

private void configureModelValidators(ModelValidationStepHandler[] modelValidators) {
    List<AttributeDefinition> alternativeAttributes = new ArrayList<AttributeDefinition>();
    for (AttributeDefinition attribute : this.attributes) {
        if (attribute.getAlternatives() != null && attribute.getAlternatives().length > 0) {
            alternativeAttributes.add(attribute);
        }
    }
    if (!alternativeAttributes.isEmpty()) {
        this.modelValidators.add(new AlternativeAttributeValidationStepHandler(alternativeAttributes.toArray(new AttributeDefinition[alternativeAttributes.size()]), isAlternativesRequired()));
    }
    if (modelValidators != null) {
        this.modelValidators.addAll(Arrays.asList(modelValidators));
    }
    this.modelValidators.add(new ModelValidationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final PathAddress address = getParentAddress(PathAddress.pathAddress(operation.require(OP_ADDR)));
            Resource resource = context.readResourceFromRoot(address);
            final ModelNode parentModel = Resource.Tools.readModel(resource);
            PartitionManagerAddHandler.INSTANCE.validateModel(context, address.getLastElement().getValue(), parentModel);
            context.stepCompleted();
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.ModelValidationStepHandler) ModelNode(org.jboss.dmr.ModelNode) AlternativeAttributeValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.AlternativeAttributeValidationStepHandler)

Aggregations

ArrayList (java.util.ArrayList)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 Resource (org.jboss.as.controller.registry.Resource)1 ModelNode (org.jboss.dmr.ModelNode)1 AlternativeAttributeValidationStepHandler (org.wildfly.extension.picketlink.common.model.validator.AlternativeAttributeValidationStepHandler)1 ModelValidationStepHandler (org.wildfly.extension.picketlink.common.model.validator.ModelValidationStepHandler)1