/**
   * Define the definition of a service; this will destroy any existing configuration associated
   * with the serviceid.
   *
   * @param service The service for the newly defined service.
   */
  public void defineService(Service service) {

    if (service.getSpringFile() == null) {
      service.setSpringFile(getServiceBeanName(service.getId()));
    }

    saveServiceDefinition(service.getId());

    // and, create the service bean
    File serviceBeanFile = getServiceBeanXmlFile(service.getId());
    if (getServiceBeanName(service.getId()).equals(service.getSpringFile())
        && !serviceBeanFile.exists()) {

      try {
        generateSpringServiceConfig(
            service.getId(),
            service.getClazz(),
            getDesignServiceType(service.getType()),
            serviceBeanFile,
            this.projectManager.getCurrentProject());
      } catch (JAXBException e) {
        throw new WMRuntimeException(e);
      } catch (IOException e) {
        throw new WMRuntimeException(e);
      }
    }
  }
  /**
   * Define the definition of a service; this will destroy any existing configuration associated
   * with the serviceid.
   *
   * @param serviceDef The service definition for the newly defined service.
   */
  @SuppressWarnings("deprecation")
  public void defineService(ServiceDefinition serviceDef, String username, String password) {

    try {
      validateServiceId(serviceDef.getServiceId());
    } catch (DuplicateServiceIdException ignore) {
      // ignore
    }

    Service oldService = getService(serviceDef.getServiceId());

    Service service = new Service();

    /** Copying the service operations to the new service */
    if (serviceDef instanceof AbstractDeprecatedServiceDefinition) {
      // List<String> opNames =
      // ((AbstractDeprecatedServiceDefinition)serviceDef).getOperationNames();
      if (oldService != null) {
        List<Operation> ops = oldService.getOperation();
        if (ops != null) {
          for (Operation op : ops) {
            // if(opNames != null && opNames.contains(op.getName())){
            service.addOperation(op);
            // }
          }
        }
      }
    }

    getCurrentServiceDefinitions().put(serviceDef.getServiceId(), service);

    IPwsServiceModifier serviceModifier;
    if (this.pwsServiceModifierBeanFactory == null || serviceDef.getPartnerName() == null) {
      serviceModifier = null;
    } else {
      serviceModifier =
          this.pwsServiceModifierBeanFactory.getPwsServiceModifier(serviceDef.getPartnerName());
    }

    try {
      for (ServiceOperation op : serviceDef.getServiceOperations(serviceModifier)) {
        doUpdateOperation(op, service, serviceDef, serviceModifier);
      }
      service.setId(serviceDef.getServiceId());
      service.setType(serviceDef.getServiceType().getTypeName());
      service.setCRUDService(serviceDef.isLiveDataService());
      if (serviceDef instanceof ReflectServiceDefinition) {
        service.setClazz(((ReflectServiceDefinition) serviceDef).getServiceClass());
      }

      if (serviceDef.getRuntimeConfiguration() != null) {
        service.setSpringFile(serviceDef.getRuntimeConfiguration());
      } else if (oldService != null && oldService.getSpringFile() != null) {
        service.setSpringFile(oldService.getSpringFile());
      }

      updateServiceTypes(service, serviceDef, username, password);
    } catch (WMRuntimeException e) {
      // if we had an error, remove the service def so we'll use the last
      // known-good one
      getCurrentServiceDefinitions().remove(serviceDef.getServiceId());
      throw e;
    }

    String svcId = service.getId();
    // TODO: Skipping salesforce setup when null is passed in for username
    // is not good programming practice.
    // TODO: The logic has to be rewritten later when we have time.
    if (svcId.equals(CommonConstants.SALESFORCE_SERVICE) && username != null) { // salesforce
      SalesforceHelper.setupSalesforceSrc(this.projectManager, username, password);
    }

    defineService(service);
  }