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