Esempio n. 1
0
  /**
   * Wrap a simple attribute def as list.
   *
   * @param def the attribute definition
   * @return the list attribute def
   */
  @Deprecated
  private static ListAttributeDefinition wrapAsList(final AttributeDefinition def) {
    final ListAttributeDefinition list =
        new ListAttributeDefinition(def.getName(), true, def.getValidator()) {

          @Override
          public ModelNode getNoTextDescription(boolean forOperation) {
            final ModelNode model = super.getNoTextDescription(forOperation);
            setValueType(model);
            return model;
          }

          @Override
          protected void addValueTypeDescription(
              final ModelNode node, final ResourceBundle bundle) {
            setValueType(node);
          }

          @Override
          public void marshallAsElement(
              final ModelNode resourceModel,
              final boolean marshalDefault,
              final XMLStreamWriter writer)
              throws XMLStreamException {
            throw new RuntimeException();
          }

          @Override
          protected void addAttributeValueTypeDescription(
              ModelNode node,
              ResourceDescriptionResolver resolver,
              Locale locale,
              ResourceBundle bundle) {
            setValueType(node);
          }

          @Override
          protected void addOperationParameterValueTypeDescription(
              ModelNode node,
              String operationName,
              ResourceDescriptionResolver resolver,
              Locale locale,
              ResourceBundle bundle) {
            setValueType(node);
          }

          private void setValueType(ModelNode node) {
            node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
          }
        };
    return list;
  }
 @Override
 public void execute(final OperationContext context, final ModelNode operation)
     throws OperationFailedException {
   final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
   final ModelNode model = resource.getModel();
   final String name = operation.require(ModelDescriptionConstants.NAME).asString();
   final AttributeDefinition def = ATTRIBUTES.get(name);
   if (def == null) {
     throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownAttribute(name)));
   }
   final ModelNode value = operation.get(ModelDescriptionConstants.VALUE);
   def.getValidator().validateParameter(name, value);
   model.get(name).set(value);
   context.reloadRequired();
   // Verify the model in a later step
   context.addStep(VERIFY_HANDLER, OperationContext.Stage.VERIFY);
   if (context.completeStep() != OperationContext.ResultAction.KEEP) {
     context.revertReloadRequired();
   }
 }
 @Override
 protected void validateValue(String name, ModelNode value) throws OperationFailedException {
   AttributeDefinition attr = attributes.get(name);
   attr.getValidator().validateParameter(name, value);
 }