public void onSave() {
    if (config == null) {
      return;
    }

    removeUnusedEndpoints();

    // remove unused
    for (int c = 0; c < config.sizeOfEndpointArray(); c++) {
      EndpointConfig ec = config.getEndpointArray(c);
      if (StringUtils.isNullOrEmpty(ec.getDomain())
          && StringUtils.isNullOrEmpty(ec.getUsername())
          && StringUtils.isNullOrEmpty(ec.getPassword())
          && StringUtils.isNullOrEmpty(ec.getWssType())
          && StringUtils.isNullOrEmpty(ec.getWssTimeToLive())
          && StringUtils.isNullOrEmpty(ec.getIncomingWss())
          && StringUtils.isNullOrEmpty(ec.getOutgoingWss())
          && ec.getMode() == EndpointConfig.Mode.COMPLEMENT) {
        synchronized (defaults) {
          defaults.remove(ec.getStringValue());
          config.removeEndpoint(c);
          c--;
        }
      }
    }

    if (config.sizeOfEndpointArray() == 0) {
      project.getConfig().unsetEndpointStrategy();
      config = null;
    }
  }
  private void removeUnusedEndpoints() {
    if (config == null) {
      return;
    }

    Set<String> endpoints = new HashSet<String>();

    for (Interface iface : project.getInterfaceList()) {
      endpoints.addAll(Arrays.asList(iface.getEndpoints()));
    }

    StringList keys = new StringList();

    synchronized (defaults) {
      for (String key : defaults.keySet()) {
        if (!endpoints.contains(key)) {
          keys.add(key);
        }
      }

      for (String key : keys) {
        EndpointDefaults def = defaults.remove(key);
        config.getEndpointList().remove(def);
      }
    }
  }
  public EndpointDefaults getEndpointDefaults(String endpoint) {
    if (config == null) {
      initConfig();
    }

    if (!defaults.containsKey(endpoint)) {
      synchronized (defaults) {
        EndpointConfig newEndpoint = config.addNewEndpoint();
        newEndpoint.setStringValue(endpoint);
        defaults.put(endpoint, new EndpointDefaults(newEndpoint));
      }
    }

    return defaults.get(endpoint);
  }
  private void initConfig() {
    ProjectConfig projectConfig = this.project.getConfig();

    if (!projectConfig.isSetEndpointStrategy()) {
      projectConfig.addNewEndpointStrategy();
    }

    config =
        (DefaultEndpointStrategyConfig)
            projectConfig.getEndpointStrategy().changeType(DefaultEndpointStrategyConfig.type);

    for (EndpointConfig endpointConfig : config.getEndpointList()) {
      if (!endpointConfig.isSetMode()) {
        endpointConfig.setMode(EndpointConfig.Mode.COMPLEMENT);
      }

      defaults.put(endpointConfig.getStringValue(), new EndpointDefaults(endpointConfig));
    }
  }