View Javadoc
1   /**
2    * This file Copyright (c) 2011-2018 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.repository.definition.RepositoryDefinition;
37  import info.magnolia.repository.definition.WorkspaceMappingDefinition;
38  
39  import java.util.Collection;
40  
41  import javax.jcr.Credentials;
42  import javax.jcr.Repository;
43  import javax.jcr.RepositoryException;
44  import javax.jcr.Session;
45  
46  
47  /**
48   * Manages JCR repositories. Initialization of a repository is handled by {@link Provider}s. Magnolia can be configured
49   * to have its workspaces in more than one repository. This is abstracted through this class which maps a set of
50   * "logical" workspace names to their actual "physical" workspace names in a repository.
51   *
52   * Configuration of providers and workspace mappings are done in repositories.xml.
53   *
54   * @see Provider
55   * @see info.magnolia.repository.definition.RepositoryMappingDefinitionReader
56   */
57  public interface RepositoryManager {
58  
59      /**
60       * Initializes by loading configuration from repositories.xml.
61       */
62      void init();
63  
64      /**
65       * Shuts down all repositories (through Provider instances) and clears all mappings.
66       */
67      void shutdown();
68  
69      // TODO The implementation of this in ContentRepository seems fishy, it clears the Repository instances and reads the xml again
70      // what is the effect on things added after init() ?
71  
72      /**
73       * Re-load all configured repositories.
74       *
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 RepositoryException exception while accessing the repository
89       */
90      boolean checkIfInitialized() throws RepositoryException;
91  
92      /**
93       * Verifies the initialization state of a workspace.
94       */
95      boolean checkIfInitialized(String logicalWorkspace) throws RepositoryException;
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     Collection<RepositoryDefinition> getRepositoryDefinitions();
139 
140     /**
141      * Returns workspace names.
142      *
143      * @return repository names
144      */
145     Collection<String> getWorkspaceNames();
146 
147     /**
148      * Registers permanently new workspace and makes it available in Magnolia.
149      *
150      * @param repository Repository name.
151      * @param logicalWorkspaceName Workspace name.
152      */
153     void createWorkspace(String repository, String logicalWorkspaceName) throws RepositoryException;
154 
155     String getRepositoryNameForWorkspace(String logicalWorkspaceName);
156 }