Class BindingReflections
- java.lang.Object
-
- org.opendaylight.mdsal.binding.spec.reflect.BindingReflections
-
public final class BindingReflections extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static @NonNull ImmutableSet<YangModuleInfo>
cacheModuleInfos(ClassLoader loader)
LoadsYangModuleInfo
instances available on suppliedClassLoader
, assuming the set of available information does not change.static Class<? extends Augmentable<?>>
findAugmentationTarget(Class<? extends Augmentation<?>> augmentation)
Find augmentation target class from concrete Augmentation class.static Class<?>
findHierarchicalParent(Class<? extends ChildOf<?>> childClass)
Find data hierarchy parent from concrete Data class.static Class<?>
findHierarchicalParent(DataObject child)
Find data hierarchy parent from concrete Data class.static QName
findQName(Class<?> dataType)
Returns a QName associated to supplied type.static Map<Class<? extends Augmentation<?>>,Augmentation<?>>
getAugmentations(Augmentable<?> input)
Deprecated, for removal: This API element is subject to removal in a future version.UseAugmentable.augmentations()
instead.static Iterable<Class<? extends DataObject>>
getChildrenClasses(Class<? extends DataContainer> type)
Scans supplied class and returns an iterable of all data children classes.static Map<Class<?>,Method>
getChildrenClassToMethod(Class<?> type)
Scans supplied class and returns an iterable of all data children classes.static Map<Class<?>,Method>
getChildrenClassToNonnullMethod(Class<?> type)
static String
getModelRootPackageName(Package pkg)
Returns root package name for supplied package.static String
getModelRootPackageName(String name)
Returns root package name for supplied package name.static @NonNull YangModuleInfo
getModuleInfo(Class<?> cls)
Returns instance ofYangModuleInfo
of declaring model for specific class.static @NonNull String
getModuleInfoClassName(String packageName)
static @NonNull QName
getQName(Class<? extends BaseIdentity> bindingClass)
static QNameModule
getQNameModule(Class<?> clz)
static boolean
isAugmentationChild(Class<?> clazz)
Checks if class is child of augmentation.static boolean
isBindingClass(Class<?> cls)
Check if supplied class is derived from YANG model.static boolean
isNotification(Class<?> potentialNotification)
Checks is supplied class is aNotification
.static boolean
isNotificationCallback(Method method)
Checks if supplied method is callback for notifications.static boolean
isRpcMethod(Method possibleMethod)
Checks if method is RPC invocation.static boolean
isRpcType(Class<? extends DataObject> targetType)
Checks if supplied class represents RPC Input / RPC Output.static boolean
isSubstitutionFor(Class potential, Class target)
Determines if two augmentation classes or case classes represents same data.static @NonNull ImmutableSet<YangModuleInfo>
loadModuleInfos()
LoadsYangModuleInfo
infos available on current classloader.static @NonNull ImmutableSet<YangModuleInfo>
loadModuleInfos(ClassLoader loader)
LoadsYangModuleInfo
infos available on supplied classloader.static Optional<Class<? extends DataContainer>>
resolveRpcInputClass(Method targetMethod)
Extracts input class for RPC method.static Optional<Class<?>>
resolveRpcOutputClass(Method targetMethod)
Extracts Output class for RPC method.
-
-
-
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 implementedAugmentation
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 implementedChildOf
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 invokingDataObject.implementedInterface()
and usesfindHierarchicalParent(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.
-
getQName
public static @NonNull QName getQName(Class<? extends BaseIdentity> bindingClass)
-
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.
-
getQNameModule
public static QNameModule getQNameModule(Class<?> clz)
-
getModuleInfo
public static @NonNull YangModuleInfo getModuleInfo(Class<?> cls)
Returns instance ofYangModuleInfo
of declaring model for specific class.- Parameters:
cls
- data object class- Returns:
- Instance of
YangModuleInfo
associated with model, from which this class was derived.
-
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 aNotification
.- Parameters:
potentialNotification
- class to examine- Returns:
- True if the class represents a Notification.
-
loadModuleInfos
public static @NonNull ImmutableSet<YangModuleInfo> loadModuleInfos()
LoadsYangModuleInfo
infos available on current classloader. This method is shorthand forloadModuleInfos(ClassLoader)
withThread.getContextClassLoader()
for current thread.- Returns:
- Set of
YangModuleInfo
available for current classloader.
-
loadModuleInfos
public static @NonNull ImmutableSet<YangModuleInfo> loadModuleInfos(ClassLoader loader)
LoadsYangModuleInfo
infos available on supplied classloader.YangModuleInfo
are discovered usingServiceLoader
forYangModelBindingProvider
.YangModelBindingProvider
are simple classes which holds only pointers to actual instanceYangModuleInfo
.When
YangModuleInfo
is available, all dependencies are recursively collected into returning set by collecting results ofYangModuleInfo.getImportedModules()
.Consider using
cacheModuleInfos(ClassLoader)
if the classloader is known to be immutable.- Parameters:
loader
- Classloader for whichYangModuleInfo
should be retrieved.- Returns:
- Set of
YangModuleInfo
available for supplied classloader.
-
cacheModuleInfos
@Beta public static @NonNull ImmutableSet<YangModuleInfo> cacheModuleInfos(ClassLoader loader)
LoadsYangModuleInfo
instances available on suppliedClassLoader
, assuming the set of available information does not change. Subsequent accesses may return cached values.YangModuleInfo
are discovered usingServiceLoader
forYangModelBindingProvider
.YangModelBindingProvider
are simple classes which holds only pointers to actual instanceYangModuleInfo
.When
YangModuleInfo
is available, all dependencies are recursively collected into returning set by collecting results ofYangModuleInfo.getImportedModules()
.- Parameters:
loader
- Class loader for whichYangModuleInfo
should be retrieved.- Returns:
- Set of
YangModuleInfo
available for supplied classloader.
-
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.UseAugmentable.augmentations()
instead.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 substitutiontarget
- Class which should be used at particular subtree- Returns:
- true if and only if classes represents same data.
-
-