public String getDataSourceName(Class daoClass) { Class intf = getDaoInterface(daoClass); String className = intf.getName(); String key = "." + namingConvention.getDaoPackageName() + "."; int index = className.lastIndexOf(key); if (index < 0) { return null; } int index2 = className.lastIndexOf('.'); if (index + key.length() - 1 == index2) { return null; } return className.substring(index + key.length(), index2); }
public Class getDaoInterface(Class clazz) { if (clazz.isInterface()) { return clazz; } for (Class target = clazz; target != Object.class; target = target.getSuperclass()) { Class[] interfaces = target.getInterfaces(); for (int i = 0; i < interfaces.length; ++i) { Class intf = interfaces[i]; if (intf.getName().endsWith(namingConvention.getDaoSuffix())) { return intf; } } } throw new DaoNotFoundRuntimeException(clazz); }