/*
   * (non-Javadoc)
   * @see com.ebmwebsourcing.petals.services.explorer.sources.EndpointSource
   * #getWsdlContainerLocation(com.ebmwebsourcing.petals.services.explorer.model.ServiceUnitBean)
   */
  @Override
  public String getWsdlContainerLocation(ServiceUnitBean suBean) {

    String jbiXmlLocation = suBean.getJbiXmlLocation();
    if (jbiXmlLocation == null) return "";

    // Case simple project: the WSDL is in the resources folder
    File f = new File(jbiXmlLocation).getParentFile();
    if ("META-INF".equals(f.getName()))
      return new File(f.getParentFile(), "resources").getAbsolutePath();

    // Case Maven project: the WSDL is in the same folder
    return f.getAbsolutePath();
  }
  /*
   * (non-Javadoc)
   * @see com.ebmwebsourcing.petals.services.explorer.sources.EndpointSource
   * #refreshServiceUnits(org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  protected Collection<ServiceUnitBean> refreshServiceUnits(IProgressMonitor monitor) {

    if (monitor == null) monitor = new NullProgressMonitor();

    List<ServiceUnitBean> suBeans = new ArrayList<ServiceUnitBean>();
    for (File projectFile : this.directory.listFiles()) {

      if (!projectFile.isDirectory()) continue;

      // Get the end-points
      for (File jbiXmlFile : getAllJbiXmlFile(projectFile)) {
        try {
          monitor.worked(1);
          Jbi jbi = JbiXmlUtils.getJbiXmlModel(jbiXmlFile);
          if (jbi.getServices() != null) {

            ServiceUnitBean suBean = new ServiceUnitBean();
            suBean.setSource(this);
            suBean.setJbiXmlLocation(jbi.eResource().getURI().toFileString());
            suBean.setServiceUnitName(projectFile.getName());
            suBean.setComponentName(getComponentId(jbiXmlFile));

            getEndpointBeans(jbi, suBean);
            if (suBean.getEndpoints().size() > 0) suBeans.add(suBean);
          }

        } catch (InvalidJbiXmlException e1) {
          PetalsServicesPlugin.log(
              e1, IStatus.WARNING, "Invalid jbi.xml located at " + jbiXmlFile.getAbsolutePath());
        }
      }
    }

    return suBeans;
  }