public static WindowsAzureRole configureKeyFeatures(
      WindowsAzureRole role, Map<String, Boolean> ftrMap) throws Exception {
    try {
      // Enable Key features
      // Session Affinity
      if (ftrMap.get("ssnAffChecked")) {
        WindowsAzureEndpoint httpEndPt = role.getEndpoint(httpEp);
        if (httpEndPt == null) {
          /*
           * server is not enabled.
           * hence create new endpoint
           * for session affinity.
           */
          if (role.isValidEndpoint(
              httpEp, WindowsAzureEndpointType.Input, HTTP_PRV_PORT, HTTP_PORT)) {
            httpEndPt =
                role.addEndpoint(httpEp, WindowsAzureEndpointType.Input, HTTP_PRV_PORT, HTTP_PORT);
          }
        }
        if (httpEndPt != null) {
          role.setSessionAffinityInputEndpoint(httpEndPt);
        }
      }

      // Caching
      if (ftrMap.get("cacheChecked")) {
        role.setCacheMemoryPercent(CACH_DFLTVAL);
        role.setCacheStorageAccountName(dashAuto);
      }

      // Remote Debugging
      if (ftrMap.get("debugChecked")) {
        if (role.isValidEndpoint(dbgEp, WindowsAzureEndpointType.Input, DEBUG_PORT, DEBUG_PORT)) {
          WindowsAzureEndpoint dbgEndPt =
              role.addEndpoint(dbgEp, WindowsAzureEndpointType.Input, DEBUG_PORT, DEBUG_PORT);
          if (dbgEndPt != null) {
            role.setDebuggingEndpoint(dbgEndPt);
            role.setStartSuspended(false);
          }
        }
      }

    } catch (Exception e) {
      throw new Exception(e.getMessage(), e);
    }
    return role;
  }
 @Override
 protected void okPressed() {
   boolean okToProceed = true;
   try {
     if (isEditEndpt) {
       // if its an edit an endpoint scenario
       okToProceed = editEndpt();
     } else {
       // for add an endpoint scenario
       boolean isValid = windowsAzureRole.isAvailableEndpointName(txtName.getText());
       if (isValid) {
         boolean isValidendpoint =
             windowsAzureRole.isValidEndpoint(
                 txtName.getText(),
                 WindowsAzureEndpointType.valueOf(comboType.getText()),
                 txtPrivatePort.getText(),
                 txtPublicPort.getText());
         if (isValidendpoint) {
           windowsAzureRole.addEndpoint(
               txtName.getText(),
               WindowsAzureEndpointType.valueOf(comboType.getText()),
               txtPrivatePort.getText(),
               txtPublicPort.getText());
         } else {
           errorTitle = Messages.dlgInvldPort;
           errorMessage = Messages.dlgPortInUse;
           MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage);
           okToProceed = false;
         }
       } else {
         errorTitle = Messages.dlgInvdEdPtName1;
         errorMessage = Messages.dlgInvdEdPtName2;
         MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage);
         okToProceed = false;
       }
     }
   } catch (WindowsAzureInvalidProjectOperationException e) {
     errorTitle = Messages.rolsErr;
     errorMessage = Messages.adRolErrMsgBox1 + Messages.adRolErrMsgBox2;
     MessageUtil.displayErrorDialog(this.getShell(), errorTitle, errorMessage);
     Activator.getDefault().log(errorMessage, e);
   }
   if (okToProceed) {
     super.okPressed();
   }
 }
 public void doOKAction() {
   try {
     if (waEndpt != null) {
       // Edit an endpoint scenario
       if (!editEndpt()) {
         return;
       }
     } else {
       // Add an endpoint scenario
       // validate name
       WindowsAzureEndpointType endPtType = (WindowsAzureEndpointType) comboType.getSelectedItem();
       String endPtName = txtName.getText().trim();
       /*
        * Check endpoint name contain
        * alphanumeric and underscore characters only.
        * Starts with alphabet.
        */
       if (WAEclipseHelperMethods.isAlphaNumericUnderscore(endPtName)) {
         boolean isValidName = waRole.isAvailableEndpointName(endPtName, endPtType);
         /*
          * Check already used endpoint name is given.
          */
         if (isValidName) {
           if (endPtType.equals(WindowsAzureEndpointType.InstanceInput)
               || endPtType.equals(WindowsAzureEndpointType.Internal)) {
             if (WAEndpointDialogUtilMethods.isDashPresent(
                 endPtType,
                 txtPrivatePort.getText(),
                 txtPrivatePortRangeEnd.getText(),
                 txtPublicPort.getText(),
                 txtPublicPortRangeEnd.getText())) {
               PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("portRangeErrMsg"));
               return;
             }
           }
           // Check for valid range 1 to 65535
           if (WAEndpointDialogUtilMethods.isValidPortRange(
               endPtType,
               txtPrivatePort.getText(),
               txtPrivatePortRangeEnd.getText(),
               txtPublicPort.getText(),
               txtPublicPortRangeEnd.getText())) {
             // Combine port range
             String publicPort =
                 WAEndpointDialogUtilMethods.combinePublicPortRange(
                     txtPublicPort.getText(),
                     txtPublicPortRangeEnd.getText(),
                     endPtType.toString());
             String privatePort =
                 WAEndpointDialogUtilMethods.combinePrivatePortRange(
                     txtPrivatePort.getText(),
                     txtPrivatePortRangeEnd.getText(),
                     endPtType.toString());
             if (privatePort.equalsIgnoreCase(AUTO)) {
               privatePort = null;
             }
             // Validate and commit endpoint addition
             if (waRole.isValidEndpoint(endPtName, endPtType, privatePort, publicPort)) {
               waRole.addEndpoint(endPtName, endPtType, privatePort, publicPort);
             } else {
               PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("dlgPortInUse"));
               return;
             }
           } else {
             PluginUtil.displayErrorDialog(message("dlgInvldPort"), message("rngErrMsg"));
             return;
           }
         } else {
           PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("dlgInvdEdPtName2"));
           return;
         }
       } else {
         PluginUtil.displayErrorDialog(message("dlgInvdEdPtName1"), message("enPtAlphNuMsg"));
         return;
       }
     }
   } catch (WindowsAzureInvalidProjectOperationException ex) {
     PluginUtil.displayErrorDialogAndLog(
         message("rolsErr"), message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), ex);
     return;
   }
   super.doOKAction();
 }
  public static WindowsAzureRole configureJDKServer(
      WindowsAzureRole role, Map<String, String> depMap) throws Exception {
    try {
      File templateFile = new File(depMap.get("tempFile"));
      if (!(depMap.get("jdkChecked").equalsIgnoreCase("false")
          && depMap.get("jdkAutoDwnldChecked").equalsIgnoreCase("true"))) {
        // Third party JDK name
        if (depMap.get("jdkThrdPartyChecked").equalsIgnoreCase("true")) {
          String jdkName = depMap.get("jdkName");
          role.setJDKSourcePath(depMap.get("jdkLoc"), templateFile, jdkName);
          role.setJDKCloudName(jdkName);
        } else {
          role.setJDKSourcePath(depMap.get("jdkLoc"), templateFile, "");
        }
        // JDK download group
        // By default auto upload will be selected.
        String jdkTabUrl = depMap.get("jdkUrl");
        if (depMap.get("jdkAutoDwnldChecked").equalsIgnoreCase("true")
            || depMap.get("jdkThrdPartyChecked").equalsIgnoreCase("true")) {
          if (jdkTabUrl.equalsIgnoreCase(AUTO_TXT)) {
            jdkTabUrl = auto;
          }
          role.setJDKCloudUploadMode(WARoleComponentCloudUploadMode.auto);
        }
        role.setJDKCloudURL(jdkTabUrl);
        role.setJDKCloudKey(depMap.get("jdkKey"));
        /*
         * By default package type is local,
         * hence store JAVA_HOME for cloud.
         */
        role.setJDKCloudHome(depMap.get("javaHome"));
      }

      // Server
      if (depMap.get("serChecked").equalsIgnoreCase("true")) {
        String srvName = depMap.get("servername");
        if (!srvName.isEmpty()) {
          String srvPriPort = WindowsAzureProjectManager.getHttpPort(srvName, templateFile);
          if (role.isValidEndpoint(httpEp, WindowsAzureEndpointType.Input, srvPriPort, HTTP_PORT)) {
            role.addEndpoint(httpEp, WindowsAzureEndpointType.Input, srvPriPort, HTTP_PORT);
          }

          role.setServer(srvName, depMap.get("serLoc"), templateFile);

          if (depMap.get("srvThrdPartyChecked").equalsIgnoreCase("true")) {
            String altSrcUrl = depMap.get("srvThrdAltSrc");
            if (!altSrcUrl.isEmpty()) {
              role.setServerCldAltSrc(altSrcUrl);
            }
            String thrdName = depMap.get("srvThrdPartyName");
            if (!thrdName.isEmpty()) {
              role.setServerCloudName(thrdName);
            }
            role.setServerCloudValue(depMap.get("srvHome"));
          }

          String srvTabUrl = depMap.get("srvUrl");
          if (depMap.get("srvAutoDwnldChecked").equalsIgnoreCase("true")
              || depMap.get("srvThrdPartyChecked").equalsIgnoreCase("true")) {
            if (srvTabUrl.equalsIgnoreCase(AUTO_TXT)) {
              srvTabUrl = auto;
            }
            role.setServerCloudUploadMode(WARoleComponentCloudUploadMode.auto);
          }
          role.setServerCloudURL(srvTabUrl);
          role.setServerCloudKey(depMap.get("srvKey"));
          role.setServerCloudHome(depMap.get("srvHome"));
        }
      }
    } catch (Exception e) {
      throw new Exception(e.getMessage(), e);
    }
    return role;
  }