Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / fromxml / AttributeConfigElement.java
1 /*
2  * Copyright (c) 2015, 2017 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.config.facade.xml.mapping.attributes.fromxml;
10
11 import com.google.common.base.Optional;
12 import javax.management.openmbean.OpenType;
13 import org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.AttributeResolvingStrategy;
14 import org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType;
15 import org.opendaylight.controller.config.util.xml.DocumentedException;
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 defaultValue;
23     private final Object value;
24     private final Optional<EditStrategyType> editStrategy;
25
26     private Optional<?> resolvedValue;
27     private Object resolvedDefaultValue;
28     private String jmxName;
29
30     public AttributeConfigElement(final Object defaultValue, final Object value,
31             final EditStrategyType editStrategyType) {
32         this.defaultValue = defaultValue;
33         this.value = value;
34         this.editStrategy = Optional.fromNullable(editStrategyType);
35     }
36
37     public void setJmxName(final String jmxName) {
38         this.jmxName = jmxName;
39     }
40
41     public String getJmxName() {
42         return jmxName;
43     }
44
45     public void resolveValue(final AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
46             final String attrName) throws DocumentedException {
47         resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
48         Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, defaultValue);
49         resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
50     }
51
52     public Optional<EditStrategyType> getEditStrategy() {
53         return editStrategy;
54     }
55
56     public static AttributeConfigElement create(final Object nullableDefault, final Object value) {
57         return new AttributeConfigElement(nullableDefault, value, null);
58     }
59
60     public static AttributeConfigElement create(final String nullableDefault, final Object value,
61             final EditStrategyType editStrategyType) {
62         return new AttributeConfigElement(nullableDefault, value, editStrategyType);
63     }
64
65     public static AttributeConfigElement createNullValue(final Object nullableDefault) {
66         return new AttributeConfigElement(nullableDefault, null, null);
67     }
68
69     public Object getValue() {
70         return value;
71     }
72
73     public Object getDefaultValue() {
74         return defaultValue;
75     }
76
77     public Optional<?> getResolvedValue() {
78         return resolvedValue;
79     }
80
81     public Object getResolvedDefaultValue() {
82         return resolvedDefaultValue;
83     }
84
85     @Override
86     public String toString() {
87         return "AttributeConfigElement [defaultValue=" + defaultValue + ", value=" + value + "]";
88     }
89 }