@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext); assertEquals(0, GeoServerExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]); expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class)) .andReturn(new String[] {"testKey", "fakeKey"}); expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]); expect(appContext.getBean("testKey")).andReturn(this); // note I'm testing null is a valid value. If that's not the case, it // should be reflected in the code, but I'm writing the test after the // code so that's what it does expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes(); expect(appContext.getBean("fakeKey")).andReturn(null); replay(appContext); List<GeoServerExtensionsTest> extensions = GeoServerExtensions.extensions(GeoServerExtensionsTest.class); assertNotNull(extensions); assertEquals(2, extensions.size()); assertTrue(extensions.contains(this)); assertTrue(extensions.contains(null)); assertEquals(3, GeoServerExtensions.extensionsCache.size()); assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class)); assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class)); assertEquals( 2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length); verify(appContext); }
try { Method s = null; if (AGGREGATE_SETVALUE_CACHE.containsKey(visitor.getClass())) { s = AGGREGATE_SETVALUE_CACHE.get(visitor.getClass()); } else {
if (rasterManager.granulesCache.containsKey(rasterFile.toURI().toString())) { granule = rasterManager.granulesCache.get(rasterFile.toURI().toString()); } else {
/** * Get an SVG ColorMap generator for the specified file * * @param file * @return * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ public static GradientColorMapGenerator getColorMapGenerator(final File file) throws SAXException, IOException, ParserConfigurationException { GradientColorMapGenerator generator = null; Utilities.ensureNonNull("file", file); final String identifier = file.getAbsolutePath(); synchronized (cache) { if (cache.containsKey(identifier)) { generator = cache.get(identifier); } else { // create the granule coverageDescriptor generator = parseSVG(file); cache.put(identifier, generator); } } return generator; }
@Override public VariableAdapter getCoverageDescriptor(Name name) { Utilities.ensureNonNull("name", name); final String name_ = name.toString(); synchronized (coverageSourceDescriptorsCache) { if (coverageSourceDescriptorsCache.containsKey(name_)) { return coverageSourceDescriptorsCache.get(name_); } // create, cache and return VariableAdapter cd; try { String origName = ancillaryFileManager.variablesMap != null ? ancillaryFileManager.variablesMap.get(name) : null; if (origName == null) { origName = name.getLocalPart(); } // else { // throw new IllegalArgumentException("Unable to locate // descriptor for Coverage: "+name); // } cd = new VariableAdapter(this, name, (VariableDS) getVariableByName(origName)); } catch (Exception e) { throw new RuntimeException(e); } coverageSourceDescriptorsCache.put(name_, cd); return cd; } }
if (coverageSliceDescriptorsCache.containsKey(granuleIndex)) { slice = coverageSliceDescriptorsCache.get(granuleIndex); } else {
/** * Return a {@link CoverageSource} related to the specified coverageName * * @param coverageName * @return * @throws IOException */ private CoverageSource getGridCoverageSource(final String coverageName) throws IOException { // Preliminar check on name availability checkIsSupported(coverageName); synchronized (coverages) { if (coverages.containsKey(coverageName)) { return coverages.get(coverageName); } // create, cache and return CoverageSource source = access.access( new NameImpl(coverageName), null, AccessType.READ_ONLY, null, null); coverages.put(coverageName, source); return source; } }
/** * Returns a default processor instance. * * <p><strong>Note:</strong> this is a temporary method, until we have GeoAPI interface for * coverage processor and a factory finder for their implementations. */ public static synchronized CoverageProcessor getInstance(final Hints hints) { if (hints == null || hints.isEmpty()) { if (DEFAULT == null) { DEFAULT = new CacheableCoverageProcessor(); processorsPool.put(new Hints(), DEFAULT); } return DEFAULT; } if (processorsPool.containsKey(hints)) return processorsPool.get(hints); final CoverageProcessor processor = new CacheableCoverageProcessor(hints); processorsPool.put(hints, processor); return processor; }
if (descriptorsCache.containsKey(featureId)) { granule = descriptorsCache.get(featureId); } else {
if(rasterManager.granulesCache.containsKey(rasterFile.toURI().toString()))
@Override public UnidataVariableAdapter getCoverageDescriptor(Name name) { Utilities.ensureNonNull("name", name); final String name_ = name.toString(); synchronized (coverageSourceDescriptorsCache) { if(coverageSourceDescriptorsCache.containsKey(name_)){ return coverageSourceDescriptorsCache.get(name_); } // create, cache and return UnidataVariableAdapter cd; try { String origName = ancillaryFileManager.variablesMap != null ? ancillaryFileManager.variablesMap.get(name) : null; if (origName == null) { origName = name.getLocalPart(); } // else { // throw new IllegalArgumentException("Unable to locate descriptor for Coverage: "+name); // } cd = new UnidataVariableAdapter(this, name, (VariableDS) getVariableByName(origName)); } catch (Exception e) { throw new RuntimeException(e); } coverageSourceDescriptorsCache.put(name_, cd); return cd; } }
/** * Return a {@link CoverageSource} related to the specified coverageName * * @param coverageName * @return * @throws IOException */ private CoverageSource getGridCoverageSource(final String coverageName) throws IOException { // Preliminar check on name availability checkIsSupported(coverageName); synchronized (coverages) { if (coverages.containsKey(coverageName)) { return coverages.get(coverageName); } // create, cache and return CoverageSource source = access.access( new NameImpl(coverageName), null, AccessType.READ_ONLY, null, null); coverages.put(coverageName, source); return source; } }
@Override public VariableAdapter getCoverageDescriptor(Name name) { Utilities.ensureNonNull("name", name); final String name_ = name.toString(); synchronized (coverageSourceDescriptorsCache) { if (coverageSourceDescriptorsCache.containsKey(name_)) { return coverageSourceDescriptorsCache.get(name_); } // create, cache and return VariableAdapter cd; try { String origName = ancillaryFileManager.variablesMap != null ? ancillaryFileManager.variablesMap.get(name) : null; if (origName == null) { origName = name.getLocalPart(); } // else { // throw new IllegalArgumentException("Unable to locate // descriptor for Coverage: "+name); // } cd = new VariableAdapter(this, name, (VariableDS) getVariableByName(origName)); } catch (Exception e) { throw new RuntimeException(e); } coverageSourceDescriptorsCache.put(name_, cd); return cd; } }
/** * Returns a default processor instance. * <p> * <strong>Note:</strong> this is a temporary method, until we have GeoAPI interface for * coverage processor and a factory finder for their implementations. */ public static synchronized CoverageProcessor getInstance(final Hints hints) { if(hints==null||hints.isEmpty()){ if (DEFAULT == null) { DEFAULT = new CacheableCoverageProcessor(); } return DEFAULT; } if(processorsPool.containsKey(hints)) return processorsPool.get(hints); final CoverageProcessor processor=new CacheableCoverageProcessor(hints); processorsPool.put(hints, processor); return processor; }
if (coverageSliceDescriptorsCache.containsKey(granuleIndex)) { slice = coverageSliceDescriptorsCache.get(granuleIndex); } else {
if(granuleDescriptorsCache.containsKey(granuleLocation)){ granule=granuleDescriptorsCache.get(granuleLocation); } else{
@Test public void testExtensions() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoServerExtensions gse = new GeoServerExtensions(); gse.setApplicationContext(appContext); assertEquals(0, GeoServerExtensions.extensionsCache.size()); expect(appContext.getBeanNamesForType(ExtensionFilter.class)).andReturn(new String[0]); expect(appContext.getBeanNamesForType(GeoServerExtensionsTest.class)) .andReturn(new String[] {"testKey", "fakeKey"}); expect(appContext.getBeanNamesForType(ExtensionProvider.class)).andReturn(new String[0]); expect(appContext.getBean("testKey")).andReturn(this); // note I'm testing null is a valid value. If that's not the case, it // should be reflected in the code, but I'm writing the test after the // code so that's what it does expect(appContext.isSingleton((String) anyObject())).andReturn(true).anyTimes(); expect(appContext.getBean("fakeKey")).andReturn(null); replay(appContext); List<GeoServerExtensionsTest> extensions = GeoServerExtensions.extensions(GeoServerExtensionsTest.class); assertNotNull(extensions); assertEquals(2, extensions.size()); assertTrue(extensions.contains(this)); assertTrue(extensions.contains(null)); assertEquals(3, GeoServerExtensions.extensionsCache.size()); assertTrue(GeoServerExtensions.extensionsCache.containsKey(GeoServerExtensionsTest.class)); assertNotNull(GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class)); assertEquals( 2, GeoServerExtensions.extensionsCache.get(GeoServerExtensionsTest.class).length); verify(appContext); }