/** * Wraps a primary and a fallback authority factories. * * <p>This constructor is protected because subclasses must declare which of the {@link * DatumAuthorityFactory}, {@link CSAuthorityFactory}, {@link CRSAuthorityFactory} and {@link * CoordinateOperationAuthorityFactory} interfaces they choose to implement. * * @param primary The primary factory. * @param fallback The factory to use as a fallback if the primary factory failed. * @see #create */ protected FallbackAuthorityFactory( final AuthorityFactory primary, final AuthorityFactory fallback) { super(primary, fallback); ensureNonNull("fallback", fallback); this.fallback = (fallback instanceof AbstractAuthorityFactory) ? (AbstractAuthorityFactory) fallback : new AuthorityFactoryAdapter(fallback); }
/** * Wraps the specified authority factories. If the specified collection contains more than one * element, then a chain of {@code FallbackAuthorityFactory} instances is created. * * @param <T> The interface to implement. * @param type The interface to implement. Should be one of {@link DatumAuthorityFactory}, * {@link CSAuthorityFactory}, {@link CRSAuthorityFactory} or {@link * CoordinateOperationAuthorityFactory}. * @param factories The factories to wrap, in iteration order. * @return The given factories as a chain of fallback factories. * @throws FactoryNotFoundException if the collection doesn't contains at least one element. * @throws ClassCastException if {@code type} is illegal. */ public static <T extends AuthorityFactory> T create( final Class<T> type, final Collection<T> factories) throws FactoryNotFoundException, ClassCastException { ensureNonNull("type", type); ensureNonNull("factories", factories); if (factories.isEmpty()) { throw new FactoryNotFoundException(Errors.format(ErrorKeys.FACTORY_NOT_FOUND_$1, type)); } return type.cast(create(false, interfaceMask(type), factories.iterator())); }
/** * Wraps the specified authority factories. If the specified collection contains more than one * element, then a chain of {@code FallbackAuthorityFactory} instances is created. The type is * inferred from the factories found in the collection. * * <p>Consider using <code>{@linkplain #create(Class, Collection) create}(type, factories) * </code> instead when the type is known at compile time. * * @param factories The factories to wrap, in iteration order. * @return The given factories as a chain of fallback factories. * @throws FactoryNotFoundException if the collection doesn't contains at least one element. * @since 2.4 */ public static AuthorityFactory create(final Collection<? extends AuthorityFactory> factories) throws FactoryNotFoundException { ensureNonNull("factories", factories); if (factories.isEmpty()) { throw new FactoryNotFoundException( Errors.format(ErrorKeys.FACTORY_NOT_FOUND_$1, AuthorityFactory.class)); } return create(false, interfaceMask(factories), factories.iterator()); }