コード例 #1
0
 private ModelNode getValueTypeDescription(boolean forOperation) {
   final ModelNode result = new ModelNode();
   result.get(ModelDescriptionConstants.TYPE).set(valueType.getType());
   result.get(ModelDescriptionConstants.DESCRIPTION); // placeholder
   result.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(valueType.isAllowExpression());
   if (forOperation) {
     result.get(ModelDescriptionConstants.REQUIRED).set(!valueType.isAllowNull());
   }
   result.get(ModelDescriptionConstants.NILLABLE).set(isAllowNull());
   final ModelNode defaultValue = valueType.getDefaultValue();
   if (!forOperation && defaultValue != null && defaultValue.isDefined()) {
     result.get(ModelDescriptionConstants.DEFAULT).set(defaultValue);
   }
   MeasurementUnit measurementUnit = valueType.getMeasurementUnit();
   if (measurementUnit != null && measurementUnit != MeasurementUnit.NONE) {
     result.get(ModelDescriptionConstants.UNIT).set(measurementUnit.getName());
   }
   final String[] alternatives = valueType.getAlternatives();
   if (alternatives != null) {
     for (final String alternative : alternatives) {
       result.get(ModelDescriptionConstants.ALTERNATIVES).add(alternative);
     }
   }
   final String[] requires = valueType.getRequires();
   if (requires != null) {
     for (final String required : requires) {
       result.get(ModelDescriptionConstants.REQUIRES).add(required);
     }
   }
   final ParameterValidator validator = valueType.getValidator();
   if (validator instanceof MinMaxValidator) {
     MinMaxValidator minMax = (MinMaxValidator) validator;
     Long min = minMax.getMin();
     if (min != null) {
       switch (valueType.getType()) {
         case STRING:
         case LIST:
         case OBJECT:
           result.get(ModelDescriptionConstants.MIN_LENGTH).set(min);
           break;
         default:
           result.get(ModelDescriptionConstants.MIN).set(min);
       }
     }
     Long max = minMax.getMax();
     if (max != null) {
       switch (valueType.getType()) {
         case STRING:
         case LIST:
         case OBJECT:
           result.get(ModelDescriptionConstants.MAX_LENGTH).set(max);
           break;
         default:
           result.get(ModelDescriptionConstants.MAX).set(max);
       }
     }
   }
   if (validator instanceof AllowedValuesValidator) {
     AllowedValuesValidator avv = (AllowedValuesValidator) validator;
     List<ModelNode> allowed = avv.getAllowedValues();
     if (allowed != null) {
       for (ModelNode ok : allowed) {
         result.get(ModelDescriptionConstants.ALLOWED).add(ok);
       }
     }
   }
   return result;
 }
コード例 #2
0
 protected void addValueTypeDescription(
     final ModelNode node,
     final String prefix,
     final ResourceBundle bundle,
     boolean forOperation,
     final ResourceDescriptionResolver resolver,
     Locale locale) {
   node.get(ModelDescriptionConstants.DESCRIPTION); // placeholder
   node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(valueType.isAllowExpression());
   if (forOperation) {
     node.get(ModelDescriptionConstants.REQUIRED).set(!valueType.isAllowNull());
   }
   node.get(ModelDescriptionConstants.NILLABLE).set(isAllowNull());
   final ModelNode defaultValue = valueType.getDefaultValue();
   if (!forOperation && defaultValue != null && defaultValue.isDefined()) {
     node.get(ModelDescriptionConstants.DEFAULT).set(defaultValue);
   }
   MeasurementUnit measurementUnit = valueType.getMeasurementUnit();
   if (measurementUnit != null && measurementUnit != MeasurementUnit.NONE) {
     node.get(ModelDescriptionConstants.UNIT).set(measurementUnit.getName());
   }
   final String[] alternatives = valueType.getAlternatives();
   if (alternatives != null) {
     for (final String alternative : alternatives) {
       node.get(ModelDescriptionConstants.ALTERNATIVES).add(alternative);
     }
   }
   final String[] requires = valueType.getRequires();
   if (requires != null) {
     for (final String required : requires) {
       node.get(ModelDescriptionConstants.REQUIRES).add(required);
     }
   }
   final ParameterValidator validator = valueType.getValidator();
   if (validator instanceof MinMaxValidator) {
     MinMaxValidator minMax = (MinMaxValidator) validator;
     Long min = minMax.getMin();
     if (min != null) {
       switch (valueType.getType()) {
         case STRING:
         case LIST:
         case OBJECT:
         case BYTES:
           node.get(ModelDescriptionConstants.MIN_LENGTH).set(min);
           break;
         default:
           node.get(ModelDescriptionConstants.MIN).set(min);
       }
     }
     Long max = minMax.getMax();
     if (max != null) {
       switch (valueType.getType()) {
         case STRING:
         case LIST:
         case OBJECT:
         case BYTES:
           node.get(ModelDescriptionConstants.MAX_LENGTH).set(max);
           break;
         default:
           node.get(ModelDescriptionConstants.MAX).set(max);
       }
     }
   }
   addAllowedValuesToDescription(node, validator);
   valueType.addValueTypeDescription(node, prefix, bundle, resolver, locale);
 }