Example #1
0
  public static void saveCasa(JbiProject project) {
    // System.out.println("CasaHelper.saveCasa()  (" + Thread.currentThread().getName()  + ")");

    FileObject casaFO = getCasaFileObject(project, false);
    if (casaFO != null) {
      try {
        DataObject casaDO = DataObject.find(casaFO);

        SaveCookie saveCookie = casaDO.getCookie(SaveCookie.class);
        if (saveCookie != null) {
          try {
            saveCookie.save();
          } catch (IOException ex) {
            ex.printStackTrace();
          }
        }
      } catch (DataObjectNotFoundException ex) {
        ex.printStackTrace();
      }
    }
  }
  public static synchronized ServiceGeneratorResult generate(final E2EDataObject dataObject) {
    if (dataObject.getServerProject() == null) {
      final NotifyDescriptor.Message dd =
          new NotifyDescriptor.Message(
              NbBundle.getMessage(
                  E2EDataObject.class,
                  "ERR_ServerProjectNotOpened", // NOI18N
                  dataObject.getConfiguration().getServerConfigutation().getProjectName()));
      DialogDisplayer.getDefault().notify(dd);
      if (Util.openProject(dataObject.getConfiguration().getServerConfigutation().getProjectPath())
          == null) {
        // It is OK don't notify user here. All notifications
        // are already inside <code>openProject</code> method
        return null;
      }
    }

    // Call save before generate
    final SaveCookie saveCookie = dataObject.getCookie(SaveCookie.class);
    if (saveCookie != null) {
      try {
        saveCookie.save();
      } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
      }
    }

    // Get configuration
    final Configuration config = dataObject.getConfiguration();
    if (config == null) {
      final NotifyDescriptor.Message dd =
          new NotifyDescriptor.Message(
              NbBundle.getMessage(E2EDataObject.class, "ERR_ConfigurationFileCorrupted")); // NOI18N
      DialogDisplayer.getDefault().notify(dd);
      return null;
    }

    if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
      final FileObject fo =
          dataObject
              .getServerProject()
              .getProjectDirectory()
              .getFileObject("build/generated/wsimport/"); // NOI18N
      if (fo == null) {
        DialogDisplayer.getDefault()
            .notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(
                        ConnectionGenerator.class, "MSG_WebProjectNotBuilt"))); // NOI18N
        return null;
      }
    }

    /*
     * All failures notifications was done via dialog windows.
     * Starting now logging will be done via  OutputLogger class.
     */

    final ProgressHandle ph =
        ProgressHandleFactory.createHandle(
            NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingJavonBridge"), // NOI18N
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                OutputLogger.getInstance().open();
              }
            });
    ph.start();
    ph.switchToIndeterminate();
    String message =
        NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingProxyStubs"); // NOI18N
    ph.progress(message);
    OutputLogger.getInstance().log(message);
    // FIXME: check for proper type
    //        config.getServices();
    //
    if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
      ph.progress(NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingProxyStubs"));
      final ProxyGenerator pg = new ProxyGenerator(dataObject);
      final String className = pg.generate();
      if (className == null) {
        ph.finish();
        StatusDisplayer.getDefault()
            .setStatusText(NbBundle.getMessage(ConnectionGenerator.class, "MSG_Failure")); // NOI18N
        return null;
      }
      config.getServices().get(0).getData().get(0).setProxyClassType(className);
    }
    //        JavonOutput[] outputs;
    //        Type type = null;
    //
    //        final InputOutput io = IOProvider.getDefault().getIO(
    //                NbBundle.getMessage( ConnectionGenerator.class, "LBL_JavonTab" ) // NOI18N
    //                , true);
    //        final OutputWriter ow = io.getOut();
    try {
      String scanning =
          NbBundle.getMessage(ConnectionGenerator.class, "MSG_ScanningDataStructures"); // NOI18N
      ph.progress(scanning);
      OutputLogger.getInstance().log(scanning);

      final JavonMappingImpl mapping = dataObject.getMapping();
      if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
        mapping.setProperty("serviceType", "WSDL");
      } else {
        mapping.setProperty("serviceType", "CLASS");
      }
      //            //ph.progress(70);
      String creating =
          NbBundle.getMessage(ConnectionGenerator.class, "MSG_CreatingJavaFiles"); // NOI18N
      ph.progress(creating);
      OutputLogger.getInstance().log(creating);
      //
      Javon javon = new Javon(mapping);
      if (javon.generate(ph)) {
        StatusDisplayer.getDefault()
            .setStatusText(
                NbBundle.getMessage(ConnectionGenerator.class, "MSG_SuccessGenerated")); // NOI18N
        OutputLogger.getInstance()
            .log(NbBundle.getMessage(ConnectionGenerator.class, "TXT_GenerationSuccess")); // NOI18N
      } else {
        StatusDisplayer.getDefault()
            .setStatusText(NbBundle.getMessage(ConnectionGenerator.class, "MSG_Failure")); // NOI18N
        OutputLogger.getInstance()
            .log(
                NbBundle.getMessage(
                    ConnectionGenerator.class, "TXT_GenerationUnsuccess")); // NOI18N
      }
      //            Streams.setOut(ow);
      //            Streams.setErr(ow);
      //            outputs = new Main().run( mapping, "" ); // NOI18N
      //
      //            for( int j = 0; j < outputs.length; j++ ) {
      //                final String list[] = outputs[j].getCreatedFiles();
      //                for( int i = 0; i < list.length; i++ ) {
      //                    final File f = new File(list[i]);
      //                    final FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f));
      //                    fo.refresh();
      //                    JavaModel.getResource(fo);
      //                }
      //            }
      //            //add servlet to container
      //            Util.addServletToWebProject(dataObject.getServerProject(),
      // dataObject.getConfiguration().getServerConfigutation().getClassDescriptor().getType());
      //
      //            final ClassDescriptor clientClassDescriptor =
      // dataObject.getConfiguration().getClientConfiguration().getClassDescriptor();
      //            final Sources s = ProjectUtils.getSources(dataObject.getClientProject());
      //            final SourceGroup sourceGroup = Util.getPreselectedGroup(
      //                    s.getSourceGroups( JavaProjectConstants.SOURCES_TYPE_JAVA ),
      //                    clientClassDescriptor.getLocation());
      //            final FileObject srcDirectory = sourceGroup.getRootFolder();
      //            final ClassPath cp = ClassPath.getClassPath(srcDirectory,ClassPath.SOURCE);
      //            JavaModel.getJavaRepository().beginTrans(false);
      //            try {
      //                JavaModel.setClassPath(cp);
      //                type =
      // JavaModel.getDefaultExtent().getType().resolve(clientClassDescriptor.getType());
      //            } catch (Exception e){
      //                ErrorManager.getDefault().notify(e);
      //            } finally {
      //                JavaModel.getJavaRepository().endTrans();
      //            }
    } finally {
      ph.finish();
      OutputLogger.getInstance().close();
    }
    //        if (type != null){
    //            //ow.println("Run / Redeploy Web Project to get changes reflected!");
    //            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
    // ConnectionGenerator.class, "MSG_SuccessGenerated" )); // NOI18N
    //        } else {
    //            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
    // ConnectionGenerator.class, "MSG_Failure" )); // NOI18N
    //            return null;
    //        }
    //        final JavaClass resultClass = (JavaClass)type;
    //        final List<Feature> features = resultClass.getFeatures();
    //        final List<Method> methods = new ArrayList<Method>();
    //        for ( final Feature elem : features ) {
    //            if (elem instanceof Method){
    //                final Method m = (Method)elem;
    //                if ("getGroupedResults".equals(m.getName())){ //NOI18N //not supported
    //                    continue;
    //                }
    //                if (m.getName().endsWith("Grouped")){ //NOI18N //not supported
    //                    continue;
    //                }
    //                if ( Modifier.isPublic(m.getModifiers()) ){
    //                    methods.add(m);
    //                }
    //            }
    //        }
    //        return new ServiceGeneratorResult(resultClass,
    //                methods.toArray(new Method[methods.size()]),
    //                Util.getServerURL(dataObject.getServerProject(),
    // dataObject.getConfiguration()));
    return null;
  }