@Test public void testGetReadableName() { Ninja ninja = new Ninja(); assertEquals("Ninja", CacheUtil.getReadableName(ninja)); BaseUser baseUser = new BaseUser(); assertEquals("Base User", CacheUtil.getReadableName(baseUser)); }
public static String getReadableName(BaseEntity obj) { Class<?> clazz = obj.getClass(); String ret = readableName.get(clazz); if (ret == null) { if (clazz.isAnnotationPresent(Auditable.class)) { String label = (clazz.getAnnotation(Auditable.class)).label(); if (!StringUtil.isEmpty(label)) { ret = label; } } if (ret == null) { try { Method method = clazz.getMethod("getReadableName"); return method.invoke(null).toString().trim(); } catch (Exception e) { String name = clazz.getSimpleName(); return NamingUtil.toLabel(name); } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " has readable name of '" + ret + "'"); } readableName.put(obj.getClass(), ret); ret = readableName.get(obj.getClass()); } return ret; }
CacheUtil { public static String getReadableName(BaseEntity obj) { Class<?> clazz = obj.getClass(); String ret = readableName.get(clazz); if (ret == null) { if (clazz.isAnnotationPresent(Auditable.class)) { String label = (clazz.getAnnotation(Auditable.class)).label(); if (!StringUtil.isEmpty(label)) { ret = label; } } if (ret == null) { try { Method method = clazz.getMethod("getReadableName"); return method.invoke(null).toString().trim(); } catch (Exception e) { String name = clazz.getSimpleName(); return NamingUtil.toLabel(name); } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " has readable name of '" + ret + "'"); } readableName.put(obj.getClass(), ret); ret = readableName.get(obj.getClass()); } return ret; } }
CacheUtil { public static String getReadableName(BaseEntity obj) { Class<?> clazz = obj.getClass(); String ret = readableName.get(clazz); if (ret == null) { if (clazz.isAnnotationPresent(Auditable.class)) { String label = (clazz.getAnnotation(Auditable.class)).label(); if (!StringUtil.isEmpty(label)) { ret = label; } } if (ret == null) { try { Method method = clazz.getMethod("getReadableName"); return method.invoke(null).toString().trim(); } catch (Exception e) { String name = clazz.getSimpleName(); return NamingUtil.toLabel(name); } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " has readable name of '" + ret + "'"); } readableName.put(obj.getClass(), ret); ret = readableName.get(obj.getClass()); } return ret; } private  CacheUtil(); }
CacheUtil { public static String getReadableName(BaseEntity obj) { Class<?> clazz = obj.getClass(); String ret = readableName.get(clazz); if (ret == null) { if (clazz.isAnnotationPresent(Auditable.class)) { String label = (clazz.getAnnotation(Auditable.class)).label(); if (!StringUtil.isEmpty(label)) { ret = label; } } if (ret == null) { try { Method method = clazz.getMethod("getReadableName"); return method.invoke(null).toString().trim(); } catch (Exception e) { String name = clazz.getSimpleName(); return NamingUtil.toLabel(name); } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " has readable name of '" + ret + "'"); } readableName.put(obj.getClass(), ret); ret = readableName.get(obj.getClass()); } return ret; } private  CacheUtil(); static String getReadableName(BaseEntity obj); static List<AuditableField> getAuditable(BaseEntity obj); static AuditableField getPrimaryField(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz, boolean includeParent); static Map<String, String> getColumnNames(BaseEntity obj); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz, boolean includeParent); @SuppressWarnings("unchecked") static List<String> getSearchableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj, Class<?> clazz); static JoinTable getJoinTableFields(BaseEntity owner, Class<?> collection); static Method getNewFormBindMethod(Class<?> clazz); static Method getUpdateFormBindMethod(Class<?> clazz); static Method getInsertMethod(Class<?> clazz); static Method getUpdateMethod(Class<?> clazz); static Method getDeleteMethod(Class<?> clazz); }
CacheUtil { public static String getReadableName(BaseEntity obj) { Class<?> clazz = obj.getClass(); String ret = readableName.get(clazz); if (ret == null) { if (clazz.isAnnotationPresent(Auditable.class)) { String label = (clazz.getAnnotation(Auditable.class)).label(); if (!StringUtil.isEmpty(label)) { ret = label; } } if (ret == null) { try { Method method = clazz.getMethod("getReadableName"); return method.invoke(null).toString().trim(); } catch (Exception e) { String name = clazz.getSimpleName(); return NamingUtil.toLabel(name); } } if (_log.isDebugEnabled()) { _log.debug(clazz.getSimpleName() + " has readable name of '" + ret + "'"); } readableName.put(obj.getClass(), ret); ret = readableName.get(obj.getClass()); } return ret; } private  CacheUtil(); static String getReadableName(BaseEntity obj); static List<AuditableField> getAuditable(BaseEntity obj); static AuditableField getPrimaryField(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz); static List<String> getPersistentFields(BaseEntity obj, Class<?> clazz, boolean includeParent); static Map<String, String> getColumnNames(BaseEntity obj); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz); static Map<String, String> getColumnNames(BaseEntity obj, Class<?> clazz, boolean includeParent); @SuppressWarnings("unchecked") static List<String> getSearchableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj); @SuppressWarnings("unchecked") static List<String> getSynchronizableFields(BaseEntity obj, Class<?> clazz); static JoinTable getJoinTableFields(BaseEntity owner, Class<?> collection); static Method getNewFormBindMethod(Class<?> clazz); static Method getUpdateFormBindMethod(Class<?> clazz); static Method getInsertMethod(Class<?> clazz); static Method getUpdateMethod(Class<?> clazz); static Method getDeleteMethod(Class<?> clazz); static final Map<Class<?>, List<AuditableField>> auditable; static final Map<Class<?>, AuditableField> primaryField; static final Map<Class<?>, String> readableName; static final Map<String, List<String>> persistentFields; static final Map<Class<?>, List<String>> synchronizeFields; static final Map<Class<?>, List<String>> searchableFields; static final Map<String, JoinTable> joinTableFields; static final Map<String, Map<String, String>> columnNames; }