1 /** 2 * This file Copyright (c) 2011-2015 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 */ 58 public interface RepositoryManager { 59 60 /** 61 * Initializes by loading configuration from repositories.xml. 62 */ 63 void init(); 64 65 /** 66 * Shuts down all repositories (through Provider instances) and clears all mappings. 67 */ 68 void shutdown(); 69 70 // TODO The implementation of this in ContentRepository seems fishy, it clears the Repository instances and reads the xml again 71 // what is the effect on things added after init() ? 72 73 /** 74 * Re-load all configured repositories. 75 * 76 * @see #init() 77 */ 78 void reload(); 79 80 Session getSession(String logicalWorkspaceName, Credentials credentials) throws RepositoryException; 81 82 Session getSystemSession(String logicalWorkspaceName) throws RepositoryException; 83 84 /** 85 * Verify the initialization state of all the workspaces. This methods returns <code>false</code> only if 86 * <strong>all</strong> the workspaces are empty (no node else than the root one). 87 * 88 * @return <code>false</code> if all the workspaces are empty, <code>true</code> if at least one of them has content. 89 * @throws AccessDeniedException repository authentication failed 90 * @throws RepositoryException exception while accessing the repository 91 */ 92 boolean checkIfInitialized() throws AccessDeniedException, RepositoryException; 93 94 /** 95 * Verifies the initialization state of a workspace. 96 */ 97 boolean checkIfInitialized(String logicalWorkspace) throws RepositoryException, AccessDeniedException; 98 99 /** 100 * Adds a repository definition and instantiates its provider. If the loadOnStartup property is true it also 101 * registers namespaces and node types. You must not call this method twice. 102 */ 103 void loadRepository(RepositoryDefinition definition) throws RepositoryNotInitializedException, InstantiationException, IllegalAccessException, ClassNotFoundException; 104 105 /** 106 * Loads a workspace by registering namespaces and node types on a workspace that has not previously been loaded. 107 * Also adds a workspace mapping that maps the physical workspace name as a logical name. 108 */ 109 void loadWorkspace(String repositoryId, String physicalWorkspaceName) throws RepositoryException; 110 111 boolean hasRepository(String repositoryId); 112 113 /** 114 * Returns repository mapping as configured, or null if not found. 115 */ 116 RepositoryDefinition getRepositoryDefinition(String repositoryId); 117 118 /** 119 * Returns the provider instance for a repository. 120 * 121 * @throws IllegalArgumentException if there is no such repository 122 */ 123 Provider getRepositoryProvider(String repositoryId); 124 125 /** 126 * Returns repository instance for a repository. 127 * 128 * @throws IllegalArgumentException if there is no such repository 129 */ 130 Repository getRepository(String repositoryId); 131 132 void addWorkspaceMapping(WorkspaceMappingDefinition mapping); 133 134 boolean hasWorkspace(String logicalWorkspaceName); 135 136 Collection<WorkspaceMappingDefinition> getWorkspaceMappings(); 137 138 WorkspaceMappingDefinition getWorkspaceMapping(String logicalWorkspaceName); 139 140 Collection<RepositoryDefinition> getRepositoryDefinitions(); 141 142 /** 143 * Returns workspace names. 144 * 145 * @return repository names 146 */ 147 Collection<String> getWorkspaceNames(); 148 149 /** 150 * Registers permanently new workspace and makes it available in Magnolia. 151 * 152 * @param repository Repository name. 153 * @param logicalWorkspaceName Workspace name. 154 */ 155 void createWorkspace(String repository, String logicalWorkspaceName) throws RepositoryException; 156 157 String getRepositoryNameForWorkspace(String logicalWorkspaceName); 158 }