View Javadoc

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  
28  /**
29   * The capabilities of a {@link RepositorySource}. This class can be used as is, or subclassed by a connector to define more
30   * complex behavior.
31   * 
32   * @see RepositorySource#getCapabilities()
33   */
34  @Immutable
35  public class RepositorySourceCapabilities {
36  
37      /**
38       * The default support for same-name-siblings is {@value} .
39       */
40      public static final boolean DEFAULT_SUPPORT_SAME_NAME_SIBLINGS = true;
41  
42      /**
43       * The default support for updates is {@value} .
44       */
45      public static final boolean DEFAULT_SUPPORT_UPDATES = false;
46  
47      /**
48       * The default support for updates is {@value} .
49       */
50      public static final boolean DEFAULT_SUPPORT_EVENTS = false;
51  
52      /**
53       * The default support for creating workspaces is {@value} .
54       */
55      public static final boolean DEFAULT_SUPPORT_CREATING_WORKSPACES = false;
56  
57      /**
58       * The default support for references is {@value} .
59       */
60      public static final boolean DEFAULT_SUPPORT_REFERENCES = true;
61  
62      /**
63       * The default support for querying workspaces is {@value} .
64       */
65      public static final boolean DEFAULT_SUPPORT_QUERIES = false;
66  
67      /**
68       * The default support for searching workspaces is {@value} .
69       */
70      public static final boolean DEFAULT_SUPPORT_SEARCHES = false;
71  
72      /**
73       * The default support for creating locks is {@value} .
74       */
75      public static final boolean DEFAULT_SUPPORT_LOCKS = false;
76  
77      private final boolean sameNameSiblings;
78      private final boolean updates;
79      private final boolean events;
80      private final boolean creatingWorkspaces;
81      private final boolean references;
82      private final boolean locks;
83      private final boolean queries;
84      private final boolean searches;
85  
86      /**
87       * Create a capabilities object using the defaults, .
88       */
89      public RepositorySourceCapabilities() {
90          this(DEFAULT_SUPPORT_SAME_NAME_SIBLINGS, DEFAULT_SUPPORT_UPDATES, DEFAULT_SUPPORT_EVENTS,
91               DEFAULT_SUPPORT_CREATING_WORKSPACES, DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES,
92               DEFAULT_SUPPORT_SEARCHES);
93      }
94  
95      public RepositorySourceCapabilities( RepositorySourceCapabilities capabilities ) {
96          this(capabilities.supportsSameNameSiblings(), capabilities.supportsUpdates(), capabilities.supportsEvents(),
97               capabilities.supportsCreatingWorkspaces(), capabilities.supportsReferences(), capabilities.supportsLocks(),
98               capabilities.supportsQueries(), capabilities.supportsSearches());
99      }
100 
101     public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
102                                          boolean supportsUpdates ) {
103         this(supportsSameNameSiblings, supportsUpdates, DEFAULT_SUPPORT_EVENTS, DEFAULT_SUPPORT_CREATING_WORKSPACES,
104              DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES, DEFAULT_SUPPORT_SEARCHES);
105     }
106 
107     public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
108                                          boolean supportsUpdates,
109                                          boolean supportsEvents,
110                                          boolean supportsCreatingWorkspaces,
111                                          boolean supportsReferences ) {
112         this(supportsSameNameSiblings, supportsUpdates, supportsEvents, supportsCreatingWorkspaces, supportsReferences,
113              DEFAULT_SUPPORT_LOCKS, DEFAULT_SUPPORT_QUERIES, DEFAULT_SUPPORT_SEARCHES);
114     }
115 
116     public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
117                                          boolean supportsUpdates,
118                                          boolean supportsEvents,
119                                          boolean supportsCreatingWorkspaces,
120                                          boolean supportsReferences,
121                                          boolean supportsLocks,
122                                          boolean supportsQueries,
123                                          boolean supportsSearches ) {
124 
125         this.sameNameSiblings = supportsSameNameSiblings;
126         this.updates = supportsUpdates;
127         this.events = supportsEvents;
128         this.creatingWorkspaces = supportsCreatingWorkspaces;
129         this.references = supportsReferences;
130         this.locks = supportsLocks;
131         this.queries = supportsQueries;
132         this.searches = supportsSearches;
133     }
134 
135     /**
136      * Return whether the source supports same name siblings. If not, then no two siblings may share the same name.
137      * 
138      * @return true if same name siblings are supported, or false otherwise
139      */
140     public boolean supportsSameNameSiblings() {
141         return sameNameSiblings;
142     }
143 
144     /**
145      * Return whether the source supports updates. This may be true, even though a particular connection made on behalf of a user
146      * may not have any update privileges. In other words, returning <code>false</code> implies that no connections would allow
147      * updates to the content.
148      * 
149      * @return true if updates are supported, or false if the source only supports reads.
150      */
151     public boolean supportsUpdates() {
152         return updates;
153     }
154 
155     /**
156      * Return whether the source supports references by identifiers.
157      * 
158      * @return true if references are supported, or false otherwise
159      */
160     public boolean supportsReferences() {
161         return references;
162     }
163 
164     /**
165      * Return whether the source supports publishing change events.
166      * 
167      * @return true if events are supported, or false if the source is not capable of generating events
168      */
169     public boolean supportsEvents() {
170         return events;
171     }
172 
173     /**
174      * Return whether the source supports creating workspaces through the connector.
175      * 
176      * @return true if creating workspaces is supported, or false if the source is not capable of creating workspaces
177      */
178     public boolean supportsCreatingWorkspaces() {
179         return creatingWorkspaces;
180     }
181 
182     /**
183      * Return whether the source supports creating locks.
184      * 
185      * @return true if locks are supported, or false if the source is not capable of creating locks
186      */
187     public boolean supportsLocks() {
188         return locks;
189     }
190 
191     /**
192      * Return whether the source supports queries.
193      * 
194      * @return true if queries are supported, or false if the source is not capable of querying content
195      */
196     public boolean supportsQueries() {
197         return queries;
198     }
199 
200     /**
201      * Return whether the source supports full-text searches.
202      * 
203      * @return true if searches are supported, or false if the source is not capable of searching content
204      */
205     public boolean supportsSearches() {
206         return searches;
207     }
208 }