Search in sources :

Example 1 with IdentityMapping

use of org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping in project controller by opendaylight.

the class ConfigSubsystemFacade method transformIdentities.

private static Map<String, Map<Optional<Revision>, IdentityMapping>> transformIdentities(final Set<Module> modules) {
    Map<String, Map<Optional<Revision>, IdentityMapping>> mappedIds = new HashMap<>();
    for (Module module : modules) {
        String namespace = module.getNamespace().toString();
        Map<Optional<Revision>, IdentityMapping> revisionsByNamespace = mappedIds.computeIfAbsent(namespace, k -> new HashMap<>());
        Optional<Revision> revision = Optional.fromJavaUtil(module.getRevision());
        IdentityMapping identityMapping = revisionsByNamespace.computeIfAbsent(revision, k -> new IdentityMapping());
        for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
            identityMapping.addIdSchemaNode(identitySchemaNode);
        }
    }
    return mappedIds;
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Revision(org.opendaylight.yangtools.yang.common.Revision) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) Module(org.opendaylight.yangtools.yang.model.api.Module) HashMap(java.util.HashMap) Map(java.util.Map) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)

Example 2 with IdentityMapping

use of org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping in project controller by opendaylight.

the class SimpleIdentityRefAttributeReadingStrategyTest method testReadIdRef.

@Test
public void testReadIdRef() throws Exception {
    final Map<String, Map<Optional<Revision>, IdentityMapping>> identityMapping = Maps.newHashMap();
    final IdentityMapping value = new IdentityMapping();
    final Optional<Revision> rev = Optional.of(Revision.of("2017-10-10"));
    identityMapping.put("namespace", Collections.singletonMap(rev, value));
    identityMapping.put("inner", Collections.singletonMap(rev, value));
    final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key", identityMapping);
    String read = key.readElementContent(XmlElement.fromString("<el xmlns=\"namespace\">local</el>"));
    assertEquals(QName.create(URI.create("namespace"), rev.toJavaUtil(), "local").toString(), read);
    read = key.readElementContent(XmlElement.fromString("<el xmlns:a=\"inner\" xmlns=\"namespace\">a:local</el>"));
    assertEquals(QName.create(URI.create("inner"), rev.toJavaUtil(), "local").toString(), read);
    read = key.readElementContent(XmlElement.fromString("<top xmlns=\"namespace\"><el>local</el></top>").getOnlyChildElement());
    assertEquals(QName.create(URI.create("namespace"), rev.toJavaUtil(), "local").toString(), read);
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Revision(org.opendaylight.yangtools.yang.common.Revision) Map(java.util.Map) Test(org.junit.Test)

Example 3 with IdentityMapping

use of org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping in project controller by opendaylight.

the class InstanceRuntimeRpc method fromXml.

public Map<String, AttributeConfigElement> fromXml(final XmlElement configRootNode) throws DocumentedException {
    Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
    // FIXME add identity map to runtime data
    Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, Collections.<String, Map<Optional<Revision>, IdentityMapping>>emptyMap());
    for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
        List<XmlElement> configNodes = configRootNode.getChildElements(readStratEntry.getKey());
        AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
        retVal.put(readStratEntry.getKey(), readElement);
    }
    resolveConfiguration(retVal);
    return retVal;
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) AttributeReadingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy) Optional(com.google.common.base.Optional) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) ObjectXmlReader(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Aggregations

IdentityMapping (org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping)3 Optional (com.google.common.base.Optional)2 Map (java.util.Map)2 Revision (org.opendaylight.yangtools.yang.common.Revision)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)1 AttributeReadingStrategy (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy)1 ObjectXmlReader (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader)1 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)1 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1