Class ModelUtils
java.lang.Object
de.hybris.platform.servicelayer.internal.converter.util.ModelUtils
This class contains some utility methods for getting/setting field values and check for methods/field. These methods
are based on reflection.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanenumEquals(HybrisEnumValue enum1, Object obj) Compares enum object with another object.static booleanexistsField(Class model, String field) Returnstrueif in the given class model a field by the given fieldname exists.static booleanexistsMethod(Class model, String method) Returnstrueif in the given class model a method by the given method name exists.static ClassgetFieldType(Class model, String field) Returns a Class object that identifies the declared type for the given field name of the given model class.static ObjectgetFieldValue(Object model, String field) Returns the value of the field (given by the field name) from the given model.static booleanisPrimitiveField(Class model, String field) Returns (per reflection)trueif in the class the field by it's given field name is a primitive type.static booleansetFieldValue(Object model, String field, Object value) Sets in the given model the given value into the field by the given field name per reflection and returnstrueif this was successful.
-
Method Details
-
getFieldValue
Returns the value of the field (given by the field name) from the given model. per reflection. Searches all superclasses of the model.- Parameters:
model- the modelfield- the field name- Returns:
nullif not such field at the model exists, otherwise the value object is returned- Throws:
IllegalStateException- if an unexpected reflection exception occurs.
-
setFieldValue
Sets in the given model the given value into the field by the given field name per reflection and returnstrueif this was successful.- Parameters:
model- the model where the value should be setfield- the field name at the modelvalue- the value to be set- Returns:
falseif no such fiel at the model was found
-
isPrimitiveField
Returns (per reflection)trueif in the class the field by it's given field name is a primitive type.- Parameters:
model- the class modelfield- the field name- Returns:
falseif the field is not primitive or the field doesn't exist in the class
-
getFieldType
Returns a Class object that identifies the declared type for the given field name of the given model class.- Parameters:
model- the model classfield- the field name- Returns:
nullif no such field was found, otherwise the type class is returned
-
existsMethod
Returnstrueif in the given class model a method by the given method name exists. The method can have any signature.- Parameters:
model- the class modelmethod- the method name- Returns:
falseif no such method exists in the given class model
-
existsField
Returnstrueif in the given class model a field by the given fieldname exists. Searches all superclasses of the given class model.- Parameters:
model- the class modelfield- the fieldname- Returns:
falseif no such field exists in the given class model
-
enumEquals
Compares enum object with another object. Used inside generated dynamic enum values.- Parameters:
enum1- the first enumobj- the second enum- Returns:
trueif both objects are dynamic enum values and have the same type and code; please note that type and code are case insensitive!
-