/**
   * Creates a socket-binding if it doesn't already exists.
   *
   * @param port port of the connector, which will be converted to socket-binding
   * @param name name of the protocol which is used by connector (ajp/http/https)
   * @return name of the socket-binding so it cant be referenced in connector
   * @throws NodeGenerationException if createDefaultSocket fails to unmarshall socket-bindings
   */
  private static String createSocketBinding(
      String port, String name, ServerMigratorResource resource) throws NodeGenerationException {
    // TODO: Refactor and change the logic MIGR-71
    for (SocketBindingBean sb : resource.getSocketTemp()) {
      if (sb.getSocketPort().equals(port)) {
        return sb.getSocketName();
      }
      if (sb.getSocketName().equals(name)) {
        name = "createdSocket";
      }
    }

    SocketBindingBean socketBinding = new SocketBindingBean();

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      if (sb.getSocketPort().equals(port)) {
        return sb.getSocketName();
      }
    }

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      if (sb.getSocketName().equals(name)) {
        name = name.concat(resource.getRandomSocket().toString());
      }
    }

    socketBinding.setSocketName(name);
    socketBinding.setSocketPort(port);

    resource.getSocketBindings().add(socketBinding);

    return name;
  }
  @Override
  public void createActions(MigrationContext ctx) throws MigrationException {
    ServerMigratorResource resource = new ServerMigratorResource();

    try {
      createDefaultSockets(ctx, resource);
    } catch (LoadMigrationException e) {
      throw new MigrationException("Migration of web server failed: " + e.getMessage(), e);
    }

    for (IConfigFragment fragment :
        ctx.getMigrationData().get(ServerMigrator.class).getConfigFragments()) {
      String what = null;
      try {
        if (fragment instanceof ConnectorAS5Bean) {
          what = "connector";
          ctx.getActions()
              .addAll(
                  createConnectorCliAction(
                      migrateConnector((ConnectorAS5Bean) fragment, resource, ctx)));
        } else if (fragment instanceof EngineBean) {
          what = "Engine (virtual-server)";
          ctx.getActions().add(createVirtualServerCliAction(migrateEngine((EngineBean) fragment)));
        } else
          throw new MigrationException(
              "Config fragment unrecognized by "
                  + this.getClass().getSimpleName()
                  + ": "
                  + fragment);
      } catch (CliScriptException | NodeGenerationException e) {
        throw new MigrationException("Migration of the " + what + " failed: " + e.getMessage(), e);
      }
    }

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      try {
        ctx.getActions().add(createSocketBindingCliAction(sb));
      } catch (CliScriptException e) {
        throw new MigrationException(
            "Creation of the new socket-binding failed: " + e.getMessage(), e);
      }
    }
  }