/** * Gets a map of all known ContextMapperFactories, keyed by their supported source/target object * type. * * @return the ContextMapperFactories map */ @SuppressWarnings("rawtypes") public static final Map<Class, ContextMapperFactory> getContextMapperFactories() { Map<Class, ContextMapperFactory> factories = new HashMap<Class, ContextMapperFactory>(); ServiceLoader<ContextMapperFactory> services = ServiceLoader.load(ContextMapperFactory.class); for (ContextMapperFactory factory : services) { factories.put(factory.getBindingDataClass(), factory); } return factories; }
/** * Will create a new ContextMapper based on the specifications of the passed in * ContextMapperModel, or if a class it not specified, will apply the rest of the model properties * on the default/fallback implementation. * * @param model contains the config details * @return the new ContextMapper instance */ @SuppressWarnings("unchecked") public final ContextMapper<D> newContextMapper(ContextMapperModel model) { ContextMapper<D> contextMapper = null; ContextMapperFactory<D> contextMapperFactory = ContextMapperFactory.getContextMapperFactory(getBindingDataClass()); if (model != null) { contextMapper = contextMapperFactory.newContextMapper( (Class<ContextMapper<D>>) Classes.forName(model.getClazz())); contextMapper.setModel(model); if (contextMapper instanceof RegexContextMapper) { RegexContextMapper<D> regexContextMapper = (RegexContextMapper<D>) contextMapper; regexContextMapper.setIncludes(model.getIncludes()); regexContextMapper.setExcludes(model.getExcludes()); regexContextMapper.setIncludeNamespaces(model.getIncludeNamespaces()); regexContextMapper.setExcludeNamespaces(model.getExcludeNamespaces()); } } else { contextMapper = contextMapperFactory.newContextMapperDefault(); } return contextMapper; }