2 * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml;
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;
18 * Parsed xml element containing configuration for one attribute of an instance
19 * of some module. Contains default value extracted from yang file.
21 public class AttributeConfigElement {
22 private final Object defaultValue;
23 private final Object value;
24 private final Optional<EditStrategyType> editStrategy;
26 private Optional<?> resolvedValue;
27 private Object resolvedDefaultValue;
28 private String jmxName;
30 public AttributeConfigElement(final Object defaultValue, final Object value,
31 final EditStrategyType editStrategyType) {
32 this.defaultValue = defaultValue;
34 this.editStrategy = Optional.fromNullable(editStrategyType);
37 public void setJmxName(final String jmxName) {
38 this.jmxName = jmxName;
41 public String getJmxName() {
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;
52 public Optional<EditStrategyType> getEditStrategy() {
56 public static AttributeConfigElement create(final Object nullableDefault, final Object value) {
57 return new AttributeConfigElement(nullableDefault, value, null);
60 public static AttributeConfigElement create(final String nullableDefault, final Object value,
61 final EditStrategyType editStrategyType) {
62 return new AttributeConfigElement(nullableDefault, value, editStrategyType);
65 public static AttributeConfigElement createNullValue(final Object nullableDefault) {
66 return new AttributeConfigElement(nullableDefault, null, null);
69 public Object getValue() {
73 public Object getDefaultValue() {
77 public Optional<?> getResolvedValue() {
81 public Object getResolvedDefaultValue() {
82 return resolvedDefaultValue;
86 public String toString() {
87 return "AttributeConfigElement [defaultValue=" + defaultValue + ", value=" + value + "]";