private static <A extends Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Stream<A> stream) throws XMLStreamException { // Write attributes before elements Stream.Builder<Attribute> objectAttributes = Stream.builder(); Iterable<A> attributes = stream::iterator; for (Attribute attribute : attributes) { if (attribute.getDefinition().getType() == ModelType.OBJECT) { objectAttributes.add(attribute); } else { writeAttribute(writer, model, attribute); } } Iterable<Attribute> elementAttributes = objectAttributes.build()::iterator; for (Attribute attribute : elementAttributes) { writeElement(writer, model, attribute); } }
protected SimpleListAttributeDefinition(final ListAttributeDefinition.Builder builder, AttributeDefinition valueType) { super(builder); this.valueType = valueType; // This class is not appropriate for lists with complex elements. Use ObjectListAttributeDefinition assert valueType.getType() != ModelType.OBJECT && valueType.getType() != ModelType.LIST; }
protected SimpleListAttributeDefinition(final ListAttributeDefinition.Builder builder, AttributeDefinition valueType) { super(builder); this.valueType = valueType; // This class is not appropriate for lists with complex elements. Use ObjectListAttributeDefinition assert valueType.getType() != ModelType.OBJECT && valueType.getType() != ModelType.LIST; }
private static ModelType[] findModelTypes(final AttributeDefinition... attributes) { final Set<ModelType> result = new HashSet<ModelType>(); for (AttributeDefinition attr : attributes) { if (attr.getType() != ModelType.OBJECT) result.add(attr.getType()); } return result.toArray(new ModelType[result.size()]); } }
private void addValueTypeDescription(final ModelNode node) { node.get(ModelDescriptionConstants.VALUE_TYPE).set(valueType.getType()); }
private void addValueTypeDescription(final ModelNode node) { node.get(ModelDescriptionConstants.VALUE_TYPE).set(valueType.getType()); }
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; }
@Deprecated static ModelNode parse(AttributeDefinition attribute, ParameterValidator validator, final String value) throws OperationFailedException { ModelNode node = ParseUtils.parseAttributeValue(value, attribute.isAllowExpression(), attribute.getType()); validator.validateParameter(attribute.getXmlName(), node); return node; }
@Deprecated static ModelNode parse(AttributeDefinition attribute, ParameterValidator validator, final String value) throws OperationFailedException { ModelNode node = ParseUtils.parseAttributeValue(value, attribute.isAllowExpression(), attribute.getType()); validator.validateParameter(attribute.getXmlName(), node); return node; }
public static double compareAttributes(AttributeDefinition attr1, AttributeDefinition attr2) { double res = 1d; res *= compareStrings(attr1.getName(), attr2.getName()); res *= compareStrings(attr1.getType().name(), attr2.getType().name()); res *= compareStrings(String.valueOf(attr1.isAllowExpression()), String.valueOf(attr2.isAllowExpression())); res *= compareStrings(String.valueOf(attr1.isAllowNull()), String.valueOf(attr2.isAllowNull())); res *= attr1.isAllowExpression() == attr2.isAllowExpression() ? 1d : 0.9d; res *= attr1.isAllowNull() == attr2.isAllowNull() ? 1d : 0.9d; return res; }
public static double compareAttributes(AttributeDefinition attr1, AttributeDefinition attr2) { double res = 1d; res *= compareStrings(attr1.getName(), attr2.getName()); res *= compareStrings(attr1.getType().name(), attr2.getType().name()); res *= compareStrings(String.valueOf(attr1.isAllowExpression()), String.valueOf(attr2.isAllowExpression())); res *= compareStrings(String.valueOf(attr1.isAllowNull()), String.valueOf(attr2.isAllowNull())); res *= attr1.isAllowExpression() == attr2.isAllowExpression() ? 1d : 0.9d; res *= attr1.isAllowNull() == attr2.isAllowNull() ? 1d : 0.9d; return res; }
abstract void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute) throws OperationFailedException;
abstract void updateModel(final OperationContext context, ModelNode model, ModelNode listAttribute) throws OperationFailedException;
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(); }
private ModelNode parse(final AttributeDefinition attribute, final String value) throws OperationFailedException { ModelNode node = ParseUtils.parseAttributeValue(value, attribute.isAllowExpression(), attribute.getType()); final ParameterValidator validator; // A bit yuck, but I didn't want to introduce a new type just for this if (attribute instanceof ListAttributeDefinition) { validator = ((ListAttributeDefinition) attribute).getElementValidator(); } else if (attribute instanceof MapAttributeDefinition) { validator = ((MapAttributeDefinition) attribute).getElementValidator(); } else { validator = attribute.getValidator(); } validator.validateParameter(attribute.getXmlName(), node); return node; }
private static <A extends Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Stream<A> stream) throws XMLStreamException { // Write attributes before elements Stream.Builder<Attribute> objectAttributes = Stream.builder(); Iterable<A> attributes = stream::iterator; for (Attribute attribute : attributes) { if (attribute.getDefinition().getType() == ModelType.OBJECT) { objectAttributes.add(attribute); } else { writeAttribute(writer, model, attribute); } } Iterable<Attribute> elementAttributes = objectAttributes.build()::iterator; for (Attribute attribute : elementAttributes) { writeElement(writer, model, attribute); } }
private ModelNode parse(final AttributeDefinition attribute, final String value) throws OperationFailedException { ModelNode node = ParseUtils.parseAttributeValue(value, attribute.isAllowExpression(), attribute.getType()); final ParameterValidator validator; // A bit yuck, but I didn't want to introduce a new type just for this if (attribute instanceof ListAttributeDefinition) { validator = ((ListAttributeDefinition) attribute).getElementValidator(); } else if (attribute instanceof MapAttributeDefinition) { validator = ((MapAttributeDefinition) attribute).getElementValidator(); } else { validator = attribute.getValidator(); } validator.validateParameter(attribute.getXmlName(), node); return node; }