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.connector.filesystem;
025    
026    import java.io.File;
027    import java.io.FilenameFilter;
028    import java.util.Set;
029    import java.util.concurrent.TimeUnit;
030    import javax.transaction.xa.XAResource;
031    import org.jboss.dna.graph.ExecutionContext;
032    import org.jboss.dna.graph.cache.CachePolicy;
033    import org.jboss.dna.graph.connector.RepositoryConnection;
034    import org.jboss.dna.graph.connector.RepositorySourceException;
035    import org.jboss.dna.graph.request.Request;
036    import org.jboss.dna.graph.request.processor.RequestProcessor;
037    
038    /**
039     * The {@link RepositoryConnection} implementation for the file system connector. The bulk of the work is performed by the
040     * {@link FileSystemRequestProcessor}.
041     * 
042     * @author Randall Hauch
043     */
044    public class FileSystemConnection implements RepositoryConnection {
045    
046        private final String sourceName;
047        private final File defaultWorkspace;
048        private final CachePolicy cachePolicy;
049        private final Set<String> availableWorkspaceNames;
050        private final boolean creatingWorkspacesAllowed;
051        private final FilenameFilter filenameFilter;
052        private final boolean updatesAllowed;
053    
054        FileSystemConnection( String sourceName,
055                              File defaultWorkspace,
056                              Set<String> availableWorkspaceNames,
057                              boolean creatingWorkspacesAllowed,
058                              CachePolicy cachePolicy,
059                              FilenameFilter filenameFilter,
060                              boolean updatesAllowed ) {
061            assert sourceName != null;
062            assert sourceName.trim().length() != 0;
063            assert availableWorkspaceNames != null;
064            this.sourceName = sourceName;
065            this.defaultWorkspace = defaultWorkspace;
066            this.availableWorkspaceNames = availableWorkspaceNames;
067            this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
068            this.cachePolicy = cachePolicy;
069            this.filenameFilter = filenameFilter;
070            this.updatesAllowed = updatesAllowed;
071        }
072    
073        /**
074         * {@inheritDoc}
075         * 
076         * @see org.jboss.dna.graph.connector.RepositoryConnection#getSourceName()
077         */
078        public String getSourceName() {
079            return sourceName;
080        }
081    
082        /**
083         * {@inheritDoc}
084         * 
085         * @see org.jboss.dna.graph.connector.RepositoryConnection#getDefaultCachePolicy()
086         */
087        public CachePolicy getDefaultCachePolicy() {
088            return cachePolicy;
089        }
090    
091        /**
092         * {@inheritDoc}
093         * 
094         * @see org.jboss.dna.graph.connector.RepositoryConnection#getXAResource()
095         */
096        public XAResource getXAResource() {
097            return null;
098        }
099    
100        /**
101         * {@inheritDoc}
102         * 
103         * @see org.jboss.dna.graph.connector.RepositoryConnection#ping(long, java.util.concurrent.TimeUnit)
104         */
105        public boolean ping( long time,
106                             TimeUnit unit ) {
107            return true;
108        }
109    
110        /**
111         * {@inheritDoc}
112         * 
113         * @see org.jboss.dna.graph.connector.RepositoryConnection#execute(org.jboss.dna.graph.ExecutionContext,
114         *      org.jboss.dna.graph.request.Request)
115         */
116        public void execute( ExecutionContext context,
117                             Request request ) throws RepositorySourceException {
118            RequestProcessor proc = new FileSystemRequestProcessor(sourceName, defaultWorkspace, availableWorkspaceNames,
119                                                                   creatingWorkspacesAllowed, context, filenameFilter, updatesAllowed);
120            try {
121                proc.process(request);
122            } finally {
123                proc.close();
124            }
125        }
126    
127        /**
128         * {@inheritDoc}
129         * 
130         * @see org.jboss.dna.graph.connector.RepositoryConnection#close()
131         */
132        public void close() {
133        }
134    }