Package org.jboss.marshalling
Class FieldSetter
- java.lang.Object
-
- org.jboss.marshalling.FieldSetter
-
public final class FieldSetter extends java.lang.Object
A setter for a (possibly final) field, which allows for correct object initialization ofSerializable
objects withreadObject()
methods, even in the presence offinal
fields.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FieldSetter.GetFieldAction
private static class
FieldSetter.Holder
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Field
field
-
Constructor Summary
Constructors Modifier Constructor Description private
FieldSetter(java.lang.reflect.Field field)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FieldSetter
get(java.lang.Class<?> clazz, java.lang.String name)
Get an instance for the current class.private java.lang.IllegalStateException
illegalState(java.lang.IllegalAccessException e)
void
set(java.lang.Object instance, java.lang.Object value)
Set the value of the field to the given object.void
setBoolean(java.lang.Object instance, boolean value)
Set the value of the field to the given value.void
setByte(java.lang.Object instance, byte value)
Set the value of the field to the given value.void
setChar(java.lang.Object instance, char value)
Set the value of the field to the given value.void
setDouble(java.lang.Object instance, double value)
Set the value of the field to the given value.void
setFloat(java.lang.Object instance, float value)
Set the value of the field to the given value.void
setInt(java.lang.Object instance, int value)
Set the value of the field to the given value.void
setLong(java.lang.Object instance, long value)
Set the value of the field to the given value.void
setShort(java.lang.Object instance, short value)
Set the value of the field to the given value.
-
-
-
Method Detail
-
set
public void set(java.lang.Object instance, java.lang.Object value) throws java.lang.IllegalArgumentException
Set the value of the field to the given object.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setBoolean
public void setBoolean(java.lang.Object instance, boolean value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setByte
public void setByte(java.lang.Object instance, byte value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setChar
public void setChar(java.lang.Object instance, char value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setDouble
public void setDouble(java.lang.Object instance, double value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setFloat
public void setFloat(java.lang.Object instance, float value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setInt
public void setInt(java.lang.Object instance, int value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setLong
public void setLong(java.lang.Object instance, long value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
setShort
public void setShort(java.lang.Object instance, short value) throws java.lang.IllegalArgumentException
Set the value of the field to the given value.- Parameters:
instance
- the instance to setvalue
- the new value- Throws:
java.lang.IllegalArgumentException
- if the given instance isnull
or not of the correct class
-
illegalState
private java.lang.IllegalStateException illegalState(java.lang.IllegalAccessException e)
-
get
public static FieldSetter get(java.lang.Class<?> clazz, java.lang.String name) throws java.lang.SecurityException, java.lang.IllegalArgumentException
Get an instance for the current class.- Parameters:
clazz
- the class containing the fieldname
- the name of the field- Returns:
- the
Field
instance - Throws:
java.lang.SecurityException
- if the field does not belong to the caller's class, or the field is staticjava.lang.IllegalArgumentException
- if there is no field of the given name on the given class
-
-