1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.connector;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.graph.request.CollectGarbageRequest;
28
29 /**
30 * The capabilities of a {@link RepositorySource}. This class can be used as is, or subclassed by a connector to define more
31 * complex behavior.
32 *
33 * @see RepositorySource#getCapabilities()
34 */
35 @Immutable
36 public class RepositorySourceCapabilities {
37
38 /**
39 * The default support for same-name-siblings is {@value} .
40 */
41 public static final boolean DEFAULT_SUPPORT_SAME_NAME_SIBLINGS = true;
42
43 /**
44 * The default support for updates is {@value} .
45 */
46 public static final boolean DEFAULT_SUPPORT_UPDATES = false;
47
48 /**
49 * The default support for updates is {@value} .
50 */
51 public static final boolean DEFAULT_SUPPORT_EVENTS = false;
52
53 /**
54 * The default support for creating workspaces is {@value} .
55 */
56 public static final boolean DEFAULT_SUPPORT_CREATING_WORKSPACES = false;
57
58 /**
59 * The default support for references is {@value} .
60 */
61 public static final boolean DEFAULT_SUPPORT_REFERENCES = true;
62
63 /**
64 * The default support for querying workspaces is {@value} .
65 */
66 public static final boolean DEFAULT_SUPPORT_QUERIES = false;
67
68 /**
69 * The default support for searching workspaces is {@value} .
70 */
71 public static final boolean DEFAULT_SUPPORT_SEARCHES = false;
72
73 /**
74 * The default support for creating locks is {@value} .
75 */
76 public static final boolean DEFAULT_SUPPORT_LOCKS = false;
77
78 /**
79 * The default support for automatic garbage collection is {@value} .
80 */
81 public static final boolean DEFAULT_SUPPORT_AUTOMATIC_GARBAGE_COLLECTION = true;
82
83 private final boolean sameNameSiblings;
84 private final boolean updates;
85 private final boolean events;
86 private final boolean creatingWorkspaces;
87 private final boolean references;
88 private final boolean locks;
89 private final boolean queries;
90 private final boolean searches;
91 private final boolean autoGarbageCollection;
92
93 /**
94 * Create a capabilities object using the defaults, .
95 */
96 public RepositorySourceCapabilities() {
97 this(DEFAULT_SUPPORT_SAME_NAME_SIBLINGS, DEFAULT_SUPPORT_UPDATES, DEFAULT_SUPPORT_EVENTS,
98 DEFAULT_SUPPORT_CREATING_WORKSPACES, DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES,
99 DEFAULT_SUPPORT_SEARCHES, DEFAULT_SUPPORT_AUTOMATIC_GARBAGE_COLLECTION);
100 }
101
102 public RepositorySourceCapabilities( RepositorySourceCapabilities capabilities ) {
103 this(capabilities.supportsSameNameSiblings(), capabilities.supportsUpdates(), capabilities.supportsEvents(),
104 capabilities.supportsCreatingWorkspaces(), capabilities.supportsReferences(), capabilities.supportsLocks(),
105 capabilities.supportsQueries(), capabilities.supportsSearches(), capabilities.supportsAutomaticGarbageCollection());
106 }
107
108 public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
109 boolean supportsUpdates ) {
110 this(supportsSameNameSiblings, supportsUpdates, DEFAULT_SUPPORT_EVENTS, DEFAULT_SUPPORT_CREATING_WORKSPACES,
111 DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES, DEFAULT_SUPPORT_SEARCHES,
112 DEFAULT_SUPPORT_AUTOMATIC_GARBAGE_COLLECTION);
113 }
114
115 public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
116 boolean supportsUpdates,
117 boolean supportsEvents,
118 boolean supportsCreatingWorkspaces,
119 boolean supportsReferences ) {
120 this(supportsSameNameSiblings, supportsUpdates, supportsEvents, supportsCreatingWorkspaces, supportsReferences,
121 DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES, DEFAULT_SUPPORT_SEARCHES,
122 DEFAULT_SUPPORT_AUTOMATIC_GARBAGE_COLLECTION);
123 }
124
125 public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
126 boolean supportsUpdates,
127 boolean supportsEvents,
128 boolean supportsCreatingWorkspaces,
129 boolean supportsReferences,
130 boolean supportsLocks,
131 boolean supportsQueries,
132 boolean supportsSearches,
133 boolean supportsAutomaticGarbageCollection ) {
134
135 this.sameNameSiblings = supportsSameNameSiblings;
136 this.updates = supportsUpdates;
137 this.events = supportsEvents;
138 this.creatingWorkspaces = supportsCreatingWorkspaces;
139 this.references = supportsReferences;
140 this.locks = supportsLocks;
141 this.queries = supportsQueries;
142 this.searches = supportsSearches;
143 this.autoGarbageCollection = supportsAutomaticGarbageCollection;
144 }
145
146 /**
147 * Return whether the source supports same name siblings. If not, then no two siblings may share the same name.
148 *
149 * @return true if same name siblings are supported, or false otherwise
150 */
151 public boolean supportsSameNameSiblings() {
152 return sameNameSiblings;
153 }
154
155 /**
156 * Return whether the source supports updates. This may be true, even though a particular connection made on behalf of a user
157 * may not have any update privileges. In other words, returning <code>false</code> implies that no connections would allow
158 * updates to the content.
159 *
160 * @return true if updates are supported, or false if the source only supports reads.
161 */
162 public boolean supportsUpdates() {
163 return updates;
164 }
165
166 /**
167 * Return whether the source supports references by identifiers.
168 *
169 * @return true if references are supported, or false otherwise
170 */
171 public boolean supportsReferences() {
172 return references;
173 }
174
175 /**
176 * Return whether the source supports publishing change events.
177 *
178 * @return true if events are supported, or false if the source is not capable of generating events
179 */
180 public boolean supportsEvents() {
181 return events;
182 }
183
184 /**
185 * Return whether the source supports creating workspaces through the connector.
186 *
187 * @return true if creating workspaces is supported, or false if the source is not capable of creating workspaces
188 */
189 public boolean supportsCreatingWorkspaces() {
190 return creatingWorkspaces;
191 }
192
193 /**
194 * Return whether the source supports creating locks.
195 *
196 * @return true if locks are supported, or false if the source is not capable of creating locks
197 */
198 public boolean supportsLocks() {
199 return locks;
200 }
201
202 /**
203 * Return whether the source supports queries.
204 *
205 * @return true if queries are supported, or false if the source is not capable of querying content
206 */
207 public boolean supportsQueries() {
208 return queries;
209 }
210
211 /**
212 * Return whether the source supports full-text searches.
213 *
214 * @return true if searches are supported, or false if the source is not capable of searching content
215 */
216 public boolean supportsSearches() {
217 return searches;
218 }
219
220 /**
221 * Return whether the source supports automatic garbage collection. If not, then the source expects explicit
222 * {@link CollectGarbageRequest} calls.
223 *
224 * @return true if automatic garbage collection is supported, or false if the source is not capable of automatically
225 * collecting all of its garbage and requires periodic, manual collection
226 */
227 public boolean supportsAutomaticGarbageCollection() {
228 return autoGarbageCollection;
229 }
230
231 /**
232 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsSameNameSiblings()}.
233 *
234 * @param sameNameSiblings the new value
235 * @return the new instance
236 */
237 public RepositorySourceCapabilities withSameNameSiblings( boolean sameNameSiblings ) {
238 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
239 queries, searches, autoGarbageCollection);
240 }
241
242 /**
243 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsUpdates()}.
244 *
245 * @param updates the new value
246 * @return the new instance
247 */
248 public RepositorySourceCapabilities withUpdates( boolean updates ) {
249 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
250 queries, searches, autoGarbageCollection);
251 }
252
253 /**
254 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsEvents()}.
255 *
256 * @param events the new value
257 * @return the new instance
258 */
259 public RepositorySourceCapabilities withEvents( boolean events ) {
260 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
261 queries, searches, autoGarbageCollection);
262 }
263
264 /**
265 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsCreatingWorkspaces()}
266 * .
267 *
268 * @param creatingWorkspaces the new value
269 * @return the new instance
270 */
271 public RepositorySourceCapabilities withCreatingWorkspaces( boolean creatingWorkspaces ) {
272 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
273 queries, searches, autoGarbageCollection);
274 }
275
276 /**
277 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsReferences()}.
278 *
279 * @param references the new value
280 * @return the new instance
281 */
282 public RepositorySourceCapabilities withReferences( boolean references ) {
283 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
284 queries, searches, autoGarbageCollection);
285 }
286
287 /**
288 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsLocks()}.
289 *
290 * @param locks the new value
291 * @return the new instance
292 */
293 public RepositorySourceCapabilities withLocks( boolean locks ) {
294 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
295 queries, searches, autoGarbageCollection);
296 }
297
298 /**
299 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsQueries()}.
300 *
301 * @param queries the new value
302 * @return the new instance
303 */
304 public RepositorySourceCapabilities withQueries( boolean queries ) {
305 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
306 queries, searches, autoGarbageCollection);
307 }
308
309 /**
310 * Create a new instance that is a copy of this instance but uses the supplied value for {@link #supportsSearches()}.
311 *
312 * @param searches the new value
313 * @return the new instance
314 */
315 public RepositorySourceCapabilities withSearches( boolean searches ) {
316 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
317 queries, searches, autoGarbageCollection);
318 }
319
320 /**
321 * Create a new instance that is a copy of this instance but uses the supplied value for
322 * {@link #supportsAutomaticGarbageCollection()}.
323 *
324 * @param autoGarbageCollection the new value
325 * @return the new instance
326 */
327 public RepositorySourceCapabilities withAutomaticGarbageCollection( boolean autoGarbageCollection ) {
328 return new RepositorySourceCapabilities(sameNameSiblings, updates, events, creatingWorkspaces, references, locks,
329 queries, searches, autoGarbageCollection);
330 }
331
332 }