/**
   * registerService
   *
   * @param wsigService
   * @throws Exception
   */
  private void registerService(WSIGService wsigService) throws Exception {

    if (null != wsigService) {
      log.info("Create new wsig service: " + wsigService.toString());

      // Register wsigService into UDDI
      if (uddiManager != null) {
        ServiceKey uddiServiceKey = uddiManager.UDDIRegister(wsigService);
        wsigService.setUddiServiceKey(uddiServiceKey);
      }

      // Store wsigService into WSIGStore
      wsigStore.addService(wsigService.getServiceName(), wsigService);
    }
  }
  private synchronized void deregisterAgent(DFAgentDescription dfad) throws Exception {

    log.info("Start wsigs's deregistration from agent: " + dfad.getName());

    WSIGService wsigService;

    AID agentId = dfad.getName();
    for (WSIGService wsigService1 : wsigStore.getServices(agentId)) {
      wsigService = wsigService1;

      // Deregister service
      deregisterService(wsigService);
    }

    log.info("End wsigs's deregistration from agent: " + dfad.getName());
  }
  /** takes down this agent. A configuration used is stored. */
  @Override
  protected void takeDown() {

    // Deregister all service
    try {
      WSIGService wsigService;
      for (WSIGService wsigService1 : wsigStore.getAllServices()) {
        wsigService = wsigService1;
        deregisterService(wsigService);
      }
    } catch (Exception e) {
      log.error("Agent " + getLocalName() + " - Error during service deregistration", e);
    }

    // Deregister WSIG agent
    try {
      DFService.deregister(this, getDefaultDF());
    } catch (Exception e) {
      log.error("Agent " + getLocalName() + " - Error during DF deregistration", e);
    }

    log.info("Agent " + getLocalName() + " - Taken down now");
  }
  private void deregisterService(WSIGService wsigService) throws Exception {

    String serviceName = wsigService.getServiceName();

    log.info("Remove wsig service " + serviceName);

    // DeRegister wsigService from UDDI
    try {
      if (uddiManager != null) {
        uddiManager.UDDIDeregister(wsigService);
      }
    } catch (Exception e) {
      log.warn("Error removing service from UDDI", e);
    }

    // Remove wsigService from WSIGStore
    wsigStore.removeService(serviceName);

    // Delete wsdl
    String filename = WSDLGeneratorUtils.getWSDLFilename(serviceName);
    log.info("Delete wsdl file " + filename);
    WSDLGeneratorUtils.deleteWSDL(filename);
  }
  private WSIGService createWSIGService(AID aid, ServiceDescription sd) throws Exception {

    // Get service prefix & name
    String servicePrefix = getServicePrefix(sd);
    String serviceName = servicePrefix + sd.getName();

    // Verify if is a wsig service
    if (!isWSIGService(sd)) {
      log.info("Service " + serviceName + " discarded (no wsig service)");
      return null;
    }

    // Verify if the service is already registered
    if (wsigStore.isServicePresent(serviceName)) {
      log.info("Service " + serviceName + " of agent " + aid.getName() + " is already registered");
      return null;
    }

    // Get ontology
    // FIX-ME elaborate only first ontology
    String ontoName = null;
    Iterator ontoIt = sd.getAllOntologies();
    if (ontoIt.hasNext()) {
      ontoName = (String) ontoIt.next();
    }
    if (ontoName == null) {
      log.info(
          "Service "
              + serviceName
              + " of agent "
              + aid.getName()
              + " have not ontology registered");
      return null;
    }

    // Create ontology instance
    String ontoClassname = WSIGConfiguration.getInstance().getOntoClassname(ontoName);
    if (ontoClassname == null) {
      log.warn("Ontology " + ontoName + " not present in WSIG configuration file");
      return null;
    }

    Ontology serviceOnto;
    try {
      Class ontoClass = Class.forName(ontoClassname);
      Method getInstanceMethod = ontoClass.getMethod("getInstance");
      serviceOnto = (Ontology) getInstanceMethod.invoke(null);
    } catch (Exception e) {
      log.warn("Ontology class " + ontoClassname + " not present in WSIG classpath", e);
      return null;
    }

    // Register new onto in anget
    getContentManager().registerOntology(serviceOnto);

    // Get mapper class
    Class mapperClass = getMapperClass(sd);

    // Create new WSIGService
    WSIGService wsigService = new WSIGService();
    wsigService.setServiceName(serviceName);
    wsigService.setServicePrefix(servicePrefix);
    wsigService.setAid(aid);
    wsigService.setWsdl(
        new URL(WSIGConfiguration.getInstance().getWsdlUri() + "/" + serviceName + ".wsdl"));
    wsigService.setOnto(serviceOnto);
    wsigService.setMapperClass(mapperClass);

    // Create wsdl
    SDToWSDL.createWSDLFromSD(this, sd, wsigService);

    return wsigService;
  }