/**
   * Finds a value in the given {@code operationObject} whose key matches this attribute's {@link
   * #getName() name} and validates it using this attribute's {@link #getValidator() validator}.
   *
   * @param operationObject model node of type {@link ModelType#OBJECT}, typically representing an
   *     operation request
   * @return the value
   * @throws OperationFailedException if the value is not valid
   */
  public ModelNode validateOperation(final ModelNode operationObject)
      throws OperationFailedException {

    ModelNode node = new ModelNode();
    if (operationObject.has(name)) {
      node.set(operationObject.get(name));
    }
    if (isAllowExpression() && node.getType() == ModelType.STRING) {
      node = ParseUtils.parsePossibleExpression(node.asString());
    }
    if (!node.isDefined() && defaultValue.isDefined()) {
      validator.validateParameter(name, defaultValue);
    } else {
      validator.validateParameter(name, node);
    }

    return node;
  }
  /**
   * Finds a value in the given {@code operationObject} whose key matches this attribute's {@link
   * #getName() name}, resolves it and validates it using this attribute's {@link #getValidator()
   * validator}. If the value is undefined and a {@link #getDefaultValue() default value} is
   * available, the default value is used.
   *
   * @param operationObject model node of type {@link ModelType#OBJECT}, typically representing an
   *     operation request
   * @return the resolved value, possibly the default value if the operation does not have a defined
   *     value matching this attribute's name
   * @throws OperationFailedException if the value is not valid
   */
  public ModelNode validateResolvedOperation(final ModelNode operationObject)
      throws OperationFailedException {
    final ModelNode node = new ModelNode();
    if (operationObject.has(name)) {
      node.set(operationObject.get(name));
    }
    if (!node.isDefined() && defaultValue.isDefined()) {
      node.set(defaultValue);
    }
    final ModelNode resolved = node.resolve();
    validator.validateParameter(name, resolved);

    return resolved;
  }
  public static ModelNode parseField(String name, String value, XMLStreamReader reader)
      throws XMLStreamException {
    final String trimmed = value == null ? null : value.trim();
    ModelNode node;
    if (trimmed != null) {
      node = new ModelNode().set(trimmed);
    } else {
      node = new ModelNode();
    }

    try {
      fieldValidator.validateParameter(name, node);
    } catch (OperationFailedException e) {
      throw new XMLStreamException(e.getFailureDescription().toString(), reader.getLocation());
    }
    return node;
  }
  /**
   * Creates and returns a {@link org.jboss.dmr.ModelNode} using the given {@code value} after first
   * validating the node against {@link #getValidator() this object's validator}.
   *
   * <p>If {@code value} is {@code null} and a {@link #getDefaultValue() default value} is
   * available, the value of that default value will be used.
   *
   * @param value the value. Will be {@link String#trim() trimmed} before use if not {@code null}.
   * @param location current location of the parser's {@link javax.xml.stream.XMLStreamReader}. Used
   *     for any exception message
   * @return {@code ModelNode} representing the parsed value
   * @throws javax.xml.stream.XMLStreamException if {@code value} is not valid
   */
  public ModelNode parse(final String value, final Location location) throws XMLStreamException {

    final String trimmed = value == null ? null : value.trim();
    ModelNode node;
    if (trimmed != null) {
      node = new ModelNode().set(trimmed);
    } else {
      node = new ModelNode();
    }

    try {
      elementValidator.validateParameter(getXmlName(), node);
    } catch (OperationFailedException e) {
      throw new XMLStreamException(e.getFailureDescription().toString(), location);
    }

    return node;
  }