@Override public <T extends Resource> ResourceMetadata<T> getResourceMetadata( Class<? extends ResourceProvider<T>> providerClass, String id ) { return (ResourceMetadata<T>) resourceMetadata.get( new DefaultResourceIdentifier<T>( providerClass, id ) ); }
/** * Implementation as proposed by Joshua Block in Effective Java (Addison-Wesley 2001), which supplies an even * distribution and is relatively fast. It is created from field <b>f</b> as follows: * <ul> * <li>boolean -- code = (f ? 0 : 1)</li> * <li>byte, char, short, int -- code = (int)f</li> * <li>long -- code = (int)(f ^ (f >>>32))</li> * <li>float -- code = Float.floatToIntBits(f);</li> * <li>double -- long l = Double.doubleToLongBits(f); code = (int)(l ^ (l >>> 32))</li> * <li>all Objects, (where equals( ) calls equals( ) for this field) -- code = f.hashCode( )</li> * <li>Array -- Apply above rules to each element</li> * </ul> * <p> * Combining the hash code(s) computed above: result = 37 * result + code; * </p> * * @return (int) ( result >>> 32 ) ^ (int) result; * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { // the 2nd millionth prime, :-) long result = 32452843; result = result * 37 + getId().hashCode(); result = result * 37 + getProvider().hashCode(); return (int) ( result >>> 32 ) ^ (int) result; }
@Override public <T extends Resource> T getResource( Class<? extends ResourceProvider<T>> providerClass, String id ) { return (T) resources.get( new DefaultResourceIdentifier( providerClass, id ) ); }
@Override public boolean equals( Object obj ) { if ( !( obj instanceof ResourceIdentifier ) ) { return false; } ResourceIdentifier<? extends Resource> id = (ResourceIdentifier<?>) obj; return getId().equals( id.getId() ) && getProvider().equals( id.getProvider() ); }
public static List<ResourceIdentifier<StyleStore>> getStyleDeps( List<StyleRefType> styles ) { List<ResourceIdentifier<StyleStore>> list = new ArrayList<ResourceIdentifier<StyleStore>>(); for ( StyleRefType srt : styles ) { String id = srt.getStyleStoreId(); list.add( new DefaultResourceIdentifier<StyleStore>( StyleStoreProvider.class, id ) ); } return list; }
private void addStandardConfig( Workspace workspace, String name, String wkssId, List<ResourceMetadata<TileMatrixSet>> list ) { URL url = DefaultTileMatrixSetProvider.class.getResource( name + ".xml" ); ResourceIdentifier<TileMatrixSet> id = new DefaultResourceIdentifier<TileMatrixSet>( TileMatrixSetProvider.class, name ); byte[] bs; try { bs = IOUtils.toByteArray( url ); ResourceLocation<TileMatrixSet> loc = new IncorporealResourceLocation<TileMatrixSet>( bs, id ); DefaultTileMatrixSetMetadata md = new DefaultTileMatrixSetMetadata( workspace, loc, this ); list.add( md ); if ( wkssId != null ) { id = new DefaultResourceIdentifier<TileMatrixSet>( TileMatrixSetProvider.class, wkssId ); loc = new IncorporealResourceLocation<TileMatrixSet>( bs, id ); md = new DefaultTileMatrixSetMetadata( workspace, loc, this ); list.add( md ); } } catch ( IOException e ) { LOG.error( "Unable to load standard tile matrix set config {}.", id ); } }
@Override public ResourceBuilder<FeatureStore> prepare() { try { SQLFeatureStoreJAXB cfg = (SQLFeatureStoreJAXB) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, location.getAsStream(), workspace ); String connid = cfg.getJDBCConnId().getValue(); dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, connid ) ); dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, "LOCK_DB" ) ); return new SqlFeatureStoreBuilder( this, cfg, workspace ); } catch ( Exception e ) { throw new ResourceInitException( e.getLocalizedMessage(), e ); } }
@Override public <T extends Resource> List<ResourceLocation<T>> findResourceLocations( ResourceManagerMetadata<T> metadata ) { List<ResourceLocation<T>> list = new ArrayList<ResourceLocation<T>>(); if ( extraResources.get( metadata.getProviderClass() ) != null ) { list.addAll( (Collection) extraResources.get( metadata.getProviderClass() ) ); } File dir = new File( directory, metadata.getWorkspacePath() ); if ( !dir.isDirectory() ) { return list; } URI base = dir.getAbsoluteFile().toURI(); for ( File f : FileUtils.listFiles( dir, new String[] { "xml", "ignore" }, true ) ) { URI uri = f.getAbsoluteFile().toURI(); uri = base.relativize( uri ); String p = uri.getPath(); ResourceState state = null; if ( p.endsWith( "xml" ) ) { p = p.substring( 0, p.length() - 4 ); } else { p = p.substring( 0, p.length() - 7 ); state = ResourceState.Deactivated; } DefaultResourceIdentifier<T> identifier = new DefaultResourceIdentifier<T>( metadata.getProviderClass(), p ); if ( state != null ) { states.setState( identifier, state ); } list.add( new DefaultResourceLocation<T>( f, identifier ) ); } return list; }
@Override public ResourceBuilder<FeatureStore> prepare() { try { MemoryFeatureStoreConfig config = (MemoryFeatureStoreConfig) unmarshall( "org.deegree.feature.persistence.memory.jaxb", CONFIG_SCHEMA, location.getAsStream(), workspace ); dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, "LOCK_DB" ) ); return new MemoryFeatureStoreBuilder( this, config, workspace ); } catch ( Exception e ) { throw new ResourceInitException( e.getLocalizedMessage(), e ); } }
@Override public ResourceBuilder<Theme> prepare() { try { RemoteWMSThemes cfg = (RemoteWMSThemes) unmarshall( "org.deegree.theme.persistence.remotewms.jaxb", provider.getSchema(), location.getAsStream(), workspace ); String id = cfg.getRemoteWMSId(); String lid = cfg.getLayerStoreId(); dependencies.add( new DefaultResourceIdentifier<LayerStore>( LayerStoreProvider.class, lid ) ); dependencies.add( new DefaultResourceIdentifier<RemoteOWS>( RemoteOWSProvider.class, id ) ); return new RemoteWmsThemeBuilder( this, workspace, cfg ); } catch ( Exception e ) { throw new ResourceInitException( "Could not parse remote WMS theme config.", e ); } }
bos.close(); ResourceIdentifier<ConnectionProvider> rid; rid = new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, id ); return new IncorporealResourceLocation<ConnectionProvider>( bos.toByteArray(), rid ); } catch ( Exception e ) {
@Override public SpringConnectionProviderBuilder prepare() { final SpringConnectionProviderConfig config; try { config = (SpringConnectionProviderConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, location.getAsStream(), workspace ); final String applicationContextHolder = config.getApplicationContextHolder(); dependencies.add( new DefaultResourceIdentifier<ApplicationContextHolder>( ApplicationContextHolderProvider.class, applicationContextHolder ) ); } catch ( Exception e ) { LOG.trace( "Stack trace:", e ); throw new ResourceInitException( e.getLocalizedMessage(), e ); } return new SpringConnectionProviderBuilder( workspace, this, config ); } }
@Override public ResourceBuilder<TileStore> prepare() { try { org.deegree.tile.persistence.merge.jaxb.MergingTileStore cfg; cfg = (org.deegree.tile.persistence.merge.jaxb.MergingTileStore) unmarshall( JAXB_NAMESPACE, provider.getSchema(), location.getAsStream(), workspace ); dependencies.add( new DefaultResourceIdentifier<TileMatrixSet>( TileMatrixSetProvider.class, cfg.getTileMatrixSetId() ) ); for ( String tileStoreId : cfg.getTileStoreId() ) { dependencies.add( new DefaultResourceIdentifier<TileStore>( TileStoreProvider.class, tileStoreId ) ); } return new MergingTileStoreBuilder( cfg, this, workspace ); } catch ( Exception e ) { throw new ResourceInitException( "Could not prepare MergingTileStore: " + e.getLocalizedMessage(), e ); } } }
/** * Returns a list of possible resource identifiers for a given workspace path. * * @param workspace * @param path * @return */ public static List<ResourceIdentifier<?>> getPossibleIdentifiers( Workspace workspace, String path ) { List<ResourceManager<?>> list = getManagersForWorkspacePath( workspace, path ); List<ResourceIdentifier<?>> result = new ArrayList<ResourceIdentifier<?>>(); for ( ResourceManager<?> mgr : list ) { Class<?> cls = mgr.getMetadata().getProviderClass(); int one = mgr.getMetadata().getWorkspacePath().endsWith( "/" ) ? 0 : 1; String id = path.substring( mgr.getMetadata().getWorkspacePath().length() + one ); result.add( new DefaultResourceIdentifier( cls, id ) ); } return result; }
@Override public ResourceBuilder<TileStore> prepare() { try { RemoteWMTSTileStoreJAXB config = unmarshallConfig(); String wmts = config.getRemoteWMTSId(); dependencies.add( new DefaultResourceIdentifier<RemoteOWS>( RemoteOWSProvider.class, wmts ) ); // does not really collect all dependencies, only the ones that can be determined from config // probably needs to be adapted to also use the matrix set ids from remote as dependencies for ( RemoteWMTSTileStoreJAXB.TileDataSet tds : config.getTileDataSet() ) { if ( tds.getTileMatrixSetId() != null ) { dependencies.add( new DefaultResourceIdentifier<TileMatrixSet>( TileMatrixSetProvider.class, tds.getTileMatrixSetId() ) ); } } return new RemoteWmtsTileStoreBuilder( config, workspace, this ); } catch ( Exception e ) { throw new ResourceInitException( "Unable to create resource " + location.getIdentifier() + ": " + e.getLocalizedMessage(), e ); } }
/** * Adds and completely initializes a synthetic resource from string. * * @param workspace * may not be <code>null</code> * @param providerClass * may not be <code>null</code> * @param id * may not be <code>null</code> * @param content * configuration content, may not be <code>null</code> * @return the initialized resource */ public static <T extends Resource> T activateSynthetic( Workspace workspace, Class<? extends ResourceProvider<T>> providerClass, String id, String content ) { IncorporealResourceLocation<? extends Resource> loc; ResourceIdentifier<T> identifier = new DefaultResourceIdentifier<T>( providerClass, id ); Charset cs = Charset.forName( "UTF-8" ); loc = new IncorporealResourceLocation<T>( content.getBytes( cs ), identifier ); workspace.add( loc ); workspace.prepare( identifier ); return workspace.init( identifier, null ); }
@Override public ResourceBuilder<TileStore> prepare() { try { FileSystemTileStoreJAXB config = (FileSystemTileStoreJAXB) unmarshall( JAXB_PACKAGE, provider.getSchema(), location.getAsStream(), workspace ); for ( FileSystemTileStoreJAXB.TileDataSet tds : config.getTileDataSet() ) { String tmsId = tds.getTileMatrixSetId(); dependencies.add( new DefaultResourceIdentifier<TileMatrixSet>( TileMatrixSetProvider.class, tmsId ) ); TileDataSetBase base = tds.getTileDataSetBase(); if ( base != null ) { dependencies.add( new DefaultResourceIdentifier<TileStore>( TileStoreProvider.class, base.getTileStoreId() ) ); } } return new FileSystemTileStoreBuilder( config, this, workspace ); } catch ( Exception e ) { String msg = "Unable to prepare FileSystemTileStore: " + e.getMessage(); LOG.error( msg ); throw new ResourceInitException( msg, e ); } }
@Override public ResourceBuilder<RenderableStore> prepare() { try { RenderableSQLStoreConfig config = (RenderableSQLStoreConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, provider.getSchema(), location.getAsStream(), workspace ); dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, config.getJDBCConnId() ) ); return new SqlRenderableStoreBuilder( config, this, workspace ); } catch ( Exception e ) { throw new ResourceInitException( e.getLocalizedMessage(), e ); } }
@Override public ResourceBuilder<FeatureStore> prepare() { SimpleSQLFeatureStoreConfig config; try { config = (SimpleSQLFeatureStoreConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, location.getAsStream(), workspace ); String connId = config.getConnectionPoolId(); if ( connId == null ) { connId = config.getJDBCConnId(); } dependencies.add( new DefaultResourceIdentifier<ConnectionProvider>( ConnectionProviderProvider.class, connId ) ); return new SimpleSqlFeatureStoreBuilder( this, config, workspace ); } catch ( Exception e ) { LOG.trace( "Stack trace:", e ); throw new ResourceInitException( e.getLocalizedMessage(), e ); } }
@Override public ResourceBuilder<TileStore> prepare() { try { org.deegree.tile.persistence.cache.jaxb.CachingTileStore cfg; cfg = (org.deegree.tile.persistence.cache.jaxb.CachingTileStore) unmarshall( "org.deegree.tile.persistence.cache.jaxb", provider.getSchema(), location.getAsStream(), workspace ); String tsid = cfg.getTileStoreId(); dependencies.add( new DefaultResourceIdentifier<TileStore>( TileStoreProvider.class, tsid ) ); return new CachingTileStoreBuilder( cfg, this, workspace ); } catch ( Exception e ) { throw new ResourceInitException( "Could not prepare tile store: " + e.getLocalizedMessage(), e ); } }