Package org.drasyl.pipeline.codec
Class TypeValidator
- java.lang.Object
-
- org.drasyl.pipeline.codec.TypeValidator
-
public class TypeValidator extends Object
TheTypeValidator
allows to define which classes and packages may be handled by a codec. It thus represents a marshalling whitelist.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClass(Class<?> clazz)
Adds a class to the list.void
addPackage(String p)
Adds a package to the list.static boolean
isTypeOf(Class<?> clazz, Class<?> superClass)
Checks ifclazz
is a subclass ofsuperClass
.static TypeValidator
of(List<String> classes, List<String> packages, boolean allowAllPrimitives, boolean allowArrayOfTypes)
static TypeValidator
of(DrasylConfig config)
void
removeClass(Class<?> clazz)
Removes a class from the list.void
removePackage(String p)
Removes a package from the list.static Class<?>
unwrapArrayComponentType(Class<?> clazzToUnwrap)
Returns the Class representing the component type of an array.boolean
validate(Class<?> clazzToTest)
Validates a givenClass
if it is allowed or not.
-
-
-
Method Detail
-
addClass
public void addClass(Class<?> clazz)
Adds a class to the list.- Parameters:
clazz
- class that should be added
-
addPackage
public void addPackage(String p)
Adds a package to the list.- Parameters:
p
- package that should be added
-
removeClass
public void removeClass(Class<?> clazz)
Removes a class from the list.- Parameters:
clazz
- class that should be removed
-
removePackage
public void removePackage(String p)
Removes a package from the list.- Parameters:
p
- package that should be removed
-
unwrapArrayComponentType
public static Class<?> unwrapArrayComponentType(Class<?> clazzToUnwrap)
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns theclazzToUnwrap
.- Parameters:
clazzToUnwrap
- class that should be unwrapped- Returns:
- the
Class
representing the component type of this class if this class is an array, otherwise the input is returned
-
validate
public boolean validate(Class<?> clazzToTest)
Validates a givenClass
if it is allowed or not.- Parameters:
clazzToTest
- class that should be validated- Returns:
- if the class is allowed or not
-
isTypeOf
public static boolean isTypeOf(Class<?> clazz, Class<?> superClass)
Checks ifclazz
is a subclass ofsuperClass
.- Parameters:
clazz
- possible subclasssuperClass
- the superclass- Returns:
- if clazz is a subclass of superClass true, otherwise false
-
of
public static TypeValidator of(List<String> classes, List<String> packages, boolean allowAllPrimitives, boolean allowArrayOfTypes)
-
of
public static TypeValidator of(DrasylConfig config)
-
-