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 / resolving / SimpleAttributeResolvingStrategy.java
index 6c53b80872cc7715f0e444f1084fe0e3662bd2c0..9a42e93d2ef972d5659077bff12055b56069544a 100644 (file)
@@ -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,
@@ -27,7 +27,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
 
     private static final Logger LOG = LoggerFactory.getLogger(SimpleAttributeResolvingStrategy.class);
 
-    SimpleAttributeResolvingStrategy(SimpleType<?> simpleType) {
+    SimpleAttributeResolvingStrategy(final SimpleType<?> simpleType) {
         super(simpleType);
     }
 
@@ -37,7 +37,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     }
 
     @Override
-    public Optional<Object> parseAttribute(String attrName, Object value) throws DocumentedException {
+    public Optional<Object> parseAttribute(final String attrName, final Object value) throws DocumentedException {
         if (value == null) {
             return Optional.absent();
         }
@@ -45,14 +45,14 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
         Class<?> cls;
         try {
             cls = Class.forName(getOpenType().getClassName());
-        } catch (ClassNotFoundException e) {
+        } catch (final ClassNotFoundException e) {
             throw new RuntimeException("Unable to locate class for " + getOpenType().getClassName(), e);
         }
 
         Util.checkType(value, String.class);
 
-        Resolver prefferedPlugin = resolverPlugins.get(cls.getCanonicalName());
-        prefferedPlugin = prefferedPlugin == null ? resolverPlugins.get(DEFAULT_RESOLVERS) : prefferedPlugin;
+        Resolver prefferedPlugin = RESOLVER_PLUGINS.get(cls.getCanonicalName());
+        prefferedPlugin = prefferedPlugin == null ? RESOLVER_PLUGINS.get(DEFAULT_RESOLVERS) : prefferedPlugin;
 
         Object parsedValue = prefferedPlugin.resolveObject(cls, attrName, (String) value);
         LOG.debug("Attribute {} : {} parsed to type {} with value {}", attrName, value, getOpenType(), parsedValue);
@@ -60,15 +60,15 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     }
 
     private static final String DEFAULT_RESOLVERS = "default";
-    private static final Map<String, Resolver> resolverPlugins = Maps.newHashMap();
+    private static final Map<String, Resolver> RESOLVER_PLUGINS = Maps.newHashMap();
 
     static {
-        resolverPlugins.put(DEFAULT_RESOLVERS, new DefaultResolver());
-        resolverPlugins.put(String.class.getCanonicalName(), new StringResolver());
-        resolverPlugins.put(Date.class.getCanonicalName(), new DateResolver());
-        resolverPlugins.put(Character.class.getCanonicalName(), new CharResolver());
-        resolverPlugins.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver());
-        resolverPlugins.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver());
+        RESOLVER_PLUGINS.put(DEFAULT_RESOLVERS, new DefaultResolver());
+        RESOLVER_PLUGINS.put(String.class.getCanonicalName(), new StringResolver());
+        RESOLVER_PLUGINS.put(Date.class.getCanonicalName(), new DateResolver());
+        RESOLVER_PLUGINS.put(Character.class.getCanonicalName(), new CharResolver());
+        RESOLVER_PLUGINS.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver());
+        RESOLVER_PLUGINS.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver());
     }
 
     interface Resolver {
@@ -78,28 +78,26 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     static class DefaultResolver implements Resolver {
 
         @Override
-        public Object resolveObject(Class<?> type, String attrName, String value) throws DocumentedException {
+        public Object resolveObject(final Class<?> type, final String attrName, final String value)
+                throws DocumentedException {
             try {
                 return parseObject(type, value);
-            } catch (Exception e) {
+            } catch (final DocumentedException e) {
                 throw new DocumentedException("Unable to resolve attribute " + attrName + " from " + value,
-                        DocumentedException.ErrorType.application,
-                        DocumentedException.ErrorTag.operation_failed,
-                        DocumentedException.ErrorSeverity.error);
+                        DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
+                        DocumentedException.ErrorSeverity.ERROR);
             }
         }
 
-        protected Object parseObject(Class<?> type, String value) throws DocumentedException {
+        protected Object parseObject(final Class<?> type, final String value) throws DocumentedException {
             Method method = null;
             try {
                 method = type.getMethod("valueOf", String.class);
                 return method.invoke(null, value);
             } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
-                LOG.trace("Error parsing object ",e);
-                throw new DocumentedException("Error parsing object.",
-                        DocumentedException.ErrorType.application,
-                        DocumentedException.ErrorTag.operation_failed,
-                        DocumentedException.ErrorSeverity.error);
+                LOG.trace("Error parsing object ", e);
+                throw new DocumentedException("Error parsing object.", DocumentedException.ErrorType.APPLICATION,
+                        DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR);
             }
         }
     }
@@ -107,7 +105,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     static class StringResolver extends DefaultResolver {
 
         @Override
-        protected Object parseObject(Class<?> type, String value) {
+        protected Object parseObject(final Class<?> type, final String value) {
             return value;
         }
     }
@@ -115,7 +113,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     static class BigIntegerResolver extends DefaultResolver {
 
         @Override
-        protected Object parseObject(Class<?> type, String value) {
+        protected Object parseObject(final Class<?> type, final String value) {
             return new BigInteger(value);
         }
     }
@@ -123,7 +121,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     static class BigDecimalResolver extends DefaultResolver {
 
         @Override
-        protected Object parseObject(Class<?> type, String value) {
+        protected Object parseObject(final Class<?> type, final String value) {
             return new BigDecimal(value);
         }
     }
@@ -131,24 +129,22 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
     static class CharResolver extends DefaultResolver {
 
         @Override
-        protected Object parseObject(Class<?> type, String value)  {
+        protected Object parseObject(final Class<?> type, final String value) {
             return value.charAt(0);
         }
     }
 
     static class DateResolver extends DefaultResolver {
         @Override
-        protected Object parseObject(Class<?> type, String value) throws DocumentedException {
+        protected Object parseObject(final Class<?> type, final String value) throws DocumentedException {
             try {
                 return Util.readDate(value);
-            } catch (ParseException e) {
-                LOG.trace("Unable parse value {} due to ",value, e);
-                throw new DocumentedException("Unable to parse value "+value+" as date.",
-                        DocumentedException.ErrorType.application,
-                        DocumentedException.ErrorTag.operation_failed,
-                        DocumentedException.ErrorSeverity.error);
+            } catch (final ParseException e) {
+                LOG.trace("Unable parse value {} due to ", value, e);
+                throw new DocumentedException("Unable to parse value " + value + " as date.",
+                        DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
+                        DocumentedException.ErrorSeverity.ERROR);
             }
         }
     }
-
 }