public void execute(
      IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
      throws CoreException {
    if (monitor != null) {
      monitor.beginTask("", 1); // $NON-NLS-1$
    }

    try {
      IDataModel model = (IDataModel) config;

      // Associate with an EAR, if necessary.

      final String earProjectName =
          (String) model.getProperty(IJ2EEModuleFacetInstallDataModelProperties.EAR_PROJECT_NAME);
      if (model.getBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.ADD_TO_EAR)) {
        if (earProjectName != null && !earProjectName.equals("")) { // $NON-NLS-1$

          String ver = fv.getVersionString();
          String j2eeVersionText =
              J2EEVersionUtil.convertVersionIntToString(
                  J2EEVersionUtil.convertConnectorVersionStringToJ2EEVersionID(ver));

          final String moduleURI =
              model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.MODULE_URI);

          final IFacetedProjectWorkingCopy fpjwc =
              (IFacetedProjectWorkingCopy) model.getProperty(FACETED_PROJECT_WORKING_COPY);

          installAndAddModuletoEAR(
              j2eeVersionText,
              earProjectName,
              fpjwc.getPrimaryRuntime(),
              project,
              moduleURI,
              monitor);
        }
      }

      if (monitor != null) {
        monitor.worked(1);
      }
    } finally {
      if (monitor != null) {
        monitor.done();
      }
    }
  }
  public void execute(
      final IProject project,
      final IProjectFacetVersion fv,
      final Object cfg,
      final IProgressMonitor monitor)
      throws CoreException {
    if (monitor != null) {
      monitor.beginTask("", 1); // $NON-NLS-1$
    }

    try {
      IDataModel model = (IDataModel) cfg;

      if (monitor != null) {
        monitor.worked(1);
      }
      // Add WTP natures.

      WtpUtils.addNaturestoEAR(project);

      final IVirtualComponent c = ComponentCore.createComponent(project, false);
      c.create(0, null);

      final IVirtualFolder earroot = c.getRootFolder();
      Path contentDirPath =
          new Path(model.getStringProperty(IEarFacetInstallDataModelProperties.CONTENT_DIR));
      earroot.createLink(contentDirPath, 0, null);
      J2EEModuleVirtualComponent.setDefaultDeploymentDescriptorFolder(
          earroot, contentDirPath, null);

      try {
        ((IDataModelOperation) model.getProperty(FacetDataModelProvider.NOTIFICATION_OPERATION))
            .execute(monitor, null);
      } catch (ExecutionException e) {
        J2EEPlugin.logError(e);
      }

      if (fv == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_70
          || fv == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_60
          || fv == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_50) {
        if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) {
          // Create the deployment descriptor (application.xml) if one doesn't exist
          IFile appXmlFile =
              earroot.getUnderlyingFolder().getFile(new Path(J2EEConstants.APPLICATION_DD_URI));
          if (!appXmlFile.exists()) {
            try {
              if (!appXmlFile.getParent().exists()
                  && (appXmlFile.getParent().getType() == IResource.FOLDER)) {
                ((IFolder) appXmlFile.getParent()).create(true, true, monitor);
              }
              String appXmlContents = null;
              if (fv == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_70) {
                appXmlContents =
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application id=\"Application_ID\" version=\"7\" xmlns=\"http://xmlns.jcp.org/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd\">\n <display-name>"
                        + XMLWriter.getEscaped(project.getName())
                        + "</display-name> \n </application> "; //$NON-NLS-1$ //$NON-NLS-2$
              } else if (fv == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_60) {
                appXmlContents =
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application id=\"Application_ID\" version=\"6\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd\">\n <display-name>"
                        + XMLWriter.getEscaped(project.getName())
                        + "</display-name> \n </application> "; //$NON-NLS-1$ //$NON-NLS-2$
              } else {
                appXmlContents =
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application id=\"Application_ID\" version=\"5\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd\">\n <display-name>"
                        + XMLWriter.getEscaped(project.getName())
                        + "</display-name> \n </application> "; //$NON-NLS-1$ //$NON-NLS-2$
              }
              appXmlFile.create(
                  new ByteArrayInputStream(appXmlContents.getBytes("UTF-8")),
                  true,
                  monitor); //$NON-NLS-1$
            } catch (UnsupportedEncodingException e) {
              J2EEPlugin.logError(e);
            }
          }
        }
      } else {
        if (!earroot.getFile(J2EEConstants.APPLICATION_DD_URI).exists()) {
          String ver = model.getStringProperty(IFacetDataModelProperties.FACET_VERSION_STR);
          int nVer = J2EEVersionUtil.convertVersionStringToInt(ver);
          EARArtifactEdit.createDeploymentDescriptor(project, nVer);
        }
      }
    } finally {
      if (monitor != null) {
        monitor.done();
      }
    }
  }