X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Fmapping%2Fattributes%2Fmapping%2FSimpleAttributeMappingStrategy.java;h=782d2435505258ef8be9b348393e21e4e259f1f0;hb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;hp=9acc4dd1f6b7f65d5f4852ae3eeb9a8f3893cbbc;hpb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;p=controller.git diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java index 9acc4dd1f6..782d243550 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/mapping/SimpleAttributeMappingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -11,61 +11,61 @@ package org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; -import java.util.Date; import java.util.Map; import javax.management.openmbean.SimpleType; -import org.opendaylight.controller.config.facade.xml.util.Util; +import org.opendaylight.yangtools.yang.common.Revision; public class SimpleAttributeMappingStrategy extends AbstractAttributeMappingStrategy> { - public SimpleAttributeMappingStrategy(SimpleType openType) { + public SimpleAttributeMappingStrategy(final SimpleType openType) { super(openType); } @Override - public Optional mapAttribute(Object value) { - if (value == null){ + public Optional mapAttribute(final Object value) { + if (value == null) { return Optional.absent(); } String expectedClass = getOpenType().getClassName(); String realClass = value.getClass().getName(); - Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass - + " but was " + realClass); + Preconditions.checkArgument(realClass.equals(expectedClass), + "Type mismatch, expected " + expectedClass + " but was " + realClass); - WriterPlugin prefferedPlugin = writerPlugins.get(value.getClass().getCanonicalName()); - prefferedPlugin = prefferedPlugin == null ? writerPlugins.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin; + WriterPlugin prefferedPlugin = WRITER_PLUGINS.get(value.getClass().getCanonicalName()); + prefferedPlugin = prefferedPlugin == null ? WRITER_PLUGINS.get(DEFAULT_WRITER_PLUGIN) : prefferedPlugin; return Optional.of(prefferedPlugin.writeObject(value)); } private static final String DEFAULT_WRITER_PLUGIN = "default"; - private static final Map writerPlugins = Maps.newHashMap(); + private static final Map WRITER_PLUGINS = Maps.newHashMap(); + static { - writerPlugins.put(DEFAULT_WRITER_PLUGIN, new DefaultWriterPlugin()); - writerPlugins.put(Date.class.getCanonicalName(), new DatePlugin()); + WRITER_PLUGINS.put(DEFAULT_WRITER_PLUGIN, new DefaultWriterPlugin()); + WRITER_PLUGINS.put(Revision.class.getCanonicalName(), new RevisionPlugin()); } /** * Custom writer plugins must implement this interface. */ - static interface WriterPlugin { + interface WriterPlugin { String writeObject(Object value); } static class DefaultWriterPlugin implements WriterPlugin { @Override - public String writeObject(Object value) { + public String writeObject(final Object value) { return value.toString(); } } - static class DatePlugin implements WriterPlugin { + static class RevisionPlugin implements WriterPlugin { @Override - public String writeObject(Object value) { - Preconditions.checkArgument(value instanceof Date, "Attribute must be Date"); - return Util.writeDate((Date) value); + public String writeObject(final Object value) { + Preconditions.checkArgument(value instanceof Revision, "Attribute must be Date"); + return ((Revision) value).toString(); } }