DNA SVN: r664 - trunk.
by dna-commits@lists.jboss.org
Author: lisbor
Date: 2008-12-08 08:09:15 -0500 (Mon, 08 Dec 2008)
New Revision: 664
Modified:
trunk/pom.xml
Log:
DNA-37 Federate schema information from relational sources
https://jira.jboss.org/jira/browse/DNA-37
POM updated to use jdbc connector
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-12-08 12:28:33 UTC (rev 663)
+++ trunk/pom.xml 2008-12-08 13:09:15 UTC (rev 664)
@@ -100,7 +100,7 @@
<roles>
<role>Developer</role>
</roles>
- <timezone>0</timezone>
+ <timezone>+10</timezone>
</developer>
</developers>
<contributors>
@@ -131,6 +131,8 @@
<module>extensions/dna-connector-svn</module>
<module>extensions/dna-connector-store-jpa</module>
<module>extensions/dna-mimetype-detector-aperture</module>
+ <module>extensions/dna-common-jdbc</module>
+ <module>extensions/dna-connector-jdbc-metadata</module>
<module>dna-integration-tests</module>
<module>docs/examples/gettingstarted</module>
</modules>
17 years, 4 months
DNA SVN: r663 - in trunk/extensions: dna-common-jdbc and 10 other directories.
by dna-commits@lists.jboss.org
Author: lisbor
Date: 2008-12-08 07:28:33 -0500 (Mon, 08 Dec 2008)
New Revision: 663
Added:
trunk/extensions/dna-connector-jdbc-metadata/
trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/
trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositoryLexicon.java
trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositorySource.java
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/jdbc/
trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.properties
Removed:
trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/sequencer/
trunk/extensions/dna-sequencer-jdbc-metadata/
Modified:
trunk/extensions/dna-common-jdbc/
trunk/extensions/dna-connector-jdbc-metadata/.classpath
trunk/extensions/dna-connector-jdbc-metadata/.project
trunk/extensions/dna-connector-jdbc-metadata/pom.xml
trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.java
Log:
DNA-37 Federate schema information from relational sources
https://jira.jboss.org/jira/browse/DNA-37
Repository Source
Property changes on: trunk/extensions/dna-common-jdbc
___________________________________________________________________
Name: svn:ignore
+ target
Copied: trunk/extensions/dna-connector-jdbc-metadata (from rev 662, trunk/extensions/dna-sequencer-jdbc-metadata)
Property changes on: trunk/extensions/dna-connector-jdbc-metadata
___________________________________________________________________
Name: svn:ignore
+ target
Name: svn:mergeinfo
+
Modified: trunk/extensions/dna-connector-jdbc-metadata/.classpath
===================================================================
--- trunk/extensions/dna-sequencer-jdbc-metadata/.classpath 2008-12-05 23:52:47 UTC (rev 662)
+++ trunk/extensions/dna-connector-jdbc-metadata/.classpath 2008-12-08 12:28:33 UTC (rev 663)
@@ -4,7 +4,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <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>
Modified: trunk/extensions/dna-connector-jdbc-metadata/.project
===================================================================
--- trunk/extensions/dna-sequencer-jdbc-metadata/.project 2008-12-05 23:52:47 UTC (rev 662)
+++ trunk/extensions/dna-connector-jdbc-metadata/.project 2008-12-08 12:28:33 UTC (rev 663)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>dna-sequencer-jdbc-metadata</name>
+ <name>dna-connector-jdbc-metadata</name>
<comment></comment>
<projects>
</projects>
Modified: trunk/extensions/dna-connector-jdbc-metadata/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-jdbc-metadata/pom.xml 2008-12-05 23:52:47 UTC (rev 662)
+++ trunk/extensions/dna-connector-jdbc-metadata/pom.xml 2008-12-08 12:28:33 UTC (rev 663)
@@ -7,10 +7,10 @@
<relativePath>../..</relativePath>
</parent>
<!-- The groupId and version values are inherited from parent -->
- <artifactId>dna-sequencer-jdbc-metadata</artifactId>
+ <artifactId>dna-connector-jdbc-metadata</artifactId>
<packaging>jar</packaging>
- <name>JBoss DNA JDBC Metadata Sequencer</name>
- <description>JBoss DNA Sequencer that processes JDBC metadata</description>
+ <name>JBoss DNA Connector to JDBC</name>
+ <description>JBoss DNA Connector that processes JDBC metadata</description>
<url>http://labs.jboss.org/dna</url>
<dependencies>
<dependency>
Copied: trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector (from rev 662, trunk/extensions/dna-sequencer-jdbc-metadata/src/main/java/org/jboss/dna/sequencer)
Property changes on: trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.java
===================================================================
--- trunk/extensions/dna-sequencer-jdbc-metadata/src/main/java/org/jboss/dna/sequencer/jdbc/JdbcMetadataI18n.java 2008-12-05 23:52:47 UTC (rev 662)
+++ trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.java 2008-12-08 12:28:33 UTC (rev 663)
@@ -19,7 +19,7 @@
* 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.sequencer.jdbc;
+package org.jboss.dna.connector.jdbc;
import java.util.Locale;
import java.util.Set;
@@ -30,7 +30,13 @@
* @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a>
*/
public class JdbcMetadataI18n {
- public static I18n sequencerTaskName;
+ public static I18n connectorName;
+ public static I18n nodeDoesNotExist;
+ public static I18n nodeTypeIsNotSupported;
+ public static I18n propertyIsRequired;
+ public static I18n errorSerializingCachePolicyInSource;
+ public static I18n locationInRequestMustHavePath;
+ public static I18n sourceIsReadOnly;
static {
try {
Added: trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositoryLexicon.java
===================================================================
--- trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositoryLexicon.java (rev 0)
+++ trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositoryLexicon.java 2008-12-08 12:28:33 UTC (rev 663)
@@ -0,0 +1,42 @@
+/*
+ * 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.jdbc;
+
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.basic.BasicName;
+
+
+/**
+ * The namespace and property names used within a {@link JdbcRepositorySource} to store internal information.
+ *
+ * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a>
+ */
+public class JdbcRepositoryLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jboss.org/dna/connector/jdbc";
+ public static final String PREFIX = "dnajdbc";
+ }
+
+ public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI, "orderedChildNames");
+ public static final Name UUID = new BasicName(Namespace.URI, "uuid");
+}
Added: trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositorySource.java (rev 0)
+++ trunk/extensions/dna-connector-jdbc-metadata/src/main/java/org/jboss/dna/connector/jdbc/JdbcRepositorySource.java 2008-12-08 12:28:33 UTC (rev 663)
@@ -0,0 +1,310 @@
+/*
+ * 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.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.naming.BinaryRefAddr;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
+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;
+
+/**
+ * A description of a JDBC resource that can be used to access database information.
+ *
+ * @author <a href="mailto:litsenko_sergey@yahoo.com">Sergiy Litsenko</a>
+ *
+ */
+public class JdbcRepositorySource implements RepositorySource, ObjectFactory {
+ private static final long serialVersionUID = 1L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+
+ /**
+ * This source supports updates 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;
+
+ /**
+ * This source supports events.
+ */
+ protected static final boolean SUPPORTS_EVENTS = true;
+ /**
+ * This source does not support same-name-siblings.
+ */
+ protected static final boolean SUPPORTS_SAME_NAME_SIBLINGS = false;
+
+ private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
+ protected String name;
+ protected final Capabilities capabilities = new Capabilities();
+ protected transient RepositoryContext repositoryContext;
+ protected CachePolicy defaultCachePolicy;
+
+ protected static final String SOURCE_NAME = "sourceName";
+ protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
+ protected static final String REPO_JNDI_NAME = "jndiName";
+ protected static final String REPO_FACTORY_JNDI_NAME = "factoryJndiName";
+ protected static final String RETRY_LIMIT = "retryLimit";
+
+ /**
+ * default constructor
+ */
+ public JdbcRepositorySource() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return capabilities;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#getConnection()
+ */
+ public RepositoryConnection getConnection() throws RepositorySourceException {
+ // TODO create Jdbc connection
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name of this source
+ *
+ * @param name the name for this source
+ */
+ public void setName( String name ) {
+ this.name = name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#initialize(org.jboss.dna.graph.connectors.RepositoryContext)
+ */
+ public void initialize( RepositoryContext context ) throws RepositorySourceException {
+ this.repositoryContext = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#setRetryLimit(int)
+ */
+ public void setRetryLimit( int limit ) {
+ retryLimit.set(limit < 0 ? 0 : limit);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Get the default cache policy for this source, or null if the global default cache policy should be used
+ *
+ * @return the default cache policy, or null if this source has no explicit default cache policy
+ */
+ public CachePolicy getDefaultCachePolicy() {
+ return defaultCachePolicy;
+ }
+
+ /**
+ * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ */
+ public synchronized void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ this.defaultCachePolicy = defaultCachePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof JdbcRepositorySource) {
+ JdbcRepositorySource that = (JdbcRepositorySource)obj;
+ if (this.getName() == null) {
+ if (that.getName() != null) return false;
+ } else {
+ if (!this.getName().equals(that.getName())) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.naming.Referenceable#getReference()
+ */
+ public Reference getReference() throws NamingException {
+ 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()));
+ }
+ if (getDefaultCachePolicy() != null) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CachePolicy policy = getDefaultCachePolicy();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(policy);
+ ref.add(new BinaryRefAddr(DEFAULT_CACHE_POLICY, baos.toByteArray()));
+ } catch (IOException e) {
+ I18n msg = JdbcMetadataI18n.errorSerializingCachePolicyInSource;
+ throw new RepositorySourceException(getName(), msg.text(policy.getClass().getName(), getName()), e);
+ }
+ }
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ // return it
+ return ref;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
+ */
+ public Object getObjectInstance( Object obj,
+ Name name,
+ Context nameCtx,
+ Hashtable<?, ?> environment ) throws Exception {
+ if (obj instanceof Reference) {
+ Map<String, Object> values = new HashMap<String, Object>();
+ 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());
+ } else if (subref instanceof BinaryRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value instanceof byte[]) {
+ // Deserialize ...
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[])value);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ value = ois.readObject();
+ values.put(key, value);
+ }
+ }
+ }
+ String sourceName = (String)values.get(SOURCE_NAME);
+ Object defaultCachePolicy = values.get(DEFAULT_CACHE_POLICY);
+ String retryLimit = (String)values.get(RETRY_LIMIT);
+
+ // Create the source instance ...
+ JdbcRepositorySource source = new JdbcRepositorySource();
+ if (sourceName != null) source.setName(sourceName);
+ if (defaultCachePolicy instanceof CachePolicy) {
+ source.setDefaultCachePolicy((CachePolicy)defaultCachePolicy);
+ }
+ if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ return source;
+ }
+ return null;
+ }
+
+ @ThreadSafe
+ protected class Capabilities extends RepositorySourceCapabilities {
+ private final AtomicBoolean supportsUpdates = new AtomicBoolean(DEFAULT_SUPPORTS_UPDATES);
+
+ /*package*/Capabilities() {
+ super(DEFAULT_SUPPORTS_UPDATES, SUPPORTS_EVENTS);
+ }
+
+ /*package*/void setSupportsUpdates( boolean supportsUpdates ) {
+ this.supportsUpdates.set(supportsUpdates);
+ }
+
+ @Override
+ public boolean supportsUpdates() {
+ return this.supportsUpdates.get();
+ }
+ }
+}
Added: trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.properties
===================================================================
--- trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.properties (rev 0)
+++ trunk/extensions/dna-connector-jdbc-metadata/src/main/resources/org/jboss/dna/connector/jdbc/JdbcMetadataI18n.properties 2008-12-08 12:28:33 UTC (rev 663)
@@ -0,0 +1,29 @@
+#
+# 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 = JDBC Connector
+nodeDoesNotExist = This node kind is missing at {0}
+nodeTypeIsNotSupported= The {0} node type is not supported
+locationInRequestMustHavePath = Location must have a path {0}
+propertyIsRequired = The {0} property is required but has no value
+errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} JdbcRepositorySource
+sourceIsReadOnly = {0} is a read-only source; no updates are allowed
\ No newline at end of file
17 years, 4 months
DNA SVN: r662 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-12-05 18:52:47 -0500 (Fri, 05 Dec 2008)
New Revision: 662
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
a small impl. for the read all children and read all properties request processing
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 18:26:07 UTC (rev 661)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 23:52:47 UTC (rev 662)
@@ -33,6 +33,7 @@
import org.jboss.dna.graph.JcrNtLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.Binary;
import org.jboss.dna.graph.properties.DateTimeFactory;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NameFactory;
@@ -41,7 +42,9 @@
import org.jboss.dna.graph.properties.PathNotFoundException;
import org.jboss.dna.graph.properties.Property;
import org.jboss.dna.graph.properties.PropertyFactory;
+import org.jboss.dna.graph.properties.ValueFactory;
import org.jboss.dna.graph.properties.basic.BasicMultiValueProperty;
+import org.jboss.dna.graph.properties.basic.InMemoryBinary;
import org.jboss.dna.graph.requests.CopyBranchRequest;
import org.jboss.dna.graph.requests.CreateNodeRequest;
import org.jboss.dna.graph.requests.DeleteBranchRequest;
@@ -227,11 +230,14 @@
SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
Date lastModified = entry.getDate();
if (lastModified != null) {
- Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED, dateFactory().create(lastModified));
+ Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED,
+ dateFactory().create(lastModified));
properties.add(jcrLastModifiedProperty);
}
if (os.toByteArray().length > 0) {
- Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA, os.toByteArray());
+ Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA,
+ binaryFactory().create(new InMemoryBinary(
+ os.toByteArray())));
properties.add(jcrDataProperty);
}
request.addProperties(properties.toArray(new BasicMultiValueProperty[0]));
@@ -305,6 +311,11 @@
}
}
+ /**
+ * Factory for sample name.
+ *
+ * @return the name factory
+ */
protected NameFactory nameFactory() {
return getExecutionContext().getValueFactories().getNameFactory();
}
@@ -321,6 +332,10 @@
return getExecutionContext().getValueFactories().getDateFactory();
}
+ protected ValueFactory<Binary> binaryFactory() {
+ return getExecutionContext().getValueFactories().getBinaryFactory();
+ }
+
protected Path getPathFor( Location location,
Request request ) {
Path path = location.getPath();
17 years, 4 months
DNA SVN: r661 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-12-05 13:26:07 -0500 (Fri, 05 Dec 2008)
New Revision: 661
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
a small impl. for the read all children and read all properties request processing
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 18:21:36 UTC (rev 660)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 18:26:07 UTC (rev 661)
@@ -227,7 +227,7 @@
SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
Date lastModified = entry.getDate();
if (lastModified != null) {
- Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED, lastModified.toString());
+ Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED, dateFactory().create(lastModified));
properties.add(jcrLastModifiedProperty);
}
if (os.toByteArray().length > 0) {
17 years, 4 months
DNA SVN: r660 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-12-05 13:21:36 -0500 (Fri, 05 Dec 2008)
New Revision: 660
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
a small impl. for the read all children and read all properties request processing
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 15:49:58 UTC (rev 659)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 18:21:36 UTC (rev 660)
@@ -30,8 +30,10 @@
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.DateTimeFactory;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NameFactory;
import org.jboss.dna.graph.properties.Path;
@@ -215,19 +217,13 @@
SVNProperties fileProperties = new SVNProperties();
List<Property> properties = new ArrayList<Property>();
getData(parent.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
-
- Property ntResourceproperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:resource");
+ Property ntResourceproperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE);
properties.add(ntResourceproperty);
String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
if (mimeType != null) {
Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIMETYPE, mimeType);
properties.add(jcrMimeTypeProperty);
}
- String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
- if (created != null) {
- Property jcrCreatedProperty = propertyFactory().create(JcrLexicon.CREATED, created);
- properties.add(jcrCreatedProperty);
- }
SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
Date lastModified = entry.getDate();
if (lastModified != null) {
@@ -243,14 +239,24 @@
SVNNodeKind kind = validateNodeKind(nodePath);
if (kind == SVNNodeKind.FILE) {
// "jcr:primaryType" property whose value is "nt:file".
- Property ntFileProperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:file");
+ Property ntFileProperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE);
request.addProperty(ntFileProperty);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ SVNProperties fileProperties = new SVNProperties();
+ getData(nodePath.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
+ String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
+ if (created != null) {
+ Property jcrCreatedProperty = propertyFactory().create(JcrLexicon.CREATED, created);
+ request.addProperty(jcrCreatedProperty);
+ }
} else if (kind == SVNNodeKind.DIR) {
// A directory maps to a single node with a name that represents the name of the directory and a
// "jcr:primaryType" property whose value is "nt:folder"
- Property property = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:folder");
+ Property property = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
request.addProperty(property);
+ SVNDirEntry dirEntry = getEntryInfo(nodePath.getString(getExecutionContext().getNamespaceRegistry()));
+ request.addProperty(propertyFactory().create(JcrLexicon.CREATED, dateFactory().create(dirEntry.getDate())));
}
}
request.setActualLocationOfNode(myLocation);
@@ -311,6 +317,10 @@
return getExecutionContext().getPropertyFactory();
}
+ protected DateTimeFactory dateFactory() {
+ return getExecutionContext().getValueFactories().getDateFactory();
+ }
+
protected Path getPathFor( Location location,
Request request ) {
Path path = location.getPath();
17 years, 4 months
DNA SVN: r659 - trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-12-05 10:49:58 -0500 (Fri, 05 Dec 2008)
New Revision: 659
Modified:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Log:
DNA-36 Federate content from SVN
Corrected compilation error.
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 15:26:03 UTC (rev 658)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 15:49:58 UTC (rev 659)
@@ -220,7 +220,7 @@
properties.add(ntResourceproperty);
String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
if (mimeType != null) {
- Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIME, mimeType);
+ Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIMETYPE, mimeType);
properties.add(jcrMimeTypeProperty);
}
String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
@@ -260,10 +260,10 @@
request.setError(e);
}
}
-
+
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.RemovePropertiesRequest)
*/
@Override
@@ -274,7 +274,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.RenameNodeRequest)
*/
@Override
17 years, 4 months
DNA SVN: r658 - in trunk/extensions/dna-connector-svn: src/main/java/org/jboss/dna/connector/svn and 2 other directories.
by dna-commits@lists.jboss.org
Author: spagop
Date: 2008-12-05 10:26:03 -0500 (Fri, 05 Dec 2008)
New Revision: 658
Added:
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
Modified:
trunk/extensions/dna-connector-svn/.classpath
trunk/extensions/dna-connector-svn/.project
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java
trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
Log:
a small impl. for the read all children and read all properties request processing
Modified: trunk/extensions/dna-connector-svn/.classpath
===================================================================
--- trunk/extensions/dna-connector-svn/.classpath 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/.classpath 2008-12-05 15:26:03 UTC (rev 658)
@@ -1,10 +1,18 @@
-<?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>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="src" path="/dna-common"/>
+ <classpathentry kind="src" path="/dna-graph"/>
+ <classpathentry kind="var" path="M2_REPO/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/joda-time/joda-time/1.4/joda-time-1.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mockito/mockito-all/1.5/mockito-all-1.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.4.3/slf4j-log4j12-1.4.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/tmatesoft/svnkit/svnkit/1.2.0.4949/svnkit-1.2.0.4949.jar"/>
+</classpath>
\ No newline at end of file
Modified: trunk/extensions/dna-connector-svn/.project
===================================================================
--- trunk/extensions/dna-connector-svn/.project 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/.project 2008-12-05 15:26:03 UTC (rev 658)
@@ -1,23 +1,16 @@
-<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>dna-connector-svn</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>
+ <name>dna-connector-svn</name>
+ <comment>JBoss DNA Connector that accesses an in-process SVN instance.</comment>
+ <projects>
+ <project>dna-common</project>
+ <project>dna-graph</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnection.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -29,10 +29,15 @@
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.properties.Name;
-import org.jboss.dna.graph.properties.NameFactory;
+import org.jboss.dna.graph.properties.PathFactory;
+import org.jboss.dna.graph.properties.PropertyFactory;
+import org.jboss.dna.graph.properties.ValueFactory;
import org.jboss.dna.graph.requests.Request;
+import org.jboss.dna.graph.requests.processor.RequestProcessor;
+import org.tmatesoft.svn.core.SVNErrorCode;
+import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.io.SVNRepository;
/**
@@ -53,24 +58,47 @@
}
};
- private Name uuidPropertyName;
private final String sourceName;
- private final String uuidPropertyNameString;
private final CachePolicy cachePolicy;
private final SVNRepository repository;
+ private final boolean updatesAllowed;
private RepositorySourceListener listener = NO_OP_LISTENER;
public SVNRepositoryConnection( String sourceName,
CachePolicy cachePolicy,
- String uuidPropertyName,
+ boolean updatesAllowed,
SVNRepository repository ) {
assert (sourceName != null);
assert (repository != null);
- assert (uuidPropertyName != null);
+
+ SVNNodeKind nodeKind = null;
+ try {
+ nodeKind = repository.checkPath("", -1);
+ if (nodeKind == SVNNodeKind.NONE) {
+ SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "No entry at URL ''{0}''",
+ repository.getLocation().getPath());
+ throw new SVNException(error);
+ } else if (nodeKind == SVNNodeKind.UNKNOWN) {
+ SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "Entry at URL ''{0}'' is a file while directory was expected",
+ repository.getLocation().getPath());
+ throw new SVNException(error);
+ } else if (nodeKind == SVNNodeKind.FILE) {
+ SVNErrorMessage error = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
+ "Entry at URL ''{0}'' is a file while directory was expected",
+ repository.getLocation().getPath());
+ throw new SVNException(error);
+ }
+ } catch (SVNException e) {
+ // deal with the exception
+ throw new RuntimeException(e);
+ }
+
this.sourceName = sourceName;
this.cachePolicy = cachePolicy;
- this.uuidPropertyNameString = uuidPropertyName;
this.repository = repository;
+ this.updatesAllowed = updatesAllowed;
}
SVNRepository getRepository() {
@@ -133,9 +161,20 @@
* @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 {
- // TODO
+ @SuppressWarnings( "unused" )
+ public void execute( final ExecutionContext context,
+ final Request request ) throws RepositorySourceException {
+
+ final PathFactory pathFactory = context.getValueFactories().getPathFactory();
+ final PropertyFactory propertyFactory = context.getPropertyFactory();
+ final ValueFactory<UUID> uuidFactory = context.getValueFactories().getUuidFactory();
+
+ RequestProcessor processor = new SVNRepositoryRequestProcessor(getSourceName(), context, repository, updatesAllowed);
+ try {
+ processor.process(request);
+ } finally {
+ processor.close();
+ }
}
/**
@@ -145,24 +184,4 @@
return this.listener;
}
- /**
- * Utility method to calculate (if required) and obtain the name that should be used to store the UUID values for each node.
- * This method may be called without regard to synchronization, since it should return the same value if it happens to be
- * called concurrently while not yet initialized.
- *
- * @param context the execution context
- * @return the name, or null if the UUID should not be stored
- */
- protected Name getUuidPropertyName( ExecutionContext context ) {
- if (uuidPropertyName == null) {
- NameFactory nameFactory = context.getValueFactories().getNameFactory();
- uuidPropertyName = nameFactory.create(this.uuidPropertyNameString);
- }
- return this.uuidPropertyName;
- }
-
- protected UUID generateUuid() {
- return UUID.randomUUID();
- }
-
}
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryConnectorI18n.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -32,10 +32,14 @@
public static I18n connectorName;
public static I18n nodeDoesNotExist;
+ public static I18n nodeIsActuallyUnknow;
+ public static I18n nodeTypeIsNotSupported;
public static I18n propertyIsRequired;
public static I18n errorSerializingCachePolicyInSource;
public static I18n objectFoundInJndiWasNotCache;
public static I18n objectFoundInJndiWasNotCacheFactory;
+ public static I18n locationInRequestMustHavePath;
+ public static I18n sourceIsReadOnly;
static {
try {
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryLexicon.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -25,7 +25,11 @@
import org.jboss.dna.graph.properties.basic.BasicName;
-
+/**
+ * The namespace and property names used within a {@link SVNRepositorySource} to store internal information.
+ *
+ * @author Serge Pagop
+ */
public class SVNRepositoryLexicon {
public static class Namespace {
@@ -34,5 +38,6 @@
}
public static final Name CHILD_PATH_SEGMENT_LIST = new BasicName(Namespace.URI, "orderedChildNames");
+ public static final Name UUID = new BasicName(Namespace.URI, "uuid");
}
Added: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java (rev 0)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositoryRequestProcessor.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -0,0 +1,395 @@
+/*
+ * 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.svn;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+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.properties.Property;
+import org.jboss.dna.graph.properties.PropertyFactory;
+import org.jboss.dna.graph.properties.basic.BasicMultiValueProperty;
+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;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNProperties;
+import org.tmatesoft.svn.core.SVNProperty;
+import org.tmatesoft.svn.core.io.SVNRepository;
+
+/**
+ * The {@link RequestProcessor} implementation for the file subversion repository connector. This is the class that does the bulk
+ * of the work in the subversion repository connector, since it processes all requests.
+ *
+ * @author Serge Emmanuel Pagop
+ */
+public class SVNRepositoryRequestProcessor extends RequestProcessor {
+
+ protected static final String BACK_SLASH = "/";
+
+ private final String defaultNamespaceUri;
+ private final boolean updatesAllowed;
+ private SVNRepository repository;
+
+ /**
+ * @param sourceName
+ * @param context
+ * @param repository
+ * @param updatesAllowed true if this connector supports updating the subversion repository, or false if the connector is read
+ * only
+ */
+ protected SVNRepositoryRequestProcessor( String sourceName,
+ ExecutionContext context,
+ SVNRepository repository,
+ boolean updatesAllowed ) {
+ super(sourceName, context);
+ this.defaultNamespaceUri = getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
+ this.updatesAllowed = updatesAllowed;
+ this.repository = repository;
+ }
+
+ /**
+ * {@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.CreateNodeRequest)
+ */
+ @Override
+ public void process( CreateNodeRequest 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.ReadAllChildrenRequest)
+ */
+ @SuppressWarnings( "unchecked" )
+ @Override
+ public void process( ReadAllChildrenRequest request ) {
+ Location myLocation = request.of();
+ Path nodePath = getPathFor(myLocation, request);
+ try {
+ SVNNodeKind kind = validateNodeKind(nodePath);
+ String requestedNodePath = nodePath.getString(getExecutionContext().getNamespaceRegistry());
+ if (kind == SVNNodeKind.FILE) { // the requested node is a file.
+ SVNDirEntry entry = getEntryInfo(requestedNodePath);
+ if (!nodePath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ String localName = entry.getName();
+ Name childName = nameFactory().create(defaultNamespaceUri, localName);
+ String url = entry.getURL().toString();
+ Property idProperty = propertyFactory().create(childName, url);
+ request.addChild(new Location(pathFactory().create(nodePath, JcrLexicon.CONTENT), idProperty));
+ }
+ } else if (kind == SVNNodeKind.DIR) { // the requested node is a directory.
+ final Collection<SVNDirEntry> dirEntries = getRepository().getDir(requestedNodePath,
+ -1,
+ null,
+ (Collection<SVNDirEntry>)null);
+ for (SVNDirEntry dirEntry : dirEntries) {
+ if (dirEntry.getKind() == SVNNodeKind.FILE) {
+ String localName = dirEntry.getName();
+ Path newPath = pathFactory().create(requestedNodePath + BACK_SLASH + localName);
+ if (!newPath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ Name childName = nameFactory().create(defaultNamespaceUri, localName);
+ String url = dirEntry.getURL().toString();
+ Property idProperty = propertyFactory().create(childName, url);
+ Location location = new Location(pathFactory().create(newPath, JcrLexicon.CONTENT), idProperty);
+ request.addChild(location);
+ }
+ } else if (dirEntry.getKind() == SVNNodeKind.DIR) {
+ String localName = dirEntry.getName();
+ Name childName = nameFactory().create(defaultNamespaceUri, localName);
+ Path childPath = pathFactory().create(nodePath, childName);
+ String url = dirEntry.getURL().toString();
+ Property idProperty = propertyFactory().create(childName, url);
+ request.addChild(childPath, idProperty);
+ }
+ }
+ }
+ request.setActualLocationOfNode(myLocation);
+ } catch (SVNException e) {
+ // if a failure occured while connecting to a repository
+ // or the user's authentication failed (see
+ // path not found in the specified revision
+ // or is not a directory
+ e.printStackTrace();
+ request.setError(e);
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.ReadAllPropertiesRequest)
+ */
+ @Override
+ public void process( ReadAllPropertiesRequest request ) {
+ Location myLocation = request.at();
+ Path nodePath = getPathFor(myLocation, request);
+ if (nodePath.isRoot()) {
+ // There are no properties on the root ...
+ request.setActualLocationOfNode(myLocation);
+ return;
+ }
+ try {
+ // See if the path is a "jcr:content" node ...
+ if (nodePath.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
+ // //"jcr:primaryType" property value of "nt:resource",
+ // "jcr:data" property whose value are the contents of the file
+ // and a few other properties, like "jcr:encoding", "jcr:mimeType" and "jcr:lastModified" and
+ // also "jcr:created" property
+ Path parent = nodePath.getParent();
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ SVNProperties fileProperties = new SVNProperties();
+ List<Property> properties = new ArrayList<Property>();
+ getData(parent.getString(getExecutionContext().getNamespaceRegistry()), fileProperties, os);
+
+ Property ntResourceproperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:resource");
+ properties.add(ntResourceproperty);
+ String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
+ if (mimeType != null) {
+ Property jcrMimeTypeProperty = propertyFactory().create(JcrLexicon.MIME, mimeType);
+ properties.add(jcrMimeTypeProperty);
+ }
+ String created = fileProperties.getStringValue(SVNProperty.COMMITTED_DATE);
+ if (created != null) {
+ Property jcrCreatedProperty = propertyFactory().create(JcrLexicon.CREATED, created);
+ properties.add(jcrCreatedProperty);
+ }
+ SVNDirEntry entry = getEntryInfo(parent.getString(getExecutionContext().getNamespaceRegistry()));
+ Date lastModified = entry.getDate();
+ if (lastModified != null) {
+ Property jcrLastModifiedProperty = propertyFactory().create(JcrLexicon.LAST_MODIFIED, lastModified.toString());
+ properties.add(jcrLastModifiedProperty);
+ }
+ if (os.toByteArray().length > 0) {
+ Property jcrDataProperty = propertyFactory().create(JcrLexicon.DATA, os.toByteArray());
+ properties.add(jcrDataProperty);
+ }
+ request.addProperties(properties.toArray(new BasicMultiValueProperty[0]));
+ } else {
+ SVNNodeKind kind = validateNodeKind(nodePath);
+ if (kind == SVNNodeKind.FILE) {
+ // "jcr:primaryType" property whose value is "nt:file".
+ Property ntFileProperty = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:file");
+ request.addProperty(ntFileProperty);
+
+ } else if (kind == SVNNodeKind.DIR) {
+ // A directory maps to a single node with a name that represents the name of the directory and a
+ // "jcr:primaryType" property whose value is "nt:folder"
+ Property property = propertyFactory().create(JcrLexicon.PRIMARY_TYPE, "nt:folder");
+ request.addProperty(property);
+ }
+ }
+ request.setActualLocationOfNode(myLocation);
+
+ } catch (SVNException e) {
+ e.printStackTrace();
+ request.setError(e);
+ }
+ }
+
+ /**
+ * {@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);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.requests.processor.RequestProcessor#process(org.jboss.dna.graph.requests.UpdatePropertiesRequest)
+ */
+ @Override
+ public void process( UpdatePropertiesRequest request ) {
+ }
+
+ protected void verifyUpdatesAllowed() {
+ if (!updatesAllowed) {
+ throw new RepositorySourceException(getSourceName(),
+ SVNRepositoryConnectorI18n.sourceIsReadOnly.text(getSourceName()));
+ }
+ }
+
+ protected NameFactory nameFactory() {
+ return getExecutionContext().getValueFactories().getNameFactory();
+ }
+
+ protected PathFactory pathFactory() {
+ return getExecutionContext().getValueFactories().getPathFactory();
+ }
+
+ protected PropertyFactory propertyFactory() {
+ return getExecutionContext().getPropertyFactory();
+ }
+
+ protected Path getPathFor( Location location,
+ Request request ) {
+ Path path = location.getPath();
+ if (path == null) {
+ I18n msg = SVNRepositoryConnectorI18n.locationInRequestMustHavePath;
+ throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
+ }
+ return path;
+ }
+
+ /**
+ * Get the content of a file.
+ *
+ * @param path - the path to that file.
+ * @param properties - the properties of the file.
+ * @param os - the output stream where to store the content.
+ * @throws SVNException - throws if such path is not at that revision or in case of a connection problem.
+ */
+ protected void getData( String path,
+ SVNProperties properties,
+ OutputStream os ) throws SVNException {
+ getRepository().getFile(path, -1, properties, os);
+
+ }
+
+ /**
+ * @return repository
+ */
+ public SVNRepository getRepository() {
+ return repository;
+ }
+
+ /**
+ * Validate the kind of node and throws an exception if necessary.
+ *
+ * @param requestedPath
+ * @return the kind.
+ */
+ protected SVNNodeKind validateNodeKind( final Path requestedPath ) {
+ String myPath = requestedPath.getString(getExecutionContext().getNamespaceRegistry());
+ SVNNodeKind kind = null;
+ try {
+ kind = getRepository().checkPath(myPath, -1);
+ if (kind == SVNNodeKind.NONE) {
+ // node does not exist or requested node is not correct.
+ throw new PathNotFoundException(new Location(requestedPath), null,
+ SVNRepositoryConnectorI18n.nodeDoesNotExist.text(myPath));
+ } else if (kind == SVNNodeKind.UNKNOWN) {
+ // node is unknown
+ throw new PathNotFoundException(new Location(requestedPath), null,
+ SVNRepositoryConnectorI18n.nodeIsActuallyUnknow.text(myPath));
+ }
+ } catch (SVNException e) {
+ // if a failure occured while connecting to a repository
+ // * or the user's authentication failed (see
+ // * {@link org.tmatesoft.svn.core.SVNAuthenticationException})
+ // TODO RepositorySourceAuthenticationException
+ }
+
+ return kind;
+ }
+
+ /**
+ * Get some important informations of a path
+ *
+ * @param path - the path
+ * @return - the {@link SVNDirEntry}.
+ */
+ protected SVNDirEntry getEntryInfo( String path ) {
+ assert path != null;
+ SVNDirEntry entry = null;
+ try {
+ entry = getRepository().info(path, -1);
+ } catch (SVNException e) {
+ // if a failure occured while connecting to a repository
+ // * or the user's authentication failed (see
+ // * {@link org.tmatesoft.svn.core.SVNAuthenticationException})
+ // TODO RepositorySourceAuthenticationException
+ }
+ return entry;
+ }
+}
Modified: trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/main/java/org/jboss/dna/connector/svn/SVNRepositorySource.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -30,7 +30,7 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
-import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.BinaryRefAddr;
import javax.naming.Context;
@@ -40,16 +40,15 @@
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.DnaLexicon;
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;
-import org.jboss.dna.graph.properties.Property;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
@@ -65,7 +64,8 @@
* {@link SVNRepository} instance or creating a new instance. This process is controlled entirely by the JavaBean properties of
* the SVNRepositorySource instance. Like other {@link RepositorySource} classes, instances of SVNRepositorySource can be placed
* into JNDI and do support the creation of {@link Referenceable JNDI referenceable} objects and resolution of references into
- * SVNRepositorySource. </p>
+ * SVNRepositorySource.
+ * </p>
*
* @author Serge Pagop
*/
@@ -77,14 +77,25 @@
*/
public static final int DEFAULT_RETRY_LIMIT = 0;
- protected static final RepositorySourceCapabilities CAPABILITIES = new RepositorySourceCapabilities(false, true);
+ /**
+ * 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 = false;
+ /**
+ * 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 String DEFAULT_UUID_PROPERTY_NAME = DnaLexicon.UUID.getString();
+ public static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 60 * 5; // 5 minutes
+
protected static final String SOURCE_NAME = "sourceName";
- protected static final String ROOT_NODE_UUID = "rootNodeUuid";
protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
- protected static final String UUID_PROPERTY_NAME = "uuidPropertyName";
protected static final String SVN_REPOS_JNDI_NAME = "svnReposJndiName";
protected static final String SVN_REPOS_FACTORY_JNDI_NAME = "svnReposFactoryJndiName";
protected static final String SVN_URL = "svnURL";
@@ -94,13 +105,13 @@
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private String name;
- private UUID rootNodeUuid = UUID.randomUUID();
- private String uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
private String svnURL;
private String svnUsername;
private String svnPassword;
private CachePolicy defaultCachePolicy;
+ private final Capabilities capabilities = new Capabilities();
+
private transient Context jndiContext;
private transient RepositoryContext repositoryContext;
private transient SVNRepository svnRepository;
@@ -110,6 +121,15 @@
*/
public SVNRepositorySource() {
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connectors.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return capabilities;
+ }
/**
* {@inheritDoc}
@@ -180,61 +200,6 @@
this.defaultCachePolicy = defaultCachePolicy;
}
- /**
- * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
- * the existing root node.
- *
- * @return the UUID of the root node for the cache.
- */
- public String getRootNodeUuid() {
- return this.rootNodeUuid.toString();
- }
-
- /**
- * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
- * the existing root node.
- *
- * @return the UUID of the root node for the cache.
- */
- public UUID getRootNodeUuidObject() {
- return this.rootNodeUuid;
- }
-
- /**
- * Set the UUID of the root node in this repository. If the cache exists, this UUID is not used but is instead set to the UUID
- * of the existing root node.
- *
- * @param rootNodeUuid the UUID of the root node for the cache, or null if the UUID should be randomly generated
- */
- public synchronized void setRootNodeUuid( String rootNodeUuid ) {
- UUID uuid = null;
- if (rootNodeUuid == null) uuid = UUID.randomUUID();
- else uuid = UUID.fromString(rootNodeUuid);
- if (this.rootNodeUuid.equals(uuid)) return; // unchanged
- this.rootNodeUuid = uuid;
- }
-
- /**
- * Get the {@link Property#getName() property name} where the UUID is stored for each node.
- *
- * @return the name of the UUID property; never null
- */
- public String getUuidPropertyName() {
- return this.uuidPropertyName;
- }
-
- /**
- * Set the {@link Property#getName() property name} where the UUID is stored for each node.
- *
- * @param uuidPropertyName the name of the UUID property, or null if the {@link #DEFAULT_UUID_PROPERTY_NAME default name}
- * should be used
- */
- public synchronized void setUuidPropertyName( String uuidPropertyName ) {
- if (uuidPropertyName == null || uuidPropertyName.trim().length() == 0) uuidPropertyName = DEFAULT_UUID_PROPERTY_NAME;
- if (this.uuidPropertyName.equals(uuidPropertyName)) return; // unchanged
- this.uuidPropertyName = uuidPropertyName;
- }
-
public String getSVNURL() {
return this.svnURL;
}
@@ -273,15 +238,25 @@
}
/**
- * {@inheritDoc}
+ * Get whether this source supports updates.
*
- * @see org.jboss.dna.graph.connectors.RepositorySource#getCapabilities()
+ * @return true if this source supports updates, or false if this source only supports reading content.
*/
- public RepositorySourceCapabilities getCapabilities() {
- return CAPABILITIES;
+ 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#getConnection()
@@ -291,10 +266,6 @@
I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("name"));
}
- if (getUuidPropertyName() == null) {
- I18n msg = SVNRepositoryConnectorI18n.propertyIsRequired;
- throw new RepositorySourceException(getUuidPropertyName(), msg.text("uuidPropertyName"));
- }
SVNURL svnURL = null;
if (this.svnRepository == null) {
try {
@@ -306,20 +277,22 @@
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
this.getSVNPassword());
this.svnRepository.setAuthenticationManager(authManager);
- }
- if (usedProtocol.equals(SVNProtocol.HTTP.value()) || usedProtocol.equals(SVNProtocol.HTTPS.value())) {
+ } else if (usedProtocol.equals(SVNProtocol.HTTP.value()) || usedProtocol.equals(SVNProtocol.HTTPS.value())) {
DAVRepositoryFactory.setup();
this.svnRepository = DAVRepositoryFactory.create(svnURL);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
this.getSVNPassword());
this.svnRepository.setAuthenticationManager(authManager);
- }
- if (usedProtocol.equals(SVNProtocol.FILE.value())) {
+ } else if (usedProtocol.equals(SVNProtocol.FILE.value())) {
FSRepositoryFactory.setup();
this.svnRepository = FSRepositoryFactory.create(svnURL);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(this.getSVNUsername(),
this.getSVNPassword());
this.svnRepository.setAuthenticationManager(authManager);
+ } else {
+ // protocol not supported by this connector
+ throw new RepositorySourceException(getSVNURL(),
+ "Protocol is not supported by this connector or there is problem in the svn url");
}
} catch (SVNException ex) {
@@ -327,8 +300,9 @@
throw new RepositorySourceException(getSVNURL(), msg.text(this.getSVNURL()), ex);
}
}
- return new SVNRepositoryConnection(this.getName(), this.getDefaultCachePolicy(), this.getUuidPropertyName(),
- this.svnRepository);
+ boolean supportsUpdates = getSupportsUpdates();
+ return new SVNRepositoryConnection(this.getName(), this.getDefaultCachePolicy(),
+ supportsUpdates, this.svnRepository);
}
protected Context getContext() {
@@ -370,12 +344,6 @@
if (getName() != null) {
ref.add(new StringRefAddr(SOURCE_NAME, getName()));
}
- if (getRootNodeUuid() != null) {
- ref.add(new StringRefAddr(ROOT_NODE_UUID, getRootNodeUuid().toString()));
- }
- if (getUuidPropertyName() != null) {
- ref.add(new StringRefAddr(UUID_PROPERTY_NAME, getUuidPropertyName()));
- }
if (getSVNURL() != null) {
ref.add(new StringRefAddr(SVN_URL, getSVNURL()));
}
@@ -434,8 +402,6 @@
}
}
String sourceName = (String)values.get(SOURCE_NAME);
- String rootNodeUuidString = (String)values.get(ROOT_NODE_UUID);
- String uuidPropertyName = (String)values.get(UUID_PROPERTY_NAME);
String svnURL = (String)values.get(SVN_URL);
String svnUsername = (String)values.get(SVN_USERNAME);
String svnPassword = (String)values.get(SVN_PASSWORD);
@@ -445,8 +411,6 @@
// Create the source instance ...
SVNRepositorySource source = new SVNRepositorySource();
if (sourceName != null) source.setName(sourceName);
- if (rootNodeUuidString != null) source.setRootNodeUuid(rootNodeUuidString);
- if (uuidPropertyName != null) source.setUuidPropertyName(uuidPropertyName);
if (svnURL != null) source.setSVNURL(svnURL);
if (svnUsername != null) source.setSVNUsername(svnUsername);
if (svnPassword != null) source.setSVNPassword(svnPassword);
@@ -459,4 +423,22 @@
return null;
}
+ @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();
+ }
+ }
+
}
Modified: trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties
===================================================================
--- trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/main/resources/org/jboss/dna/connector/svn/SVNConnectorI18n.properties 2008-12-05 15:26:03 UTC (rev 658)
@@ -21,8 +21,11 @@
#
connectorName = SVN Connector
-nodeDoesNotExist = Could not find an existing node at {0}
+nodeDoesNotExist = This node kind is missing at {0}
+locationInRequestMustHavePath = Location must have a path {0}
+nodeIsActuallyUnknow = This node kind is actually unknown {0}
propertyIsRequired = The {0} property is required but has no value
errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} SVNRepositorySource
objectFoundInJndiWasNotSVNRepository = Object in JNDI at {0} found by SVNRepositorySource {1} was expected to be a typ of org.tmatesoft.svn.core.io.SVNRepository but instead was {2}
-objectFoundInJndiWasNotSVNRepositoryFactory =Object in JNDI at {0} found by SVNRepositorySource {1} was expected to be a typ of org.tmatesoft.svn.core.io.SVNRepositoryFactory but instead was {2}
\ No newline at end of file
+objectFoundInJndiWasNotSVNRepositoryFactory =Object in JNDI at {0} found by SVNRepositorySource {1} was expected to be a typ of org.tmatesoft.svn.core.io.SVNRepositoryFactory but instead was {2}
+sourceIsReadOnly = {0} is a read-only source; no updates are allowed
\ No newline at end of file
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNConnectorTestUtil.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -43,10 +43,13 @@
* @return {@link DAVRepository}.
* @throws SVNException - when error situation.
*/
- public static DAVRepository createDAVRepositoryURL( String url,
- String username,
- String password ) throws SVNException {
+ public static DAVRepository createRepository( String url,
+ String username,
+ String password ) throws SVNException {
+ // for DAV (over http and https)
DAVRepositoryFactory.setup();
+
+
// The factory knows how to create a DAVRepository
DAVRepository repository = (DAVRepository)DAVRepositoryFactory.create(SVNURL.parseURIDecoded(url));
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password);
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -28,22 +28,46 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.verify;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
+import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.Node;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connectors.RepositorySourceListener;
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.properties.PropertyFactory;
+import org.jboss.dna.graph.properties.Path.Segment;
+import org.jboss.dna.graph.requests.ReadAllChildrenRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
+import org.tmatesoft.svn.core.SVNDirEntry;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.SVNNodeKind;
+import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepository;
+import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;
+import org.tmatesoft.svn.core.io.SVNRepository;
/**
* @author Serge Pagop
@@ -58,15 +82,21 @@
private DAVRepository davRepository;
private String uuidPropertyName;
private String sourceName;
+ private Graph graph;
@Mock
private CachePolicy policy;
+ @Mock
+ private ReadAllChildrenRequest request;
+
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
+ context.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX, JcrLexicon.Namespace.URI);
+ context.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX, JcrNtLexicon.Namespace.URI);
pathFactory = context.getValueFactories().getPathFactory();
propertyFactory = context.getPropertyFactory();
nameFactory = context.getValueFactories().getNameFactory();
@@ -76,38 +106,34 @@
String username = "anonymous";
String password = "anonymous";
// Set up the appropriate factory for a particular protocol
- davRepository = SVNConnectorTestUtil.createDAVRepositoryURL(url, username, password);
+ davRepository = SVNConnectorTestUtil.createRepository(url, username, password);
sourceName = "the source name";
- uuidPropertyName = "dna:uuid";
- connection = new SVNRepositoryConnection(sourceName, policy, uuidPropertyName, davRepository);
+ connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE, davRepository);
+ // And create the graph ...
+ graph = Graph.create(connection, context);
}
@After
public void afterEach() {
+ try {
+ if (connection != null) connection.close();
+ } finally {
+ }
}
@Test( expected = AssertionError.class )
public void shouldFailToInstantiateIfSourceNameIsNull() {
sourceName = null;
- connection = new SVNRepositoryConnection(sourceName, policy, uuidPropertyName, davRepository);
+ connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE, davRepository);
}
-
+
@Test( expected = AssertionError.class )
public void shouldFailToInstantiateIfRepositoryIsNull() {
davRepository = null;
- connection = new SVNRepositoryConnection(sourceName, policy, uuidPropertyName, davRepository);
+ connection = new SVNRepositoryConnection(sourceName, policy, Boolean.FALSE, davRepository);
}
-
-
- @Test( expected = AssertionError.class )
- public void shouldFailToInstantiateIfUuidPropertyNameIsNull() throws Exception {
- uuidPropertyName = null;
- connection = new SVNRepositoryConnection(sourceName, policy, uuidPropertyName, davRepository);
-
- }
-
@Test
public void shouldInstantiateWithValidSourceAndDAVRepositoryReferences() throws Exception {
assertThat(connection, is(notNullValue()));
@@ -123,16 +149,16 @@
assertThat(connection.getDefaultCachePolicy(), is(sameInstance(policy)));
}
- @Test
- public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws Exception {
- CachePolicy policy = mock(CachePolicy.class);
- davRepository = mock(DAVRepository.class);
- connection = new SVNRepositoryConnection("the source name", policy, SVNRepositorySource.DEFAULT_UUID_PROPERTY_NAME,
- davRepository);
- stub(davRepository.getRepositoryRoot(true)).toReturn(null);
- assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
- verify(davRepository).getRepositoryRoot(true);
- }
+ // @Test
+ // public void shouldGetTheSVNRepositoryRootFromTheSVNRepositoryWhenPinged() throws Exception {
+ // CachePolicy policy = mock(CachePolicy.class);
+ // davRepository = mock(DAVRepository.class);
+ // connection = new SVNRepositoryConnection("the source name", policy, SVNRepositorySource.DEFAULT_UUID_PROPERTY_NAME,
+ // davRepository);
+ // stub(davRepository.getRepositoryRoot(true)).toReturn(null);
+ // assertThat(connection.ping(1, TimeUnit.SECONDS), is(true));
+ // verify(davRepository).getRepositoryRoot(true);
+ // }
@Test
public void shouldHaveNoOpListenerWhenCreated() {
@@ -154,40 +180,49 @@
assertThat(connection.getListener(), is(sameInstance(SVNRepositoryConnection.NO_OP_LISTENER)));
}
+ @Test( expected = PathNotFoundException.class )
+ public void shouldFailToGetChildrenFromAWrongRequestedPath() {
+ List<Location> l = graph.getChildren().of(pathFactory.create("wrongRequestedPath"));
+ }
+
@Test
- public void shouldGetUuidPropertyNameFromSouceAndShouldNotChangeDuringLifetimeOfConnection() {
- Name name = connection.getUuidPropertyName(context);
- assertThat(name.getLocalName(), is("uuid"));
- assertThat(name.getNamespaceUri(), is(DnaLexicon.Namespace.URI));
- for (int i = 0; i != 10; ++i) {
- Name name2 = connection.getUuidPropertyName(context);
- assertThat(name2, is(sameInstance(name)));
- }
+ public void shouldReturnTheContentNodePathOfTheFile() {
+ List<Location> locations00 = graph.getChildren().of(pathFactory.create("/trunk/extensions/dna-connector-svn/src/test/resources/nodeA/itemA1.txt"));
+ assertThat(locations00.isEmpty(), is(false));
+ assertThat(containsPaths(locations00).contains("/trunk/extensions/dna-connector-svn/src/test/resources/nodeA/itemA1.txt/jcr:content"),
+ is(true));
+
}
@Test
- public void shouldGenerateUuid() {
- for (int i = 0; i != 100; ++i) {
- assertThat(connection.generateUuid(), is(notNullValue()));
+ public void shouldListLocationForChildrenOfAParentPath() {
+
+ // read children from the root node.
+ List<Location> l = graph.getChildren().of(pathFactory.create("/"));
+ assertThat(containsPaths(l).contains("/trunk"), is(true));
+ assertThat(containsPaths(l).contains("/branches"), is(true));
+ assertThat(containsPaths(l).contains("/tags"), is(true));
+
+ List<Location> locations02 = graph.getChildren().of(pathFactory.create("/trunk/extensions/dna-connector-svn/src/test/resources/nodeA"));
+ assertThat(locations02.size() > 0, is(true));
+ assertThat(containsPaths(locations02).contains("/trunk/extensions/dna-connector-svn/src/test/resources/nodeA/itemA1.txt/jcr:content"),
+ is(true));
+ assertThat(containsPaths(locations02).contains("/trunk/extensions/dna-connector-svn/src/test/resources/nodeA/itemA2.txt/jcr:content"),
+ is(true));
+
+ List<Location> locations03 = graph.getChildren().of(pathFactory.create("/trunk/extensions/dna-connector-svn/src/test/resources/nodeB"));
+ assertThat(locations03.size() > 0, is(true));
+ assertThat(containsPaths(locations03).contains("/trunk/extensions/dna-connector-svn/src/test/resources/nodeB/JBossORG-EULA.txt/jcr:content"),
+ is(true));
+ assertThat(containsPaths(locations03).contains("/trunk/extensions/dna-connector-svn/src/test/resources/nodeB/nodeB1"),
+ is(true));
+ }
+
+ protected Collection<String> containsPaths( Collection<Location> locations ) {
+ List<String> paths = new ArrayList<String>();
+ for (Location location : locations) {
+ paths.add(location.getPath().getString(context.getNamespaceRegistry(), new UrlEncoder()));
}
+ return paths;
}
-
-
- /**
- * Create a Repository instance from the file-protocol.
- *
- * @return {@link FSRepository} the repository
- * @throws Exception - in case of a exceptional error during the access.
- */
- // @SuppressWarnings( "unused" )
- // private FSRepository createFSRepositoryFromFileProtocol() throws Exception {
- // //TODO to be changed
- // // String url = "file:///Users/sp/SVNRepos/test";
- // String url = "";
- // // Set up the appropriate factory for a particular protocol
- // FSRepositoryFactory.setup();
- // // The factory knows how to create a DAVRepository
- // FSRepository fsRepository = (FSRepository)FSRepositoryFactory.create(SVNURL.parseURIDecoded(url));
- // return fsRepository;
- // }
}
Modified: trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java
===================================================================
--- trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2008-12-04 23:03:08 UTC (rev 657)
+++ trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositorySourceTest.java 2008-12-05 15:26:03 UTC (rev 658)
@@ -203,8 +203,6 @@
source.setSVNUsername(username);
source.setSVNPassword(password);
source.setDefaultCachePolicy(cachePolicy);
- source.setRootNodeUuid(rootNodeUuid != null ? rootNodeUuid.toString() : null);
- source.setUuidPropertyName(uuidPropertyName);
Reference ref = source.getReference();
@@ -219,8 +217,6 @@
}
assertThat((String)refAttributes.remove(SVNRepositorySource.SOURCE_NAME), is(source.getName()));
- assertThat((String)refAttributes.remove(SVNRepositorySource.ROOT_NODE_UUID), is(source.getRootNodeUuid()));
- assertThat((String)refAttributes.remove(SVNRepositorySource.UUID_PROPERTY_NAME), is(source.getUuidPropertyName()));
assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_URL), is(source.getSVNURL()));
assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_USERNAME), is(source.getSVNUsername()));
assertThat((String)refAttributes.remove(SVNRepositorySource.SVN_PASSWORD), is(source.getSVNPassword()));
@@ -237,8 +233,6 @@
assertThat(recoveredSource, is(notNullValue()));
assertThat(recoveredSource.getName(), is(source.getName()));
- assertThat(recoveredSource.getRootNodeUuid(), is(source.getRootNodeUuid()));
- assertThat(recoveredSource.getUuidPropertyName(), is(source.getUuidPropertyName()));
assertThat(recoveredSource.getSVNURL(), is(source.getSVNURL()));
assertThat(recoveredSource.getSVNUsername(), is(source.getSVNUsername()));
assertThat(recoveredSource.getSVNPassword(), is(source.getSVNPassword()));
17 years, 4 months
DNA SVN: r657 - in trunk: extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-12-04 18:03:08 -0500 (Thu, 04 Dec 2008)
New Revision: 657
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrMixLexicon.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
Log:
DNA-34 - Federate content stored on file system
Added a few more pieces of the implementation. Still need to address determining mime types, binary values (see DNA-260), and unit tests.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java 2008-12-04 21:36:58 UTC (rev 656)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrLexicon.java 2008-12-04 23:03:08 UTC (rev 657)
@@ -37,5 +37,11 @@
public static final Name UUID = new BasicName(Namespace.URI, "uuid");
public static final Name NAME = new BasicName(Namespace.URI, "name");
public static final Name PRIMARY_TYPE = new BasicName(Namespace.URI, "primaryType");
+ public static final Name MIXIN_TYPES = new BasicName(Namespace.URI, "mixinTypes");
public static final Name CONTENT = new BasicName(Namespace.URI, "content");
+ public static final Name CREATED = new BasicName(Namespace.URI, "created");
+ public static final Name ENCODED = new BasicName(Namespace.URI, "encoded");
+ public static final Name MIMETYPE = new BasicName(Namespace.URI, "mimeType");
+ public static final Name DATA = new BasicName(Namespace.URI, "data");
+ public static final Name LAST_MODIFIED = new BasicName(Namespace.URI, "lastModified");
}
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrMixLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrMixLexicon.java (rev 0)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrMixLexicon.java 2008-12-04 23:03:08 UTC (rev 657)
@@ -0,0 +1,40 @@
+/*
+ * 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.graph;
+
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.basic.BasicName;
+
+/**
+ * @author Randall Hauch
+ */
+public class JcrMixLexicon {
+
+ public static class Namespace {
+ public static final String URI = "http://www.jcp.org/jcr/mix/1.0";
+ public static final String PREFIX = "mix";
+ }
+
+ public static final Name REFERENCEABLE = new BasicName(Namespace.URI, "referenceable");
+ public static final Name VERSIONABLE = new BasicName(Namespace.URI, "versionable");
+ public static final Name LOCKABLE = new BasicName(Namespace.URI, "lockable");
+}
Property changes on: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrMixLexicon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java 2008-12-04 21:36:58 UTC (rev 656)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/JcrNtLexicon.java 2008-12-04 23:03:08 UTC (rev 657)
@@ -38,4 +38,5 @@
public static final Name FILE = new BasicName(Namespace.URI, "file");
public static final Name FOLDER = new BasicName(Namespace.URI, "folder");
public static final Name RESOURCE = new BasicName(Namespace.URI, "resource");
+ public static final Name BASE = new BasicName(Namespace.URI, "base");
}
Modified: 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 2008-12-04 21:36:58 UTC (rev 656)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java 2008-12-04 23:03:08 UTC (rev 657)
@@ -27,13 +27,16 @@
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
+import org.jboss.dna.graph.JcrNtLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.DateTimeFactory;
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.properties.PropertyFactory;
import org.jboss.dna.graph.requests.CopyBranchRequest;
import org.jboss.dna.graph.requests.CreateNodeRequest;
import org.jboss.dna.graph.requests.DeleteBranchRequest;
@@ -139,17 +142,36 @@
}
// Get the java.io.File object that represents the location ...
- File parent = getExistingFileFor(path, location, request);
- if (parent.isDirectory()) {
+ File file = getExistingFileFor(path, location, request);
+ PropertyFactory factory = getExecutionContext().getPropertyFactory();
+ DateTimeFactory dateFactory = getExecutionContext().getValueFactories().getDateFactory();
+ // Note that we don't have 'created' timestamps, just last modified, so we'll have to use them
+ if (file.isDirectory()) {
// Add properties for the directory ...
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER));
+ request.addProperty(factory.create(JcrLexicon.CREATED, dateFactory.create(file.lastModified())));
} 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 ...
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE));
+ request.addProperty(factory.create(JcrLexicon.LAST_MODIFIED, dateFactory.create(file.lastModified())));
+ // Don't really know the encoding, either ...
+ // request.addProperty(factory.create(JcrLexicon.ENCODED, stringFactory.create("UTF-8")));
+ // Discover the mime type ...
+ // String mimeType = ...
+ // request.addProperty(factory.create(JcrLexicon.MIMETYPE, mimeType));
+
+ // Now put the file's content into the "jcr:data" property ...
+ // BinaryFactory binaryFactory = getExecutionContext().getValueFactories().getBinaryFactory();
+ // request.addProperty(factory.create(JcrLexicon.DATA, binaryFactory.create(file)));
+
} else {
// The request is to get properties for the node representing the file
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE));
+ request.addProperty(factory.create(JcrLexicon.CREATED, dateFactory.create(file.lastModified())));
}
}
17 years, 4 months
DNA SVN: r656 - in trunk/extensions: dna-connector-filesystem and 21 other directories.
by dna-commits@lists.jboss.org
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
+ */
+@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
17 years, 4 months
DNA SVN: r655 - trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2008-12-04 16:35:16 -0500 (Thu, 04 Dec 2008)
New Revision: 655
Modified:
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java
Log:
DNA-40 Persistant storage for information not stored in other repository sources
Updated a few JavaDocs (small changes).
Modified: trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java
===================================================================
--- trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java 2008-12-04 21:34:49 UTC (rev 654)
+++ trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java 2008-12-04 21:35:16 UTC (rev 655)
@@ -59,6 +59,10 @@
import org.jboss.dna.graph.connectors.RepositorySourceException;
/**
+ * The {@link RepositorySource} for the connector that stores content in a (custom) relational database. This connector uses Java
+ * Persistence API as the interface to the database, with Hibernate as the JPA implementation. (Note that some Hibernate-specific
+ * features are used.)
+ *
* @author Randall Hauch
*/
public class JpaSource implements RepositorySource, ObjectFactory {
@@ -188,7 +192,9 @@
}
/**
- * @param name Sets name to the specified value.
+ * Set the name for the source
+ *
+ * @param name the new name for the source
*/
public void setName( String name ) {
if (name != null) {
17 years, 4 months