Class BindingReflections


  • public final class BindingReflections
    extends Object
    • Method Detail

      • findAugmentationTarget

        public static Class<? extends Augmentable<?>> findAugmentationTarget​(Class<? extends Augmentation<?>> augmentation)
        Find augmentation target class from concrete Augmentation class. This method uses first generic argument of implemented Augmentation interface.
        Parameters:
        augmentation - Augmentation subclass for which we want to determine augmentation target.
        Returns:
        Augmentation target - class which augmentation provides additional extensions.
      • findHierarchicalParent

        public static Class<?> findHierarchicalParent​(Class<? extends ChildOf<?>> childClass)
        Find data hierarchy parent from concrete Data class. This method uses first generic argument of implemented ChildOf interface.
        Parameters:
        childClass - child class for which we want to find the parent class.
        Returns:
        Parent class, e.g. class of which the childClass is ChildOf.
      • findHierarchicalParent

        public static Class<?> findHierarchicalParent​(DataObject child)
        Find data hierarchy parent from concrete Data class. This method is shorthand which gets DataObject class by invoking DataObject.implementedInterface() and uses findHierarchicalParent(Class).
        Parameters:
        child - Child object for which the parent needs to be located.
        Returns:
        Parent class, or null if a parent is not found.
      • findQName

        public static QName findQName​(Class<?> dataType)
        Returns a QName associated to supplied type.
        Parameters:
        dataType - Data type class
        Returns:
        QName associated to supplied dataType. If dataType is Augmentation method does not return canonical QName, but QName with correct namespace revision, but virtual local name, since augmentations do not have name. May return null if QName is not present.
      • isRpcMethod

        public static boolean isRpcMethod​(Method possibleMethod)
        Checks if method is RPC invocation.
        Parameters:
        possibleMethod - Method to check
        Returns:
        true if method is RPC invocation, false otherwise.
      • resolveRpcOutputClass

        public static Optional<Class<?>> resolveRpcOutputClass​(Method targetMethod)
        Extracts Output class for RPC method.
        Parameters:
        targetMethod - method to scan
        Returns:
        Optional.empty() if result type could not be get, or return type is Void.
      • resolveRpcInputClass

        public static Optional<Class<? extends DataContainer>> resolveRpcInputClass​(Method targetMethod)
        Extracts input class for RPC method.
        Parameters:
        targetMethod - method to scan
        Returns:
        Optional.empty() if RPC has no input, RPC input type otherwise.
      • isAugmentationChild

        public static boolean isAugmentationChild​(Class<?> clazz)
        Checks if class is child of augmentation.
      • getModelRootPackageName

        public static String getModelRootPackageName​(Package pkg)
        Returns root package name for supplied package.
        Parameters:
        pkg - Package for which find model root package.
        Returns:
        Package of model root.
      • getModelRootPackageName

        public static String getModelRootPackageName​(String name)
        Returns root package name for supplied package name.
        Parameters:
        name - Package for which find model root package.
        Returns:
        Package of model root.
      • getModuleInfo

        public static @NonNull YangModuleInfo getModuleInfo​(Class<?> cls)
        Returns instance of YangModuleInfo of declaring model for specific class.
        Parameters:
        cls - data object class
        Returns:
        Instance of YangModuleInfo associated with model, from which this class was derived.
      • getModuleInfoClassName

        public static @NonNull String getModuleInfoClassName​(String packageName)
      • isBindingClass

        public static boolean isBindingClass​(Class<?> cls)
        Check if supplied class is derived from YANG model.
        Parameters:
        cls - Class to check
        Returns:
        true if class is derived from YANG model.
      • isNotificationCallback

        public static boolean isNotificationCallback​(Method method)
        Checks if supplied method is callback for notifications.
        Parameters:
        method - method to check
        Returns:
        true if method is notification callback.
      • isNotification

        public static boolean isNotification​(Class<?> potentialNotification)
        Checks is supplied class is a Notification.
        Parameters:
        potentialNotification - class to examine
        Returns:
        True if the class represents a Notification.
      • isRpcType

        public static boolean isRpcType​(Class<? extends DataObject> targetType)
        Checks if supplied class represents RPC Input / RPC Output.
        Parameters:
        targetType - Class to be checked
        Returns:
        true if class represents RPC Input or RPC Output class.
      • getChildrenClasses

        public static Iterable<Class<? extends DataObject>> getChildrenClasses​(Class<? extends DataContainer> type)
        Scans supplied class and returns an iterable of all data children classes.
        Parameters:
        type - YANG Modeled Entity derived from DataContainer
        Returns:
        Iterable of all data children, which have YANG modeled entity
      • getChildrenClassToMethod

        public static Map<Class<?>,​Method> getChildrenClassToMethod​(Class<?> type)
        Scans supplied class and returns an iterable of all data children classes.
        Parameters:
        type - YANG Modeled Entity derived from DataContainer
        Returns:
        Iterable of all data children, which have YANG modeled entity
      • getChildrenClassToNonnullMethod

        @Beta
        public static Map<Class<?>,​Method> getChildrenClassToNonnullMethod​(Class<?> type)
      • getAugmentations

        @Deprecated(forRemoval=true)
        public static Map<Class<? extends Augmentation<?>>,​Augmentation<?>> getAugmentations​(Augmentable<?> input)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Extracts augmentation from Binding DTO field using reflection.
        Parameters:
        input - Instance of DataObject which is augmentable and may contain augmentation
        Returns:
        Map of augmentations if read was successful, otherwise empty map.
      • isSubstitutionFor

        public static boolean isSubstitutionFor​(Class potential,
                                                Class target)
        Determines if two augmentation classes or case classes represents same data.

        Two augmentations or cases could be substituted only if and if:

        • Both implements same interfaces
        • Both have same children
        • If augmentations: Both have same augmentation target class. Target class was generated for data node in grouping.
        • If cases: Both are from same choice. Choice class was generated for data node in grouping.

        Explanation: Binding Specification reuses classes generated for groupings as part of normal data tree, this classes from grouping could be used at various locations and user may not be aware of it and may use incorrect case or augmentation in particular subtree (via copy constructors, etc).

        Parameters:
        potential - Class which is potential substitution
        target - Class which should be used at particular subtree
        Returns:
        true if and only if classes represents same data.