Top Description Fields Constructors Methods
org.freedesktop.dbus.utils

public final Class DBusObjects

extends Object
Class Inheritance
Imports
org.freedesktop.dbus.DBusPath, org.freedesktop.dbus.exceptions.*, org.freedesktop.dbus.interfaces.DBusInterface, java.lang.reflect.Modifier, java.util.LinkedHashSet, .Set, java.util.function.Function, .Predicate, .Supplier, java.util.regex.Pattern

Various validations.
Author
hypfvieh
Since
5.0.0 - 2023-11-08

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Pattern
private static final int
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
ensurePublicInterfaces(Object
object to check
_object
)

Ensures that all interfaces found on the given object a public accessable.

private static <T,
exception type
X extends DBusException
>
T

Returns:

checked input
requireBase
(T
input
_input
,
Predicate<T>
predicate for validation if value is not null or blank in case of string
_validation
,
Function<String, X>
function providing a new exception which will be thrown, will receive _customMessage if given or string value of input
_exSupplier
,
String
custom exception message text, null to omit
_customMessage
)

Basic checks of input (e.g. null checks).

public static String

Returns:

input if valid
requireBusName
(String
string to check
_busName
)

Ensures given string is a valid bus name.

public static String

Returns:

input if valid
requireBusName
(String
string to check
_busName
,
String
custom exception message
_customMessage
)

Ensures given string is a valid bus name.

public static String

Returns:

input if valid
requireBusNameOrConnectionId
(String
string to check
_busNameOrConnId
)

Ensures given string is a valid bus name or connection Id.

public static String

Returns:

input if valid
requireConnectionId
(String
string to check
_connId
)

Ensures given string is a valid connection Id.

public static Class<?>

Returns:

input if valid
requireDBusInterface
(Class<?>
class to check
_clz
)

Ensures that the given class is implements or extends DBusInterface class.

public static Class<?>

Returns:

input if valid
requireDBusInterface
(Class<?>
class to check
_clz
,
String
custom error message
_customMsg
)

Ensures that the given class is implements or extends DBusInterface class.

public static String

Returns:

input if valid
requireNotBusName
(String
string to check
_busName
,
String
custom exception message
_customMessage
)

Ensures given string is NOT a valid bus name.

public static <
input type
T
,
exception type to throw
X extends Exception
>
T

Returns:

input if not null
requireNotNull
(T
input to validate
_input
,
Supplier<X>
supplier providing exception which will be thrown if input is null
_exception
)

Ensure given value is not null.

public static String

Returns:

input string if valid
requireObjectPath
(String
string to check
_objectPath
)

Ensures given string is a valid object path.

public static DBusPath

Returns:

input DBusPath if valid
requireObjectPath
(DBusPath
to check
_dbusPath
)

Ensures given DBusPath is a valid object path.

public static String

Returns:

input string if valid
requireObjectPath
(String
string to check
_objectPath
,
String
custom error message
_customMsg
)

Ensures given string is a valid object path.

public static DBusPath

Returns:

input DBusPath if valid
requireObjectPath
(DBusPath
to check
_dbusPath
,
String
custom error message
_customMsg
)

Ensures given DBusPath is a valid object path.

public static Class<?>

Returns:

input if valid
requirePackage
(Class<?>
class to check
_clz
)

Ensures that the given class is part of a package.

public static Class<?>

Returns:

input if valid
requirePackage
(Class<?>
class to check
_clz
,
String
custom error message
_customMsg
)

Ensures that the given class is part of a package.

public static boolean

Returns:

true if valid
validateBusName
(String
input to check
_busName
)

Checks if input is valid bus name.

public static boolean

Returns:

true if class has a package
validateClassHasPackage
(Class<?>
class to check
_clz
)

Checks if given class has/is in a package.

public static boolean

Returns:

true if valid
validateConnectionId
(String
input to check
_connectionId
)

Checks if input is a valid connection Id.

public static boolean

Returns:

true if class is compatible
validateDBusInterface
(Class<?>
class to check
_clz
)

Checks if given class is compatible with DBusInterface class.

public static boolean

Returns:

true if invalid
validateNotBusName
(String
input to check
_busName
)

Checks if input is NOT a valid bus name.

public static boolean

Returns:

true if invalid
validateNotConnectionId
(String
input to check
_connectionId
)

Checks if input is NOT a valid connection Id.

public static boolean

Returns:

true if invalid
validateNotObjectPath
(String
input to check
_objectPath
)

Checks if input is NOT a valid object path.

public static boolean

Returns:

true if valid
validateObjectPath
(String
input to check
_objectPath
)

Checks if input is a valid object path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUSNAME_REGEXback to summary
private static final Pattern BUSNAME_REGEX
CONNID_REGEXback to summary
private static final Pattern CONNID_REGEX
MAX_NAME_LENGTHback to summary
private static final int MAX_NAME_LENGTH
OBJECT_REGEX_PATTERNback to summary
private static final Pattern OBJECT_REGEX_PATTERN

Constructor Detail

DBusObjectsback to summary
private DBusObjects()

Method Detail

ensurePublicInterfacesback to summary
public static void ensurePublicInterfaces(Object _object) throws InvalidInterfaceSignature

Ensures that all interfaces found on the given object a public accessable.

Parameters
_object:Object

object to check

Exceptions
InvalidInterfaceSignature:
when there is any interface on the given object which is non public
requireBaseback to summary
private static <T, X extends DBusException> T requireBase(T _input, Predicate<T> _validation, Function<String, X> _exSupplier, String _customMessage) throws String-:X

Basic checks of input (e.g. null checks).

Parameters
<X>
exception type
_input:T

input

_validation:Predicate<T>

predicate for validation if value is not null or blank in case of string

_exSupplier:Function<String, X>

function providing a new exception which will be thrown, will receive _customMessage if given or string value of input

_customMessage:String

custom exception message text, null to omit

Returns:T

checked input

Exceptions
String-:X:
when validation fails
requireBusNameback to summary
public static String requireBusName(String _busName) throws InvalidBusNameException

Ensures given string is a valid bus name.

Parameters
_busName:String

string to check

Returns:String

input if valid

Exceptions
InvalidBusNameException:
when input is not a valid bus name
requireBusNameback to summary
public static String requireBusName(String _busName, String _customMessage) throws InvalidBusNameException

Ensures given string is a valid bus name.

Parameters
_busName:String

string to check

_customMessage:String

custom exception message

Returns:String

input if valid

Exceptions
InvalidBusNameException:
when input is not a valid bus name
requireBusNameOrConnectionIdback to summary
public static String requireBusNameOrConnectionId(String _busNameOrConnId) throws InvalidBusNameException

Ensures given string is a valid bus name or connection Id.

Parameters
_busNameOrConnId:String

string to check

Returns:String

input if valid

Exceptions
InvalidBusNameException:
when input is not a valid bus name or connection Id
requireConnectionIdback to summary
public static String requireConnectionId(String _connId) throws InvalidBusNameException

Ensures given string is a valid connection Id.

Parameters
_connId:String

string to check

Returns:String

input if valid

Exceptions
InvalidBusNameException:
when input is not a valid connection Id
requireDBusInterfaceback to summary
public static Class<?> requireDBusInterface(Class<?> _clz) throws MissingInterfaceImplementationException

Ensures that the given class is implements or extends DBusInterface class.

Parameters
_clz:Class<?>

class to check

Returns:Class<?>

input if valid

Exceptions
MissingInterfaceImplementationException:
when class is incompatible
requireDBusInterfaceback to summary
public static Class<?> requireDBusInterface(Class<?> _clz, String _customMsg) throws MissingInterfaceImplementationException

Ensures that the given class is implements or extends DBusInterface class.

Parameters
_clz:Class<?>

class to check

_customMsg:String

custom error message

Returns:Class<?>

input if valid

Exceptions
MissingInterfaceImplementationException:
when class is incompatible
requireNotBusNameback to summary
public static String requireNotBusName(String _busName, String _customMessage) throws InvalidBusNameException

Ensures given string is NOT a valid bus name.

Parameters
_busName:String

string to check

_customMessage:String

custom exception message

Returns:String

input if valid

Exceptions
InvalidBusNameException:
when input is a valid bus name
requireNotNullback to summary
public static <T, X extends Exception> T requireNotNull(T _input, Supplier<X> _exception) throws Supplier-:X

Ensure given value is not null.

Parameters
<T>
input type
<X>
exception type to throw
_input:T

input to validate

_exception:Supplier<X>

supplier providing exception which will be thrown if input is null

Returns:T

input if not null

Exceptions
Supplier-:X:
exception provided by supplier thrown when input was null
requireObjectPathback to summary
public static String requireObjectPath(String _objectPath) throws InvalidObjectPathException

Ensures given string is a valid object path.

Parameters
_objectPath:String

string to check

Returns:String

input string if valid

Exceptions
InvalidObjectPathException:
when input is not a valid object path
requireObjectPathback to summary
public static DBusPath requireObjectPath(DBusPath _dbusPath) throws InvalidObjectPathException

Ensures given DBusPath is a valid object path.

Parameters
_dbusPath:DBusPath

to check

Returns:DBusPath

input DBusPath if valid

Exceptions
InvalidObjectPathException:
when input is not a valid object path
requireObjectPathback to summary
public static String requireObjectPath(String _objectPath, String _customMsg) throws InvalidObjectPathException

Ensures given string is a valid object path.

Parameters
_objectPath:String

string to check

_customMsg:String

custom error message

Returns:String

input string if valid

Exceptions
InvalidObjectPathException:
when input is not a valid object path
requireObjectPathback to summary
public static DBusPath requireObjectPath(DBusPath _dbusPath, String _customMsg) throws InvalidObjectPathException

Ensures given DBusPath is a valid object path.

Parameters
_dbusPath:DBusPath

to check

_customMsg:String

custom error message

Returns:DBusPath

input DBusPath if valid

Exceptions
InvalidObjectPathException:
when input is not a valid object path
requirePackageback to summary
public static Class<?> requirePackage(Class<?> _clz) throws ClassOutsideOfPackageException

Ensures that the given class is part of a package.

Parameters
_clz:Class<?>

class to check

Returns:Class<?>

input if valid

Exceptions
ClassOutsideOfPackageException:
when class has no package
requirePackageback to summary
public static Class<?> requirePackage(Class<?> _clz, String _customMsg) throws ClassOutsideOfPackageException

Ensures that the given class is part of a package.

Parameters
_clz:Class<?>

class to check

_customMsg:String

custom error message

Returns:Class<?>

input if valid

Exceptions
ClassOutsideOfPackageException:
when class has no package
validateBusNameback to summary
public static boolean validateBusName(String _busName)

Checks if input is valid bus name.

Parameters
_busName:String

input to check

Returns:boolean

true if valid

validateClassHasPackageback to summary
public static boolean validateClassHasPackage(Class<?> _clz)

Checks if given class has/is in a package.

Parameters
_clz:Class<?>

class to check

Returns:boolean

true if class has a package

validateConnectionIdback to summary
public static boolean validateConnectionId(String _connectionId)

Checks if input is a valid connection Id.

Parameters
_connectionId:String

input to check

Returns:boolean

true if valid

validateDBusInterfaceback to summary
public static boolean validateDBusInterface(Class<?> _clz)

Checks if given class is compatible with DBusInterface class.

Parameters
_clz:Class<?>

class to check

Returns:boolean

true if class is compatible

validateNotBusNameback to summary
public static boolean validateNotBusName(String _busName)

Checks if input is NOT a valid bus name.

Parameters
_busName:String

input to check

Returns:boolean

true if invalid

validateNotConnectionIdback to summary
public static boolean validateNotConnectionId(String _connectionId)

Checks if input is NOT a valid connection Id.

Parameters
_connectionId:String

input to check

Returns:boolean

true if invalid

validateNotObjectPathback to summary
public static boolean validateNotObjectPath(String _objectPath)

Checks if input is NOT a valid object path.

Parameters
_objectPath:String

input to check

Returns:boolean

true if invalid

validateObjectPathback to summary
public static boolean validateObjectPath(String _objectPath)

Checks if input is a valid object path.

Parameters
_objectPath:String

input to check

Returns:boolean

true if valid