private void applyFeatures() { try { for (Class<? extends Annotation> featureAnnotation : features) { boolean isFeatureSupported = ReflectionUtil.isAnnotationPresentInHierarchy(originalTransferManager.getClass(), featureAnnotation); if (isFeatureSupported) { Class<? extends TransferManager> featureTransferManagerClass = getFeatureTransferManagerClass(featureAnnotation); wrappedTransferManager = apply(wrappedTransferManager, featureTransferManagerClass, featureAnnotation); } else { logger.log(Level.INFO, "- SKIPPING unsupported optional feature " + featureAnnotation.getSimpleName()); } } } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw new RuntimeException("Unable to annotate TransferManager with feature.", e); } }
/** * Wraps of the previously requested feature transfer managers and casts the result to the requested class. * If no specific class is requested, {@link #asDefault()} can be used instead. * * @param featureAnnotation Feature annotation corresponding to the requested transfer manager * @return {@link TransferManager} casted to the feature lasted wrapped (and requested by this method) */ @SuppressWarnings("unchecked") public <T extends TransferManager> T as(Class<? extends Annotation> featureAnnotation) { Class<T> implementingTransferManagerClass = (Class<T>) getFeatureTransferManagerClass(featureAnnotation); return wrap(implementingTransferManagerClass); }