Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D7D639165 for ; Thu, 5 Apr 2012 09:30:08 +0000 (UTC) Received: (qmail 49235 invoked by uid 500); 5 Apr 2012 09:30:08 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 49207 invoked by uid 500); 5 Apr 2012 09:30:08 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-commits@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 49190 invoked by uid 99); 5 Apr 2012 09:30:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Apr 2012 09:30:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Apr 2012 09:30:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 46252238890B; Thu, 5 Apr 2012 09:29:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1309719 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java Date: Thu, 05 Apr 2012 09:29:35 -0000 To: oak-commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120405092935.46252238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Thu Apr 5 09:29:34 2012 New Revision: 1309719 URL: http://svn.apache.org/viewvc?rev=1309719&view=rev Log: OAK-32: Drop MicroKernel.dispose() Simplify MKF by pre-parsing parts of the repository URL Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java?rev=1309719&r1=1309718&r2=1309719&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java Thu Apr 5 09:29:34 2012 @@ -54,66 +54,68 @@ public class MicroKernelFactory { * @return a new instance */ public static synchronized MicroKernel getInstance(String url) { - if (url.startsWith("mem:") || url.startsWith("simple:")) { + int colon = url.indexOf(':'); + if (colon == -1) { + throw new IllegalArgumentException("Unknown repository URL: " + url); + } + + String head = url.substring(0, colon); + String tail = url.substring(colon + 1); + if (head.equals("mem") || head.equals("simple")) { boolean clean = false; - if (url.endsWith(";clean")) { - url = url.substring(0, url.length() - ";clean".length()); + if (tail.endsWith(";clean")) { + tail = tail.substring(0, tail.length() - ";clean".length()); clean = true; } - url = url.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", ".")); - - String name; - if (url.startsWith("simple:")) { - name = url.substring("simple:".length()); - } else { - name = url.substring("mem:".length()); - } + tail = tail.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", ".")); if (clean) { - String dir = url.substring(url.lastIndexOf(':') + 1); + String dir = tail.substring(tail.lastIndexOf(':') + 1); try { FileUtils.deleteRecursive(dir, false); } catch (Exception e) { throw ExceptionFactory.convert(e); } - INSTANCES.remove(name); + INSTANCES.remove(tail); } - SimpleKernelImpl instance = INSTANCES.get(name); + SimpleKernelImpl instance = INSTANCES.get(tail); if (instance == null) { - instance = new SimpleKernelImpl(name); - INSTANCES.put(name, instance); + instance = new SimpleKernelImpl(tail); + INSTANCES.put(tail, instance); } return instance; - } else if (url.startsWith("log:")) { - return new LogWrapper(getInstance(url.substring("log:".length()))); - } else if (url.startsWith("sec:")) { + } else if (head.equals("log")) { + return new LogWrapper(getInstance(tail)); + } else if (head.equals("sec")) { return SecurityWrapper.get(url); - } else if (url.startsWith("virtual:")) { + } else if (head.equals("virtual")) { return VirtualRepositoryWrapper.get(url); - } else if (url.startsWith("index:")) { - return new IndexWrapper(getInstance(url.substring("index:".length()))); - } else if (url.startsWith("fs:")) { + } else if (head.equals("index")) { + return new IndexWrapper(getInstance(tail)); + } else if (head.equals("fs:")) { boolean clean = false; - if (url.endsWith(";clean")) { - url = url.substring(0, url.length() - ";clean".length()); + if (tail.endsWith(";clean")) { + tail = tail.substring(0, tail.length() - ";clean".length()); clean = true; } - String dir = url.substring("fs:".length()); - dir = dir.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", ".")); + + tail = tail.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", ".")); + if (clean) { try { - FileUtils.deleteRecursive(dir + "/" + ".mk", false); + FileUtils.deleteRecursive(tail + "/" + ".mk", false); } catch (IOException e) { throw ExceptionFactory.convert(e); } } - return new MicroKernelImpl(dir); - } else if (url.startsWith("http:")) { + + return new MicroKernelImpl(tail); + } else if (head.equals("http")) { return new Client(url); - } else if (url.startsWith("http-bridge:")) { - MicroKernel mk = getInstance(url.substring("http-bridge:".length())); + } else if (head.equals("http-bridge")) { + MicroKernel mk = getInstance(tail); final Server server = new Server(mk); try {