예제 #1
0
  private BindingContext createBindingContext() {
    final PropertyContainer container =
        PropertyContainer.createObjectBacked(
            variableItem.variableConfig, new ParameterDescriptorFactory());
    final BindingContext context = new BindingContext(container);

    PropertyDescriptor descriptor = container.getDescriptor(PROPERTY_VARIABLE_NAME);
    descriptor.setDescription("The name for the source band.");
    descriptor.setValidator(new VariableNameValidator());
    container.setDefaultValues();

    return context;
  }
예제 #2
0
  private Map<String, Object> convertParameterMap(
      String operatorName, Map<String, String> parameterMap) throws ValidationException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    PropertyContainer container =
        ParameterDescriptorFactory.createMapBackedOperatorPropertyContainer(
            operatorName, parameters);
    // explicitly set default values for putting them into the backing map
    container.setDefaultValues();

    // handle xml parameters
    Object parametersObject = metadataResourceEngine.getVelocityContext().get("parameterFile");
    if (parametersObject instanceof Resource) {
      Resource paramatersResource = (Resource) parametersObject;
      if (paramatersResource.isXml()) {
        OperatorSpiRegistry operatorSpiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry();
        OperatorSpi operatorSpi = operatorSpiRegistry.getOperatorSpi(operatorName);
        Class<? extends Operator> operatorClass = operatorSpi.getOperatorClass();
        DefaultDomConverter domConverter =
            new DefaultDomConverter(operatorClass, new ParameterDescriptorFactory());

        DomElement parametersElement = createDomElement(paramatersResource.getContent());
        try {
          domConverter.convertDomToValue(parametersElement, container);
        } catch (ConversionException e) {
          String msgPattern = "Can not convert XML parameters for operator '%s'";
          throw new RuntimeException(String.format(msgPattern, operatorName));
        }
      }
    }

    for (Entry<String, String> entry : parameterMap.entrySet()) {
      String paramName = entry.getKey();
      String paramValue = entry.getValue();
      final Property property = container.getProperty(paramName);
      if (property != null) {
        property.setValueFromText(paramValue);
      } else {
        throw new RuntimeException(
            String.format("Parameter '%s' is not known by operator '%s'", paramName, operatorName));
      }
    }
    return parameters;
  }