/** Checks the availability of the specified factory. */ private static boolean isAvailable(final AuthorityFactory factory) { return !(factory instanceof OptionalFactory) || ((OptionalFactory) factory).isAvailable(); }
/** * Returns {@code true} if this factory and its underlying {@linkplain #getAuthorityFactory * authority factory} are available for use. */ public boolean isAvailable() { try { final CoordinateOperationAuthorityFactory authorityFactory = getAuthorityFactory(); if (authorityFactory instanceof OptionalFactory) { return ((OptionalFactory) authorityFactory).isAvailable(); } return true; } catch (FactoryRegistryException exception) { // No factory found. Ignore the exception since it is the // purpose of this method to figure out this kind of case. return false; } } }
/** * Returns {@code true} if the specified factory is available. * * <p>Safely checks {@link OptionalFactory#isAvailable()} which can be used at runtime to allow * a factory to confirm its dependencies (such as a JDBC driver) are available on the CLASSPATH. * * @return true if factory instance is available for use */ private boolean isAvailable(final Object factory) { if (!(factory instanceof OptionalFactory)) { return true; } final OptionalFactory optionalFactory = (OptionalFactory) factory; final Class<? extends OptionalFactory> type = optionalFactory.getClass(); if (!testingAvailability.addAndCheck(type)) { throw new RecursiveSearchException(type); } try { return optionalFactory.isAvailable(); } finally { testingAvailability.removeAndCheck(type); } }