public void saveRootGroup() {
   try {
     SaasUtil.saveSaasGroup(rootGroup, new File(WEBSVC_HOME, SERVICE_GROUP_XML));
   } catch (Exception ex) {
     Exceptions.printStackTrace(ex);
   }
 }
 private WadlSaas createWadlService(SaasGroup parent, String url, String packageName) {
   initRootGroup();
   String displayName = SaasUtil.getWadlServiceDirName(url);
   WadlSaas service = new WadlSaas(parent, url, displayName, packageName);
   service.toStateReady(false);
   service.setUserDefined(true);
   parent.addService(service);
   service.save();
   fireChange(PROP_SERVICES, parent, null, service);
   return service;
 }
 private void loadUserDefinedGroups() {
   FileObject input = FileUtil.toFileObject(new File(WEBSVC_HOME, SERVICE_GROUP_XML));
   try {
     if (input != null) {
       rootGroup = SaasUtil.loadSaasGroup(input);
     }
   } catch (Exception e) {
     Exceptions.printStackTrace(e);
   }
   if (rootGroup == null) {
     Group g = new Group();
     g.setName(ROOT_GROUP);
     rootGroup = new SaasGroup((SaasGroup) null, g);
   }
 }
  public Saas createSaasService(SaasGroup parent, String url, String packageName) {
    String saasType = SaasUtil.getSaasType(url);

    if (Saas.NS_WSDL.equals(saasType)) {
      if (WsdlUtil.hasWsdlSupport()) {
        return createWsdlService(parent, url, packageName);
      } else {
        throw new RuntimeException(
            NbBundle.getMessage(SaasServicesModel.class, "MSG_WsdlServiceNotSupported"));
      }
    } else if (Saas.NS_WADL.equals(saasType)) {
      return createWadlService(parent, url, packageName);
    } else {
      throw new RuntimeException(
          NbBundle.getMessage(SaasServicesModel.class, "MSG_UnknownSaasType"));
    }
  }
  private void loadSaasServiceFile(FileObject saasFile, boolean userDefined) {
    try {
      SaasServices ss = SaasUtil.loadSaasServices(saasFile);
      Group g = ss.getSaasMetadata().getGroup();
      SaasGroup parent = rootGroup;

      Saas service = null;
      if (g == null || g.getName() == null || g.getName().trim().length() == 0) {
        service = createService(parent, ss);
        if (service != null) {
          service.setUserDefined(userDefined);
          parent.addService(service);
        }
      } else {
        while (g != null) {
          SaasGroup child = parent.getChildGroup(g.getName());
          if (child == null) {
            child = new SaasGroup(parent, g);
            parent.addChildGroup(child);
          }

          child.setUserDefined(userDefined);

          if (g.getGroup().size() == 0) {
            service = createService(child, ss);
            if (service != null) {
              service.setUserDefined(userDefined);
              child.addService(service);
            }
            break;
          } else {
            // 'group' element part of straight path, has only single child
            g = g.getGroup().get(0);
            parent = child; // march on towards tip
          }
        }
      }
      if (service != null) service.upgrade();
    } catch (Exception ex) {
      Exceptions.printStackTrace(
          Exceptions.attachMessage(ex, "Error loading saas file: " + saasFile.getPath()));
    }
  }