/** * @author Carlos Gonzalez Pereira (cgmp@mega.ist.utl.pt) */ package net.sourceforge.fenixedu.util; import java.lang.reflect.Constructor; import java.util.Collection; import net.sourceforge.fenixedu._development.PropertiesManager; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.Role; import net.sourceforge.fenixedu.domain.person.RoleType; import com.linkare.commons.metainfo.Linkare; /** * * This class is responsible for handling all complex operations done to the * username * * @author - Carlos Gonzalez Pereira (cgmp@mega.ist.utl.pt) * */ @Linkare(author = "Paulo Zenida", comments = "Changed the implementation so that the actual logic is delegated to another class, which must implement the interface IUsernameUtils") public class UsernameUtils extends FenixUtil { private static final String USERNAME_UTILS_CLASS = "username.utils.class"; private static final String USERNAME_UTILS_CLASS_NAME = PropertiesManager.getProperty(USERNAME_UTILS_CLASS); private static final long serialVersionUID = 1L; private static Class usernameUtilsClass; private static IUsernameUtils delegator; static { delegator = DefaultUsernameUtils.getInstance(); if (USERNAME_UTILS_CLASS_NAME != null) { try { usernameUtilsClass = (Class) Class.forName(USERNAME_UTILS_CLASS_NAME); } catch (ClassNotFoundException e) { System.err.println("Username utils class " + usernameUtilsClass + " was not found"); e.printStackTrace(); } if (usernameUtilsClass != null && usernameUtilsClass != DefaultUsernameUtils.class) { try { Constructor constructor = usernameUtilsClass.getDeclaredConstructor(); boolean isAccessible = constructor.isAccessible(); delegator = constructor.newInstance(); constructor.setAccessible(isAccessible); } catch (Exception e) { e.printStackTrace(); } } } } public static boolean shouldHaveUID(Person person) { return delegator.shouldHaveUID(person); } public static String updateIstUsername(Person person) { return delegator.updateInstitutionalUsername(person); } public static String generateNewUsername(RoleType roleType, Person person) { return delegator.generateNewUsername(roleType, person); } public static Role getMostImportantRole(Collection roles) { return delegator.getMostImportantRole(roles); } }