コード例 #1
0
    @Override
    public TransformedOperation transformOperation(
        final TransformationContext context, final PathAddress address, final ModelNode operation)
        throws OperationFailedException {
      final String attribute = operation.require(NAME).asString();
      boolean containsExpression = false;
      if (attributeNames.contains(attribute)) {
        if (operation.hasDefined(VALUE)) {
          AttributeTransformationRequirementChecker checker;
          if (attributeCheckers != null && (checker = attributeCheckers.get(attribute)) != null) {
            if (checker.isAttributeTransformationRequired(
                attribute, operation.get(VALUE), context)) {
              containsExpression = true;
            }
          } else if (SIMPLE_EXPRESSIONS.isAttributeTransformationRequired(
              attribute, operation.get(VALUE), context)) {
            containsExpression = true;
          }
        }
      }
      final boolean rejectResult = containsExpression;
      if (rejectResult) {
        // Create the rejection policy
        final OperationRejectionPolicy rejectPolicy =
            new OperationRejectionPolicy() {
              @Override
              public boolean rejectOperation(ModelNode preparedResult) {
                // Reject successful operations
                return true;
              }

              @Override
              public String getFailureDescription() {
                return context
                    .getLogger()
                    .getAttributeWarning(
                        address, operation, MESSAGES.attributesDontSupportExpressions(), attribute);
              }
            };
        return new TransformedOperation(
            operation, rejectPolicy, OperationResultTransformer.ORIGINAL_RESULT);
      }
      // In case it's not an expressions just forward unmodified
      return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT);
    }
コード例 #2
0
 /**
  * Check the model for expression values.
  *
  * @param model the model
  * @return the attribute containing an expression
  */
 private Set<String> checkModel(final ModelNode model, TransformationContext context)
     throws OperationFailedException {
   final Set<String> attributes = new HashSet<String>();
   AttributeTransformationRequirementChecker checker;
   for (final String attribute : attributeNames) {
     if (model.hasDefined(attribute)) {
       if (attributeCheckers != null && (checker = attributeCheckers.get(attribute)) != null) {
         if (checker.isAttributeTransformationRequired(attribute, model.get(attribute), context)) {
           attributes.add(attribute);
         }
       } else if (SIMPLE_EXPRESSIONS.isAttributeTransformationRequired(
           attribute, model.get(attribute), context)) {
         attributes.add(attribute);
       }
     }
   }
   return attributes;
 }