/** * Creates a finder using the specified factory. This constructor is protected because instances * of this class should not be created directly. Use {@link * AbstractAuthorityFactory#getIdentifiedObjectFinder} instead. * * @param factory The factory to scan for the identified objects. * @param type The type of objects to lookup. */ protected IdentifiedObjectFinder( final AuthorityFactory factory, final Class /*<? extends IdentifiedObject>*/ type) { setProxy(AuthorityFactoryProxy.getInstance(factory, type)); }
/** * Returns the set of authority codes. * * @throws FactoryException if access to the underlying database failed. */ public final Set /*<String>*/ getAuthorityCodes() throws FactoryException { return getAuthorityFactory().getAuthorityCodes(getType()); }
/** * Returns a set of authority codes that <strong>may</strong> identify the same object than the * specified one. The returned set must contains the code of every objects that are {@linkplain * CRS#equalsIgnoreMetadata equals, ignoring metadata}, to the specified one. However the set is * not required to contains only the codes of those objects; it may conservatively contains the * code for more objects if an exact search is too expensive. * * <p>This method is invoked by the default {@link #find find} method implementation. The caller * may iterates through every returned codes, instantiate the objects and compare them with the * specified one in order to determine which codes are really applicable. * * <p>The default implementation returns the same set than <code> * {@linkplain AuthorityFactory#getAuthorityCodes getAuthorityCodes}(type)</code> where {@code * type} is the interface specified at construction type. Subclasses should override this method * in order to return a smaller set, if they can. * * @param object The object looked up. * @return A set of code candidates. * @throws FactoryException if an error occured while fetching the set of code candidates. */ protected Set /*<String>*/ getCodeCandidates(final IdentifiedObject object) throws FactoryException { return getProxy().getAuthorityCodes(); }
proxy = AuthorityFactoryProxy.getInstance(factory, GeographicCRS.class); assertTrue(proxy.getClass().getName().endsWith("Geographic")); assertSame(expected, proxy.create("83")); assertSame(expected, proxy.create("CRS:83")); proxy = AuthorityFactoryProxy.getInstance(factory, CoordinateReferenceSystem.class); assertTrue(proxy.getClass().getName().endsWith("CRS")); assertSame(expected, proxy.create("83")); assertSame(expected, proxy.create("CRS:83")); proxy = AuthorityFactoryProxy.getInstance(factory, IdentifiedObject.class); assertTrue(proxy.getClass().getName().endsWith("Default")); assertSame(expected, proxy.create("83")); assertSame(expected, proxy.create("CRS:83")); proxy = AuthorityFactoryProxy.getInstance(factory, ProjectedCRS.class); assertTrue(proxy.getClass().getName().endsWith("Projected")); try { assertSame(expected, proxy.create("83")); fail(); } catch (FactoryException e) { proxy = AuthorityFactoryProxy.getInstance(factory, TemporalCRS.class); assertTrue(proxy.getClass().getName().endsWith("Default")); try { assertSame(expected, proxy.create("83")); fail(); } catch (FactoryException e) {
/** Returns the next finder in the specified set of factories, or {@code null} if none. */ final IdentifiedObjectFinder next(final Iterator<AuthorityFactory> it) throws FactoryException { while (it.hasNext()) { final AuthorityFactory factory = it.next(); if (exclude(factory)) { continue; } if (factory instanceof AbstractAuthorityFactory) { final IdentifiedObjectFinder finder = ((AbstractAuthorityFactory) factory) .getIdentifiedObjectFinder(getProxy().getType()); if (finder != null) { finder.setFullScanAllowed(isFullScanAllowed()); return finder; } } } return null; }
final Citation authority = getProxy().getAuthorityFactory().getAuthority(); final boolean isAll = ReferencingFactory.ALL.equals(authority); for (final Iterator it = object.getIdentifiers().iterator(); it.hasNext(); ) { candidate = getProxy().create(id.getCode()); } catch (NoSuchAuthorityCodeException e) {
IdentifiedObject candidate; try { candidate = getProxy().create(code); } catch (FactoryException e) { LOGGER.log(Level.FINEST, "Could not create '" + code + "':" + e);
/** Returns a string representation of this proxy, for debugging purpose only. */ @Override public String toString() { return toString(AuthorityFactoryProxy.class); }
/** * The Authority for this Finder; used during get Identifier. * * @return Citation for the authority being represented. */ protected Citation getAuthority() { return getProxy().getAuthorityFactory().getAuthority(); } /** Returns the identifier for the specified object. */
/** Tests {@link AuthorityFactoryProxy#getType(Class)}. */ @Test public void testType() { assertEquals(ProjectedCRS.class, AuthorityFactoryProxy.getType(ProjectedCRS.class)); assertEquals(ProjectedCRS.class, AuthorityFactoryProxy.getType(DefaultProjectedCRS.class)); assertEquals(GeographicCRS.class, AuthorityFactoryProxy.getType(GeographicCRS.class)); assertEquals( GeographicCRS.class, AuthorityFactoryProxy.getType(DefaultGeographicCRS.class)); assertEquals(DerivedCRS.class, AuthorityFactoryProxy.getType(DefaultDerivedCRS.class)); assertEquals( CoordinateReferenceSystem.class, AuthorityFactoryProxy.getType(AbstractDerivedCRS.class)); assertEquals( GeodeticDatum.class, AuthorityFactoryProxy.getType(DefaultGeodeticDatum.class)); }
/** Returns a string representation of this finder, for debugging purpose only. */ @Override public String toString() { return getProxy().toString(IdentifiedObjectFinder.class); }
/** Returns the user-supplied factories. */ final Collection<AuthorityFactory> getFactories() { return ((ManyAuthoritiesFactory) getProxy().getAuthorityFactory()).getFactories(); }
/** Returns a string representation of the specified object, for debugging purpose only. */ final String toString(final Class owner) { final AuthorityFactory factory = getAuthorityFactory(); return Classes.getShortName(owner) + '[' + Classes.getShortName(getType()) + " in " + Classes.getShortClassName(factory) + "(\"" + factory.getAuthority().getTitle() + "\")]"; }
/** Makes sure that {@link #fallback} is initialized. */ private void ensureFallback() throws FactoryException { if (fallback == null) { fallback = FallbackAuthorityFactory.this.fallback.getIdentifiedObjectFinder( getProxy().getType()); } fallback.setFullScanAllowed(isFullScanAllowed()); }
worker.findCache = findCache; setProxy(AuthorityFactoryProxy.getInstance(worker, type));
/** 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 a proxy instance which will create objects of the specified type using the specified * factory. * * @param factory The factory to use for object creations. * @param type The type of objects to be created by the proxy. */ public static AuthorityFactoryProxy getInstance( final AuthorityFactory factory, Class /*<? extends IdentifiedObject>*/ type) { AbstractAuthorityFactory.ensureNonNull("type", type); AbstractAuthorityFactory.ensureNonNull("factory", factory); type = getType(type); /* * Checks for some special cases for which a fast implementation is available. */ if (factory instanceof CRSAuthorityFactory) { final CRSAuthorityFactory crsFactory = (CRSAuthorityFactory) factory; if (type.equals(ProjectedCRS.class)) return new Projected(crsFactory); if (type.equals(GeographicCRS.class)) return new Geographic(crsFactory); if (type.equals(CoordinateReferenceSystem.class)) return new CRS(crsFactory); } /* * Fallback on the generic case using reflection. */ return new Default(factory, type); }