/** 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; }
"Should find without the need for scan, since we can use the CRS:84 identifier.", CRS84, finder.find(CRS84)); finder.find(DefaultGeographicCRS.WGS84)); "A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.find(DefaultGeographicCRS.WGS84)); "At the contrary of testFind(), the scan result should be cached.", CRS84, finder.find(DefaultGeographicCRS.WGS84));
/** 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 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; }
"Should find without the need for scan, since we can use the CRS:84 identifier.", CRS84, finder.find(CRS84)); "Allowing scanning should not make any difference for this CRS84 instance.", CRS84, finder.find(CRS84)); assertNull( "Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.", finder.find(DefaultGeographicCRS.WGS84)); "A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.find(DefaultGeographicCRS.WGS84)); "The scan result should not be cached.", finder.find(DefaultGeographicCRS.WGS84)); assertNull( "Should not find WGS84 without a full scan, since it doesn't contains the CRS:84 identifier.", finder.find(search)); "A full scan should allow us to find WGS84, since it is equals ignoring metadata to CRS:84.", CRS84, finder.find(search));
candidate = finder.find(object); if (candidate != null) { synchronized (findPool) {
candidate = finder.find(object); if (candidate != null) { synchronized (findPool) {
/** Lookups for the specified object. */ @Override public IdentifiedObject find(final IdentifiedObject object) throws FactoryException { IdentifiedObject candidate = super.find(object); if (candidate != null) { return candidate; } IdentifiedObjectFinder finder; final Iterator<AuthorityFactory> it = fromFactoryRegistry().iterator(); while ((finder = next(it)) != null) { candidate = finder.find(object); if (candidate != null) { break; } } return candidate; }
/** Lookups for the specified object. */ @Override public IdentifiedObject find(final IdentifiedObject object) throws FactoryException { /* * Try to create from the identifier before to scan over every factories, * because the identifier may contains the authority name, in which case * we can pickup directly the right factory instead of trying them all. */ IdentifiedObject candidate = createFromIdentifiers(object); if (candidate != null) { return candidate; } final Collection<AuthorityFactory> factories = getFactories(); if (factories != null) { IdentifiedObjectFinder finder; final Iterator<AuthorityFactory> it = factories.iterator(); while ((finder = next(it)) != null) { candidate = finder.find(object); if (candidate != null) { break; } } } return candidate; }
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; }
return super.getCodeCandidates(object); dependency = getIdentifiedObjectFinder(dependency.getClass()).find(dependency); Identifier id = AbstractIdentifiedObject.getIdentifier(dependency, getAuthority()); if (id == null || (code = id.getCode()) == null) {
/** * Looks up an object from this authority factory which is equals, ignoring metadata, to the * specified object. The default implementation performs the same lookup than the backing * store and caches the result. */ @Override public IdentifiedObject find(final IdentifiedObject object) throws FactoryException { IdentifiedObject candidate; candidate = (IdentifiedObject) findCache.get(object); if (candidate != null) { return candidate; } try { findCache.writeLock(object); // avoid searching for the same object twice IdentifiedObject found = super.find(object); if (found == null) { return null; // not found } candidate = (IdentifiedObject) findCache.peek(object); if (candidate == null) { findCache.put(object, found); return found; } else { return candidate; } } finally { findCache.writeUnLock(object); } }
IdentifiedObject found = finder.find(object); if (found != null) { try {
found = super.find(object); } catch (Exception e) { throw new FactoryException(e);