X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2Fmapping%2Foperations%2FDefaultGetSchema.java;h=53107048760dbee1ae27f23be7977b15481ba39a;hp=ba9e4d0f8a14fe9cd44c906dc57a91011a89ca99;hb=ecd49a2e11021576f51052ad54f785c9b0e65122;hpb=66bb5943ab1aad5d4b969a8a75c382c7590fb181 diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java index ba9e4d0f8a..5310704876 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultGetSchema.java @@ -8,75 +8,49 @@ package org.opendaylight.controller.netconf.impl.mapping.operations; -import java.util.HashMap; +import com.google.common.base.Optional; +import com.google.common.collect.Maps; import java.util.Map; - -import org.opendaylight.controller.netconf.api.NetconfSession; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.api.NetconfOperationRouter; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; -import org.opendaylight.controller.netconf.mapping.api.DefaultNetconfOperation; -import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; -import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation; +import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException; +import org.opendaylight.controller.netconf.util.mapping.AbstractLastNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.google.common.base.Optional; -import com.google.common.collect.Maps; - -public final class DefaultGetSchema extends AbstractNetconfOperation implements DefaultNetconfOperation { +public final class DefaultGetSchema extends AbstractLastNetconfOperation { + public static final String GET_SCHEMA = "get-schema"; + public static final String IDENTIFIER = "identifier"; + public static final String VERSION = "version"; + private static final Logger LOG = LoggerFactory.getLogger(DefaultGetSchema.class); private final CapabilityProvider cap; - private NetconfSession netconfSession; - - private static final Logger logger = LoggerFactory.getLogger(DefaultGetSchema.class); public DefaultGetSchema(CapabilityProvider cap, String netconfSessionIdForReporting) { super(netconfSessionIdForReporting); this.cap = cap; } - public static final String GET_SCHEMA = "get-schema"; - public static final String IDENTIFIER = "identifier"; - public static final String VERSION = "version"; - @Override - protected HandlingPriority canHandle(String netconfOperationName, String namespace) { - if (netconfOperationName.equals("get-schema") == false) - return HandlingPriority.CANNOT_HANDLE; - if (namespace.equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING) == false) - return HandlingPriority.CANNOT_HANDLE; + protected String getOperationName() { + return GET_SCHEMA; + } - return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY; + @Override + protected String getOperationNamespace() { + return XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING; } @Override - protected Element handle(Document document, XmlElement xml, NetconfOperationRouter router) - throws NetconfDocumentedException { + protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { GetSchemaEntry entry; - try { - entry = new GetSchemaEntry(xml); - } catch (final IllegalArgumentException e) { - logger.warn("Error parsing xml", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(NetconfDocumentedException.ErrorTag.bad_attribute.name(), e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), e, NetconfDocumentedException.ErrorType.rpc, - NetconfDocumentedException.ErrorTag.bad_attribute, NetconfDocumentedException.ErrorSeverity.error, - errorInfo); - } catch (final IllegalStateException e) { - logger.warn("Error parsing xml", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(NetconfDocumentedException.ErrorTag.bad_attribute.name(), e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), e, NetconfDocumentedException.ErrorType.rpc, - NetconfDocumentedException.ErrorTag.bad_attribute, NetconfDocumentedException.ErrorSeverity.error, - errorInfo); - } + entry = new GetSchemaEntry(xml); String schema; try { @@ -84,18 +58,16 @@ public final class DefaultGetSchema extends AbstractNetconfOperation implements } catch (IllegalStateException e) { Map errorInfo = Maps.newHashMap(); errorInfo.put(entry.identifier, e.getMessage()); - logger.warn("Rpc error: {}", NetconfDocumentedException.ErrorTag.operation_failed, e); + LOG.warn("Rpc error: {}", NetconfDocumentedException.ErrorTag.operation_failed, e); throw new NetconfDocumentedException(e.getMessage(), NetconfDocumentedException.ErrorType.application, NetconfDocumentedException.ErrorTag.operation_failed, NetconfDocumentedException.ErrorSeverity.error, errorInfo); } Element getSchemaResult; - getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema); - XmlUtil.addNamespaceAttr(getSchemaResult, - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING); - - logger.info("{} operation successful", GET_SCHEMA); + getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema, + Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING)); + LOG.trace("{} operation successful", GET_SCHEMA); return getSchemaResult; } @@ -104,11 +76,17 @@ public final class DefaultGetSchema extends AbstractNetconfOperation implements private final String identifier; private final Optional version; - GetSchemaEntry(XmlElement getSchemaElement) { + GetSchemaEntry(XmlElement getSchemaElement) throws NetconfDocumentedException { getSchemaElement.checkName(GET_SCHEMA); getSchemaElement.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING); - XmlElement identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER); + XmlElement identifierElement = null; + try { + identifierElement = getSchemaElement.getOnlyChildElementWithSameNamespace(IDENTIFIER); + } catch (MissingNameSpaceException e) { + LOG.trace("Can't get identifier element as only child element with same namespace due to ",e); + throw NetconfDocumentedException.wrap(e); + } identifier = identifierElement.getTextContent(); Optional versionElement = getSchemaElement .getOnlyChildElementWithSameNamespaceOptionally(VERSION); @@ -117,15 +95,6 @@ public final class DefaultGetSchema extends AbstractNetconfOperation implements } else { version = Optional.absent(); } - } } - - public void setNetconfSession(NetconfSession s) { - this.netconfSession = s; - } - - public NetconfSession getNetconfSession() { - return netconfSession; - } }