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 * Re-load all configured repositories. 74 * @see #init() 75 */ 76 void reload(); 77 78 Session getSession(String logicalWorkspaceName, Credentials credentials) throws RepositoryException; 79 80 Session getSystemSession(String logicalWorkspaceName) throws RepositoryException; 81 82 /** 83 * Verify the initialization state of all the workspaces. This methods returns <code>false</code> only if 84 * <strong>all</strong> the workspaces are empty (no node else than the root one). 85 * 86 * @return <code>false</code> if all the workspaces are empty, <code>true</code> if at least one of them has content. 87 * @throws AccessDeniedException repository authentication failed 88 * @throws RepositoryException exception while accessing the repository 89 */ 90 boolean checkIfInitialized() throws AccessDeniedException, RepositoryException; 91 92 /** 93 * Verifies the initialization state of a workspace. 94 */ 95 boolean checkIfInitialized(String logicalWorkspace) throws RepositoryException, AccessDeniedException; 96 97 /** 98 * Adds a repository definition and instantiates its provider. If the loadOnStartup property is true it also 99 * registers namespaces and node types. You must not call this method twice. 100 */ 101 void loadRepository(RepositoryDefinition definition) throws RepositoryNotInitializedException, InstantiationException, IllegalAccessException, ClassNotFoundException; 102 103 /** 104 * Loads a workspace by registering namespaces and node types on a workspace that has not previously been loaded. 105 * Also adds a workspace mapping that maps the physical workspace name as a logical name. 106 */ 107 void loadWorkspace(String repositoryId, String physicalWorkspaceName) throws RepositoryException; 108 109 boolean hasRepository(String repositoryId); 110 111 /** 112 * Returns repository mapping as configured, or null if not found. 113 */ 114 RepositoryDefinition getRepositoryDefinition(String repositoryId); 115 116 /** 117 * Returns the provider instance for a repository. 118 * 119 * @throws IllegalArgumentException if there is no such repository 120 */ 121 Provider getRepositoryProvider(String repositoryId); 122 123 /** 124 * Returns repository instance for a repository. 125 * 126 * @throws IllegalArgumentException if there is no such repository 127 */ 128 Repository getRepository(String repositoryId); 129 130 void addWorkspaceMapping(WorkspaceMappingDefinition mapping); 131 132 boolean hasWorkspace(String logicalWorkspaceName); 133 134 Collection<WorkspaceMappingDefinition> getWorkspaceMappings(); 135 136 WorkspaceMappingDefinition getWorkspaceMapping(String logicalWorkspaceName); 137 138 /** 139 * Returns workspace names. 140 * 141 * @return repository names 142 */ 143 Collection<String> getWorkspaceNames(); 144 }