Search in sources :

Example 1 with XmlElement

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);
}
Also used : HashMap(java.util.HashMap) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with XmlElement

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();
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectXmlWriter(org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml.ObjectXmlWriter) ObjectMapper(org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.ObjectMapper)

Example 3 with XmlElement

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);
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) RuntimeRpcElementResolved(org.opendaylight.controller.config.facade.xml.rpc.RuntimeRpcElementResolved) Rpcs(org.opendaylight.controller.config.facade.xml.rpc.Rpcs) ModuleRpcs(org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs) InstanceRuntimeRpc(org.opendaylight.controller.config.facade.xml.rpc.InstanceRuntimeRpc) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ModuleRpcs(org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs) ObjectName(javax.management.ObjectName)

Example 4 with XmlElement

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);
}
Also used : XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Example 5 with XmlElement

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;
}
Also used : XmlUtil(org.opendaylight.controller.config.util.xml.XmlUtil) Multimap(com.google.common.collect.Multimap) EditStrategyType(org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Optional(com.google.common.base.Optional) Document(org.w3c.dom.Document) Map(java.util.Map) EnumResolver(org.opendaylight.controller.config.facade.xml.osgi.EnumResolver) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Collection(java.util.Collection) Set(java.util.Set) ObjectName(javax.management.ObjectName) Maps(com.google.common.collect.Maps) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Revision(org.opendaylight.yangtools.yang.common.Revision) Element(org.w3c.dom.Element) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ObjectNameUtil(org.opendaylight.controller.config.api.jmx.ObjectNameUtil) Collections(java.util.Collections) XmlMappingConstants(org.opendaylight.controller.config.util.xml.XmlMappingConstants) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Aggregations

XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)14 AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)5 Map (java.util.Map)4 Optional (com.google.common.base.Optional)3 ObjectName (javax.management.ObjectName)3 IdentityMapping (org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping)3 EditStrategyType (org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType)3 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)3 Element (org.w3c.dom.Element)3 Preconditions (com.google.common.base.Preconditions)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Multimap (com.google.common.collect.Multimap)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2