class ViewInstanceEntity implements ViewInstanceDefinition {

  public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context)
      throws IllegalStateException {

    Map<String, ValidationResult> propertyResults = new HashMap<>();

    if (context.equals(Validator.ValidationContext.PRE_CREATE) ||
        context.equals(Validator.ValidationContext.PRE_UPDATE)) {

      // make sure that there is an instance property value defined
      // for each required view parameter
      Set<String> requiredParameterNames = new HashSet<>();
      for (ViewParameterEntity parameter : viewEntity.getParameters()) {
        if (parameter.isRequired()) {
          // Don't enforce 'required' validation for cluster config parameters since
          // the value will be obtained through cluster association, not user input
          if (parameter.getClusterConfig()== null) {
            requiredParameterNames.add(parameter.getName());
          }
        }
      }
      Map<String, String> propertyMap = getPropertyMap();
      for (Map.Entry<String, String> entry : propertyMap.entrySet()) {
        if (entry.getValue() != null) {
          requiredParameterNames.remove(entry.getKey());
        }
      }
      // required but missing instance properties...
      for (String requiredParameterName : requiredParameterNames) {
        propertyResults.put(requiredParameterName,
            new ValidationResultImpl(false,
                "No property values exist for the required parameter " + requiredParameterName + "."));
      }
    }

    ValidationResult instanceResult = null;
    Validator         validator     = viewEntity.getValidator();

    // if the view provides its own validator, run it
    if (validator != null) {
      instanceResult = validator.validateInstance(this, context);
      for ( String property : getPropertyMap().keySet()) {
        if (!propertyResults.containsKey(property)) {
          propertyResults.put(property,
              ValidationResultImpl.create(validator.validateProperty(property, this, context)));
        }
      }
    }
    return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults);
  }

  public  ViewInstanceEntity();
  public  ViewInstanceEntity(ViewEntity view, InstanceConfig instanceConfig);
  public  ViewInstanceEntity(ViewEntity view, String name);
  public  ViewInstanceEntity(ViewEntity view, String name, String label);

}