Class ModelUtils
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.converter.util.ModelUtils
-
public final class ModelUtils extends java.lang.ObjectThis class contains some utility methods for getting/setting field values and check for methods/field. These methods are based on reflection.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanenumEquals(HybrisEnumValue enum1, java.lang.Object obj)Compares enum object with another object.static booleanexistsField(java.lang.Class model, java.lang.String field)Returnstrueif in the given class model a field by the given fieldname exists.static booleanexistsMethod(java.lang.Class model, java.lang.String method)Returnstrueif in the given class model a method by the given method name exists.static java.lang.ClassgetFieldType(java.lang.Class model, java.lang.String field)Returns a Class object that identifies the declared type for the given field name of the given model class.static java.lang.ObjectgetFieldValue(java.lang.Object model, java.lang.String field)Returns the value of the field (given by the field name) from the given model.static booleanisPrimitiveField(java.lang.Class model, java.lang.String field)Returns (per reflection)trueif in the class the field by it's given field name is a primitive type.static booleansetFieldValue(java.lang.Object model, java.lang.String field, java.lang.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 Detail
-
getFieldValue
public static java.lang.Object getFieldValue(java.lang.Object model, java.lang.String field)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:
java.lang.IllegalStateException- if an unexpected reflection exception occurs.
-
setFieldValue
public static boolean setFieldValue(java.lang.Object model, java.lang.String field, java.lang.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.- 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
public static boolean isPrimitiveField(java.lang.Class model, java.lang.String field)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
public static java.lang.Class getFieldType(java.lang.Class model, java.lang.String field)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
public static boolean existsMethod(java.lang.Class model, java.lang.String method)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
public static boolean existsField(java.lang.Class model, java.lang.String field)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
public static boolean enumEquals(HybrisEnumValue enum1, java.lang.Object obj)
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!
-
-