1 /** 2 * This file Copyright (c) 2011 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.repository; 35 36 import info.magnolia.cms.security.AccessDeniedException; 37 import info.magnolia.repository.definition.RepositoryDefinition; 38 import info.magnolia.repository.definition.WorkspaceMappingDefinition; 39 40 import java.util.Collection; 41 42 import javax.jcr.Credentials; 43 import javax.jcr.Repository; 44 import javax.jcr.RepositoryException; 45 import javax.jcr.Session; 46 47 48 /** 49 * Manages JCR repositories. Initialization of a repository is handled by {@link Provider}s. Magnolia can be configured 50 * to have its workspaces in more than one repository. This is abstracted through this class which maps a set of 51 * "logical" workspace names to their actual "physical" workspace names in a repository. 52 * 53 * Configuration of providers and workspace mappings are done in repositories.xml. 54 * 55 * @see Provider 56 * @see info.magnolia.repository.definition.RepositoryMappingDefinitionReader 57 * @version $Id$ 58 */ 59 public interface RepositoryManager { 60 61 /** 62 * Initializes by loading configuration from repositories.xml. 63 */ 64 void init(); 65 66 /** 67 * Shuts down all repositories (through Provider instances) and clears all mappings. 68 */ 69 void shutdown(); 70 71 // TODO The implementation of this in ContentRepository seems fishy, it clears the Repository instances and reads the xml again 72 // what is the effect on things added after init() ? 73 /** 74 * Re-load all configured repositories. 75 * @see #init() 76 */ 77 void reload(); 78 79 Session getSession(String logicalWorkspaceName, Credentials credentials) throws RepositoryException; 80 81 Session getSystemSession(String logicalWorkspaceName) throws RepositoryException; 82 83 /** 84 * Verify the initialization state of all the workspaces. This methods returns <code>false</code> only if 85 * <strong>all</strong> the workspaces are empty (no node else than the root one). 86 * 87 * @return <code>false</code> if all the workspaces are empty, <code>true</code> if at least one of them has content. 88 * @throws AccessDeniedException repository authentication failed 89 * @throws RepositoryException exception while accessing the repository 90 */ 91 boolean checkIfInitialized() throws AccessDeniedException, RepositoryException; 92 93 /** 94 * Verifies the initialization state of a workspace. 95 */ 96 boolean checkIfInitialized(String logicalWorkspace) throws RepositoryException, AccessDeniedException; 97 98 /** 99 * Adds a repository definition and instantiates its provider. If the loadOnStartup property is true it also 100 * registers namespaces and node types. You must not call this method twice. 101 */ 102 void loadRepository(RepositoryDefinition definition) throws RepositoryNotInitializedException, InstantiationException, IllegalAccessException, ClassNotFoundException; 103 104 /** 105 * Loads a workspace by registering namespaces and node types on a workspace that has not previously been loaded. 106 * Also adds a workspace mapping that maps the physical workspace name as a logical name. 107 */ 108 void loadWorkspace(String repositoryId, String physicalWorkspaceName) throws RepositoryException; 109 110 boolean hasRepository(String repositoryId); 111 112 /** 113 * Returns repository mapping as configured, or null if not found. 114 */ 115 RepositoryDefinition getRepositoryDefinition(String repositoryId); 116 117 /** 118 * Returns the provider instance for a repository. 119 * 120 * @throws IllegalArgumentException if there is no such repository 121 */ 122 Provider getRepositoryProvider(String repositoryId); 123 124 /** 125 * Returns repository instance for a repository. 126 * 127 * @throws IllegalArgumentException if there is no such repository 128 */ 129 Repository getRepository(String repositoryId); 130 131 void addWorkspaceMapping(WorkspaceMappingDefinition mapping); 132 133 boolean hasWorkspace(String logicalWorkspaceName); 134 135 Collection<WorkspaceMappingDefinition> getWorkspaceMappings(); 136 137 WorkspaceMappingDefinition getWorkspaceMapping(String logicalWorkspaceName); 138 139 /** 140 * Returns workspace names. 141 * 142 * @return repository names 143 */ 144 Collection<String> getWorkspaceNames(); 145 }