2 * Copyright (c) 2015 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(Object defaultValue, Object value, final EditStrategyType editStrategyType) {
31 this.defaultValue = defaultValue;
33 this.editStrategy = Optional.fromNullable(editStrategyType);
36 public void setJmxName(String jmxName) {
37 this.jmxName = jmxName;
40 public String getJmxName() {
44 public void resolveValue(AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
45 String attrName) throws DocumentedException {
46 resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
47 Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, defaultValue);
48 resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
51 public Optional<EditStrategyType> getEditStrategy() {
55 public static AttributeConfigElement create(Object nullableDefault, Object value) {
56 return new AttributeConfigElement(nullableDefault, value, null);
59 public static AttributeConfigElement createNullValue(Object nullableDefault) {
60 return new AttributeConfigElement(nullableDefault, null, null);
63 public static AttributeConfigElement create(final String nullableDefault, final Object value, final EditStrategyType editStrategyType) {
64 return new AttributeConfigElement(nullableDefault, value, editStrategyType);
67 public Object getValue() {
71 public Object getDefaultValue() {
75 public Optional<?> getResolvedValue() {
79 public Object getResolvedDefaultValue() {
80 return resolvedDefaultValue;
84 public String toString() {
85 return "AttributeConfigElement [defaultValue=" + defaultValue + ", value=" + value + "]";