/** * Returns a finder which can be used for looking up unidentified objects. The finder fetchs a * fully {@linkplain IdentifiedObject identified object} from an incomplete one, for example * from an object without identifier or "{@code AUTHORITY[...]}" element in <cite>Well Known * Text</cite> terminology. * * @param type The type of objects to look for. Should be a GeoAPI interface like {@code * GeographicCRS.class}, but this method accepts also implementation class. If the type is * unknown, use {@code IdentifiedObject.class}. A more accurate type may help to speed up * the search, since it reduces the amount of tables to scan in some implementations like * the factories backed by EPSG database. * @return A finder to use for looking up unidentified objects. * @throws FactoryException if the finder can not be created. * @since 2.4 */ public IdentifiedObjectFinder getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type) throws FactoryException { return new IdentifiedObjectFinder(this, type); }
IdentifiedObject candidate = createFromIdentifiers(object); if (candidate != null) { return candidate; candidate = createFromNames(object); if (candidate != null) { return candidate; candidate = createFromCodes(object, true); if (candidate != null) { return candidate; return fullScan ? createFromCodes(object, false) : null;
/** Lookups for the specified object. */ @Override public IdentifiedObject find(final IdentifiedObject object) throws FactoryException { IdentifiedObject candidate = finder.find(object); if (candidate != null) { return candidate; } ensureFallback(); candidate = fallback.find(object); return candidate; }
/** * Returns the identifier of the specified object, or {@code null} if none. The default * implementation invokes <code>{@linkplain #find find}(object)</code> and extracts the code * from the returned {@linkplain IdentifiedObject identified object}. */ public String findIdentifier(final IdentifiedObject object) throws FactoryException { final IdentifiedObject candidate = find(object); return (candidate != null) ? getIdentifier(candidate) : null; }
throws FactoryException { final Set /*<String>*/ codes = specific ? getSpecificCodeCandidates(object) : getCodeCandidates(object); for (final Iterator it = codes.iterator(); it.hasNext(); ) { final String code = (String) it.next(); IdentifiedObject candidate; try { candidate = getProxy().create(code); } catch (FactoryException e) { LOGGER.log(Level.FINEST, "Could not create '" + code + "':" + e); candidate = deriveEquivalent(candidate, object); if (candidate != null) { return candidate;
/** * Tests {@link IdentifiedObjectFinder#createFromCodes}. We uses the CRS factory for testing * purpose. */ @Test public void testCreateFromCodes() throws FactoryException { final CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("CRS", null); final IdentifiedObjectFinder proxy = new IdentifiedObjectFinder(factory, GeographicCRS.class); CoordinateReferenceSystem expected = factory.createCoordinateReferenceSystem("84"); assertNotSame(expected, DefaultGeographicCRS.WGS84); assertSame(expected, proxy.createFromCodes(expected, false)); assertSame(expected, proxy.createFromIdentifiers(expected)); assertNull(proxy.createFromNames(expected)); assertSame(expected, proxy.createFromCodes(DefaultGeographicCRS.WGS84, false)); assertNull(proxy.createFromIdentifiers(DefaultGeographicCRS.WGS84)); assertNull(proxy.createFromNames(DefaultGeographicCRS.WGS84)); expected = factory.createCoordinateReferenceSystem("83"); assertSame(expected, proxy.createFromCodes(expected, false)); assertSame(expected, proxy.createFromIdentifiers(expected)); assertNull(proxy.createFromNames(expected)); } }
factory.getIdentifiedObjectFinder(CoordinateReferenceSystem.class); finder.setFullScanAllowed(false); assertSame( "Should find without the need for scan, since we can use the CRS:84 identifier.", CRS84, finder.find(CRS84)); finder.setFullScanAllowed(false); assertNull( "Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.", finder.find(DefaultGeographicCRS.WGS84)); finder.setFullScanAllowed(true); assertSame( "A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.find(DefaultGeographicCRS.WGS84)); finder.setFullScanAllowed(false); assertSame( "At the contrary of testFind(), the scan result should be cached.", CRS84, finder.find(DefaultGeographicCRS.WGS84)); assertEquals("CRS:84", finder.findIdentifier(DefaultGeographicCRS.WGS84));
final IdentifiedObjectFinder finder = factory.getIdentifiedObjectFinder(CoordinateReferenceSystem.class); assertTrue("Newly created finder should default to full scan.", finder.isFullScanAllowed()); finder.setFullScanAllowed(false); assertSame( "Should find without the need for scan, since we can use the CRS:84 identifier.", CRS84, finder.find(CRS84)); finder.setFullScanAllowed(true); assertSame( "Allowing scanning should not make any difference for this CRS84 instance.", CRS84, finder.find(CRS84)); finder.setFullScanAllowed(false); assertNull( "Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.", finder.find(DefaultGeographicCRS.WGS84)); finder.setFullScanAllowed(true); assertSame( "A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.find(DefaultGeographicCRS.WGS84)); finder.setFullScanAllowed(false); assertNull(
/** Returns the identifier of the specified object, or {@code null} if none. */ @Override public String findIdentifier(final IdentifiedObject object) throws FactoryException { String candidate = finder.findIdentifier(object); if (candidate != null) { return candidate; } ensureFallback(); candidate = fallback.findIdentifier(object); return candidate; } }
final IdentifiedObjectFinder finder = xyFactory.getIdentifiedObjectFinder(object.getClass()); finder.setFullScanAllowed(fullScan); return finder.findIdentifier(object);
private Identifier identifySubObject( AbstractAuthorityFactory factory, IdentifiedObject dependency) throws FactoryException { IdentifiedObjectFinder identifiedObjectFinder = factory.getIdentifiedObjectFinder(dependency.getClass()); identifiedObjectFinder.setFullScanAllowed(isFullScanAllowed()); IdentifiedObject identifiedDependency = identifiedObjectFinder.find(dependency); Identifier id = AbstractIdentifiedObject.getIdentifier(identifiedDependency, getAuthority()); return id; }
/** Set whatever an exhaustive scan against all registered objects is allowed. */ @Override public void setFullScanAllowed(final boolean fullScan) { finder.setFullScanAllowed(fullScan); super.setFullScanAllowed(fullScan); }
where = "ELLIPSOID_CODE"; } else { return super.getCodeCandidates(object); dependency = getIdentifiedObjectFinder(dependency.getClass()).find(dependency); Identifier id = AbstractIdentifiedObject.getIdentifier(dependency, getAuthority()); if (id == null || (code = id.getCode()) == null) { return super.getCodeCandidates(object);
IdentifiedObject candidate; try { candidate = getProxy().create(object.getName().getCode()); candidate = deriveEquivalent(candidate, object); if (candidate != null) { return candidate; final GenericName id = (GenericName) it.next(); try { candidate = getProxy().create(id.toString()); } catch (FactoryException e) { candidate = deriveEquivalent(candidate, object); if (candidate != null) { return candidate;
/** * Returns a set of authority codes that <strong>may</strong> identify the same object than * the specified one. The default implementation delegates to the backing finder. */ @Override protected Set /*<String>*/ getCodeCandidates(final IdentifiedObject object) throws FactoryException { return finder.getCodeCandidates(object); }
/** * Returns {@code candidate}, or an object derived from {@code candidate}, if it is * {@linkplain CRS#equalsIgnoreMetadata equals ignoring metadata} to the specified model. * The default implementation delegates to the backing finder. */ @Override protected IdentifiedObject deriveEquivalent( final IdentifiedObject candidate, final IdentifiedObject model) throws FactoryException { return finder.deriveEquivalent(candidate, model); } }
/** Returns the identifier for the specified object. */ final String getIdentifier(final IdentifiedObject object) { Citation authority = getAuthority(); if (ReferencingFactory.ALL.equals(authority)) { /* * "All" is a pseudo-authority declared by AllAuthoritiesFactory. This is not a real * authority, so we will not find any identifier if we search for this authority. We * will rather pickup the first identifier, regardless its authority. */ authority = null; } ReferenceIdentifier identifier = AbstractIdentifiedObject.getIdentifier(object, authority); if (identifier == null) { identifier = object.getName(); // Should never be null past this point, since 'name' is a mandatory attribute. } final String codespace = identifier.getCodeSpace(); final String code = identifier.getCode(); if (codespace != null) { return codespace + org.geotools.util.GenericName.DEFAULT_SEPARATOR + code; } else { return code; } }
/** Tests the {@link IdentifiedObjectFinder#find} method. */ @Test public void testFind() throws FactoryException { final AbstractAuthorityFactory all = AllAuthoritiesFactory.DEFAULT; final IdentifiedObjectFinder finder = all.getIdentifiedObjectFinder(CoordinateReferenceSystem.class); finder.setFullScanAllowed(false); assertNull( "Should not find the CRS without a scan.", finder.find(DefaultGeographicCRS.WGS84)); finder.setFullScanAllowed(true); final IdentifiedObject find = finder.find(DefaultGeographicCRS.WGS84); assertNotNull("With scan allowed, should find the CRS.", find); assertTrue(CRS.equalsIgnoreMetadata(find, DefaultGeographicCRS.WGS84)); assertSame(all.createCoordinateReferenceSystem("CRS:84"), find); assertEquals("CRS:84", finder.findIdentifier(DefaultGeographicCRS.WGS84)); } }
/** Returns the identifier for the specified object. */ @Override public String findIdentifier(final IdentifiedObject object) throws FactoryException { IdentifiedObject candidate; synchronized (findPool) { candidate = findPool.get(object); } if (candidate != null) { return getIdentifier(candidate); } // We don't rely on super-class implementation, because we want to // take advantage of the method overriden by AllAuthoritiesFactory. return finder.findIdentifier(object); } }
finder.setFullScanAllowed(fullScan); final String code = finder.findIdentifier(crs); if (code != null) { return code;