1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.repository;
35
36 import java.util.Collection;
37 import java.util.Hashtable;
38 import java.util.Map;
39 import javax.jcr.Repository;
40
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 import info.magnolia.repository.definition.RepositoryDefinition;
45 import info.magnolia.repository.definition.WorkspaceMappingDefinition;
46
47
48
49
50
51
52
53 public class WorkspaceMapping {
54
55 private static final Logger log = LoggerFactory.getLogger(WorkspaceMapping.class);
56
57
58
59
60 private Map<String, Repository> repositories = new Hashtable<String, Repository>();
61
62
63
64
65 private Map<String, Provider> providers = new Hashtable<String, Provider>();
66
67
68
69
70 private Map<String, RepositoryDefinition> repositoryDefinitions = new Hashtable<String, RepositoryDefinition>();
71
72
73
74
75 private Map<String, WorkspaceMappingDefinition> workspaceMappingDefinitions = new Hashtable<String, WorkspaceMappingDefinition>();
76
77
78 public void clearRepositories() {
79 repositories.clear();
80 }
81
82 public void clearAll() {
83 providers.clear();
84 repositoryDefinitions.clear();
85 workspaceMappingDefinitions.clear();
86 clearRepositories();
87 }
88
89 public void addRepositoryDefinition(RepositoryDefinition repositoryDefinition) {
90 repositoryDefinitions.put(repositoryDefinition.getName(), repositoryDefinition);
91 }
92
93
94
95
96 public void addWorkspaceMapping(WorkspaceMappingDefinition mapping) {
97 if (workspaceMappingDefinitions.containsKey(mapping.getLogicalWorkspaceName())) {
98 return;
99 }
100
101 addWorkspaceMappingDefinition(mapping);
102
103 RepositoryDefinition repositoryDefinition = getRepositoryDefinition(mapping.getRepositoryName());
104 if (!repositoryDefinition.getWorkspaces().contains(mapping.getPhysicalWorkspaceName())) {
105 repositoryDefinition.addWorkspace(mapping.getPhysicalWorkspaceName());
106 }
107 }
108
109 public void addWorkspaceMappingDefinition(WorkspaceMappingDefinition definition) {
110 workspaceMappingDefinitions.put(definition.getLogicalWorkspaceName(), definition);
111 }
112
113
114
115
116 public RepositoryDefinition getRepositoryDefinition(String repositoryId) {
117 return repositoryDefinitions.get(repositoryId);
118 }
119
120 public Collection<String> getLogicalWorkspaceNames() {
121 return workspaceMappingDefinitions.keySet();
122 }
123
124 public WorkspaceMappingDefinition getWorkspaceMapping(String logicalWorkspaceName) {
125 return workspaceMappingDefinitions.get(logicalWorkspaceName);
126 }
127
128 public Collection<WorkspaceMappingDefinition> getWorkspaceMappings() {
129 return workspaceMappingDefinitions.values();
130 }
131
132 public void setRepository(String repositoryId, Repository repository) {
133 repositories.put(repositoryId, repository);
134 }
135
136 public void setRepositoryProvider(String repositoryId, Provider provider) {
137 providers.put(repositoryId, provider);
138 }
139
140
141
142
143 public Repository getRepository(String repositoryId) {
144 Repository repository = repositories.get(repositoryId);
145 if (repository == null) {
146 final String s = "Failed to retrieve repository '" + repositoryId + "'. Your Magnolia instance might not have been initialized properly.";
147 log.warn(s);
148 throw new IllegalArgumentException(s);
149 }
150 return repository;
151 }
152
153
154
155
156 public Provider getRepositoryProvider(String repositoryId) {
157 Provider provider = providers.get(repositoryId);
158 if (provider == null) {
159 final String s = "Failed to retrieve repository provider '" + repositoryId + "'. Your Magnolia instance might not have been initialized properly.";
160 log.warn(s);
161 throw new IllegalArgumentException(s);
162 }
163 return provider;
164 }
165
166 public Collection<RepositoryDefinition> getRepositoryDefinitions() {
167 return repositoryDefinitions.values();
168 }
169 }