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