X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Fruntime%2FInstanceRuntime.java;fp=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Fruntime%2FInstanceRuntime.java;h=0000000000000000000000000000000000000000;hb=ac6f2699cd0c1e340cc32e8f0d0ca94c8e9c0cc0;hp=c0532317d83df389e01b7af3d657cdaa36dd9ae1;hpb=f43b01b81319959b1907e3e04537f5169e7f33d8;p=controller.git diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java deleted file mode 100644 index c0532317d8..0000000000 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/runtime/InstanceRuntime.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.config.facade.xml.runtime; - -import com.google.common.base.Optional; -import com.google.common.collect.Collections2; -import com.google.common.collect.Sets; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import javax.management.ObjectName; -import org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig; -import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class InstanceRuntime { - - private static final String KEY_ATTRIBUTE_KEY = "key"; - - private final InstanceConfig instanceMapping; - private final Map childrenMappings; - private final Map jmxToYangChildRbeMapping; - - public InstanceRuntime(InstanceConfig instanceMapping, Map childrenMappings, - Map jmxToYangChildRbeMapping) { - this.instanceMapping = instanceMapping; - this.childrenMappings = childrenMappings; - this.jmxToYangChildRbeMapping = jmxToYangChildRbeMapping; - } - - /** - * Finds all children runtime beans, same properties and values as current root - * + any number of additional properties. - */ - private Set findChildren(ObjectName innerRootBean, Set childRbeOns) { - final Map wantedProperties = innerRootBean.getKeyPropertyList(); - - return Sets.newHashSet(Collections2.filter(childRbeOns, on -> { - Map localProperties = on.getKeyPropertyList(); - for (Entry propertyEntry : wantedProperties.entrySet()) { - if (!localProperties.containsKey(propertyEntry.getKey())) { - return false; - } - if (!localProperties.get(propertyEntry.getKey()).equals(propertyEntry.getValue())) { - return false; - } - if (localProperties.size() <= wantedProperties.size()) { - return false; - } - } - return true; - })); - } - - /** - * Finds next level root runtime beans, beans that have the same properties as - * current root + one additional. - */ - private Set getRootBeans(Set childRbeOns, final String string, final int keyListSize) { - return Sets.newHashSet(Collections2.filter(childRbeOns, on -> { - if (on.getKeyPropertyList().size() != keyListSize + 1) { - return false; - } - return on.getKeyPropertyList().containsKey(string); - })); - } - - public Element toXml(ObjectName rootOn, Set childRbeOns, Document document, Element parentElement, - String namespace, final EnumResolver enumResolver) { - return toXml(rootOn, childRbeOns, document, null, parentElement, namespace, enumResolver); - } - - public Element toXml(ObjectName rootOn, Set childRbeOns, Document document, String instanceIndex, - Element parentElement, String namespace, final EnumResolver enumResolver) { - Element xml = instanceMapping.toXml(rootOn, namespace, document, parentElement, enumResolver); - - if (instanceIndex != null) { - xml.setAttribute(KEY_ATTRIBUTE_KEY, instanceIndex); - } - - for (Entry childMappingEntry : childrenMappings.entrySet()) { - Set innerRootBeans = getRootBeans(childRbeOns, childMappingEntry.getKey(), - rootOn.getKeyPropertyList().size()); - - for (ObjectName objectName : innerRootBeans) { - Set innerChildRbeOns = findChildren(objectName, childRbeOns); - String runtimeInstanceIndex = objectName.getKeyProperty(childMappingEntry.getKey()); - - String elementName = jmxToYangChildRbeMapping.get(childMappingEntry.getKey()); - - Element innerXml = XmlUtil.createElement(document, elementName, Optional.of(namespace)); - childMappingEntry.getValue().toXml(objectName, innerChildRbeOns, document, runtimeInstanceIndex, - innerXml, namespace, enumResolver); - xml.appendChild(innerXml); - } - } - return xml; - } -}