[dna-commits] DNA SVN: r656 - in trunk/extensions: dna-connector-filesystem and 21 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Dec 4 16:36:58 EST 2008


Author: rhauch
Date: 2008-12-04 16:36:58 -0500 (Thu, 04 Dec 2008)
New Revision: 656

Added:
   trunk/extensions/dna-connector-filesystem/
   trunk/extensions/dna-connector-filesystem/.classpath
   trunk/extensions/dna-connector-filesystem/.project
   trunk/extensions/dna-connector-filesystem/pom.xml
   trunk/extensions/dna-connector-filesystem/src/
   trunk/extensions/dna-connector-filesystem/src/main/
   trunk/extensions/dna-connector-filesystem/src/main/java/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
   trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
   trunk/extensions/dna-connector-filesystem/src/main/resources/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/
   trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
   trunk/extensions/dna-connector-filesystem/src/test/
   trunk/extensions/dna-connector-filesystem/src/test/java/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemI18nTest.java
   trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java
   trunk/extensions/dna-connector-filesystem/src/test/resources/
Log:
DNA-34  - Federate content stored on file system

Created an intial implementation of a read-only connector that is able to expose multiple directories as content.  A few things still need to be completed, even for the read-only case, but those will be done shortly.


Property changes on: trunk/extensions/dna-connector-filesystem
___________________________________________________________________
Name: svn:ignore
   + target


Added: trunk/extensions/dna-connector-filesystem/.classpath
===================================================================
--- trunk/extensions/dna-connector-filesystem/.classpath	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/.classpath	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: trunk/extensions/dna-connector-filesystem/.project
===================================================================
--- trunk/extensions/dna-connector-filesystem/.project	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/.project	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>dna-connector-filesystem</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Added: trunk/extensions/dna-connector-filesystem/pom.xml
===================================================================
--- trunk/extensions/dna-connector-filesystem/pom.xml	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/pom.xml	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.jboss.dna</groupId>
+    <artifactId>dna</artifactId>
+    <version>0.4-SNAPSHOT</version>
+    <relativePath>../..</relativePath>
+  </parent>
+  <!-- The groupId and version values are inherited from parent -->
+  <artifactId>dna-connector-filesystem</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss DNA Connector to a local file system</name>
+  <description>JBoss DNA Connector that exposes the files and directories of (part of) a local file system.</description>
+  <url>http://labs.jboss.org/dna</url>
+  <!--
+    Define the dependencies. Note that all version and scopes default to those defined in the dependencyManagement section of the
+    parent pom.
+  -->
+  <dependencies>
+    <!-- 
+    JBoss DNA
+    -->
+    <dependency>
+      <groupId>org.jboss.dna</groupId>
+      <artifactId>dna-graph</artifactId>
+    </dependency>
+    <!-- 
+    Testing (note the scope)
+    -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.dna</groupId>
+      <artifactId>dna-common</artifactId>
+      <version>${pom.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.dna</groupId>
+      <artifactId>dna-graph</artifactId>
+      <version>${pom.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <!-- 
+    Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing) 
+    -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+    <!-- 
+    Java Concurrency in Practice annotations
+    -->
+    <dependency>
+      <groupId>net.jcip</groupId>
+      <artifactId>jcip-annotations</artifactId>
+    </dependency>
+  </dependencies>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-report-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
\ No newline at end of file

Added: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.filesystem;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import javax.transaction.xa.XAResource;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.cache.CachePolicy;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.connectors.RepositorySourceListener;
+import org.jboss.dna.graph.requests.Request;
+import org.jboss.dna.graph.requests.processor.RequestProcessor;
+
+/**
+ * The {@link RepositoryConnection} implementation for the file system connector. The bulk of the work is performed by the
+ * {@link FileSystemRequestProcessor}.
+ * 
+ * @author Randall Hauch
+ */
+public class FileSystemConnection implements RepositoryConnection {
+
+    private final String sourceName;
+    private final Map<String, File> rootsByName;
+    private final CachePolicy cachePolicy;
+    private final CopyOnWriteArrayList<RepositorySourceListener> listeners = new CopyOnWriteArrayList<RepositorySourceListener>();
+    private final FilenameFilter filenameFilter;
+    private final boolean updatesAllowed;
+
+    FileSystemConnection( String sourceName,
+                          Map<String, File> rootsByName,
+                          CachePolicy cachePolicy,
+                          FilenameFilter filenameFilter,
+                          boolean updatesAllowed ) {
+        assert sourceName != null;
+        assert sourceName.trim().length() != 0;
+        assert rootsByName != null;
+        assert rootsByName.size() >= 1;
+        this.sourceName = sourceName;
+        this.rootsByName = rootsByName;
+        this.cachePolicy = cachePolicy;
+        this.filenameFilter = filenameFilter;
+        this.updatesAllowed = updatesAllowed;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#getSourceName()
+     */
+    public String getSourceName() {
+        return sourceName;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#getDefaultCachePolicy()
+     */
+    public CachePolicy getDefaultCachePolicy() {
+        return cachePolicy;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#getXAResource()
+     */
+    public XAResource getXAResource() {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#setListener(org.jboss.dna.graph.connectors.RepositorySourceListener)
+     */
+    public void setListener( RepositorySourceListener listener ) {
+        if (listener != null) {
+            listeners.addIfAbsent(listener);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#ping(long, java.util.concurrent.TimeUnit)
+     */
+    public boolean ping( long time,
+                         TimeUnit unit ) {
+        return true;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#execute(org.jboss.dna.graph.ExecutionContext,
+     *      org.jboss.dna.graph.requests.Request)
+     */
+    public void execute( ExecutionContext context,
+                         Request request ) throws RepositorySourceException {
+        RequestProcessor proc = new FileSystemRequestProcessor(sourceName, context, rootsByName, filenameFilter, updatesAllowed);
+        try {
+            proc.process(request);
+        } finally {
+            proc.close();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositoryConnection#close()
+     */
+    public void close() {
+    }
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.filesystem;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ */
+public final class FileSystemI18n {
+
+    public static I18n connectorName;
+    public static I18n fileSystemPathDoesNotExist;
+    public static I18n fileSystemPathsDoNotExist;
+    public static I18n propertyIsRequired;
+    public static I18n locationInRequestMustHavePath;
+    public static I18n sameNameSiblingsAreNotAllowed;
+    public static I18n onlyTheDefaultNamespaceIsAllowed;
+    public static I18n sourceIsReadOnly;
+
+    static {
+        try {
+            I18n.initialize(FileSystemI18n.class);
+        } catch (final Exception err) {
+            System.err.println(err);
+        }
+    }
+
+    public static Set<Locale> getLocalizationProblemLocales() {
+        return I18n.getLocalizationProblemLocales(FileSystemI18n.class);
+    }
+
+    public static Set<String> getLocalizationProblems() {
+        return I18n.getLocalizationProblems(FileSystemI18n.class);
+    }
+
+    public static Set<String> getLocalizationProblems( Locale locale ) {
+        return I18n.getLocalizationProblems(FileSystemI18n.class, locale);
+    }
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,319 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.filesystem;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Map;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.NameFactory;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.PathFactory;
+import org.jboss.dna.graph.properties.PathNotFoundException;
+import org.jboss.dna.graph.requests.CopyBranchRequest;
+import org.jboss.dna.graph.requests.CreateNodeRequest;
+import org.jboss.dna.graph.requests.DeleteBranchRequest;
+import org.jboss.dna.graph.requests.MoveBranchRequest;
+import org.jboss.dna.graph.requests.ReadAllChildrenRequest;
+import org.jboss.dna.graph.requests.ReadAllPropertiesRequest;
+import org.jboss.dna.graph.requests.RemovePropertiesRequest;
+import org.jboss.dna.graph.requests.RenameNodeRequest;
+import org.jboss.dna.graph.requests.Request;
+import org.jboss.dna.graph.requests.UpdatePropertiesRequest;
+import org.jboss.dna.graph.requests.processor.RequestProcessor;
+
+/**
+ * The {@link RequestProcessor} implementation for the file systme connector. This is the class that does the bulk of the work in
+ * the file system connector, since it processes all requests.
+ * 
+ * @author Randall Hauch
+ */
+public class FileSystemRequestProcessor extends RequestProcessor {
+
+    private final Map<String, File> rootsByName;
+    private final String defaultNamespaceUri;
+    private final FilenameFilter filenameFilter;
+    private final boolean updatesAllowed;
+
+    /**
+     * @param sourceName
+     * @param context
+     * @param rootsByName
+     * @param filenameFilter the filename filter to use to restrict the allowable nodes, or null if all files/directories are to
+     *        be exposed by this connector
+     * @param updatesAllowed true if this connector supports updating the file system, or false if the connector is readonly
+     */
+    protected FileSystemRequestProcessor( String sourceName,
+                                          ExecutionContext context,
+                                          Map<String, File> rootsByName,
+                                          FilenameFilter filenameFilter,
+                                          boolean updatesAllowed ) {
+        super(sourceName, context);
+        assert rootsByName != null;
+        assert rootsByName.size() >= 1;
+        this.rootsByName = rootsByName;
+        this.defaultNamespaceUri = getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
+        this.filenameFilter = filenameFilter;
+        this.updatesAllowed = updatesAllowed;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.ReadAllChildrenRequest)
+     */
+    @Override
+    public void process( ReadAllChildrenRequest request ) {
+        Location location = request.of();
+        Path parentPath = getPathFor(location, request);
+        if (parentPath.isRoot()) {
+            // Add each of the root files as a child ...
+            for (String rootFile : rootsByName.keySet()) {
+                Path pathToRoot = pathFactory().create("/" + rootFile);
+                request.addChild(new Location(pathToRoot));
+            }
+        } else {
+            // Find the existing file for the parent ...
+            File parent = getExistingFileFor(parentPath, location, request);
+            if (parent.isDirectory()) {
+                // Create a Location for each file and directory contained by the parent directory ...
+                PathFactory pathFactory = pathFactory();
+                NameFactory nameFactory = nameFactory();
+                for (String localName : parent.list(filenameFilter)) {
+                    Name childName = nameFactory.create(defaultNamespaceUri, localName);
+                    Path childPath = pathFactory.create(parentPath, childName);
+                    request.addChild(new Location(childPath));
+                }
+            } else {
+                // The parent is a java.io.File, and the path may refer to the node that is either the "nt:file" parent
+                // node, or the child "jcr:content" node...
+                if (!parentPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+                    // This node represents the "nt:file" parent node, so the only child is the "jcr:content" node ...
+                    Path contentPath = pathFactory().create(parentPath, JcrLexicon.CONTENT);
+                    Location content = new Location(contentPath);
+                    request.addChild(content);
+                }
+                // otherwise, the path ends in "jcr:content", and there are no children
+            }
+        }
+        request.setActualLocationOfNode(location);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.ReadAllPropertiesRequest)
+     */
+    @Override
+    public void process( ReadAllPropertiesRequest request ) {
+        Location location = request.at();
+        Path path = getPathFor(location, request);
+        if (path.isRoot()) {
+            // There are no properties on the root ...
+            request.setActualLocationOfNode(location);
+            return;
+        }
+
+        // Get the java.io.File object that represents the location ...
+        File parent = getExistingFileFor(path, location, request);
+        if (parent.isDirectory()) {
+            // Add properties for the directory ...
+
+        } else {
+            // It is a file, but ...
+            if (path.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+                // The request is to get properties of the "jcr:content" child node ...
+
+            } else {
+                // The request is to get properties for the node representing the file
+            }
+
+        }
+        request.setActualLocationOfNode(location);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.CreateNodeRequest)
+     */
+    @Override
+    public void process( CreateNodeRequest request ) {
+        verifyUpdatesAllowed();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.UpdatePropertiesRequest)
+     */
+    @Override
+    public void process( UpdatePropertiesRequest request ) {
+        verifyUpdatesAllowed();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.CopyBranchRequest)
+     */
+    @Override
+    public void process( CopyBranchRequest request ) {
+        verifyUpdatesAllowed();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.DeleteBranchRequest)
+     */
+    @Override
+    public void process( DeleteBranchRequest request ) {
+        verifyUpdatesAllowed();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.MoveBranchRequest)
+     */
+    @Override
+    public void process( MoveBranchRequest request ) {
+        verifyUpdatesAllowed();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.RemovePropertiesRequest)
+     */
+    @Override
+    public void process( RemovePropertiesRequest request ) {
+        verifyUpdatesAllowed();
+        super.process(request);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.RenameNodeRequest)
+     */
+    @Override
+    public void process( RenameNodeRequest request ) {
+        verifyUpdatesAllowed();
+        super.process(request);
+    }
+
+    protected void verifyUpdatesAllowed() {
+        if (!updatesAllowed) {
+            throw new RepositorySourceException(getSourceName(), FileSystemI18n.sourceIsReadOnly.text(getSourceName()));
+        }
+    }
+
+    protected NameFactory nameFactory() {
+        return getExecutionContext().getValueFactories().getNameFactory();
+    }
+
+    protected PathFactory pathFactory() {
+        return getExecutionContext().getValueFactories().getPathFactory();
+    }
+
+    protected Path getPathFor( Location location,
+                               Request request ) {
+        Path path = location.getPath();
+        if (path == null) {
+            I18n msg = FileSystemI18n.locationInRequestMustHavePath;
+            throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+        }
+        return path;
+    }
+
+    /**
+     * This utility files the existing {@link File} at the supplied path, and in the process will verify that the path is actually
+     * valid.
+     * <p>
+     * Note that this connector represents a file as two nodes: a parent node with a name that matches the file and a "
+     * <code>jcr:primaryType</code>" of "<code>nt:file</code>"; and a child node with the name "<code>jcr:content</code>" and a "
+     * <code>jcr:primaryType</code>" of "<code>nt:resource</code>". The parent "<code>nt:file</code>" node and its properties
+     * represents the file itself, whereas the child "<code>nt:resource</code>" node and its properties represent the content of
+     * the file.
+     * </p>
+     * <p>
+     * As such, this method will return the File object for paths representing both the parent "<code>nt:file</code>" and child "
+     * <code>nt:resource</code>" node.
+     * </p>
+     * 
+     * @param path
+     * @param location the location containing the path; may not be null
+     * @param request the request containing the path (and the location); may not be null
+     * @return the existing {@link File file} for the path; never null
+     * @throws PathNotFoundException if the path does not represent an existing file
+     */
+    protected File getExistingFileFor( Path path,
+                                       Location location,
+                                       Request request ) {
+        assert path != null;
+        assert location != null;
+        assert request != null;
+        File file = null;
+        // See if the path is a "jcr:content" node ...
+        if (path.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+            // We only want to use the parent path to find the actual file ...
+            path = path.getParent();
+        }
+        for (Path.Segment segment : path) {
+            String localName = segment.getName().getLocalName();
+            // Verify the segment is valid ...
+            if (segment.getIndex() > 1) {
+                I18n msg = FileSystemI18n.sameNameSiblingsAreNotAllowed;
+                throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+            }
+            if (!segment.getName().getNamespaceUri().equals(defaultNamespaceUri)) {
+                I18n msg = FileSystemI18n.onlyTheDefaultNamespaceIsAllowed;
+                throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+            }
+            if (file == null) {
+                // We're looking to match one of the file roots ...
+                file = rootsByName.get(localName);
+            } else {
+                // The segment should exist as a child of the file ...
+                file = new File(file, localName);
+            }
+            if (file == null || !file.exists()) {
+                // Unable to complete the path, so prepare the exception by determining the lowest path that exists ...
+                Path lowest = path;
+                while (lowest.getLastSegment() != segment) {
+                    lowest = lowest.getParent();
+                }
+                lowest = lowest.getParent();
+                throw new PathNotFoundException(location, lowest);
+            }
+        }
+        assert file != null;
+        return file;
+    }
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,354 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.dna.connector.filesystem;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.naming.Context;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.cache.CachePolicy;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.connectors.RepositoryContext;
+import org.jboss.dna.graph.connectors.RepositorySource;
+import org.jboss.dna.graph.connectors.RepositorySourceCapabilities;
+import org.jboss.dna.graph.connectors.RepositorySourceException;
+
+/**
+ * The {@link RepositorySource} for the connector that exposes an area of the local file system as content in a repository.
+ * 
+ * @author Randall Hauch
+ */
+ at ThreadSafe
+public class FileSystemSource implements RepositorySource, ObjectFactory {
+
+    /**
+     * The first serialized version of this source. Version {@value} .
+     */
+    private static final long serialVersionUID = 1L;
+
+    protected static final String SOURCE_NAME = "sourceName";
+    protected static final String CACHE_TIME_TO_LIVE_IN_MILLISECONDS = "cacheTimeToLiveInMilliseconds";
+    protected static final String RETRY_LIMIT = "retryLimit";
+    protected static final String FILE_SYSTEM_PATHS = "fileSystemPaths";
+
+    /**
+     * This source supports events.
+     */
+    protected static final boolean SUPPORTS_EVENTS = true;
+    /**
+     * This source supports same-name-siblings.
+     */
+    protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = true;
+    /**
+     * This source supports udpates by default, but each instance may be configured to {@link #setSupportsUpdates(boolean) be
+     * read-only or updateable}.
+     */
+    public static final boolean DEFAULT_SUPPORTS_UPDATES = true;
+
+    public static final int DEFAULT_RETRY_LIMIT = 0;
+    public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5 minutes
+
+    private String name;
+    private int retryLimit = DEFAULT_RETRY_LIMIT;
+    private int cacheTimeToLiveInMilliseconds = DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS * 1000;
+    private String[] fileSystemPaths;
+    private final Capabilities capabilities = new Capabilities();
+    private transient CachePolicy cachePolicy;
+
+    /**
+     * 
+     */
+    public FileSystemSource() {
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#getCapabilities()
+     */
+    public RepositorySourceCapabilities getCapabilities() {
+        return capabilities;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#getName()
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set the name for the source
+     * 
+     * @param name the new name for the source
+     */
+    public synchronized void setName( String name ) {
+        if (name != null) {
+            name = name.trim();
+            if (name.length() == 0) name = null;
+        }
+        this.name = name;
+    }
+
+    /**
+     * Get the file system paths to each directory or file that should be exposed immediately the root node nodes in this
+     * connector. If not specified, all of the file system's root will be used.
+     * 
+     * @return the paths in the file system path to the top-level files and/or directories, or null if not yet set and the file
+     *         system's roots should be used
+     */
+    public String[] getFileSystemPaths() {
+        return fileSystemPaths;
+    }
+
+    /**
+     * Set the file system paths to each directory or file that should be exposed immediately the root node nodes in this
+     * connector. If not specified, all of the file system's root will be used.
+     * 
+     * @param fileSystemPaths the paths in the file system path to the top-level files and/or directories, or null if not yet set
+     *        and the file system's roots should be used
+     */
+    public synchronized void setFileSystemPaths( String[] fileSystemPaths ) {
+        this.fileSystemPaths = fileSystemPaths;
+    }
+
+    /**
+     * Get whether this source supports updates.
+     * 
+     * @return true if this source supports updates, or false if this source only supports reading content.
+     */
+    public boolean getSupportsUpdates() {
+        return capabilities.supportsUpdates();
+    }
+
+    /**
+     * Set whether this source supports updates.
+     * 
+     * @param supportsUpdates true if this source supports updating content, or false if this source only supports reading
+     *        content.
+     */
+    public synchronized void setSupportsUpdates( boolean supportsUpdates ) {
+        capabilities.setSupportsUpdates(supportsUpdates);
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#getRetryLimit()
+     */
+    public int getRetryLimit() {
+        return retryLimit;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#setRetryLimit(int)
+     */
+    public synchronized void setRetryLimit( int limit ) {
+        if (limit < 0) limit = 0;
+        this.retryLimit = limit;
+    }
+
+    /**
+     * Get the time in milliseconds that content returned from this source may used while in the cache.
+     * 
+     * @return the time to live, in milliseconds, or 0 if the time to live is not specified by this source
+     */
+    public int getCacheTimeToLiveInMilliseconds() {
+        return cacheTimeToLiveInMilliseconds;
+    }
+
+    /**
+     * Set the time in milliseconds that content returned from this source may used while in the cache.
+     * 
+     * @param cacheTimeToLive the time to live, in milliseconds; 0 if the time to live is not specified by this source; or a
+     *        negative number for the default value
+     */
+    public synchronized void setCacheTimeToLiveInMilliseconds( int cacheTimeToLive ) {
+        if (cacheTimeToLive < 0) cacheTimeToLive = DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS;
+        this.cacheTimeToLiveInMilliseconds = cacheTimeToLive;
+        this.cachePolicy = cacheTimeToLiveInMilliseconds > 0 ? new FileSystemCachePolicy(cacheTimeToLiveInMilliseconds) : null;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#initialize(org.jboss.dna.graph.connectors.RepositoryContext)
+     */
+    public void initialize( RepositoryContext context ) throws RepositorySourceException {
+        // No need to do anything
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see javax.naming.Referenceable#getReference()
+     */
+    public Reference getReference() {
+        String className = getClass().getName();
+        String factoryClassName = this.getClass().getName();
+        Reference ref = new Reference(className, factoryClassName, null);
+
+        if (getName() != null) {
+            ref.add(new StringRefAddr(SOURCE_NAME, getName()));
+        }
+        String[] paths = getFileSystemPaths();
+        if (paths != null && paths.length != 0) {
+            ref.add(new StringRefAddr(FILE_SYSTEM_PATHS, StringUtil.combineLines(paths)));
+        }
+        ref.add(new StringRefAddr(CACHE_TIME_TO_LIVE_IN_MILLISECONDS, Integer.toString(getCacheTimeToLiveInMilliseconds())));
+        ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+        return ref;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getObjectInstance( Object obj,
+                                     javax.naming.Name name,
+                                     Context nameCtx,
+                                     Hashtable<?, ?> environment ) throws Exception {
+        if (obj instanceof Reference) {
+            Map<String, String> values = new HashMap<String, String>();
+            Reference ref = (Reference)obj;
+            Enumeration<?> en = ref.getAll();
+            while (en.hasMoreElements()) {
+                RefAddr subref = (RefAddr)en.nextElement();
+                if (subref instanceof StringRefAddr) {
+                    String key = subref.getType();
+                    Object value = subref.getContent();
+                    if (value != null) values.put(key, value.toString());
+                }
+            }
+            String sourceName = values.get(SOURCE_NAME);
+            String combinedPaths = values.get(FILE_SYSTEM_PATHS);
+            String[] fileSystemPaths = null;
+            if (combinedPaths != null) {
+                List<String> paths = StringUtil.splitLines(combinedPaths);
+                fileSystemPaths = paths.toArray(new String[paths.size()]);
+            }
+            String cacheTtlInMillis = values.get(CACHE_TIME_TO_LIVE_IN_MILLISECONDS);
+            String retryLimit = values.get(RETRY_LIMIT);
+
+            // Create the source instance ...
+            FileSystemSource source = new FileSystemSource();
+            if (sourceName != null) source.setName(sourceName);
+            if (fileSystemPaths != null) source.setFileSystemPaths(fileSystemPaths);
+            if (cacheTtlInMillis != null) source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(cacheTtlInMillis));
+            if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+            return source;
+        }
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.jboss.dna.graph.connectors.RepositorySource#getConnection()
+     */
+    public synchronized RepositoryConnection getConnection() throws RepositorySourceException {
+        String sourceName = getName();
+        if (sourceName == null || sourceName.trim().length() == 0) {
+            I18n msg = FileSystemI18n.propertyIsRequired;
+            throw new RepositorySourceException(getName(), msg.text("name"));
+        }
+        Map<String, File> rootsByName = new HashMap<String, File>();
+        String[] fileSystemPaths = getFileSystemPaths();
+        if (fileSystemPaths != null && fileSystemPaths.length != 0) {
+            // Find each of the paths ...
+            List<String> pathsThatDontExist = new ArrayList<String>();
+            for (String fileSystemPath : fileSystemPaths) {
+                File root = new File(fileSystemPath);
+                if (!root.exists()) {
+                    pathsThatDontExist.add(fileSystemPath);
+                } else {
+                    rootsByName.put(root.getName(), root);
+                }
+            }
+            if (!pathsThatDontExist.isEmpty()) {
+                int count = pathsThatDontExist.size();
+                I18n msg = count == 1 ? FileSystemI18n.fileSystemPathDoesNotExist : FileSystemI18n.fileSystemPathsDoNotExist;
+                throw new RepositorySourceException(getName(), msg.text(getName(), pathsThatDontExist, count));
+            }
+        } else {
+            // No file system paths specified, so get all of the file system's roots ...
+            for (File root : File.listRoots()) {
+                rootsByName.put(root.getName(), root);
+            }
+        }
+        FilenameFilter filenameFilter = null;
+        boolean supportsUpdates = getSupportsUpdates();
+        return new FileSystemConnection(name, rootsByName, cachePolicy, filenameFilter, supportsUpdates);
+    }
+
+    @ThreadSafe
+    protected class Capabilities extends RepositorySourceCapabilities {
+        private final AtomicBoolean supportsUpdates = new AtomicBoolean(DEFAULT_SUPPORTS_UPDATES);
+
+        /*package*/Capabilities() {
+            super(SUPPORTS_SAME_NAME_SIBLINGS, DEFAULT_SUPPORTS_UPDATES, SUPPORTS_EVENTS);
+        }
+
+        /*package*/void setSupportsUpdates( boolean supportsUpdates ) {
+            this.supportsUpdates.set(supportsUpdates);
+        }
+
+        @Override
+        public boolean supportsUpdates() {
+            return this.supportsUpdates.get();
+        }
+    }
+
+    @Immutable
+    /*package*/class FileSystemCachePolicy implements CachePolicy {
+        private static final long serialVersionUID = 1L;
+        private final int ttl;
+
+        /*package*/FileSystemCachePolicy( int ttl ) {
+            this.ttl = ttl;
+        }
+
+        public long getTimeToLive() {
+            return ttl;
+        }
+
+    }
+
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,30 @@
+#
+# JBoss, Home of Professional Open Source.
+# Copyright 2008, Red Hat Middleware LLC, and individual contributors
+# as indicated by the @author tags. See the copyright.txt file in the
+# distribution for a full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+#
+
+connectorName = JPA Graph Store Connector
+fileSystemPathsDoNotExist = {2} of the file system paths specified on the {0} source do not exist or are invalid: {1}
+fileSystemPathDoesNotExist = One of the file system paths specified on the {0} source does not exist or is invalid: {1}
+propertyIsRequired = The {0} property is required but has no value
+locationInRequestMustHavePath = {0} requires a path in the request: {1}
+sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
+onlyTheDefaultNamespaceIsAllowed = {0} requires node names use the default namespace: {1}
+sourceIsReadOnly = {0} is a read-only source; no updates are allowed


Property changes on: trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemI18nTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemI18nTest.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemI18nTest.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.filesystem;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author Randall Hauch
+ */
+public class FileSystemI18nTest extends AbstractI18nTest {
+
+    public FileSystemI18nTest() {
+        super(FileSystemI18n.class);
+    }
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemI18nTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java	                        (rev 0)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java	2008-12-04 21:36:58 UTC (rev 656)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.filesystem;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class FileSystemSourceTest {
+
+    private FileSystemSource source;
+    private RepositoryConnection connection;
+
+    @Before
+    public void beforeEach() throws Exception {
+        this.source = new FileSystemSource();
+        // Set the mandatory properties ...
+        this.source.setName("Test Repository");
+    }
+
+    @After
+    public void afterEach() throws Exception {
+        if (this.connection != null) {
+            this.connection.close();
+        }
+    }
+
+    @Test
+    public void shouldReturnNonNullCapabilities() {
+        assertThat(source.getCapabilities(), is(notNullValue()));
+    }
+
+    @Test
+    public void shouldSupportSameNameSiblings() {
+        assertThat(source.getCapabilities().supportsSameNameSiblings(), is(true));
+    }
+
+    @Test
+    public void shouldSupportUpdates() {
+        assertThat(source.getCapabilities().supportsUpdates(), is(true));
+    }
+
+    @Test
+    public void shouldHaveNullSourceNameUponConstruction() {
+        source = new FileSystemSource();
+        assertThat(source.getName(), is(nullValue()));
+    }
+
+    @Test
+    public void shouldAllowSettingName() {
+        source.setName("Something");
+        assertThat(source.getName(), is("Something"));
+        source.setName("another name");
+        assertThat(source.getName(), is("another name"));
+    }
+
+    @Test
+    public void shouldAllowSettingNameToNull() {
+        source.setName("some name");
+        source.setName(null);
+        assertThat(source.getName(), is(nullValue()));
+    }
+
+    @Test
+    public void shouldHaveDefaultRetryLimit() {
+        assertThat(source.getRetryLimit(), is(FileSystemSource.DEFAULT_RETRY_LIMIT));
+    }
+
+    @Test
+    public void shouldSetRetryLimitToZeroWhenSetWithNonPositiveValue() {
+        source.setRetryLimit(0);
+        assertThat(source.getRetryLimit(), is(0));
+        source.setRetryLimit(-1);
+        assertThat(source.getRetryLimit(), is(0));
+        source.setRetryLimit(-100);
+        assertThat(source.getRetryLimit(), is(0));
+    }
+
+    @Test
+    public void shouldAllowRetryLimitToBeSet() {
+        for (int i = 0; i != 100; ++i) {
+            source.setRetryLimit(i);
+            assertThat(source.getRetryLimit(), is(i));
+        }
+    }
+
+    @Test( expected = RepositorySourceException.class )
+    public void shouldFailToCreateConnectionIfSourceHasNoName() {
+        source.setName(null);
+        source.getConnection();
+    }
+
+    @Test
+    public void shouldCreateConnection() throws Exception {
+        connection = source.getConnection();
+        assertThat(connection, is(notNullValue()));
+    }
+
+    @Test
+    public void shouldAllowMultipleConnectionsToBeOpenAtTheSameTime() throws Exception {
+        List<RepositoryConnection> connections = new ArrayList<RepositoryConnection>();
+        try {
+            for (int i = 0; i != 10; ++i) {
+                RepositoryConnection conn = source.getConnection();
+                assertThat(conn, is(notNullValue()));
+                connections.add(conn);
+            }
+        } finally {
+            // Close all open connections ...
+            for (RepositoryConnection conn : connections) {
+                if (conn != null) {
+                    try {
+                        conn.close();
+                    } catch (Throwable t) {
+                        t.printStackTrace();
+                    }
+                }
+            }
+        }
+    }
+}


Property changes on: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemSourceTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list