public static void addControllerService(
      final Element element,
      final ControllerServiceNode serviceNode,
      final StringEncryptor encryptor) {
    final Element serviceElement = element.getOwnerDocument().createElement("controllerService");
    addTextElement(serviceElement, "id", serviceNode.getIdentifier());
    addTextElement(serviceElement, "name", serviceNode.getName());
    addTextElement(serviceElement, "comment", serviceNode.getComments());
    addTextElement(
        serviceElement,
        "class",
        serviceNode.getControllerServiceImplementation().getClass().getCanonicalName());

    final ControllerServiceState state = serviceNode.getState();
    final boolean enabled =
        (state == ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING);
    addTextElement(serviceElement, "enabled", String.valueOf(enabled));

    addConfiguration(
        serviceElement, serviceNode.getProperties(), serviceNode.getAnnotationData(), encryptor);

    element.appendChild(serviceElement);
  }
예제 #2
0
  /**
   * Extracts the values for the configured properties from the specified ControllerService.
   *
   * @param controllerService service
   * @param controllerServiceDTO dto
   * @return properties
   */
  private Map<String, String> extractConfiguredPropertyValues(
      ControllerServiceNode controllerService, ControllerServiceDTO controllerServiceDTO) {
    Map<String, String> values = new HashMap<>();

    if (controllerServiceDTO.getName() != null) {
      values.put(NAME, controllerService.getName());
    }
    if (controllerServiceDTO.getAnnotationData() != null) {
      values.put(ANNOTATION_DATA, controllerService.getAnnotationData());
    }
    if (controllerServiceDTO.getProperties() != null) {
      // for each property specified, extract its configured value
      Map<String, String> properties = controllerServiceDTO.getProperties();
      Map<PropertyDescriptor, String> configuredProperties = controllerService.getProperties();
      for (String propertyName : properties.keySet()) {
        // build a descriptor for getting the configured value
        PropertyDescriptor propertyDescriptor =
            new PropertyDescriptor.Builder().name(propertyName).build();
        String configuredPropertyValue = configuredProperties.get(propertyDescriptor);

        // if the configured value couldn't be found, use the default value from the actual
        // descriptor
        if (configuredPropertyValue == null) {
          propertyDescriptor =
              locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor);
          configuredPropertyValue = propertyDescriptor.getDefaultValue();
        }
        values.put(propertyName, configuredPropertyValue);
      }
    }
    if (controllerServiceDTO.getComments() != null) {
      values.put(COMMENTS, controllerService.getComments());
    }

    return values;
  }