writer.close(); WorkspaceUtils.activateSynthetic( workspace, LayerStoreProvider.class, id, new String( bos.toByteArray(), Charset.forName( "UTF-8" ) ) );
/** * Collects all transitive dependencies of the resource node given. * * @param list * may not be <code>null</code> * @param node * may not be <code>null</code> */ public static void collectDependencies( List<ResourceMetadata<? extends Resource>> list, ResourceNode<? extends Resource> node ) { if ( node == null ) { return; } for ( ResourceNode<? extends Resource> n : node.getDependencies() ) { if ( n.getMetadata() != null ) { list.add( n.getMetadata() ); collectDependencies( list, n ); } } }
/** * Transitively collects all resources which depend on the resource connected to the node given. * * @param list * may not be <code>null</code> * @param node * may not be <code>null</code> */ public static void collectDependents( List<ResourceMetadata<? extends Resource>> list, ResourceNode<? extends Resource> node ) { if ( node == null ) { return; } for ( ResourceNode<? extends Resource> n : node.getDependents() ) { if ( n.getMetadata() != null ) { list.add( n.getMetadata() ); collectDependents( list, n ); } } }
public static void restart( String path, HttpServletResponse resp ) throws IOException, ServletException { Pair<DeegreeWorkspace, String> p = getWorkspaceAndPath( path ); resp.setContentType( "text/plain" ); try { if ( p.second != null ) { Workspace ws = p.first.getNewWorkspace(); List<ResourceIdentifier<?>> ids = WorkspaceUtils.getPossibleIdentifiers( ws, p.second ); for ( ResourceIdentifier<?> id : ids ) { WorkspaceUtils.reinitializeChain( ws, id ); } return; } OGCFrontController fc = OGCFrontController.getInstance(); fc.setActiveWorkspaceName( p.first.getName() ); fc.reload(); } catch ( Exception e ) { IOUtils.write( "Error while reloading: " + e.getLocalizedMessage() + "\n", resp.getOutputStream() ); return; } IOUtils.write( "Restart complete.", resp.getOutputStream() ); }
/** * Destroys and initializes all resources connected to the resource with the given id. * * @param workspace * may not be <code>null</code> * @param id * may not be <code>null</code> */ public static void reinitializeChain( Workspace workspace, ResourceIdentifier<? extends Resource> id ) { ResourceNode<? extends Resource> node = workspace.getDependencyGraph().getNode( id ); List<ResourceMetadata<? extends Resource>> list = new ArrayList<ResourceMetadata<? extends Resource>>(); ResourceMetadata<? extends Resource> meta = workspace.getResourceMetadata( id.getProvider(), id.getId() ); if ( meta == null ) { return; } list.add( meta ); collectDependencies( list, node ); collectDependents( list, node ); ResourceGraph g = new ResourceGraph( list ); list = g.toSortedList(); workspace.destroy( list.get( 0 ).getIdentifier() ); for ( ResourceMetadata<? extends Resource> md : list ) { workspace.add( md.getLocation() ); workspace.init( md.getIdentifier(), null ); } }
/** * 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; }
public void transform() throws TransformerException, XMLStreamException { OwsManager mgr = workspace.getResourceManager( OwsManager.class ); List<OWS> wmss = mgr.getByOWSClass( WMSController.class ); for ( OWS ows : wmss ) { ResourceMetadata<? extends Resource> md = ows.getMetadata(); ResourceIdentifier<? extends Resource> id = md.getIdentifier(); File loc = md.getLocation().resolveToFile( id.getId() + ".xml" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); transformer.transform( new StreamSource( loc ), new StreamResult( bos ) ); ThemeXmlStreamEncoder.writeOut( bos ); WorkspaceUtils.activateSynthetic( workspace, ThemeProvider.class, id.getId(), new String( bos.toByteArray(), Charset.forName( "UTF-8" ) ) ); } }
graph.insertNode( md ); List<ResourceMetadata<? extends Resource>> dependencies = new ArrayList<ResourceMetadata<?>>(); WorkspaceUtils.collectDependencies( dependencies, graph.getNode( id ) ); mdList.addAll( dependencies );