private ServiceSetting FindServiceSettingOfOfferedService(
      OfferedService offService, String setName) {
    for (int i = 0; i < offService.getServiceSettings().size(); i++) {
      if (offService.getServiceSettings().get(i).getName().equalsIgnoreCase(setName)) {
        return offService.getServiceSettings().get(i);
      }
    }

    return null;
  }
  public void CreateSetting(
      String setttingName,
      String defaultValue,
      String settingDescription,
      boolean newServiceCreated,
      OfferedService offService,
      OfferedResource offeredResource,
      boolean readable,
      boolean writable,
      boolean isOptional) {

    // http://repos.pii.tssg.org:8080/repository/rest/configParamAtomic/586

    // NodeList ParamAtomicNode = xmlutl.getNodeListFromObject (
    // configParamAtomicDocument , "//configParamAtomic[@id="+setId+"]");
    log("setttingName = " + setttingName);
    log("setDescription = " + settingDescription);

    ServiceSetting servSetting = null;
    if (!newServiceCreated) {
      log("try to find  servSetting : " + setttingName + " for service : " + offService);
      servSetting = FindServiceSettingOfOfferedService(offService, setttingName);
    }

    if (newServiceCreated || (servSetting == null)) {
      servSetting = ServicesFactory.eINSTANCE.createServiceSetting();
      servSetting.setName(setttingName);
      servSetting.setDescription(settingDescription);
      servSetting.setId(offService.getServiceSettings().size() + 1);
      servSetting.setUniqueID(offService.getUniqueID() + "_set_" + servSetting.getId());
      servSetting.setCanBePublished(false);
      servSetting.setUserEditable(writable);
      servSetting.setUserExposed(true);
      servSetting.setReadable(readable);
      servSetting.setWritable(writable);

      // The following constraint means that the parameter is available
      // after the CREATE operation!
      // SettingConstraint setconstraint =
      // ServicesFactory.eINSTANCE.createSettingConstraint();
      // setconstraint.setForOperation(ServiceResourceOperation.OP_CREATE);
      // setconstraint.setAvailableAfterOperation(true);
      // servSetting.getSettingConstraints().add(setconstraint);

      offService.getServiceSettings().add(servSetting);
      log("servSettings = OK!");
    }
    // service settings now to resource settings

    if (offeredResource != null) {
      ResourceSetting resourceSetting = ResourcesFactory.eINSTANCE.createResourceSetting();
      resourceSetting.setName(setttingName);

      brTypeString sType = brokermodel.services.ServicesFactory.eINSTANCE.createbrTypeString();
      sType.setDefaultValue(defaultValue);
      resourceSetting.setSettingType(sType);

      resourceSetting.setDescription(settingDescription);
      resourceSetting.setId(servSetting.getId());
      resourceSetting.setUniqueID(offeredResource.getUniqueID() + "_set_" + servSetting.getId());
      resourceSetting.setCanBePublished(false);
      resourceSetting.setUserEditable(writable);
      resourceSetting.setUserExposed(true);
      resourceSetting.setReadable(readable);
      resourceSetting.setWritable(writable);
      resourceSetting.setOptional(isOptional);
      resourceSetting.setImplServiceSetting(servSetting);
      offeredResource.getResourceSettings().add(resourceSetting);

      log("ResourceSettings = OK!");
    }
  }
  private void CreateOfferedService_Resource_Contract(
      String serviceName, Site partnerSite, Node resNode, Boolean createResource) {

    String resourceName = xmlutl.getNodeValueFromObject(resNode, "@component_name");
    log("resourceName : " + resourceName);
    String resourceSpecID = xmlutl.getNodeValueFromObject(resNode, "@component_id");

    if (resourceName.equals("")) {
      resourceName = xmlutl.getNodeValueFromObject(resNode, "hostname/text()");
    }

    //		NodeList resourceSpecNodes = xmlutl.getNodeListFromObject( resourceSpecDocument,
    // "//resourceSpec [@id="+resourceSpecID+"]");
    String offeredServiceName = serviceName;

    log("offeredService offeredServiceName: " + offeredServiceName);
    String offeredServiceDescr = "sfa " + offeredServiceName;
    //		//add back these for the service settings
    //		String configParamCompositeId = xmlutl.getNodeValueFromObject(resourceSpecNodes.item(0),
    // "configurationParameters/@id");
    //		log("configParamCompositeId offServ="+offeredServiceName+", configParamCompositeId
    // ="+configParamCompositeId);
    //
    //		//before creating the service, check if exists
    Boolean newServiceCreated = false;

    //		OfferedService offService = FindOfferedServiceFromID(  resourceSpecID );
    //		if (offService==null)
    OfferedService offService = FindOfferedServiceFromName(offeredServiceName);

    if (offService == null) {
      offService = ServicesFactory.eINSTANCE.createOfferedService();
      offService.setId(0); // not used in SFA?!
      //			offService.setUniqueID("os"+Integer.parseInt(resourceSpecID));
      offService.setUniqueID("os" + offeredServiceName);
      offService.setName(offeredServiceName);

      // offService.setDefaultValue();
      offService.setDescription(offeredServiceDescr);
      log("offeredService offeredServiceDescr: " + offeredServiceDescr);
      broker.getOfferedServices().add(offService);
      newServiceCreated = true;
    }

    // IF <configParamType>reference</configParamType> can be assigned

    // add the service as offered Resource also of Partner...a Contract must be also created here!
    OfferedResource offeredResource = null;
    if (createResource) {
      offeredResource = ResourcesFactory.eINSTANCE.createOfferedResource();
      partnerSite.getOfferedResourcesList().add(offeredResource);
      offeredResource.setBelongsToSite(partnerSite);
      offeredResource.setId(0); // not used in SFA?!
      offeredResource.setUniqueID(resourceName);
      //			String prefix="";
      //			if ((partnerSite.getPtm() != null) && (partnerSite.getPtm().getName() != null))
      //				prefix = partnerSite.getPtm().getName();
      offeredResource.setName(
          resourceName); // in SFA seems node names are unique//Will replace . with _
      offeredResource.setDescription(offeredServiceDescr);
      offeredResource.setImplOfferedService(offService);
      offeredResource.setMultitonMaxOccur(
          1); // we have atleast one of these resources to be reserved

      int prefix = partnerSite.getBelongsToProvider().getId();

      offeredResource.setGeocoords("-170, 50");

      CreateResourceContract(offeredResource);
    }

    CreateSetting(
        "hostname",
        "defvalHostNameSet",
        "node hostname",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        false,
        true);
    CreateSetting(
        "vsys",
        "",
        "request access to a vsys script on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);
    CreateSetting(
        "initscript",
        "",
        "initscript on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);
    CreateSetting(
        "vsys_vnet",
        "",
        "initscript on the selected node",
        newServiceCreated,
        offService,
        offeredResource,
        true,
        true,
        true);

    // Finally add service to the general ServiceCategories
    generalTaxonomy.getTaxonomies().get(0).getHasServices().add(offService);
  }