use of org.ehrbase.serialisation.util.SnakeToCamel in project openEHR_SDK by ehrbase.
the class CanonicalUtil method getAttributeValue.
/**
* resolves an attribute of a RMObject
* NB. borrowed from CAttribute.java in validation
*
* @param obj
* @param attributePath
* @return
*/
private static Object getAttributeValue(Object obj, String attributePath) {
if (obj == null)
return null;
Class rmClass = obj.getClass();
Object value;
Method getter;
String getterName;
if (attributePath.startsWith("is_")) {
// conventionally, a getter for a boolean uses 'is' as a prefix
getterName = "is" + new SnakeToCamel(attributePath.substring(3)).convert();
} else
getterName = "get" + new SnakeToCamel(attributePath).convert();
try {
getter = rmClass.getMethod(getterName);
value = getter.invoke(obj, null);
} catch (Exception e) {
throw new IllegalStateException("unresolved attribute:" + attributePath + " for class:" + rmClass);
}
return value;
}
Aggregations