jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r721389 - in /jackrabbit/trunk/jackrabbit-jcr-rmi: ./ src/main/java/org/apache/jackrabbit/rmi/repository/ src/main/resources/META-INF/services/ src/test/java/org/apache/jackrabbit/test/rmi/repository/ src/test/resources/
Date Fri, 28 Nov 2008 09:00:54 GMT
Author: mreutegg
Date: Fri Nov 28 01:00:54 2008
New Revision: 721389

URL: http://svn.apache.org/viewvc?rev=721389&view=rev
Log:
JCR-1834: Create RepositoryFactory implementation

Added:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-rmi/   (props changed)
    jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Nov 28 01:00:54 2008
@@ -1,11 +1,12 @@
-*.iml
-*.ipr
-*.iws
-target
-velocity.log
-.settings
-.classpath
-.project
-*.xml.md5
-*-pom-snapshot-version
-.checkstyle
+*.iml
+*.ipr
+*.iws
+target
+velocity.log
+.settings
+.classpath
+.project
+*.xml.md5
+*-pom-snapshot-version
+.checkstyle
+*.log

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml?rev=721389&r1=721388&r2=721389&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/pom.xml Fri Nov 28 01:00:54 2008
@@ -99,6 +99,12 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-core</artifactId>
+      <version>1.6-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
     <!-- Runtime dependencies -->
     <dependency>
       <groupId>javax.jcr</groupId>

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java?rev=721389&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java
Fri Nov 28 01:00:54 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.repository;
+
+import java.util.Map;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.jsr283.RepositoryFactory;
+import org.apache.jackrabbit.rmi.client.LocalAdapterFactory;
+
+/**
+ * <code>RepositoryFactoryImpl</code> implements a JSR 283 repository factory
+ * that connects to a repository that is exposed through RMI.
+ * <p/>
+ * This implementation does not support the notion of a default repository.
+ */
+public class RepositoryFactoryImpl implements RepositoryFactory {
+
+    /**
+     * The name of the rmi url property.
+     */
+    public static final String REPOSITORY_RMI_URL
+            = "org.apache.jackrabbit.repository.rmi.url";
+
+    /**
+     * The name of the local adapter factory property.
+     */
+    public static final String REPOSITORY_RMI_LOCAL_ADAPTER_FACTORY
+            = "org.apache.jackrabbit.repository.rmi.local.adapter.factory";
+
+    public Repository getRepository(Map parameters) throws RepositoryException {
+        if (parameters == null) {
+            // this implementation does not support a default repository
+            return null;
+        }
+
+        String url = (String) parameters.get(REPOSITORY_RMI_URL);
+        if (url == null) {
+            // don't know how to handle
+            return null;
+        }
+
+        LocalAdapterFactory factory = createLocalAdapterFactory(parameters);
+        if (factory == null) {
+            return new RMIRemoteRepository(url);
+        } else {
+            return new RMIRemoteRepository(factory, url);
+        }
+    }
+
+    private LocalAdapterFactory createLocalAdapterFactory(Map params) {
+        String className = (String) params.get(REPOSITORY_RMI_LOCAL_ADAPTER_FACTORY);
+        if (className != null) {
+            try {
+                return (LocalAdapterFactory) Class.forName(className).newInstance();
+            } catch (Exception e) {
+                // return null and use default
+            }
+        }
+        return null;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RepositoryFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory?rev=721389&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory
Fri Nov 28 01:00:54 2008
@@ -0,0 +1,21 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+#
+# This file lists the repository factory implementation for jackrabbit-jcr-rmi
+#
+
+org.apache.jackrabbit.rmi.repository.RepositoryFactoryImpl
+

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/resources/META-INF/services/org.apache.jackrabbit.api.jsr283.RepositoryFactory
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java?rev=721389&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java
Fri Nov 28 01:00:54 2008
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.rmi.repository;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+import javax.jcr.Repository;
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.RepositoryException;
+import javax.imageio.spi.ServiceRegistry;
+
+import org.apache.jackrabbit.api.jsr283.RepositoryFactory;
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.core.RepositoryFactoryImpl;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.rmi.server.RemoteAdapterFactory;
+import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitServerAdapterFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>RepositoryFactoryImplTest</code>...
+ */
+public class RepositoryFactoryImplTest extends TestCase {
+
+    private static final Credentials CREDENTIALS
+            = new SimpleCredentials("user", "pass".toCharArray());
+
+    private static final File TARGET = new File("target");
+
+    private static final File REPO_HOME = new File(TARGET, "repository");
+
+    private static final File REPO_CONF = new File(REPO_HOME, "repository.xml");
+
+    private static final String RMI_URL = "rmi://localhost/repository";
+
+    static {
+        REPO_HOME.mkdirs();
+        if (!REPO_CONF.exists()) {
+            try {
+                // get default configuration from jackrabbit-core
+                InputStream in = RepositoryImpl.class.getResourceAsStream("repository.xml");
+                try {
+                    OutputStream out = new FileOutputStream(REPO_CONF);
+                    try {
+                        byte[] buffer = new byte[1024];
+                        int len;
+                        while ((len = in.read(buffer)) != -1) {
+                            out.write(buffer, 0, len);
+                        }
+                    } finally {
+                        out.close();
+                    }
+                } finally {
+                    in.close();
+                }
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        // try to create a registry
+        try {
+            LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
+        } catch (RemoteException e) {
+            // ignore
+        }
+    }
+
+    private Repository repository;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        // get a local repository
+        Map params = new HashMap();
+        params.put(RepositoryFactoryImpl.REPOSITORY_CONF, REPO_CONF.getAbsolutePath());
+        params.put(RepositoryFactoryImpl.REPOSITORY_HOME, REPO_HOME.getAbsolutePath());
+        repository = RepositoryManager.getRepository(params);
+        
+    }
+
+    protected void tearDown() throws Exception {
+        // shutdown local repository
+        if (repository instanceof JackrabbitRepository) {
+            ((JackrabbitRepository) repository).shutdown();
+        }
+        super.tearDown();
+    }
+
+    public void testConnect() throws Exception {
+        // setup remote repository
+        RemoteAdapterFactory raf = new JackrabbitServerAdapterFactory();
+        Naming.bind(RMI_URL, raf.getRemoteRepository(repository));
+
+        Map params = new HashMap();
+        params.put(org.apache.jackrabbit.rmi.repository.RepositoryFactoryImpl.REPOSITORY_RMI_URL,
RMI_URL);
+        Repository r = RepositoryManager.getRepository(params);
+        r.login(CREDENTIALS).logout();
+    }
+
+    private static final class RepositoryManager {
+
+        private static Repository getRepository(Map parameters)
+                throws RepositoryException {
+            Repository repo = null;
+            Iterator factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);
+            while (factories.hasNext()) {
+                RepositoryFactory factory = (RepositoryFactory) factories.next();
+                repo = factory.getRepository(parameters);
+                if (repo != null) {
+                    break;
+                }
+            }
+            return repo;
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/java/org/apache/jackrabbit/test/rmi/repository/RepositoryFactoryImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties?rev=721389&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties Fri Nov 28 01:00:54
2008
@@ -0,0 +1,32 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+# Set root logger level to DEBUG and its only appender to file.
+log4j.rootLogger=INFO, file
+
+# 'stdout' is set to be a ConsoleAppender.
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+
+# 'stdout' uses PatternLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}:
%m (%F, line %L)\n
+
+# 'file' is set to be a FileAppender.
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.File=target/jcr.log
+
+# 'file' uses PatternLayout.
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m
(%F, line %L)\n

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message