jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1133338 - /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
Date Wed, 08 Jun 2011 10:53:32 GMT
Author: thomasm
Date: Wed Jun  8 10:53:31 2011
New Revision: 1133338

URL: http://svn.apache.org/viewvc?rev=1133338&view=rev
Log:
A factory to create a MicroKernel instance

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java?rev=1133338&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
Wed Jun  8 10:53:31 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.mk;
+
+import java.io.File;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.mem.MemoryKernelImpl;
+
+/**
+ * A factory to create a MicroKernel instance.
+ */
+public class MicroKernelFactory {
+
+    /**
+     * Get an instance. Supported URLs:
+     * <ul>
+     * <li>mem: (in-memory implementation)</li>
+     * <li>fs:target/test (using the directory ./target/mk-test)</li>
+     * <li>fs:target/mk-test;clean (same, but delete the old repository first)</li>
+     * <li>fs:{homeDir} (use the system property homeDir or '.' if not set)</li>
+     * </ul>
+     *
+     * @param url the repository URL
+     * @return a new instance
+     */
+    public static MicroKernel getInstance(String url) {
+        if (url.startsWith("mem:")) {
+            return new MemoryKernelImpl();
+        } else if (url.startsWith("fs:")) {
+            String dir = url.substring("fs:".length());
+            dir = dir.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", "."));
+            if (dir.endsWith(";clean")) {
+                dir = dir.substring(0, dir.indexOf(";clean"));
+                new File(dir, ".mk/db/revs.h2.db").delete();
+            }
+            return new MicroKernelImpl(dir);
+        } else {
+            throw new IllegalArgumentException(url);
+        }
+    }
+
+}



Mime
View raw message