fa249da7f2c81d98d27d2940c17c314bec8dc55e
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / AttributeConfigElement.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 javax.management.openmbean.OpenType;
12
13 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
14 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving.AttributeResolvingStrategy;
15
16 import com.google.common.base.Optional;
17
18 /**
19  * Parsed xml element containing configuration for one attribute of an instance
20  * of some module. Contains default value extracted from yang file.
21  */
22 public class AttributeConfigElement {
23     private final Object dafaultValue;
24     private final Object value;
25
26     private Optional<?> resolvedValue;
27     private Object resolvedDefaultValue;
28     private String jmxName;
29
30     public AttributeConfigElement(Object dafaultValue, Object value) {
31         this.dafaultValue = dafaultValue;
32         this.value = value;
33     }
34
35     public void setJmxName(String jmxName) {
36         this.jmxName = jmxName;
37     }
38
39     public String getJmxName() {
40         return jmxName;
41     }
42
43     public void resolveValue(AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
44             String attrName) {
45         resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
46         Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, dafaultValue);
47         resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
48
49     }
50
51     public static AttributeConfigElement create(AttributeIfc attributeIfc, Object value) {
52         return new AttributeConfigElement(attributeIfc.getNullableDefault(), value);
53     }
54
55     public static AttributeConfigElement createNullValue(AttributeIfc attributeIfc) {
56         return new AttributeConfigElement(attributeIfc.getNullableDefault(), null);
57     }
58
59     public Object getValue() {
60         return value;
61     }
62
63     public Optional<?> getResolvedValue() {
64         return resolvedValue;
65     }
66
67     public Object getResolvedDefaultValue() {
68         return resolvedDefaultValue;
69     }
70
71     @Override
72     public String toString() {
73         return "AttributeConfigElement [dafaultValue=" + dafaultValue + ", value=" + value + "]";
74     }
75
76 }