private void scan() { LOG.info( "--------------------------------------------------------------------------------" ); LOG.info( "Scanning resources." ); LOG.info( "--------------------------------------------------------------------------------" ); for ( ResourceManager<? extends Resource> mgr : resourceManagers.values() ) { mgr.find(); Collection<? extends ResourceMetadata<? extends Resource>> mds = mgr.getResourceMetadata(); for ( ResourceMetadata<? extends Resource> md : mds ) { resourceMetadata.put( md.getIdentifier(), md ); if ( states.getState( md.getIdentifier() ) != Deactivated ) { states.setState( md.getIdentifier(), Scanned ); } } } }
/** * 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; }
private void removeMetadataFromResourceManager( ResourceIdentifier<?> id ) { for ( ResourceManager<?> mgr : getResourceManagers() ) { for ( ResourceMetadata<?> md : mgr.getResourceMetadata() ) { if ( md.getIdentifier() == id ) { mgr.remove (md); return; } } } }
ResourceManager<?> mgr = iter.next(); LOG.info( "Found resource manager {}.", mgr.getClass().getSimpleName() ); resourceManagers.put( mgr.getMetadata().getProviderClass(), mgr ); LOG.info( "Starting up resource manager {}.", mgr.getClass().getSimpleName() ); mgr.startup( this );
@Override public <T extends Resource> void add( ResourceLocation<T> location ) { LOG.info( "Scanning {}", location.getIdentifier() ); ResourceManager<T> mgr = (ResourceManager) resourceManagers.get( location.getIdentifier().getProvider() ); ResourceMetadata<T> md = mgr.add( location ); resourceMetadata.put( md.getIdentifier(), md ); }
/** * Searches for resource managers corresponding to a workspace path. * * @param workspace * may not be <code>null</code> * @param path * may not be <code>null</code>, may contain other path elements * @return a list of matching resource managers, may be empty but never <code>null</code> */ public static List<ResourceManager<?>> getManagersForWorkspacePath( Workspace workspace, String path ) { List<ResourceManager<?>> result = new ArrayList<ResourceManager<?>>(); List<ResourceManager<?>> list = workspace.getResourceManagers(); for ( ResourceManager<?> mgr : list ) { ResourceManagerMetadata<?> md = mgr.getMetadata(); if ( path.startsWith( md.getWorkspacePath() ) ) { result.add( mgr ); } } return result; }
@Override public <T extends Resource> ResourceLocation<T> persist( ResourceLocation<T> location ) { ResourceManager<?> mgr = managers.get( location.getIdentifier().getProvider() ); File file = new File( directory, mgr.getMetadata().getWorkspacePath() ); file = new File( file, location.getIdentifier().getId() + ".xml" ); file.getParentFile().mkdirs(); try { // copy to avoid persisting from same file File tmp = File.createTempFile( "config", ".xml" ); FileUtils.copyInputStreamToFile( location.getAsStream(), tmp ); tmp.renameTo( file ); return new DefaultResourceLocation<T>( file, location.getIdentifier() ); } catch ( Exception e ) { throw new ResourceException( "Could not persist resource location: " + e.getLocalizedMessage(), e ); } }