Package org.apache.sis.internal.util
Class FinalFieldSetter
java.lang.Object
org.apache.sis.internal.util.FinalFieldSetter
Convenience methods for setting the final field of an object.
This class shall be used only after deserialization or cloning of Apache SIS objects.
The usage pattern is:
On deserialization:
On clone:
Same as above but invokingcloneFailure(e)
if the operation failed.
The exception to be thrown is not the same.
Historical note
Previous version was implementingPrivilegedAction<FinalFieldSetter<T>>
for working in the context of a security manager. This feature has been removed
since java.security.AccessController
has been deprecated in Java 17.- Since:
- 1.0
- Version:
- 1.2
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Do not allow instantiation of this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeException
Creates an exception for aclone()
method.static InvalidClassException
Creates an exception for areadObject(ObjectInputStream)
method.static <T> void
Sets the values of the final fields.static <T> void
Sets the value of the final field.
-
Constructor Details
-
FinalFieldSetter
private FinalFieldSetter()Do not allow instantiation of this class.
-
-
Method Details
-
set
public static <T> void set(Class<T> classe, String field, T instance, Object value) throws NoSuchFieldException, IllegalAccessException Sets the value of the final field.- Type Parameters:
T
- the type of object in which to set a final field. Should be Apache SIS classes only.- Parameters:
classe
- the Apache SIS class of object for which to set a final field.field
- the name of the final field for which to set a value.instance
- the instance on which to set the value.value
- the value to set.- Throws:
NoSuchFieldException
- if the given field has not been found.IllegalAccessException
- if the value cannot be set.
-
set
public static <T> void set(Class<T> classe, String field, String second, T instance, Object value, Object more) throws NoSuchFieldException, IllegalAccessException Sets the values of the final fields.- Type Parameters:
T
- the type of object in which to set a final field. Should be Apache SIS classes only.- Parameters:
classe
- the Apache SIS class of object for which to set a final field.field
- the name of the first final field for which to set a value.second
- the name of the second final field for which to set a value.instance
- the instance on which to set the value.value
- the value of the first field to set.more
- the value of the second field to set.- Throws:
NoSuchFieldException
- if a given field has not been found.IllegalAccessException
- if a value cannot be set.
-
readFailure
Creates an exception for areadObject(ObjectInputStream)
method.- Parameters:
cause
- the failure.- Returns:
- the exception to throw.
-
cloneFailure
Creates an exception for aclone()
method.- Parameters:
cause
- the failure.- Returns:
- the exception to throw.
-