class WlsDynamicServerConfig extends WlsServerConfig {

  static WlsDynamicServerConfig create(
      String name,
      int index,
      String clusterName,
      String domainName,
      boolean calculatedListenPorts,
      WlsServerConfig serverTemplate) {
    Integer listenPort = serverTemplate.getListenPort();
    Integer sslListenPort = serverTemplate.getSslListenPort();
    List<NetworkAccessPoint> networkAccessPoints = new ArrayList<>();
    if (serverTemplate.getNetworkAccessPoints() != null) {
      for (NetworkAccessPoint networkAccessPoint : serverTemplate.getNetworkAccessPoints()) {
        Integer networkAccessPointListenPort = networkAccessPoint.getListenPort();
        if (calculatedListenPorts) {
          networkAccessPointListenPort =
              networkAccessPointListenPort == null
                  ? (DEFAULT_NAP_LISTEN_PORT_RANGE_BASE + index)
                  : networkAccessPointListenPort + index;
        }
        networkAccessPoints.add(
            new NetworkAccessPoint(
                networkAccessPoint.getName(),
                networkAccessPoint.getProtocol(),
                networkAccessPointListenPort,
                networkAccessPoint.getPublicPort()));
      }
    }
    // calculate listen ports if configured to do so
    if (calculatedListenPorts) {
      listenPort =
          (listenPort == null) ? (DEFAULT_LISTEN_PORT_RANGE_BASE + index) : (listenPort + index);
      sslListenPort =
          (sslListenPort == null)
              ? (DEFAULT_SSL_LISTEN_PORT_RANGE_BASE + index)
              : (sslListenPort + index);
    }
    MacroSubstitutor macroSubstitutor =
        new MacroSubstitutor(index, name, clusterName, domainName, serverTemplate.getMachineName());
    return new WlsDynamicServerConfig(
        name,
        listenPort,
        macroSubstitutor.substituteMacro(serverTemplate.getListenAddress()),
        sslListenPort,
        macroSubstitutor.substituteMacro(serverTemplate.getMachineName()),
        serverTemplate.getAdminPort(),
        networkAccessPoints);
  }

  private  WlsDynamicServerConfig(
      String name,
      Integer listenPort,
      String listenAddress,
      Integer sslListenPort,
      String machineName,
      Integer adminPort,
      List<NetworkAccessPoint> networkAccessPoints);

}