private static StreamNameType parseStreamIfPresent(final XmlElement operationElement)
     throws NetconfDocumentedException {
   final Optional<XmlElement> stream =
       operationElement.getOnlyChildElementWithSameNamespaceOptionally("stream");
   return stream.isPresent()
       ? new StreamNameType(stream.get().getTextContent())
       : NetconfNotificationManager.BASE_STREAM_NAME;
 }
  @Override
  protected Element handleWithNoSubsequentOperations(
      final Document document, final XmlElement operationElement)
      throws NetconfDocumentedException {
    operationElement.checkName(CREATE_SUBSCRIPTION);
    operationElement.checkNamespace(CreateSubscriptionInput.QNAME.getNamespace().toString());
    // FIXME reimplement using CODEC_REGISTRY and parse everything into generated class instance
    // Waiting ofr https://git.opendaylight.org/gerrit/#/c/13763/

    // FIXME filter could be supported same way as netconf server filters get and get-config results
    final Optional<XmlElement> filter =
        operationElement.getOnlyChildElementWithSameNamespaceOptionally("filter");
    Preconditions.checkArgument(filter.isPresent() == false, "Filter element not yet supported");

    // Replay not supported
    final Optional<XmlElement> startTime =
        operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
    Preconditions.checkArgument(
        startTime.isPresent() == false, "StartTime element not yet supported");

    // Stop time not supported
    final Optional<XmlElement> stopTime =
        operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
    Preconditions.checkArgument(
        stopTime.isPresent() == false, "StopTime element not yet supported");

    final StreamNameType streamNameType = parseStreamIfPresent(operationElement);

    Preconditions.checkNotNull(netconfSession);
    // Premature streams are allowed (meaning listener can register even if no provider is available
    // yet)
    if (notifications.isStreamAvailable(streamNameType) == false) {
      LOG.warn(
          "Registering premature stream {}. No publisher available yet for session {}",
          streamNameType,
          getNetconfSessionIdForReporting());
    }

    final NotificationListenerRegistration notificationListenerRegistration =
        notifications.registerNotificationListener(
            streamNameType, new NotificationSubscription(netconfSession));
    subscriptions.add(notificationListenerRegistration);

    return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
  }
  EditConfigXmlParser.EditConfigExecution fromXml(
      final XmlElement xml,
      final Config cfgMapping,
      TransactionProvider transactionProvider,
      ConfigRegistryClient configRegistryClient)
      throws NetconfDocumentedException {

    EditStrategyType editStrategyType = EditStrategyType.getDefaultStrategy();

    xml.checkName(EditConfigXmlParser.EDIT_CONFIG);
    xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);

    XmlElement targetElement =
        xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY);
    XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
    String datastoreValue = targetChildNode.getName();
    Datastore targetDatastore = Datastore.valueOf(datastoreValue);
    logger.debug("Setting {} to '{}'", EditConfigXmlParser.TARGET_KEY, targetDatastore);

    // check target
    Preconditions.checkArgument(
        targetDatastore == Datastore.candidate,
        "Only %s datastore supported for edit config but was: %s",
        Datastore.candidate,
        targetDatastore);

    // Test option
    TestOption testOption;
    Optional<XmlElement> testOptionElementOpt =
        xml.getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.TEST_OPTION_KEY);
    if (testOptionElementOpt.isPresent()) {
      String testOptionValue = testOptionElementOpt.get().getTextContent();
      testOption = EditConfigXmlParser.TestOption.getFromXmlName(testOptionValue);
    } else {
      testOption = EditConfigXmlParser.TestOption.getDefault();
    }
    logger.debug("Setting {} to '{}'", EditConfigXmlParser.TEST_OPTION_KEY, testOption);

    // Error option
    Optional<XmlElement> errorOptionElement =
        xml.getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.ERROR_OPTION_KEY);
    if (errorOptionElement.isPresent()) {
      String errorOptionParsed = errorOptionElement.get().getTextContent();
      if (false == errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION))
        throw new UnsupportedOperationException(
            "Only "
                + EditConfigXmlParser.DEFAULT_ERROR_OPTION
                + " supported for "
                + EditConfigXmlParser.ERROR_OPTION_KEY
                + ", was "
                + errorOptionParsed);
    }

    // Default op
    Optional<XmlElement> defaultContent =
        xml.getOnlyChildElementWithSameNamespaceOptionally(
            EditConfigXmlParser.DEFAULT_OPERATION_KEY);
    if (defaultContent.isPresent()) {
      String mergeStrategyString = defaultContent.get().getTextContent();
      logger.trace("Setting merge strategy to {}", mergeStrategyString);
      editStrategyType = EditStrategyType.valueOf(mergeStrategyString);
    }
    Set<ObjectName> instancesForFillingServiceRefMapping = Collections.emptySet();
    if (editStrategyType == EditStrategyType.merge) {
      instancesForFillingServiceRefMapping =
          Datastore.getInstanceQueryStrategy(targetDatastore, transactionProvider)
              .queryInstances(configRegistryClient);
      logger.trace(
          "Pre-filling services from following instances: {}",
          instancesForFillingServiceRefMapping);
    }

    XmlElement configElement =
        xml.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CONFIG_KEY);

    return new EditConfigXmlParser.EditConfigExecution(
        xml,
        cfgMapping,
        configElement,
        testOption,
        instancesForFillingServiceRefMapping,
        editStrategyType);
  }