/** * Sets the factories. This method is invoked by the {@link AllAuthoritiesFactory} subclass * only. No one else should invoke this method, since factories should be immutable. */ final synchronized void setFactories(final Collection<AuthorityFactory> factories) { this.factories = createFallbacks(factories); }
/** * Returns {@code true} if the specified factory should be excluded from the search. We exclude * adapters around {@link AllAuthoritiesFactory}. This code actually aims to exclude {@link * URN_AuthorityFactory} and similar adapters around all factories, since it leads to duplicated * search and innacurate identifier to be returned by {@link #findIdentifier}. */ private static boolean exclude(final AuthorityFactory factory) { if (ManyAuthoritiesFactory.class.isInstance(factory)) { return true; } if (factory instanceof AuthorityFactoryAdapter) { final AuthorityFactoryAdapter adapter = (AuthorityFactoryAdapter) factory; return exclude(adapter.crsFactory) || exclude(adapter.csFactory) || exclude(adapter.datumFactory) || exclude(adapter.operationFactory); } return false; }
/** * Returns the CS authority factory for the specified {@code "AUTHORITY:NUMBER"} code. * * @param code The code to parse. * @return The authority factory. * @throws NoSuchAuthorityCodeException if no authority name has been found. */ @Override protected CSAuthorityFactory getCSAuthorityFactory(final String code) throws NoSuchAuthorityCodeException { return getAuthorityFactory(CSAuthorityFactory.class, code); }
final <T extends AuthorityFactory> T getAuthorityFactory(final Class<T> type, final String code) throws NoSuchAuthorityCodeException { ensureNonNull("code", code); String authority = null; FactoryRegistryException cause = null; final Collection<AuthorityFactory> factories = getFactories(); final char separator = getSeparator(code); for (int split = code.lastIndexOf(separator); split >= 0; split = code.lastIndexOf(separator, split - 1)) { if (!canSeparateAt(code, split)) { continue; factory = fromFactoryRegistry(authority, type); } catch (FactoryRegistryException exception) { cause = exception; throw noSuchAuthority(code, authority, cause);
try { inProgress.set(Boolean.TRUE); for (String authority : getAuthorityNames()) { authority = authority.trim(); final char separator = getSeparator(authority); final AuthorityFactory factory; try { factory = getAuthorityFactory(factoryType, dummyCode); } catch (NoSuchAuthorityCodeException e) { continue;
factory = getAuthorityFactory(FACTORY_TYPES[type], code); } catch (NoSuchAuthorityCodeException exception) { if (failure == null) { failure = noSuchAuthorityCode(IdentifiedObject.class, code);
/** * Same as {@link #fromFactoryRegistry(String, Class)}, but returns every factories that fit the * given type. The factories are added to the specified set. */ final void fromFactoryRegistry( final String authority, final Class<? extends AuthorityFactory> type, final Set<AuthorityFactory> addTo) { for (int i = 0; i < OBJECT_TYPES.length; i++) { if (OBJECT_TYPES[i].isAssignableFrom(type)) { final AuthorityFactory factory; try { factory = fromFactoryRegistry(authority, FACTORY_TYPES[i]); } catch (FactoryRegistryException e) { // No factory for the given authority. It may be normal. continue; } if (!exclude(factory)) { addTo.add(factory); } } } }
/** * Returns the direct dependencies. Current implementation returns the internal structure * because we know that this package will not modifies it. But if the method become public, we * will need to returns a unmodifiable view. */ @Override Collection<? super AuthorityFactory> dependencies() { return getFactories(); }
/** Returns a factory for the specified authority and type. */ @Override final <T extends AuthorityFactory> T fromFactoryRegistry( final String authority, final Class<T> type) throws FactoryRegistryException { final AuthorityFactory f; if (CRSAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCRSAuthorityFactory(authority, getHints()); } else if (CSAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCSAuthorityFactory(authority, getHints()); } else if (DatumAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getDatumAuthorityFactory(authority, getHints()); } else if (CoordinateOperationAuthorityFactory.class.equals(type)) { f = ReferencingFactoryFinder.getCoordinateOperationAuthorityFactory( authority, getHints()); } else { f = super.fromFactoryRegistry(authority, type); } return type.cast(f); }
return new ManyAuthoritiesFactory(factories);
factory = getAuthorityFactory(FACTORY_TYPES[type], code); } catch (NoSuchAuthorityCodeException exception) { if (failure == null) { failure = noSuchAuthorityCode(IdentifiedObject.class, code);
/** Returns the authority names of every factories given at construction time. */ public Set<String> getAuthorityNames() { final Set<String> names = new HashSet<String>(); final Collection<AuthorityFactory> factories = getFactories(); if (factories != null) { for (final AuthorityFactory factory : factories) { names.add(Citations.getIdentifier(factory.getAuthority())); } } return names; }
/** Returns all factories to try. */ private Set<AuthorityFactory> fromFactoryRegistry() { final ManyAuthoritiesFactory factory = (ManyAuthoritiesFactory) getProxy().getAuthorityFactory(); final Class<? extends AuthorityFactory> type = getProxy().getType(); final Set<AuthorityFactory> factories = new LinkedHashSet<AuthorityFactory>(); for (final String authority : ReferencingFactoryFinder.getAuthorityNames()) { factory.fromFactoryRegistry(authority, type, factories); } // Removes the factories already tried by super-class. final Collection<AuthorityFactory> done = getFactories(); if (done != null) { factories.removeAll(done); } return factories; }
/** * Returns the CRS authority factory for the specified {@code "AUTHORITY:NUMBER"} code. * * @param code The code to parse. * @return The authority factory. * @throws NoSuchAuthorityCodeException if no authority name has been found. */ @Override protected CRSAuthorityFactory getCRSAuthorityFactory(final String code) throws NoSuchAuthorityCodeException { return getAuthorityFactory(CRSAuthorityFactory.class, code); }
/** Returns the user-supplied factories. */ final Collection<AuthorityFactory> getFactories() { return ((ManyAuthoritiesFactory) getProxy().getAuthorityFactory()).getFactories(); }
/** * Creates a new factory using the specified set of user factories. Any call to a {@code * createFoo(code)} method will scan the supplied factories in their iteration order. The first * factory implementing the appropriate interface and having the expected {@linkplain * AuthorityFactory#getAuthority authority name} will be used. * * <p>If the {@code factories} collection contains more than one factory for the same authority * and interface, then all additional factories will be {@linkplain FallbackAuthorityFactory * fallbacks}, to be tried in iteration order only if the first acceptable factory failed to * create the requested object. * * @param factories A set of user-specified factories to try before to delegate to {@link * GeometryFactoryFinder}. */ public ManyAuthoritiesFactory(final Collection<? extends AuthorityFactory> factories) { super(NORMAL_PRIORITY); inProgress = new ThreadLocal<Boolean>(); if (factories != null && !factories.isEmpty()) { for (final AuthorityFactory factory : factories) { if (factory instanceof Factory) { hints.putAll(((Factory) factory).getImplementationHints()); } } this.factories = createFallbacks(factories); } }
/** * Returns the operation authority factory for the specified {@code "AUTHORITY:NUMBER"} code. * * @param code The code to parse. * @return The authority factory. * @throws NoSuchAuthorityCodeException if no authority name has been found. */ @Override protected CoordinateOperationAuthorityFactory getCoordinateOperationAuthorityFactory( final String code) throws NoSuchAuthorityCodeException { return getAuthorityFactory(CoordinateOperationAuthorityFactory.class, code); }
/** * Returns the factories to be used by {@link ManyAuthoritiesFactory}. If the registered * factories changed since the last time this method has been invoked, then this method recreate * the set. */ @Override Collection<AuthorityFactory> getFactories() { final Collection<String> authorities = ReferencingFactoryFinder.getAuthorityNames(); if (authorities != authorityNames) { authorityNames = authorities; final Hints hints = getHints(); final Set<AuthorityFactory> factories = new LinkedHashSet<AuthorityFactory>(); factories.addAll(ReferencingFactoryFinder.getCRSAuthorityFactories(hints)); factories.addAll(ReferencingFactoryFinder.getCSAuthorityFactories(hints)); factories.addAll(ReferencingFactoryFinder.getDatumAuthorityFactories(hints)); factories.addAll( ReferencingFactoryFinder.getCoordinateOperationAuthorityFactories(hints)); setFactories(factories); } return super.getFactories(); }
/** * Returns the datum authority factory for the specified {@code "AUTHORITY:NUMBER"} code. * * @param code The code to parse. * @return The authority factory. * @throws NoSuchAuthorityCodeException if no authority name has been found. */ @Override protected DatumAuthorityFactory getDatumAuthorityFactory(final String code) throws NoSuchAuthorityCodeException { return getAuthorityFactory(DatumAuthorityFactory.class, code); }
/** * Returns a generic object authority factory for the specified {@code "AUTHORITY:NUMBER"} code. * * @param code The code to parse. * @return The authority factory. * @throws NoSuchAuthorityCodeException if no authority name has been found. */ @Override protected AuthorityFactory getAuthorityFactory(final String code) throws NoSuchAuthorityCodeException { return getAuthorityFactory(AuthorityFactory.class, code); }