2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
12 import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
14 import org.opendaylight.controller.netconf.util.xml.XmlElement;
15 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
17 import java.util.List;
19 public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReadingStrategy<AttributeIfc> {
21 public ObjectNameAttributeReadingStrategy(DependencyAttribute attributeIfc) {
26 AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
28 XmlElement firstChild = configNodes.get(0);
29 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild
30 + " but was " + configNodes.size());
32 Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild);
33 return AttributeConfigElement.create(getAttributeIfc(), resolve(firstChild));
36 private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) {
37 XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY);
38 String serviceName = typeElement.getTextContent();
39 XmlElement nameElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY);
40 String dependencyName = nameElement.getTextContent();
42 return new ObjectNameAttributeMappingStrategy.MappedDependency(serviceName, dependencyName);