| 39 | private static final Map<Class<?>, Object> facets = new HashMap<>(); |
| 40 | |
| 41 | public static <T> T getFacet(Class<T> cl) |
| 42 | { |
| 43 | T facet = (T) facets.get(cl); |
| 44 | if (facet == null) |
| 45 | { |
| 46 | // First check for the facet being defined by Spring |
| 47 | facet = SpringHelper.getBean(cl); |
| 48 | if (facet == null) |
| 49 | { |
| 50 | // Fall back to the old hardcoded system |
| 51 | Logging.errorPrint("Using Legacy Load for Facet: " + cl.getName(), |
| 52 | (Object) Thread.currentThread().getStackTrace()); |
| 53 | try |
| 54 | { |
| 55 | facet = cl.getConstructor().newInstance(); |
| 56 | } |
| 57 | catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) |
| 58 | { |
| 59 | Logging.errorPrint("unable to construct old style Facet", e); |
| 60 | } |
| 61 | } |
| 62 | facets.put(cl, facet); |
| 63 | } |
| 64 | return facet; |
| 65 | } |
| 66 | |
| 67 | } |