@Override
  protected Layer doCreateFromCapabilities(OGCCapabilities caps, AVList params) {
    String serviceName = caps.getServiceInformation().getServiceName();
    if (serviceName == null
        || !(serviceName.equalsIgnoreCase(OGCConstants.WMS_SERVICE_NAME)
            || serviceName.equalsIgnoreCase("WMS"))) {
      String message =
          Logging.getMessage("WMS.NotWMSService", serviceName != null ? serviceName : "null");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    if (params == null) params = new AVListImpl();

    if (params.getStringValue(AVKey.LAYER_NAMES) == null) {
      // Use the first named layer since no other guidance given
      List<WMSLayerCapabilities> namedLayers = ((WMSCapabilities) caps).getNamedLayers();

      if (namedLayers == null || namedLayers.size() == 0 || namedLayers.get(0) == null) {
        String message = Logging.getMessage("WMS.NoLayersFound");
        Logging.logger().severe(message);
        throw new IllegalStateException(message);
      }

      params.setValue(AVKey.LAYER_NAMES, namedLayers.get(0).getName());
    }

    return new WMSTiledImageLayer((WMSCapabilities) caps, params);
  }
  /**
   * Returns all named layers in the capabilities document.
   *
   * @return an unordered list of the document's named layers.
   */
  public List<WMSLayerCapabilities> getNamedLayers() {
    if (this.getCapabilityInformation() == null
        || this.getCapabilityInformation().getLayerCapabilities() == null) return null;

    List<WMSLayerCapabilities> namedLayers = new ArrayList<WMSLayerCapabilities>();

    for (WMSLayerCapabilities layer : this.getCapabilityInformation().getLayerCapabilities()) {
      namedLayers.addAll(layer.getNamedLayers());
    }

    return namedLayers;
  }