Removed sonar warnings. 34/48034/9
authorDana Kutenicsova <dana.kutenics@gmail.com>
Thu, 13 Oct 2016 16:34:52 +0000 (18:34 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 21 Nov 2016 08:30:14 +0000 (08:30 +0000)
Change-Id: I2dbe2018cc1d2672f98fd3aea9e01c7d851eacc8
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BaseIdentity.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingMapping.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingStreamEventWriter.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/KeyedInstanceIdentifier.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/AugmentationFieldGetter.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/BindingReflections.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtil.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/NotificationListenerInvoker.java

index 9f55b64d52201e232f1de572fa56b53ecadd3725..fec92f24972d500fc0e3c4fcb4dd0dc7000bd729 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.yangtools.yang.binding;
 
 /**
  * Base Identity
- * 
+ *
  */
 public abstract class BaseIdentity {
 
-    public final static BaseIdentity INSTANCE = new BaseIdentity() {
+    public static final BaseIdentity INSTANCE = new BaseIdentity() {
     };
 
     protected BaseIdentity() {
index 5a73217066f8a0eb14b9d445bd1f42d6f27795ed..72f63cc060aacbdfd2c1ccbc9557bd695de21445 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.binding;
 
 import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableSet;
@@ -162,7 +161,7 @@ public final class BindingMapping {
     public static String getGetterSuffix(final QName name) {
         checkArgument(name != null, "Name should not be null.");
         final String candidate = toFirstUpper(toCamelCase(name.getLocalName()));
-        return ("Class".equals(candidate) ? "XmlClass" : candidate);
+        return "Class".equals(candidate) ? "XmlClass" : candidate;
     }
 
     public static String getPropertyName(final String yangIdentifier) {
index 8215f164210a731ccc019bfcb9b82fd8694363e2..cd943e94009302ddad9c4b13fca930de12626e0e 100644 (file)
@@ -123,7 +123,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void leafNode(String localName, Object value) throws IOException, IllegalArgumentException;
+    void leafNode(String localName, Object value) throws IOException;
 
     /**
      *
@@ -149,7 +149,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startLeafSet(String localName, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startLeafSet(String localName, int childSizeHint) throws IOException;
 
     /**
      *
@@ -175,7 +175,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startOrderedLeafSet(String localName, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startOrderedLeafSet(String localName, int childSizeHint) throws IOException;
 
     /**
      * Emits a leaf set entry node
@@ -188,7 +188,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             If node was emitted outside <code>leaf set</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException;
+    void leafSetEntryNode(Object value) throws IOException;
 
     /**
      *
@@ -225,7 +225,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startContainerNode(Class<? extends DataObject> container, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startContainerNode(Class<? extends DataObject> container, int childSizeHint) throws IOException;
 
     /**
      *
@@ -252,7 +252,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startUnkeyedList(Class<? extends DataObject> localName, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startUnkeyedList(Class<? extends DataObject> localName, int childSizeHint) throws IOException;
 
     /**
      * Emits start of new unkeyed list item.
@@ -283,7 +283,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             If node was emitted outside <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startUnkeyedListItem(int childSizeHint) throws IOException, IllegalStateException;
+    void startUnkeyedListItem(int childSizeHint) throws IOException;
 
     /**
      *
@@ -308,7 +308,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      * @throws IOException if an underlying IO error occurs
      */
     <T extends DataObject & Identifiable<?>> void startMapNode(Class<T> mapEntryType, int childSizeHint)
-            throws IOException, IllegalArgumentException;
+            throws IOException;
 
     /**
      *
@@ -333,7 +333,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      * @throws IOException if an underlying IO error occurs
      */
     <T extends DataObject & Identifiable<?>> void startOrderedMapNode(Class<T> mapEntryType, int childSizeHint)
-           throws IOException, IllegalArgumentException;
+            throws IOException;
 
     /**
      *
@@ -367,7 +367,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             If node was emitted outside <code>map entry</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startMapEntryNode(Identifier<?> keyValues, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startMapEntryNode(Identifier<?> keyValues, int childSizeHint) throws IOException;
 
     /**
      * Emits start of choice node.
@@ -389,7 +389,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startChoiceNode(Class<? extends DataContainer> choice, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startChoiceNode(Class<? extends DataContainer> choice, int childSizeHint) throws IOException;
 
     /**
      *
@@ -411,7 +411,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      * @throws IllegalArgumentException
      * @throws IOException if an underlying IO error occurs
      */
-    void startCase(Class<? extends DataObject> caze, int childSizeHint) throws IOException, IllegalArgumentException;
+    void startCase(Class<? extends DataObject> caze, int childSizeHint) throws IOException;
 
     /**
      * Emits start of augmentation node.
@@ -440,7 +440,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             If augmentation is invalid in current context.
      * @throws IOException if an underlying IO error occurs
      */
-    void startAugmentationNode(Class<? extends Augmentation<?>> augmentationType) throws IOException, IllegalArgumentException;
+    void startAugmentationNode(Class<? extends Augmentation<?>> augmentationType) throws IOException;
 
     /**
      * Emits anyxml node event.
@@ -453,7 +453,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      *             <code>choice</code> <code>unkeyed list</code> node.
      * @throws IOException if an underlying IO error occurs
      */
-    void anyxmlNode(String name, Object value) throws IOException, IllegalArgumentException;
+    void anyxmlNode(String name, Object value) throws IOException;
 
     /**
      * Emits end event for node.
@@ -461,8 +461,7 @@ public interface BindingStreamEventWriter extends Closeable, Flushable {
      * @throws IllegalStateException If there is no open node.
      * @throws IOException if an underlying IO error occurs
      */
-    void endNode() throws IOException, IllegalStateException;
-
+    void endNode() throws IOException;
     @Override
     void flush() throws IOException;
 
index 240b5036e44531c43a99502cc4146e790b496994..cde6f7f1d8b9cb14e4c90af8e0c2794b9cde472b 100644 (file)
@@ -209,7 +209,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
         for (final PathArgument a : pathArguments) {
             if (type.equals(a.getType())) {
                 @SuppressWarnings("unchecked")
-                final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(Iterables.limit(pathArguments, i));
+                final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(
+                        Iterables.limit(pathArguments, i));
                 return ret;
             }
 
@@ -334,7 +335,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @return A builder instance
      */
     public InstanceIdentifierBuilder<T> builder() {
-        return new InstanceIdentifierBuilderImpl<T>(new Item<T>(targetType), pathArguments, hash, isWildcarded());
+        return new InstanceIdentifierBuilderImpl<>(new Item<T>(targetType), pathArguments, hash, isWildcarded());
     }
 
     private InstanceIdentifier<?> childIdentifier(final PathArgument arg) {
@@ -532,7 +533,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
         Class<? extends DataObject> getType();
     }
 
-    private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
+    private abstract static class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
         private static final long serialVersionUID = 1L;
         private final Class<T> type;
 
index a69b98879fffece20cf415fc1e006df3dbb99150..2710ee07388daf8fdf825491e6bbee7ff594284f 100644 (file)
@@ -35,7 +35,7 @@ public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K e
 
     @Override
     public final InstanceIdentifierBuilder<T> builder() {
-        return new InstanceIdentifierBuilderImpl<T>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), pathArguments, hashCode(), isWildcarded());
+        return new InstanceIdentifierBuilderImpl<>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), pathArguments, hashCode(), isWildcarded());
     }
 
     @Override
index cfec5c36668a8f0afa5e600007317384f33dced2..448a4616f2688963f14be70af7192f593e7e30b9 100644 (file)
@@ -44,6 +44,9 @@ abstract class AugmentationFieldGetter {
         }
     };
 
+    private static final LoadingCache<Class<?>, AugmentationFieldGetter> AUGMENTATION_GETTERS = CacheBuilder.newBuilder().weakKeys().build(
+            new AugmentationGetterLoader());
+
     /**
      *
      * Retrieves augmentations from supplied object
@@ -53,9 +56,6 @@ abstract class AugmentationFieldGetter {
      */
     protected abstract Map<Class<? extends Augmentation<?>>, Augmentation<?>> getAugmentations(final Object input);
 
-    private static final LoadingCache<Class<?>, AugmentationFieldGetter> AUGMENTATION_GETTERS = CacheBuilder
-            .newBuilder().weakKeys().build(new AugmentationGetterLoader());
-
     public static AugmentationFieldGetter getGetter(final Class<? extends Object> clz) {
         if(AugmentationHolder.class.isAssignableFrom(clz)) {
             return AUGMENTATION_HOLDER_GETTER;
index a11c5a4bc04f07ed285c9533e8e8b1ef1bdcca3d..789f9542ee4a051e3e85db114ba28e56f0e7705a 100644 (file)
@@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
 import com.google.common.collect.Sets;
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.net.URI;
@@ -274,14 +273,10 @@ public class BindingReflections {
         checkArgument(cls != null);
         String packageName = getModelRootPackageName(cls.getPackage());
         final String potentialClassName = getModuleInfoClassName(packageName);
-        return ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Callable<YangModuleInfo>() {
-            @Override
-            public YangModuleInfo call() throws ClassNotFoundException, IllegalAccessException,
-                    IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
-                Class<?> moduleInfoClass = Thread.currentThread().getContextClassLoader().loadClass(potentialClassName);
-                return (YangModuleInfo) moduleInfoClass.getMethod("getInstance").invoke(null);
-            }
-        });
+        return ClassLoaderUtils.withClassLoader(cls.getClassLoader(), (Callable<YangModuleInfo>) () -> {
+            Class<?> moduleInfoClass = Thread.currentThread().getContextClassLoader().loadClass(potentialClassName);
+            return (YangModuleInfo) moduleInfoClass.getMethod("getInstance").invoke(null);
+         });
     }
 
     public static String getModuleInfoClassName(final String packageName) {
@@ -300,7 +295,7 @@ public class BindingReflections {
         if (DataContainer.class.isAssignableFrom(cls) || Augmentation.class.isAssignableFrom(cls)) {
             return true;
         }
-        return (cls.getName().startsWith(BindingMapping.PACKAGE_PREFIX));
+        return cls.getName().startsWith(BindingMapping.PACKAGE_PREFIX);
     }
 
     /**
@@ -446,9 +441,9 @@ public class BindingReflections {
         return ret;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     private static Optional<Class<? extends DataContainer>> getYangModeledReturnType(final Method method) {
-        if (method.getName().equals("getClass") || !method.getName().startsWith("get")
+        if ("getClass".equals(method.getName()) || !method.getName().startsWith("get")
                 || method.getParameterTypes().length > 0) {
             return Optional.absent();
         }
@@ -460,19 +455,13 @@ public class BindingReflections {
         } else if (List.class.isAssignableFrom(returnType)) {
             try {
                 return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(),
-                        new Callable<Optional<Class<? extends DataContainer>>>() {
-                            @SuppressWarnings("rawtypes")
-                            @Override
-                            public Optional<Class<? extends DataContainer>> call() {
-                                Type listResult = ClassLoaderUtils.getFirstGenericParameter(method
-                                        .getGenericReturnType());
-                                if (listResult instanceof Class
-                                        && DataContainer.class.isAssignableFrom((Class) listResult)) {
-                                    return Optional.<Class<? extends DataContainer>> of((Class) listResult);
-                                }
-                                return Optional.absent();
+                        (Callable<Optional<Class<? extends DataContainer>>>) () -> {
+                            Type listResult = ClassLoaderUtils.getFirstGenericParameter(method.getGenericReturnType());
+                            if (listResult instanceof Class
+                                    && DataContainer.class.isAssignableFrom((Class) listResult)) {
+                                return Optional.<Class<? extends DataContainer>> of((Class) listResult);
                             }
-
+                            return Optional.absent();
                         });
             } catch (Exception e) {
                 /*
@@ -493,97 +482,93 @@ public class BindingReflections {
         public Optional<QName> load(final Class<?> key) throws Exception {
             return resolveQNameNoCache(key);
         }
-    }
 
-    /**
-     *
-     * Tries to resolve QName for supplied class.
-     *
-     * Looks up for static field with name from constant
-     * {@link BindingMapping#QNAME_STATIC_FIELD_NAME} and returns value if
-     * present.
-     *
-     * If field is not present uses {@link #computeQName(Class)} to compute
-     * QName for missing types.
-     *
-     * @param key
-     * @return
-     */
-    private static Optional<QName> resolveQNameNoCache(final Class<?> key) {
-        try {
-            Field field = key.getField(BindingMapping.QNAME_STATIC_FIELD_NAME);
-            Object obj = field.get(null);
-            if (obj instanceof QName) {
-                return Optional.of((QName) obj);
-            }
+        /**
+         *
+         * Tries to resolve QName for supplied class.
+         *
+         * Looks up for static field with name from constant {@link BindingMapping#QNAME_STATIC_FIELD_NAME} and returns
+         * value if present.
+         *
+         * If field is not present uses {@link #computeQName(Class)} to compute QName for missing types.
+         *
+         * @param key
+         * @return
+         */
+        private static Optional<QName> resolveQNameNoCache(final Class<?> key) {
+            try {
+                Field field = key.getField(BindingMapping.QNAME_STATIC_FIELD_NAME);
+                Object obj = field.get(null);
+                if (obj instanceof QName) {
+                    return Optional.of((QName) obj);
+                }
 
-        } catch (NoSuchFieldException e) {
-            return Optional.of(computeQName(key));
-
-        } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
-            /*
-             *
-             * It is safe to log this this exception on debug, since this method
-             * should not fail. Only failures are possible if the runtime /
-             * backing.
-             */
-            LOG.debug("Unexpected exception during extracting QName for {}", key, e);
-        }
-        return Optional.absent();
-    }
+            } catch (NoSuchFieldException e) {
+                return Optional.of(computeQName(key));
 
-    /**
-     * Computes QName for supplied class
-     *
-     * Namespace and revision are same as {@link YangModuleInfo} associated with
-     * supplied class.
-     * <p>
-     * If class is
-     * <ul>
-     * <li>rpc input: local name is "input".
-     * <li>rpc output: local name is "output".
-     * <li>augmentation: local name is "module name".
-     * </ul>
-     *
-     * There is also fallback, if it is not possible to compute QName using
-     * following algorithm returns module QName.
-     *
-     * FIXME: Extend this algorithm to also provide QName for YANG modeled
-     * simple types.
-     *
-     * @throws IllegalStateException
-     *             If YangModuleInfo could not be resolved
-     * @throws IllegalArgumentException
-     *             If supplied class was not derived from YANG model.
-     *
-     */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    private static QName computeQName(final Class key) {
-        if (isBindingClass(key)) {
-            YangModuleInfo moduleInfo;
-            try {
-                moduleInfo = getModuleInfo(key);
-            } catch (Exception e) {
-                throw new IllegalStateException("Unable to get QName for " + key + ". YangModuleInfo was not found.", e);
+            } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
+                /*
+                 *
+                 * It is safe to log this this exception on debug, since this method
+                 * should not fail. Only failures are possible if the runtime /
+                 * backing.
+                 */
+                LOG.debug("Unexpected exception during extracting QName for {}", key, e);
             }
-            final QName module = getModuleQName(moduleInfo).intern();
-            if (Augmentation.class.isAssignableFrom(key)) {
-                return module;
-            } else if (isRpcType(key)) {
-                final String className = key.getSimpleName();
-                if (className.endsWith(BindingMapping.RPC_OUTPUT_SUFFIX)) {
-                    return QName.create(module, "output").intern();
-                } else {
-                    return QName.create(module, "input").intern();
+            return Optional.absent();
+        }
+
+        /**
+         * Computes QName for supplied class
+         *
+         * Namespace and revision are same as {@link YangModuleInfo} associated with supplied class.
+         * <p>
+         * If class is
+         * <ul>
+         * <li>rpc input: local name is "input".
+         * <li>rpc output: local name is "output".
+         * <li>augmentation: local name is "module name".
+         * </ul>
+         *
+         * There is also fallback, if it is not possible to compute QName using following algorithm returns module
+         * QName.
+         *
+         * FIXME: Extend this algorithm to also provide QName for YANG modeled simple types.
+         *
+         * @throws IllegalStateException If YangModuleInfo could not be resolved
+         * @throws IllegalArgumentException If supplied class was not derived from YANG model.
+         *
+         */
+        @SuppressWarnings({ "rawtypes", "unchecked" })
+        private static QName computeQName(final Class key) {
+            if (isBindingClass(key)) {
+                YangModuleInfo moduleInfo;
+                try {
+                    moduleInfo = getModuleInfo(key);
+                } catch (Exception e) {
+                    throw new IllegalStateException("Unable to get QName for " + key
+                            + ". YangModuleInfo was not found.", e);
                 }
+                final QName module = getModuleQName(moduleInfo).intern();
+                if (Augmentation.class.isAssignableFrom(key)) {
+                    return module;
+                } else if (isRpcType(key)) {
+                    final String className = key.getSimpleName();
+                    if (className.endsWith(BindingMapping.RPC_OUTPUT_SUFFIX)) {
+                        return QName.create(module, "output").intern();
+                    } else {
+                        return QName.create(module, "input").intern();
+                    }
+                }
+                /*
+                 * Fallback for Binding types which do not have QNAME field
+                 */
+                return module;
+            } else {
+                throw new IllegalArgumentException("Supplied class " + key + "is not derived from YANG.");
             }
-            /*
-             * Fallback for Binding types which do not have QNAME field
-             */
-            return module;
-        } else {
-            throw new IllegalArgumentException("Supplied class " + key + "is not derived from YANG.");
         }
+
     }
 
     /**
index f4fcf71359e0e63754fec9210d982150b1482c28..1cdd9e4faa76f9965be08c51dc2b7e21ad099275 100644 (file)
@@ -33,6 +33,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
 public class DataObjectReadingUtil {
 
+    private static final DataObjectReadingStrategy REAUSABLE_AUGMENTATION_READING_STRATEGY = new AugmentationReadingStrategy();
+
     private DataObjectReadingUtil() {
         throw new UnsupportedOperationException("Utility class. Instantion is not allowed.");
     }
@@ -103,9 +105,8 @@ public class DataObjectReadingUtil {
     private static DataObjectReadingStrategy resolveReadStrategy(final Class<? extends DataContainer> parentClass,
             final Class<? extends DataContainer> type) {
 
-        DataObjectReadingStrategy strategy = createReadStrategy(parentClass, type);
         // FIXME: Add caching of strategies
-        return strategy;
+        return createReadStrategy(parentClass, type);
     }
 
     private static DataObjectReadingStrategy createReadStrategy(final Class<? extends DataContainer> parent,
@@ -128,19 +129,8 @@ public class DataObjectReadingUtil {
         return new ContainerReadingStrategy(parent, child);
     }
 
-    private static Method resolveGetterMethod(final Class<? extends DataContainer> parent, final Class<?> child) {
-        String methodName = "get" + child.getSimpleName();
-        try {
-            return parent.getMethod(methodName);
-        } catch (NoSuchMethodException e) {
-            throw new IllegalArgumentException(e);
-        } catch (SecurityException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
     @SuppressWarnings("rawtypes")
-    private static abstract class DataObjectReadingStrategy {
+    private abstract static class DataObjectReadingStrategy {
 
         private final Class<? extends DataContainer> parentType;
         private final Class<? extends DataContainer> childType;
@@ -181,6 +171,17 @@ public class DataObjectReadingUtil {
 
         public abstract DataContainer read(DataContainer parent, Class<?> childType);
 
+        private static Method resolveGetterMethod(final Class<? extends DataContainer> parent, final Class<?> child) {
+            String methodName = "get" + child.getSimpleName();
+            try {
+                return parent.getMethod(methodName);
+            } catch (NoSuchMethodException e) {
+                throw new IllegalArgumentException(e);
+            } catch (SecurityException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
     }
 
     @SuppressWarnings("rawtypes")
@@ -245,11 +246,7 @@ public class DataObjectReadingUtil {
                         return readAll(dataList, builder);
                     }
                 }
-            } catch (InvocationTargetException e) {
-                throw new IllegalStateException(e);
-            } catch (IllegalAccessException e) {
-                throw new IllegalStateException(e);
-            } catch (IllegalArgumentException e) {
+            } catch (InvocationTargetException | IllegalArgumentException | IllegalAccessException e) {
                 throw new IllegalStateException(e);
             }
             return Collections.emptyMap();
@@ -285,8 +282,6 @@ public class DataObjectReadingUtil {
 
     }
 
-    private static final DataObjectReadingStrategy REAUSABLE_AUGMENTATION_READING_STRATEGY = new AugmentationReadingStrategy();
-
     private static final class AugmentationReadingStrategy extends DataObjectReadingStrategy {
 
         public AugmentationReadingStrategy() {
index 3476d34027f3acb6b1abe2a48ce35657c31a44b1..9ce933fcb04121751e98efb1f38eaba4a8460c5e 100644 (file)
@@ -41,6 +41,32 @@ public final class NotificationListenerInvoker {
             .newBuilder().weakKeys()
             .build(new CacheLoader<Class<? extends NotificationListener>, NotificationListenerInvoker>() {
 
+                private NotificationListenerInvoker createInvoker(
+                        final Class<? extends NotificationListener> key) {
+                    return new NotificationListenerInvoker(createInvokerMap(key));
+                }
+
+                private Map<QName, MethodHandle> createInvokerMap(final Class<? extends NotificationListener> key) {
+                    final Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle> builder();
+                    for (final Method method : key.getMethods()) {
+                        if (BindingReflections.isNotificationCallback(method)) {
+
+                            final Class<?> notification = method.getParameterTypes()[0];
+                            final QName name = BindingReflections.findQName(notification);
+                            MethodHandle handle;
+                            try {
+                                handle = LOOKUP.unreflect(method).asType(MethodType.methodType(void.class,
+                                        NotificationListener.class, DataContainer.class));
+                                ret.put(name, handle);
+                            } catch (final IllegalAccessException e) {
+                                throw new IllegalStateException("Can not access public method.", e);
+                            }
+                        }
+
+                    }
+                    return ret.build();
+                }
+
                 @Override
                 public NotificationListenerInvoker load(final Class<? extends NotificationListener> key) throws Exception {
                     return createInvoker(key);
@@ -94,29 +120,4 @@ public final class NotificationListenerInvoker {
         }
     }
 
-    private static NotificationListenerInvoker createInvoker(final Class<? extends NotificationListener> key) {
-        return new NotificationListenerInvoker(createInvokerMap(key));
-    }
-
-    private static Map<QName, MethodHandle> createInvokerMap(final Class<? extends NotificationListener> key) {
-        final Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle>builder();
-        for (final Method method : key.getMethods()) {
-            if (BindingReflections.isNotificationCallback(method)) {
-
-                final Class<?> notification = method.getParameterTypes()[0];
-                final QName name = BindingReflections.findQName(notification);
-                MethodHandle handle;
-                try {
-                    handle = LOOKUP.unreflect(method).asType(
-                            MethodType.methodType(void.class, NotificationListener.class, DataContainer.class));
-                    ret.put(name, handle);
-                } catch (final IllegalAccessException e) {
-                    throw new IllegalStateException("Can not access public method.", e);
-                }
-            }
-
-        }
-        return ret.build();
-    }
-
 }