private boolean isAllowed(final AttributeDefinition def, final Set<String> definedKeys) { final String[] alternatives = def.getAlternatives(); if (alternatives != null) { for (final String alternative : alternatives) { if (definedKeys.contains(alternative)) { return false; } } } return true; }
private boolean isAllowed(final AttributeDefinition def, final Set<String> definedKeys) { final String[] alternatives = def.getAlternatives(); if (alternatives != null) { for (final String alternative : alternatives) { if (definedKeys.contains(alternative)) { return false; } } } return true; }
IdentityProviderConfigAddStepHandler(final AttributeDefinition... attributes) { super(ModelElement.IDENTITY_PROVIDER.getName()); this.attributes = attributes != null ? attributes : new AttributeDefinition[0]; for (AttributeDefinition attribute : this.attributes) { if (attribute.getAlternatives() != null && attribute.getAlternatives().length > 0) { this.alternativeAttributes.add(attribute); } } }
IdentityProviderConfigAddStepHandler(final AttributeDefinition... attributes) { super(ModelElement.IDENTITY_PROVIDER.getName()); this.attributes = attributes != null ? attributes : new AttributeDefinition[0]; for (AttributeDefinition attribute : this.attributes) { if (attribute.getAlternatives() != null && attribute.getAlternatives().length > 0) { this.alternativeAttributes.add(attribute); } } }
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); } }); }
boolean isRequired(final AttributeDefinition def, final ModelNode model) { final boolean required = def.isRequired(); return required ? ! hasAlternative(def.getAlternatives(), model, true) : required; }
boolean isRequired(final AttributeDefinition def, final ModelNode model) { final boolean required = def.isRequired(); return required ? ! hasAlternative(def.getAlternatives(), model, true) : required; }
boolean isRequired(final AttributeDefinition def, final ModelNode model) { final boolean required = ! def.isAllowNull(); return required ? ! hasAlternative(def.getAlternatives(), model, true) : required; }
boolean isRequired(final AttributeDefinition def, final ModelNode model) { final boolean required = ! def.isAllowNull(); return required ? ! hasAlternative(def.getAlternatives(), model, true) : required; }
boolean isAllowed(final AttributeDefinition def, final ModelNode model) { final String[] alternatives = def.getAlternatives(); if(alternatives != null) { for(final String alternative : alternatives) { if(model.hasDefined(alternative)) { if(ATTRIBUTES.get(alternative).getType() == ModelType.BOOLEAN) { return ! model.get(alternative).asBoolean(); } return false; } } } return true; }
boolean isAllowed(final AttributeDefinition def, final ModelNode model) { final String[] alternatives = def.getAlternatives(); if(alternatives != null) { for(final String alternative : alternatives) { if(model.hasDefined(alternative)) { if(ATTRIBUTES.get(alternative).getType() == ModelType.BOOLEAN) { return ! model.get(alternative).asBoolean(); } return false; } } } return true; }
boolean isAllowed(final AttributeDefinition def, final ModelNode model) { final String[] alternatives = def.getAlternatives(); if(alternatives != null) { for(final String alternative : alternatives) { if(model.hasDefined(alternative)) { if(ATTRIBUTES.get(alternative).getType() == ModelType.BOOLEAN) { return ! model.get(alternative).asBoolean(); } return false; } } } return true; }
boolean isAllowed(final AttributeDefinition def, final ModelNode model) { final String[] alternatives = def.getAlternatives(); if(alternatives != null) { for(final String alternative : alternatives) { if(model.hasDefined(alternative)) { if(ATTRIBUTES.get(alternative).getType() == ModelType.BOOLEAN) { return ! model.get(alternative).asBoolean(); } return false; } } } return true; }
@Override public void throwError() throws OperationFailedException { String[] alternatives = attr.getAlternatives(); if (alternatives == null) { throw ControllerLogger.ROOT_LOGGER.required(attributeName); } else { Set<String> requiredAlternatives = new HashSet<>(); for (int i = 0; i < alternatives.length; i++) { AttributeDefinition requiredAttr = getAttributeDefinition(alternatives[i], attributes); if (requiredAttr != null && requiredAttr.isRequired() && !requiredAttr.isResourceOnly()) { requiredAlternatives.add(alternatives[i]); } } throw ControllerLogger.ROOT_LOGGER.requiredWithAlternatives(attributeName, requiredAlternatives); } }} );
@Override public void throwError() throws OperationFailedException { String[] alternatives = attr.getAlternatives(); if (alternatives == null) { throw ControllerLogger.ROOT_LOGGER.required(attributeName); } else { Set<String> requiredAlternatives = new HashSet<>(); for (int i = 0; i < alternatives.length; i++) { AttributeDefinition requiredAttr = getAttributeDefinition(alternatives[i], attributes); if (requiredAttr != null && requiredAttr.isRequired() && !requiredAttr.isResourceOnly()) { requiredAlternatives.add(alternatives[i]); } } throw ControllerLogger.ROOT_LOGGER.requiredWithAlternatives(attributeName, requiredAlternatives); } }} );
private boolean isRequired(final AttributeDefinition def, final Set<String> definedKeys) { return def.isRequired() && !def.isResourceOnly() && !hasAlternative(def.getAlternatives(), definedKeys); }
private boolean isRequired(final AttributeDefinition def, final Set<String> definedKeys) { return def.isRequired() && !def.isResourceOnly() && !hasAlternative(def.getAlternatives(), definedKeys); }
private static void validateAndSet(final AttributeDefinition definition, final ModelNode operation, final ModelNode subModel) throws OperationFailedException { final String attributeName = definition.getName(); final boolean has = operation.has(attributeName); if(! has && definition.isRequired(operation)) { throw ServerMessages.MESSAGES.attributeIsRequired(attributeName); } if(has) { if(! definition.isAllowed(operation)) { throw ServerMessages.MESSAGES.attributeNotAllowedWhenAlternativeIsPresent(attributeName, Arrays.asList(definition.getAlternatives())); } definition.validateAndSet(operation, subModel); } else { // create the undefined node subModel.get(definition.getName()); } }
private static void validateAndSet(final AttributeDefinition definition, final ModelNode operation, final ModelNode subModel) throws OperationFailedException { final String attributeName = definition.getName(); final boolean has = operation.has(attributeName); if(! has && definition.isRequired(operation)) { throw ServerMessages.MESSAGES.attributeIsRequired(attributeName); } if(has) { if(! definition.isAllowed(operation)) { throw ServerMessages.MESSAGES.attributeNotAllowedWhenAlternativeIsPresent(attributeName, Arrays.asList(definition.getAlternatives())); } definition.validateAndSet(operation, subModel); } else { // create the undefined node subModel.get(definition.getName()); } }
public AbstractAttributeDefinitionBuilder(final String attributeName, final AttributeDefinition basis) { this.name = attributeName != null ? attributeName : basis.getName(); this.type = basis.getType(); this.xmlName = basis.getXmlName(); this.allowNull = basis.isAllowNull(); this.allowExpression = basis.isAllowExpression(); this.defaultValue = basis.getDefaultValue(); this.measurementUnit = basis.getMeasurementUnit(); this.alternatives = basis.getAlternatives(); this.requires = basis.getRequires(); this.validator = basis.getValidator(); Set<AttributeAccess.Flag> basisFlags = basis.getFlags(); this.flags = basisFlags.toArray(new AttributeAccess.Flag[basisFlags.size()]); this.attributeMarshaller = basis.getAttributeMarshaller(); }