コード例 #1
0
  // TODO move this kind of logic into AttributeDefinition itself
  private static ModelNode validateResolvedModel(
      final AttributeDefinition definition,
      final OperationContext context,
      final ModelNode subModel)
      throws OperationFailedException {
    final String attributeName = definition.getName();
    final boolean has = subModel.has(attributeName);
    if (!has && definition.isRequired(subModel)) {
      throw ServerMessages.MESSAGES.attributeIsRequired(attributeName);
    }
    ModelNode result;
    if (has) {
      if (!definition.isAllowed(subModel)) {
        if (subModel.hasDefined(attributeName)) {
          throw ServerMessages.MESSAGES.attributeNotAllowedWhenAlternativeIsPresent(
              attributeName, Arrays.asList(definition.getAlternatives()));
        } else {
          // create the undefined node
          result = new ModelNode();
        }
      } else {
        result = definition.resolveModelAttribute(context, subModel);
      }
    } else {
      // create the undefined node
      result = new ModelNode();
    }

    return result;
  }
コード例 #2
0
 // TODO move this kind of logic into AttributeDefinition itself
 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.attributeIsInvalid(attributeName);
     }
     definition.validateAndSet(operation, subModel);
   } else {
     // create the undefined node
     subModel.get(definition.getName());
   }
 }