/**
   * Supports WCS 1.0.0
   *
   * <p>uses the WCSCapabilitiesType returned by the GetCapabilities-Operation to produce a
   * Content-object.
   *
   * @param wc
   * @return
   * @throws OXFException
   */
  public Contents mapContents(WCSCapabilitiesType wc) {

    List<CoverageOfferingBriefType> covOffList = wc.getContentMetadata().getCoverageOfferingBrief();

    ArrayList<Dataset> dataIdentificationList = new ArrayList<Dataset>();

    for (CoverageOfferingBriefType covOff : covOffList) {

      // --- create identifier:
      List<JAXBElement> nameList = covOff.getName();
      String identifier = nameList.get(0).getValue().toString();

      // --- create title:
      String title = covOff.getLabel();

      // --- create boundingBox:
      LonLatEnvelopeType lle = covOff.getLonLatEnvelope();

      // directPositionList enth�lt 2 Double-Listen die die Koordinatenwerte f�r die 2 definierenden
      // Punkte der BBox enthalten
      List<DirectPositionType> directPositionList = lle.getPos();

      DirectPositionType dpt0 = directPositionList.get(0);
      DirectPositionType dpt1 = directPositionList.get(1);

      double[] lowerLeft = new double[dpt0.getValue().size()];
      for (int i = 0; i < dpt0.getValue().size(); i++) {
        lowerLeft[i] = dpt0.getValue().get(i);
      }

      double[] upperRight = new double[dpt1.getValue().size()];
      for (int i = 0; i < dpt1.getValue().size(); i++) {
        upperRight[i] = dpt1.getValue().get(i);
      }

      String srsName = covOff.getLonLatEnvelope().getSrsName();

      BoundingBox bBox = new BoundingBox(srsName, lowerLeft, upperRight);

      // --- create srs:
      String[] srsArray = new String[] {lle.getSrsName()};

      // --- create temporalDomain:
      List<TimePositionType> timePosList = lle.getTimePosition();
      List<ITime> timeList = new ArrayList<ITime>();
      if (timePosList != null) {
        for (TimePositionType timePosition : timePosList) {
          ITime time = TimeFactory.createTime(timePosition.getValue().toString());
          timeList.add(time);
        }
      }

      // add Dataset to list:
      Dataset dataID =
          new Dataset(
              title,
              identifier,
              new BoundingBox[] {bBox},
              null,
              srsArray,
              null,
              null,
              null,
              (timeList.isEmpty() ? null : new TemporalValueDomain(timeList)),
              null,
              null);
      dataIdentificationList.add(dataID);
    }

    Contents c = new Contents(dataIdentificationList);

    return c;
  }
  /**
   * Supports WCS 1.0.0:
   *
   * <p>uses the CoverageOfferingDescription returned by the DescribeCoverage-Operation to produce a
   * Content-object.
   *
   * @param w
   * @return
   * @throws OXFException
   * @throws EmptyParameterException
   */
  public Contents mapContents(CoverageDescription cd, OXFThrowableCollection throwCollect) {

    List<CoverageOfferingType> covOffList = cd.getCoverageOffering();

    ArrayList<Dataset> dataIdentificationList = new ArrayList<Dataset>();

    for (CoverageOfferingType covOff : covOffList) {

      // --- create identifier:
      List<JAXBElement> nameList = covOff.getName();
      String identifier = nameList.get(0).getValue().toString();

      // --- create title:
      String title = covOff.getLabel();

      // --- create boundingBox:
      // TODO: fuer die BBox koennte man auch
      // "(SpatialDomainType)covOff.getDomainSet().getContent().get(0).getValue()" nehmen

      ArrayList<BoundingBox> bBoxArrayList = new ArrayList<BoundingBox>();

      List<DirectPositionType> directPositionList = null;
      String srsName = null;

      if (covOff.getLonLatEnvelope() != null) {
        /*
         * WCS 1.0.0 schema comment to 'LonLatEnvelopeBaseType': "For WCS use, LonLatEnvelopeBaseType
         * restricts gml:Envelope to the WGS84 geographic CRS with Longitude preceding Latitude and
         * both using decimal degrees only. If included, height values are third and use metre units."
         */
        LonLatEnvelopeType lle = covOff.getLonLatEnvelope();
        directPositionList = lle.getPos();

        srsName = covOff.getLonLatEnvelope().getSrsName();

        if (srsName == null) {
          srsName = DEFAULT_SRS;
        }
        bBoxArrayList.add(makeBBox(srsName, directPositionList));
      }

      List<JAXBElement> domainSetList = covOff.getDomainSet().getContent();
      JAXBElement firstDomainSet = domainSetList.get(0);

      if (firstDomainSet.getValue() != null) {
        SpatialDomainType spatialDomain = (SpatialDomainType) firstDomainSet.getValue();
        for (JAXBElement jaxvEnvelope : spatialDomain.getEnvelope()) {
          EnvelopeType envelope = (EnvelopeType) jaxvEnvelope.getValue();

          directPositionList = envelope.getPos();

          srsName = envelope.getSrsName();

          bBoxArrayList.add(makeBBox(srsName, directPositionList));
        }
      }

      // --- create timeEnvelope:
      List<JAXBElement> domainSet = covOff.getDomainSet().getContent();

      List<ITime> timeList = new ArrayList<ITime>();

      for (int i = 0; i < domainSet.size(); i++) {
        if (domainSet
            .get(i)
            .getName()
            .toString()
            .equals("{http://www.opengis.net/wcs}temporalDomain")) {

          TimeSequenceType timeSequence = (TimeSequenceType) domainSet.get(i).getValue();
          List<Object> timeObjectList = timeSequence.getTimePositionOrTimePeriod();

          for (Object o : timeObjectList) {
            if (o instanceof TimePositionType) {
              TimePositionType timePosition = (TimePositionType) o;
              try {
                ITime time = TimeFactory.createTime(timePosition.getValue().toString());
                timeList.add(time);
              } catch (IllegalArgumentException e) {
                // catch Time declarations with wrong syntax.
                throwCollect.addThrowable(e);
              }
            } else if (o instanceof TimePeriodType) {
              TimePeriodType timePeriod = (TimePeriodType) o;
              // TODO: ITime time =
              // TimeFactory.createTime(timePeriod.getBeginPosition().getValue().toString()
              // + "/" + timePeriod.getEndPosition().getValue().toString()
              // + "/" + timePeriod.getTimeResolution());
              // temporalDomain.add(time);

            }
          }
        }
      }

      // --- create outputFormat:
      List<String> outputFormats = new ArrayList<String>();
      for (CodeListType clt : covOff.getSupportedFormats().getFormats()) {
        for (String formatString : clt.getValue()) {
          outputFormats.add(formatString);
        }
      }

      String[] outputFormatsArray = new String[outputFormats.size()];
      outputFormats.toArray(outputFormatsArray);

      // --- create availableCRSs:
      List<String> availableCRSs = new ArrayList<String>();
      for (CodeListType clt : covOff.getSupportedCRSs().getNativeCRSs()) {
        for (String crsString : clt.getValue()) {
          if (!availableCRSs.contains(crsString)) {
            availableCRSs.add(crsString);
          }
        }
      }
      for (CodeListType clt : covOff.getSupportedCRSs().getRequestCRSs()) {
        for (String crsString : clt.getValue()) {
          if (!availableCRSs.contains(crsString)) {
            availableCRSs.add(crsString);
          }
        }
      }
      for (CodeListType clt : covOff.getSupportedCRSs().getRequestResponseCRSs()) {
        for (String crsString : clt.getValue()) {
          if (!availableCRSs.contains(crsString)) {
            availableCRSs.add(crsString);
          }
        }
      }
      String[] availableCRSsArray = new String[availableCRSs.size()];
      availableCRSs.toArray(availableCRSsArray);

      BoundingBox[] bBoxes = bBoxArrayList.toArray(new BoundingBox[0]);
      // add Dataset to list:
      Dataset dataID =
          new Dataset(
              title,
              identifier,
              bBoxes,
              outputFormatsArray,
              availableCRSsArray,
              null,
              null,
              null,
              (timeList.isEmpty() ? null : new TemporalValueDomain(timeList)),
              null,
              null);
      dataIdentificationList.add(dataID);
    }

    Contents c = new Contents(dataIdentificationList);

    return c;
  }