use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.
the class Services method fromXml.
// TODO support edit strategies on services
public static Services fromXml(final XmlElement xml) throws DocumentedException {
Map<String, Map<String, Map<String, String>>> retVal = new HashMap<>();
List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
xml.checkUnrecognisedElements(services);
for (XmlElement service : services) {
XmlElement typeElement = service.getOnlyChildElement(TYPE_KEY);
Entry<String, String> prefixNamespace = typeElement.findNamespaceOfTextContent();
Preconditions.checkState(prefixNamespace.getKey() != null && !prefixNamespace.getKey().equals(""), "Type attribute was not prefixed");
Map<String, Map<String, String>> namespaceToServices = retVal.computeIfAbsent(prefixNamespace.getValue(), k -> new HashMap<>());
String serviceName = ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
Map<String, String> innerMap = namespaceToServices.computeIfAbsent(serviceName, k -> new HashMap<>());
List<XmlElement> instances = service.getChildElements(XmlMappingConstants.INSTANCE_KEY);
service.checkUnrecognisedElements(instances, typeElement);
for (XmlElement instance : instances) {
XmlElement nameElement = instance.getOnlyChildElement(NAME_KEY);
String refName = nameElement.getTextContent();
if (!ModifyAction.DELETE.toString().toLowerCase().equals(instance.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0))) {
XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY);
String providerName = providerElement.getTextContent();
instance.checkUnrecognisedElements(nameElement, providerElement);
innerMap.put(refName, providerName);
} else {
// since this is a delete we dont have a provider name - we want empty service
// instance
innerMap.put(refName, EMPTY_PROVIDER);
}
}
}
return resolveServices(retVal);
}
use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.
the class RpcFacade method toXml.
public Element toXml(final Document doc, final Object result, final OperationExecution execution) throws DocumentedException {
AttributeMappingStrategy<?, ? extends OpenType<?>> mappingStrategy = new ObjectMapper().prepareStrategy(execution.getReturnType());
Optional<?> mappedAttributeOpt = mappingStrategy.mapAttribute(result);
Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, execution.getReturnType().getOpenType());
// FIXME: multiple return values defined as leaf-list and list in yang should
// not be wrapped in output xml element,
// they need to be appended directly under rpc-reply element
//
// 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 = XmlUtil.createElement(doc, "output", Optional.of(XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
new ObjectXmlWriter().prepareWritingStrategy(execution.getReturnType().getAttributeYangName(), execution.getReturnType(), doc).writeElement(tempParent, execution.getNamespace(), mappedAttributeOpt.get());
XmlElement xmlElement = XmlElement.fromDomElement(tempParent);
return xmlElement.getChildElements().size() > 1 ? tempParent : xmlElement.getOnlyChildElement().getDomElement();
}
use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.
the class RpcFacade method fromXml.
public OperationExecution fromXml(final XmlElement xml) throws DocumentedException {
final String namespace;
namespace = xml.getNamespace();
final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
final String operationName = xml.getName();
final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(contextInstanceElement.getTextContent(), operationName, namespace);
final Rpcs rpcs = mapRpcs();
final ModuleRpcs rpcMapping = rpcs.getRpcMapping(id);
final InstanceRuntimeRpc instanceRuntimeRpc = rpcMapping.getRpc(id.getRuntimeBeanName(), operationName);
// TODO move to Rpcs after xpath attribute is redesigned
final ObjectName on = id.getObjectName(rpcMapping);
Map<String, AttributeConfigElement> attributes = instanceRuntimeRpc.fromXml(xml);
attributes = sortAttributes(attributes, xml);
return new OperationExecution(on, instanceRuntimeRpc.getName(), attributes, instanceRuntimeRpc.getReturnType(), namespace);
}
use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.
the class Config method resolveModule.
private <T> void resolveModule(final Map<String, Multimap<String, T>> retVal, final ServiceRegistryWrapper serviceTracker, final XmlElement moduleElement, final EditStrategyType defaultStrategy, final ResolvingStrategy<T> resolvingStrategy) throws DocumentedException {
XmlElement typeElement = null;
typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
Entry<String, String> prefixToNamespace = typeElement.findNamespaceOfTextContent();
String moduleNamespace = prefixToNamespace.getValue();
XmlElement nameElement = null;
nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.NAME_KEY);
String instanceName = nameElement.getTextContent();
String factoryNameWithPrefix = typeElement.getTextContent();
String prefixOrEmptyString = prefixToNamespace.getKey();
String factoryName = getFactoryName(factoryNameWithPrefix, prefixOrEmptyString);
ModuleConfig moduleMapping = getModuleMapping(moduleNamespace, instanceName, factoryName);
Multimap<String, T> innerMap = retVal.computeIfAbsent(moduleNamespace, k -> HashMultimap.create());
T resolvedElement = resolvingStrategy.resolveElement(moduleMapping, moduleElement, serviceTracker, instanceName, moduleNamespace, defaultStrategy);
innerMap.put(factoryName, resolvedElement);
}
use of org.opendaylight.controller.config.util.xml.XmlElement in project controller by opendaylight.
the class Config method fromXmlModulesResolved.
// TODO refactor, replace string representing namespace with namespace class
// TODO refactor, replace Map->Multimap with e.g. ConfigElementResolved
// class
public Map<String, Multimap<String, ModuleElementResolved>> fromXmlModulesResolved(final XmlElement xml, final EditStrategyType defaultEditStrategyType, final ServiceRegistryWrapper serviceTracker) throws DocumentedException {
Optional<XmlElement> modulesElement = getModulesElement(xml);
List<XmlElement> moduleElements = getModulesElementList(modulesElement);
Map<String, Multimap<String, ModuleElementResolved>> retVal = Maps.newHashMap();
ResolvingStrategy<ModuleElementResolved> resolvingStrategy = (moduleMapping, moduleElement, serviceTracker1, instanceName, moduleNamespace, defaultStrategy) -> moduleMapping.fromXml(moduleElement, serviceTracker1, instanceName, moduleNamespace, defaultStrategy, identityMap, enumResolver);
for (XmlElement moduleElement : moduleElements) {
resolveModule(retVal, serviceTracker, moduleElement, defaultEditStrategyType, resolvingStrategy);
}
return retVal;
}
Aggregations