/**
   * Creates a <code>DCPType</code> object from the passed <code>DCPType</code> element.
   * <p>
   * NOTE: Currently the <code>OnlineResources</code> included in the <code>DCPType</code> are
   * just stored as simple <code>URLs</code> (not as <code>OnLineResource</code> instances)!
   * <p>
   * NOTE: In an <code>OGCStandardCapabilitiesDocument</code> the <code>XLinks</code> (the
   * <code>URLs</code>) are stored in separate elements (<code>OnlineResource</code>), in
   * an <code>OGCCommonCapabilitiesDocument</code> they are the
   * <code>Get<code>/<code>Post</code> elements themselves.
   *
   * @param element
   * @param namespaceURI
   * @return created <code>DCPType</code>
   * @throws XMLParsingException
   * @see org.deegree.owscommon.OWSCommonCapabilities
   */
  protected DCPType getDCPType(Element element, URI namespaceURI) throws XMLParsingException {
    try {
      Element elem = XMLTools.getRequiredChildElement("HTTP", namespaceURI, element);
      ElementList el = XMLTools.getChildElements("Get", namespaceURI, elem);

      URL[] get = new URL[el.getLength()];
      for (int i = 0; i < get.length; i++) {
        Element ell = XMLTools.getRequiredChildElement("OnlineResource", namespaceURI, el.item(i));
        String s = XMLTools.getRequiredAttrValue("href", XLNNS, ell);
        get[i] = new URL(s);
      }
      el = XMLTools.getChildElements("Post", namespaceURI, elem);

      URL[] post = new URL[el.getLength()];
      for (int i = 0; i < post.length; i++) {
        Element ell = XMLTools.getRequiredChildElement("OnlineResource", namespaceURI, el.item(i));
        String s = XMLTools.getRequiredAttrValue("href", XLNNS, ell);
        post[i] = new URL(s);
      }
      Protocol protocol = new HTTP(get, post);
      return new DCPType(protocol);
    } catch (MalformedURLException e) {
      throw new XMLParsingException(
          "Couldn't parse DCPType onlineresoure URL about\n" + StringTools.stackTraceToString(e));
    }
  }
 /**
  * Creates an <tt>ExceptionFormat</tt> instance from the passed element.
  *
  * @param element
  * @return the new instance
  */
 protected ExceptionFormat getExceptionFormat(Element element, URI namespaceURI) {
   ElementList el = XMLTools.getChildElements("Format", namespaceURI, element);
   String[] formats = new String[el.getLength()];
   for (int i = 0; i < formats.length; i++) {
     formats[i] = XMLTools.getStringValue(el.item(i));
   }
   return new ExceptionFormat(formats);
 }
  /**
   * parses a CS-W 2.0 transaction request
   *
   * @param id of the TransactionRequest
   * @return a new transaction parsed from the this xml-encoded request.
   * @throws XMLParsingException
   * @throws OGCWebServiceException
   */
  @Override
  public Transaction parse(String id) throws XMLParsingException, OGCWebServiceException {

    LOG.logDebug("parsing CS-W Transaction request");

    // 'service'-attribute (required, must be CSW)
    String service = XMLTools.getRequiredNodeAsString(getRootElement(), "@service", nsContext);
    if (!service.equals("CSW")) {
      ExceptionCode code = ExceptionCode.INVALIDPARAMETERVALUE;
      throw new InvalidParameterValueException("GetRecordById", "'service' must be 'CSW'", code);
    }

    String version = XMLTools.getRequiredNodeAsString(getRootElement(), "@version", nsContext);
    if (!"2.0.2".equals(version)) {
      throw new OGCWebServiceException(
          "GetRecordByIdDocument_2_0_2",
          Messages.getMessage("CSW_NOT_SUPPORTED_VERSION", "2.0.2", "2.0.2", version),
          ExceptionCode.INVALIDPARAMETERVALUE);
    }
    boolean verbose =
        XMLTools.getNodeAsBoolean(getRootElement(), "./@verboseResponse", nsContext, false);

    List<Operation> ops = new ArrayList<Operation>();

    ElementList el = XMLTools.getChildElements(getRootElement());
    for (int i = 0; i < el.getLength(); i++) {
      Element e = el.item(i);
      // TODO check for qualified name
      if ("Insert".equals(e.getLocalName())) {
        ops.add(parseInsert(e));
      } else if ("Update".equals(e.getLocalName())) {
        ops.add(parseUpdate(e));
      } else if ("Delete".equals(e.getLocalName())) {
        ops.add(parseDelete(e));
      }
    }

    // in the future the vendorSpecificParameters
    Map<String, String> vendorSpecificParameters = parseDRMParams(this.getRootElement());

    return new Transaction(version, id, vendorSpecificParameters, ops, verbose);
  }
  /**
   * Creates a class representation of the <code>deegreeParams</code>- section.
   *
   * @return
   * @throws InvalidConfigurationException
   */
  public CatalogueDeegreeParams getDeegreeParams() throws InvalidConfigurationException {

    CatalogueDeegreeParams deegreeParams = null;

    try {
      Node root = this.getRootElement();
      Element element = XMLTools.getRequiredChildElement("deegreeParams", DEEGREECSW, root);

      // 'deegreecsw:DefaultOnlineResource'-element (mandatory)
      OnlineResource defaultOnlineResource =
          parseOnLineResource(
              XMLTools.getRequiredChildElement("DefaultOnlineResource", DEEGREECSW, element));

      // 'deegreecsw:CacheSize'-element (optional, default: 100)
      int cacheSize = XMLTools.getNodeAsInt(element, "./deegreecsw:CacheSize", nsContext, 100);

      // 'deegreecsw:RequestTimeLimit'-element (optional, default: 2)
      int requestTimeLimit =
          XMLTools.getNodeAsInt(element, "./deegreecsw:RequestTimeLimit", nsContext, 2);

      // 'deegreecsw:Encoding'-element (optional, default: UTF-8)
      String characterSet = XMLTools.getStringValue("Encoding", DEEGREECSW, element, "UTF-8");

      // default output schema used by a catalogue
      String defaultOutputSchema =
          XMLTools.getStringValue("DefaultOutputSchema", DEEGREECSW, element, "OGCCORE");

      // 'deegreecsw:WFSResource'-element (mandatory)
      SimpleLink wfsResource =
          parseSimpleLink(XMLTools.getRequiredChildElement("WFSResource", DEEGREECSW, element));

      // 'deegreecsw:CatalogAddresses'-element (optional)
      Element catalogAddressesElement =
          XMLTools.getChildElement("CatalogAddresses", DEEGREECSW, element);
      OnlineResource[] catalogAddresses = new OnlineResource[0];
      if (catalogAddressesElement != null) {
        // 'deegreecsw:CatalogAddresses'-element (optional)
        ElementList el =
            XMLTools.getChildElements("CatalogAddress", DEEGREECSW, catalogAddressesElement);
        catalogAddresses = new OnlineResource[el.getLength()];
        for (int i = 0; i < catalogAddresses.length; i++) {
          catalogAddresses[i] = parseOnLineResource(el.item(i));
        }
      }

      OnlineResource transInXslt = null;
      Element elem = (Element) XMLTools.getNode(element, "deegreecsw:TransactionInputXSLT", nsc);
      if (elem != null) {
        transInXslt = parseOnLineResource(elem);
      }
      OnlineResource transOutXslt = null;
      elem = (Element) XMLTools.getNode(element, "deegreecsw:TransactionOutputXSLT", nsc);
      if (elem != null) {
        transOutXslt = parseOnLineResource(elem);
      }
      if ((transInXslt != null && transOutXslt == null)
          || (transInXslt == null && transOutXslt != null)) {
        throw new InvalidConfigurationException(
            "if CSW-deegreeParam "
                + "'TransactionInputXSLT' is defined 'TransactionOutputXSLT' must "
                + "be defined too and vice versa!");
      }

      // 'deegreecsw:HarvestRepository'-element (optional)
      Element harvestRepositoryElement =
          XMLTools.getChildElement("HarvestRepository", DEEGREECSW, element);
      JDBCConnection harvestRepository = null;
      if (harvestRepositoryElement != null) {
        // 'deegreecsw:Connection'-element (optional)
        Element connectionElement =
            XMLTools.getChildElement("Connection", DEEGREECSW, harvestRepositoryElement);
        if (connectionElement != null) {
          harvestRepository =
              new JDBCConnection(
                  XMLTools.getRequiredStringValue("Driver", DEEGREECSW, connectionElement),
                  XMLTools.getRequiredStringValue("Logon", DEEGREECSW, connectionElement),
                  XMLTools.getRequiredStringValue("User", DEEGREECSW, connectionElement),
                  XMLTools.getRequiredStringValue("Password", DEEGREECSW, connectionElement),
                  null,
                  null,
                  null);
        }
      }
      deegreeParams =
          new CatalogueDeegreeParams(
              defaultOnlineResource,
              cacheSize,
              requestTimeLimit,
              characterSet,
              wfsResource,
              catalogAddresses,
              harvestRepository,
              defaultOutputSchema,
              transInXslt,
              transOutXslt);
    } catch (XMLParsingException e) {
      throw new InvalidConfigurationException(
          "Error parsing the deegreeParams "
              + "section of the CSW configuration: \n"
              + e.getMessage()
              + StringTools.stackTraceToString(e));
    }
    return deegreeParams;
  }