001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006     * See the AUTHORS.txt file in the distribution for a full listing of 
007     * individual contributors. 
008     *
009     * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010     * is licensed to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     *
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.graph.connector;
025    
026    import net.jcip.annotations.Immutable;
027    
028    /**
029     * The capabilities of a {@link RepositorySource}. This class can be used as is, or subclassed by a connector to define more
030     * complex behavior.
031     * 
032     * @see RepositorySource#getCapabilities()
033     * @author Randall Hauch
034     */
035    @Immutable
036    public class RepositorySourceCapabilities {
037    
038        /**
039         * The default support for same-name-siblings is {@value} .
040         */
041        public static final boolean DEFAULT_SUPPORT_SAME_NAME_SIBLINGS = true;
042    
043        /**
044         * The default support for updates is {@value} .
045         */
046        public static final boolean DEFAULT_SUPPORT_UPDATES = false;
047    
048        /**
049         * The default support for updates is {@value} .
050         */
051        public static final boolean DEFAULT_SUPPORT_EVENTS = false;
052    
053        /**
054         * The default support for creating workspaces is {@value} .
055         */
056        public static final boolean DEFAULT_SUPPORT_CREATING_WORKSPACES = false;
057    
058        /**
059         * The default support for creating workspaces is {@value} .
060         */
061        public static final boolean DEFAULT_SUPPORT_REFERENCES = true;
062    
063        private boolean sameNameSiblings;
064        private boolean updates;
065        private boolean events;
066        private boolean creatingWorkspaces;
067        private boolean references;
068    
069        /**
070         * Create a capabilities object using the defaults, .
071         */
072        public RepositorySourceCapabilities() {
073            this(DEFAULT_SUPPORT_SAME_NAME_SIBLINGS, DEFAULT_SUPPORT_UPDATES, DEFAULT_SUPPORT_EVENTS,
074                 DEFAULT_SUPPORT_CREATING_WORKSPACES, DEFAULT_SUPPORT_REFERENCES);
075        }
076    
077        public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
078                                             boolean supportsUpdates ) {
079            this(supportsSameNameSiblings, supportsUpdates, DEFAULT_SUPPORT_EVENTS, DEFAULT_SUPPORT_CREATING_WORKSPACES,
080                 DEFAULT_SUPPORT_REFERENCES);
081        }
082    
083        public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
084                                             boolean supportsUpdates,
085                                             boolean supportsEvents,
086                                             boolean supportsCreatingWorkspaces,
087                                             boolean supportsReferences ) {
088            this.sameNameSiblings = supportsSameNameSiblings;
089            this.updates = supportsUpdates;
090            this.events = supportsEvents;
091            this.creatingWorkspaces = supportsCreatingWorkspaces;
092            this.references = supportsReferences;
093        }
094    
095        /**
096         * Return whether the source supports same name siblings. If not, then no two siblings may share the same name.
097         * 
098         * @return true if same name siblings are supported, or false otherwise
099         */
100        public boolean supportsSameNameSiblings() {
101            return sameNameSiblings;
102        }
103    
104        /**
105         * Return whether the source supports updates. This may be true, even though a particular connection made on behalf of a user
106         * may not have any update privileges. In other words, returning <code>false</code> implies that no connections would allow
107         * updates to the content.
108         * 
109         * @return true if updates are supported, or false if the source only supports reads.
110         */
111        public boolean supportsUpdates() {
112            return updates;
113        }
114    
115        /**
116         * Return whether the source supports references by identifiers.
117         * 
118         * @return true if references are supported, or false otherwise
119         */
120        public boolean supportsReferences() {
121            return references;
122        }
123    
124        /**
125         * Return whether the source supports publishing change events.
126         * 
127         * @return true if events are supported, or false if the source is not capable of generating events
128         */
129        public boolean supportsEvents() {
130            return events;
131        }
132    
133        /**
134         * Return whether the source supports creating workspaces through the connector.
135         * 
136         * @return true if creating workspaces is supported, or false if the source is not capable of creating workspaces
137         */
138        public boolean supportsCreatingWorkspaces() {
139            return creatingWorkspaces;
140        }
141    }