Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / config / ModuleConfig.java
1 /*
2  * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.config.facade.xml.mapping.config;
10
11 import com.google.common.base.Optional;
12 import java.util.Map;
13 import javax.management.ObjectName;
14 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
15 import org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping;
16 import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
17 import org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType;
18 import org.opendaylight.controller.config.util.xml.DocumentedException;
19 import org.opendaylight.controller.config.util.xml.XmlElement;
20 import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
21 import org.opendaylight.controller.config.util.xml.XmlUtil;
22 import org.opendaylight.yangtools.yang.common.Revision;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25
26 public class ModuleConfig {
27
28     private final String moduleName;
29     private final InstanceConfig instanceConfig;
30
31     public ModuleConfig(final String moduleName, final InstanceConfig mbeanMapping) {
32         this.moduleName = moduleName;
33         this.instanceConfig = mbeanMapping;
34     }
35
36     public Element toXml(final ObjectName instanceON, final Document document, final String namespace,
37             final EnumResolver enumResolver) {
38         final Optional<String> configNs = Optional
39                 .of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
40         Element root = XmlUtil.createElement(document, XmlMappingConstants.MODULE_KEY, configNs);
41
42         // type belongs to config.yang namespace, but needs to be <type
43         // prefix:moduleNS>prefix:moduleName</type>
44
45         Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY,
46                 XmlMappingConstants.PREFIX, namespace, moduleName, configNs);
47
48         root.appendChild(typeElement);
49         // name belongs to config.yang namespace
50         String instanceName = ObjectNameUtil.getInstanceName(instanceON);
51         Element nameElement = XmlUtil.createTextElement(document, XmlMappingConstants.NAME_KEY, instanceName, configNs);
52
53         root.appendChild(nameElement);
54
55         root = instanceConfig.toXml(instanceON, namespace, document, root, enumResolver);
56
57         return root;
58     }
59
60     public ModuleElementResolved fromXml(final XmlElement moduleElement, final ServiceRegistryWrapper depTracker,
61             final String instanceName, final String moduleNamespace, final EditStrategyType defaultStrategy,
62             final Map<String, Map<Optional<Revision>, IdentityMapping>> identityMap, final EnumResolver enumResolver)
63             throws DocumentedException {
64
65         InstanceConfigElementResolved ice = instanceConfig.fromXml(moduleElement, depTracker, moduleNamespace,
66                 defaultStrategy, identityMap, enumResolver);
67         return new ModuleElementResolved(instanceName, ice);
68     }
69
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.