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
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
13 import org.opendaylight.controller.netconf.util.xml.XmlElement;
15 import javax.management.openmbean.OpenType;
16 import java.util.List;
18 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy<AttributeIfc> {
20 public SimpleAttributeReadingStrategy(AttributeIfc attributeIfc) {
25 * @param elementOpenType
27 public SimpleAttributeReadingStrategy(OpenType<?> elementOpenType) {
28 super(new AttributeIfcWrapper(elementOpenType));
32 AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
33 XmlElement xmlElement = configNodes.get(0);
34 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
35 + " but was " + configNodes.size());
37 String textContent = xmlElement.getTextContent();
39 Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
40 return AttributeConfigElement.create(getAttributeIfc(), textContent);
44 * Wrapper for JavaAttribute inner element attributes (in case JavaAttribute
47 static class AttributeIfcWrapper implements AttributeIfc {
49 private final OpenType<?> elementOpenType;
51 public AttributeIfcWrapper(OpenType<?> elementOpenType) {
52 this.elementOpenType = elementOpenType;
56 public String getAttributeYangName() {
61 public String getNullableDescription() {
66 public String getNullableDefault() {
71 public String getUpperCaseCammelCase() {
76 public String getLowerCaseCammelCase() {
81 public OpenType<?> getOpenType() {
82 return elementOpenType;