import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+
public class CompositeAttributeWritingStrategy implements AttributeWritingStrategy {
protected final String key;
public void writeElement(Element parentElement, String namespace, Object value) {
Util.checkType(value, Map.class);
- Element innerNode = document.createElement(key);
- XmlUtil.addNamespaceAttr(innerNode, namespace);
+ Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
Map<?, ?> map = (Map<?, ?>) value;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+
public class ObjectNameAttributeWritingStrategy implements AttributeWritingStrategy {
private final Document document;
@Override
public void writeElement(Element parentElement, String namespace, Object value) {
Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
- Element innerNode = document.createElement(key);
- XmlUtil.addNamespaceAttr(innerNode, namespace);
+ Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace));
String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName();
String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName();
String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace();
- Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlNetconfConstants.TYPE_KEY, XmlNetconfConstants.PREFIX,
- moduleName);
- XmlUtil.addPrefixedNamespaceAttr(typeElement, XmlNetconfConstants.PREFIX, namespaceForType);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlUtil.createPrefixedValue(XmlNetconfConstants.PREFIX, XmlNetconfConstants.TYPE_KEY), XmlNetconfConstants.PREFIX,
+ moduleName, Optional.<String>of(namespaceForType));
innerNode.appendChild(typeElement);
- final Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, refName);
+ final Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, refName, Optional.<String>absent());
innerNode.appendChild(nameElement);
parentElement.appendChild(innerNode);
import java.util.Map.Entry;
import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+
public class RuntimeBeanEntryWritingStrategy extends CompositeAttributeWritingStrategy {
public RuntimeBeanEntryWritingStrategy(Document document, String key,
public void writeElement(Element parentElement, String namespace, Object value) {
Util.checkType(value, Map.class);
- Element innerNode = document.createElement(key);
+ Element innerNode = XmlUtil.createElement(document, key, Optional.<String>absent());
Map<?, ?> map = (Map<?, ?>) value;
// bean
Util.checkType(runtimeBeanInstanceMappingEntry.getValue(), Map.class);
Map<?, ?> innerMap = (Map<?, ?>) runtimeBeanInstanceMappingEntry.getValue();
- Element runtimeInstanceNode = document.createElement("_"
- + (String) runtimeBeanInstanceMappingEntry.getKey());
+ Element runtimeInstanceNode = XmlUtil.createElement(document, "_"
+ + (String) runtimeBeanInstanceMappingEntry.getKey(), Optional.<String>absent());
innerNode.appendChild(runtimeInstanceNode);
for (Entry<?, ?> innerObjectEntry : innerMap.entrySet()) {
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+
public class SimpleAttributeWritingStrategy implements AttributeWritingStrategy {
private final Document document;
public void writeElement(Element parentElement, String namespace, Object value) {
value = preprocess(value);
Util.checkType(value, String.class);
- Element innerNode = createElement(document, key, (String) value);
- XmlUtil.addNamespaceAttr(innerNode, namespace);
+ Element innerNode = createElement(document, key, (String) value, Optional.of(namespace));
parentElement.appendChild(innerNode);
}
- protected Element createElement(Document document, String key, String value) {
- return XmlUtil.createTextElement(document, key, (String) value);
+ protected Element createElement(Document document, String key, String value, Optional<String> namespace) {
+ Element typeElement = XmlUtil.createElement(document, key, namespace);
+
+ typeElement.appendChild(document.createTextNode(value));
+ return typeElement;
}
protected Object preprocess(Object value) {
import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.opendaylight.yangtools.yang.common.QName;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import org.w3c.dom.Element;
public class SimpleIdentityRefAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
}
@Override
- protected Element createElement(Document doc, String key, String value) {
+ protected Element createElement(Document doc, String key, String value, Optional<String> namespace) {
QName qName = QName.create(value);
String identity = qName.getLocalName();
- Element element = XmlUtil.createPrefixedTextElement(doc, key, PREFIX, identity);
-
String identityNamespace = qName.getNamespace().toString();
- XmlUtil.addPrefixedNamespaceAttr(element, PREFIX, identityNamespace);
+ Element element = XmlUtil.createPrefixedTextElement(doc, XmlUtil.createPrefixedValue(PREFIX, key), PREFIX, identity, Optional.<String>of(identityNamespace));
return element;
}
}
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import javax.management.ObjectName;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkState;
-import static java.lang.String.format;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
public class Config {
private final Logger logger = LoggerFactory.getLogger(Config.class);
Element root = dataElement;
if (maybeNamespace.isPresent()) {
- XmlUtil.addNamespaceAttr(root, maybeNamespace.get());
+ root.setAttributeNS(maybeNamespace.get(), dataElement.getNodeName(), "xmlns");
}
- Element modulesElement = document.createElement(XmlNetconfConstants.MODULES_KEY);
- XmlUtil.addNamespaceAttr(modulesElement,
- XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
+ Element modulesElement = XmlUtil.createElement(document, XmlNetconfConstants.MODULES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
root.appendChild(modulesElement);
for (String moduleNamespace : moduleToInstances.keySet()) {
for (Entry<String, Collection<ObjectName>> moduleMappingEntry : moduleToInstances.get(moduleNamespace)
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+
+import javax.management.ObjectName;
+
import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import javax.management.ObjectName;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
+import com.google.common.base.Optional;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
public class ModuleConfig {
}
public Element toXml(ObjectName instanceON, ServiceRegistryWrapper depTracker, Document document, String namespace) {
- Element root = document.createElement(XmlNetconfConstants.MODULE_KEY);
+ Element root = XmlUtil.createElement(document, XmlNetconfConstants.MODULE_KEY, Optional.<String>absent());
// Xml.addNamespaceAttr(document, root, namespace);
final String prefix = getPrefix(namespace);
- Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlNetconfConstants.TYPE_KEY, prefix,
- moduleName);
- XmlUtil.addPrefixedNamespaceAttr(typeElement, prefix, namespace);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlUtil.createPrefixedValue(prefix, XmlNetconfConstants.TYPE_KEY), prefix,
+ moduleName, Optional.<String>of(namespace));
// Xml.addNamespaceAttr(document, typeElement,
// XMLUtil.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
root.appendChild(typeElement);
- Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY,
- ObjectNameUtil.getInstanceName(instanceON));
+ Element nameElement = XmlUtil.createTextElement(document, XmlUtil.createPrefixedValue(prefix, XmlNetconfConstants.NAME_KEY),
+ ObjectNameUtil.getInstanceName(instanceON), Optional.<String>of(namespace));
// Xml.addNamespaceAttr(document, nameElement,
// XMLUtil.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
root.appendChild(nameElement);
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.management.ObjectName;
+
import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy;
import org.opendaylight.controller.netconf.util.xml.XmlElement;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import javax.management.ObjectName;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
public final class Services {
}
public static Element toXml(ServiceRegistryWrapper serviceRegistryWrapper, Document document) {
- Element root = document.createElement(XmlNetconfConstants.SERVICES_KEY);
- XmlUtil.addNamespaceAttr(root, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
+ Element root = XmlUtil.createElement(document, XmlNetconfConstants.SERVICES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
Map<String, Map<String, Map<String, String>>> mappedServices = serviceRegistryWrapper.getMappedServices();
for (String namespace : mappedServices.keySet()) {
for (Entry<String, Map<String, String>> serviceEntry : mappedServices.get(namespace).entrySet()) {
- Element serviceElement = document.createElement(SERVICE_KEY);
+ Element serviceElement = XmlUtil.createElement(document, SERVICE_KEY, Optional.<String>absent());
root.appendChild(serviceElement);
- Element typeElement = XmlUtil.createPrefixedTextElement(document, TYPE_KEY, XmlNetconfConstants.PREFIX,
- serviceEntry.getKey());
- XmlUtil.addPrefixedNamespaceAttr(typeElement, XmlNetconfConstants.PREFIX, namespace);
+ Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlUtil.createPrefixedValue(XmlNetconfConstants.PREFIX, TYPE_KEY), XmlNetconfConstants.PREFIX,
+ serviceEntry.getKey(), Optional.of(namespace));
serviceElement.appendChild(typeElement);
for (Entry<String, String> instanceEntry : serviceEntry.getValue().entrySet()) {
- Element instanceElement = document.createElement(XmlNetconfConstants.INSTANCE_KEY);
+ Element instanceElement = XmlUtil.createElement(document, XmlNetconfConstants.INSTANCE_KEY, Optional.<String>absent());
serviceElement.appendChild(instanceElement);
- Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey());
+ Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey(), Optional.<String>absent());
instanceElement.appendChild(nameElement);
- Element providerElement = XmlUtil.createTextElement(document, PROVIDER_KEY, instanceEntry.getValue());
+ Element providerElement = XmlUtil.createTextElement(document, PROVIDER_KEY, instanceEntry.getValue(), Optional.<String>absent());
instanceElement.appendChild(providerElement);
}
}
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Sets;
-import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import javax.management.ObjectName;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import javax.management.ObjectName;
+
+import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.InstanceConfig;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+
public class InstanceRuntime {
/**
String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey());
- Element innerXml = document.createElement(elementName);
+ Element innerXml = XmlUtil.createElement(document, elementName, Optional.<String>absent());
childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document,
runtimeInstanceIndex, innerXml, namespace);
xml.appendChild(innerXml);
package org.opendaylight.controller.netconf.confignetconfconnector.mapping.runtime;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ModuleConfig;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import javax.management.ObjectName;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
+import com.google.common.base.Optional;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
public class Runtime {
}
public Element toXml(Set<ObjectName> instancesToMap, Set<ObjectName> configBeans, Document document, ServiceRegistryWrapper serviceRegistry) {
- Element root = document.createElement(XmlNetconfConstants.DATA_KEY);
+ Element root = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.<String>absent());
- Element modulesElement = document.createElement(XmlNetconfConstants.MODULES_KEY);
- XmlUtil.addNamespaceAttr(modulesElement,
- XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
+ Element modulesElement = XmlUtil.createElement(document, XmlNetconfConstants.MODULES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
root.appendChild(modulesElement);
Map<String, Multimap<String, ObjectName>> moduleToRuntimeInstance = mapInstancesToModules(instancesToMap);
import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
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;
+
public class Commit extends AbstractConfigNetconfOperation {
private static final Logger logger = LoggerFactory.getLogger(Commit.class);
}
logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
- return document.createElement(XmlNetconfConstants.OK);
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
}
import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
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;
+
public class DiscardChanges extends AbstractConfigNetconfOperation {
public static final String DISCARD = "discard-changes";
}
logger.trace("Changes discarded successfully from datastore {}", Datastore.candidate);
- return document.createElement(XmlNetconfConstants.OK);
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
}
import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
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.base.Preconditions;
public class Validate extends AbstractConfigNetconfOperation {
logger.trace("Datastore {} validated successfully", Datastore.candidate);
- return document.createElement(XmlNetconfConstants.OK);
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
}
import org.opendaylight.controller.config.api.ValidationException;
import org.opendaylight.controller.config.util.ConfigRegistryClient;
import org.opendaylight.controller.config.util.ConfigTransactionClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser.EditConfigExecution;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
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.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.slf4j.Logger;
import org.w3c.dom.Element;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
logger.trace("Operation {} successful", EditConfigXmlParser.EDIT_CONFIG);
- return document.createElement(XmlNetconfConstants.OK);
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
private void executeSet(ConfigRegistryClient configRegistryClient,
import org.opendaylight.controller.config.util.ConfigRegistryClient;
import org.opendaylight.controller.config.util.ConfigTransactionClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.Datastore;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfig;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
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;
private Element getResponseInternal(final Document document, final ConfigRegistryClient configRegistryClient,
final Datastore source) throws NetconfDocumentedException {
- Element dataElement = document.createElement(XmlNetconfConstants.DATA_KEY);
+ Element dataElement = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.<String>absent());
final Set<ObjectName> instances = Datastore.getInstanceQueryStrategy(source, this.transactionProvider)
.queryInstances(configRegistryClient);
import javax.management.openmbean.OpenType;
import org.opendaylight.controller.config.util.ConfigRegistryClient;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc;
import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.Rpcs;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
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;
// Either allow List of Elements to be returned from NetconfOperation or
// pass reference to parent output xml element for netconf operations to
// append result(s) on their own
- Element tempParent = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, "output");
+ Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
new ObjectXmlWriter().prepareWritingStrategy(elementName, returnType, doc).writeElement(tempParent, namespace, mappedAttributeOpt.get());
XmlElement xmlElement = XmlElement.fromDomElement(tempParent);
execution.on, execution.attributes, result);
if (execution.isVoid()) {
- return document.createElement("ok");
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
} else {
return toXml(document, result, execution.returnType, execution.namespace,
execution.returnType.getAttributeYangName());
package org.opendaylight.controller.netconf.confignetconfconnector;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.commons.lang3.StringUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.ObjectName;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
public class NetconfMappingTest extends AbstractConfigTest {
String enumContent = "TWO";
for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
- String name = moduleElement.getOnlyChildElement("name").getTextContent();
+ String name = moduleElement.getOnlyChildElement("prefix:name").getTextContent();
if(name.equals(INSTANCE_NAME)) {
XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
assertEquals(enumContent, enumAttr.getTextContent());
package org.opendaylight.controller.netconf.impl;
-import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.util.Timer;
import io.netty.util.concurrent.Promise;
+
+import java.io.InputStream;
+
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+
import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import java.io.InputStream;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
CapabilityProvider capabilityProvider = new CapabilityProviderImpl(factoriesListener.getSnapshot(sessionId));
for (String capability : capabilityProvider.getCapabilities()) {
- final Element capabilityElement = helloMessageTemplate.createElement(XmlNetconfConstants.CAPABILITY);
+ final Element capabilityElement = XmlUtil.createElement(helloMessageTemplate, XmlNetconfConstants.CAPABILITY, Optional.<String>absent());
capabilityElement.setTextContent(capability);
capabilitiesElement.appendChild(capabilityElement);
}
import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
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.w3c.dom.Document;
import org.w3c.dom.Element;
+import com.google.common.base.Optional;
+
public class DefaultCloseSession extends AbstractSingletonNetconfOperation {
public static final String CLOSE_SESSION = "close-session";
private final AutoCloseable sessionResources;
NetconfDocumentedException.ErrorSeverity.error, Collections.singletonMap(
NetconfDocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
}
- return document.createElement(XmlNetconfConstants.OK);
+ return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
}
package org.opendaylight.controller.netconf.impl.mapping.operations;
-import com.google.common.base.Optional;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
+import java.util.Map;
+
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
import org.opendaylight.controller.netconf.util.mapping.AbstractLastNetconfOperation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import java.util.HashMap;
-import java.util.Map;
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
public final class DefaultGetSchema extends AbstractLastNetconfOperation {
public static final String GET_SCHEMA = "get-schema";
}
Element getSchemaResult;
- getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema);
- XmlUtil.addNamespaceAttr(getSchemaResult,
- XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING);
-
+ getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema,
+ Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING));
logger.trace("{} operation successful", GET_SCHEMA);
return getSchemaResult;
import org.w3c.dom.Document;\r
import org.w3c.dom.Element;\r
\r
+import com.google.common.base.Optional;\r
+\r
public class DefaultStartExi extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {\r
\r
public static final String START_EXI = "start-exi";\r
@Override\r
protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException {\r
\r
-\r
- Element getSchemaResult = document\r
- .createElement(XmlNetconfConstants.OK);\r
- XmlUtil.addNamespaceAttr(getSchemaResult,\r
- XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);\r
-\r
+ Element getSchemaResult = XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));\r
\r
throw new UnsupportedOperationException("Not implemented");\r
\r
package org.opendaylight.controller.netconf.util.mapping;
+import java.util.Map;
+
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import java.util.Map;
+import com.google.common.base.Optional;
public abstract class AbstractNetconfOperation implements NetconfOperation {
private final String netconfSessionIdForReporting;
Map<String, Attr> attributes = requestElement.getAttributes();
Element response = handle(document, operationElement, subsequentOperation);
- Element rpcReply = document.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
- XmlNetconfConstants.RPC_REPLY_KEY);
+ Element rpcReply = XmlUtil.createElement(document, XmlNetconfConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
if(XmlElement.fromDomElement(response).hasNamespace()) {
rpcReply.appendChild(response);
} else {
- Element responseNS = document.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, response.getNodeName());
+ Element responseNS = XmlUtil.createElement(document, response.getNodeName(), Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
NodeList list = response.getChildNodes();
while(list.getLength()!=0) {
responseNS.appendChild(list.item(0));
import org.xml.sax.SAXException;
import com.google.common.base.Charsets;
+import com.google.common.base.Optional;
public final class XmlUtil {
public static final String XMLNS_ATTRIBUTE_KEY = "xmlns";
+ private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
private static final DocumentBuilderFactory BUILDERFACTORY;
static {
}
}
- public static Element createTextElement(Document document, String name, String content) {
- Element typeElement = document.createElement(name);
- typeElement.appendChild(document.createTextNode(content));
- return typeElement;
- }
-
- public static void addNamespaceAttr(Element root, String namespace) {
- root.setAttribute(XMLNS_ATTRIBUTE_KEY, namespace);
+ public static Element createElement(final Document document, String qName, Optional<String> namespaceURI) {
+ if(namespaceURI.isPresent()) {
+ final Element element = document.createElementNS(namespaceURI.get(), qName);
+ String name = XMLNS_ATTRIBUTE_KEY;
+ if(element.getPrefix() != null) {
+ name += ":" + element.getPrefix();
+ }
+ element.setAttributeNS(XMLNS_URI, name, namespaceURI.get());
+ return element;
+ }
+ return document.createElement(qName);
}
- public static void addPrefixedNamespaceAttr(Element root, String prefix, String namespace) {
- root.setAttribute(concat(XMLNS_ATTRIBUTE_KEY, prefix), namespace);
+ public static Element createTextElement(Document document, String qName, String content, Optional<String> namespaceURI) {
+ Element typeElement = createElement(document, qName, namespaceURI);
+ typeElement.appendChild(document.createTextNode(content));
+ return typeElement;
}
- public static Element createPrefixedTextElement(Document document, String key, String prefix, String content) {
- return createTextElement(document, key, concat(prefix, content));
+ public static Element createPrefixedTextElement(Document document, String qName, String prefix, String content, Optional<String> namespace) {
+ return createTextElement(document, qName, createPrefixedValue(prefix, content), namespace);
}
- private static String concat(String prefix, String value) {
+ public static String createPrefixedValue(String prefix, String value) {
return prefix + ":" + value;
}