Initial code drop of netconf protocol implementation
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / SimpleAttributeReadingStrategy.java
1 /*
2  * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.attributes.fromxml;
10
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;
14
15 import javax.management.openmbean.OpenType;
16 import java.util.List;
17
18 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy<AttributeIfc> {
19
20     public SimpleAttributeReadingStrategy(AttributeIfc attributeIfc) {
21         super(attributeIfc);
22     }
23
24     /**
25      * @param elementOpenType
26      */
27     public SimpleAttributeReadingStrategy(OpenType<?> elementOpenType) {
28         super(new AttributeIfcWrapper(elementOpenType));
29     }
30
31     @Override
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());
36
37         String textContent = xmlElement.getTextContent();
38
39         Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
40         return AttributeConfigElement.create(getAttributeIfc(), textContent);
41     }
42
43     /**
44      * Wrapper for JavaAttribute inner element attributes (in case JavaAttribute
45      * is array)
46      */
47     static class AttributeIfcWrapper implements AttributeIfc {
48
49         private final OpenType<?> elementOpenType;
50
51         public AttributeIfcWrapper(OpenType<?> elementOpenType) {
52             this.elementOpenType = elementOpenType;
53         }
54
55         @Override
56         public String getAttributeYangName() {
57             return null;
58         }
59
60         @Override
61         public String getNullableDescription() {
62             return null;
63         }
64
65         @Override
66         public String getNullableDefault() {
67             return null;
68         }
69
70         @Override
71         public String getUpperCaseCammelCase() {
72             return null;
73         }
74
75         @Override
76         public String getLowerCaseCammelCase() {
77             return null;
78         }
79
80         @Override
81         public OpenType<?> getOpenType() {
82             return elementOpenType;
83         }
84
85     }
86 }